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

92 lines
3.0 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 { formatAmount, formatQuantity } from '@/lib/formatters';
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, { symbol: a.symbol, type: a.type }]));
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 assetInfo = assetMap.get(tx.assetId);
const symbol = assetInfo?.symbol || tx.assetId;
const assetType = assetInfo?.type || 'CASH';
return (
<TableRow key={tx.id}>
<TableCell className="font-medium">{symbol}</TableCell>
<TableCell>{typeLabels[tx.txType] || tx.txType}</TableCell>
<TableCell>{formatQuantity(tx.quantity, assetType)}</TableCell>
<TableCell>{formatAmount(tx.price)}</TableCell>
<TableCell>{formatAmount(tx.fee)}</TableCell>
<TableCell>{tx.txCurrency}</TableCell>
<TableCell>
{tx.executedAt
? new Date(tx.executedAt).toLocaleString('zh-CN')
: '-'}
</TableCell>
</TableRow>
);
})
)}
</TableBody>
</Table>
</div>
</div>
);
}