diff --git a/app/trades/page.tsx b/app/trades/page.tsx index 3d793d9..823e860 100644 --- a/app/trades/page.tsx +++ b/app/trades/page.tsx @@ -24,6 +24,27 @@ function calcExpectedProfit(direction: string, entryPrice: number, betAmount: nu return betAmount * (1 / price - 1); } +function renderCountdown(endDateStr: unknown) { + const originalDate = String(endDateStr).slice(0, 10); + const endDate = new Date(String(endDateStr)); + if (isNaN(endDate.getTime())) return {originalDate}; + const now = new Date(); + const diffMs = endDate.getTime() - now.getTime(); + const diffDays = diffMs / (1000 * 60 * 60 * 24); + + if (diffMs <= 0) { + return 已过期; + } else if (diffDays > 7) { + return {Math.floor(diffDays)}天后; + } else if (diffDays >= 3) { + return {Math.floor(diffDays)}天后; + } else { + const days = Math.floor(diffDays); + const hours = Math.floor((diffMs % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); + return {days}天 {hours}h后; + } +} + const statusMap: Record = { open: "进行中", won: "盈利 ✅", lost: "亏损 ❌" }; const statusVariant: Record = { open: "secondary", won: "default", lost: "destructive" @@ -127,7 +148,7 @@ export default async function TradesPage() { +${expProfit.toFixed(2)} ) : -} - {String(r[5]).slice(0, 10)} + {renderCountdown(r[5])} {statusMap[r[6]] ?? r[6]}