stock-portfolio_byQwen3.6/app/dashboard/transactions/page.tsx

89 lines
2.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { getAssets } from '@/actions/asset';
import { getTransactions } from '@/actions/transaction';
import { AddTransactionDialog } from '@/components/transactions/add-transaction-dialog';
import {
Table,
TableBody,
TableCaption,
TableCell,
TableHead,
TableHeader,
TableRow,
} from '@/components/ui/table';
export default async function TransactionsPage() {
const [assets, transactions] = await Promise.all([
getAssets(),
getTransactions(),
]);
const typeLabels: Record<string, string> = {
BUY: '买入',
SELL: '卖出',
DIVIDEND: '分红',
AIRDROP: '空投',
FEE: '手续费',
};
const assetMap = new Map(assets.map((a) => [a.id, a.symbol]));
return (
<div className="space-y-6">
<div className="flex items-center justify-between">
<h1 className="text-2xl font-bold"></h1>
<AddTransactionDialog assets={assets} />
</div>
<div className="rounded-md border">
<Table>
<TableCaption>
{transactions.length}
</TableCaption>
<TableHeader>
<TableRow>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
</TableRow>
</TableHeader>
<TableBody>
{transactions.length === 0 ? (
<TableRow>
<TableCell
colSpan={7}
className="text-center text-muted-foreground"
>
"添加流水"
</TableCell>
</TableRow>
) : (
transactions.map((tx) => {
const symbol = assetMap.get(tx.assetId) || tx.assetId;
return (
<TableRow key={tx.id}>
<TableCell className="font-medium">{symbol}</TableCell>
<TableCell>{typeLabels[tx.txType] || tx.txType}</TableCell>
<TableCell>{tx.quantity}</TableCell>
<TableCell>{tx.price}</TableCell>
<TableCell>{tx.fee}</TableCell>
<TableCell>{tx.txCurrency}</TableCell>
<TableCell>
{tx.executedAt
? new Date(tx.executedAt).toLocaleString('zh-CN')
: '-'}
</TableCell>
</TableRow>
);
})
)}
</TableBody>
</Table>
</div>
</div>
);
}