diff --git a/src/app/history/page.tsx b/src/app/history/page.tsx new file mode 100644 index 0000000..586ca81 --- /dev/null +++ b/src/app/history/page.tsx @@ -0,0 +1,141 @@ +import { prisma } from '@/lib/prisma' +import { getServerSession } from 'next-auth' +import { authOptions } from '@/lib/auth' +import { redirect } from 'next/navigation' +import { formatCurrency, formatNumber, formatPnl, pnlColor } from '@/lib/utils' +import Link from 'next/link' +import { TrendingUp } from 'lucide-react' +import { formatDistanceToNow } from 'date-fns' + +export const dynamic = 'force-dynamic' + +const PAGE_SIZE = 50 + +interface PageProps { + searchParams: { page?: string } +} + +export default async function TradeHistoryPage({ searchParams }: PageProps) { + const session = await getServerSession(authOptions) + if (!session) redirect('/auth/signin') + + const page = Math.max(1, parseInt(searchParams.page ?? '1', 10)) + + const [total, trades] = await Promise.all([ + prisma.trade.count({ where: { userId: session.user.id } }), + prisma.trade.findMany({ + where: { userId: session.user.id }, + orderBy: { createdAt: 'desc' }, + take: PAGE_SIZE, + skip: (page - 1) * PAGE_SIZE, + include: { + hashtag: { select: { tag: true, displayTag: true } }, + }, + }), + ]) + + const totalPages = Math.max(1, Math.ceil(total / PAGE_SIZE)) + + return ( +
No trades yet.
+ + Browse trending hashtags → + ++ {formatDistanceToNow(t.createdAt, { addSuffix: true })} +
+{formatCurrency(t.profit)}
+ ) : ( + <> +{formatNumber(t.shares)} sh @ {formatCurrency(t.price)}
+{formatCurrency(t.total)}
+ {(t.type === 'SELL_LONG' || t.type === 'SELL_SHORT') && ( ++ {formatPnl(t.profit)} +
+ )} + > + )} +