fix: show -- instead of 0 when account data fetch fails on dashboard

Replace zero-value fallback with undefined, pass accountFailed prop to
distinguish load failure from initial loading skeleton.
This commit is contained in:
Dean
2026-03-27 20:57:39 +08:00
committed by shinchan-zhai
parent 4a483eaca6
commit d6e3088998
2 changed files with 22 additions and 16 deletions

View File

@@ -322,10 +322,7 @@ function App() {
const selectedTrader = traders?.find((t) => t.trader_id === selectedTraderId)
// When polling has permanently failed, provide zero-value data instead of keeping skeleton
const effectiveAccount = (accountPollOff && !account)
? { total_equity: 0, available_balance: 0, total_pnl: 0, total_pnl_pct: 0, position_count: 0, margin_used: 0, margin_used_pct: 0 } as AccountInfo
: account
const effectiveAccount = account
const effectivePositions = (positionsPollOff && !positions) ? [] as Position[] : positions
const effectiveDecisions = (decisionsPollOff && !decisions) ? [] as DecisionRecord[] : decisions
@@ -545,6 +542,7 @@ function App() {
selectedTrader={selectedTrader}
status={status}
account={effectiveAccount}
accountFailed={accountPollOff}
positions={effectivePositions}
decisions={effectiveDecisions}
decisionsLimit={decisionsLimit}

View File

@@ -103,6 +103,7 @@ interface TraderDashboardPageProps {
onNavigateToTraders: () => void
status?: SystemStatus
account?: AccountInfo
accountFailed?: boolean
positions?: Position[]
decisions?: DecisionRecord[]
decisionsLimit: number
@@ -117,6 +118,7 @@ export function TraderDashboardPage({
selectedTrader,
status,
account,
accountFailed,
positions,
decisions,
decisionsLimit,
@@ -488,6 +490,12 @@ export function TraderDashboardPage({
<span>EQ::{account.total_equity?.toFixed(2)}</span>
<span>PNL::{account.total_pnl?.toFixed(2)}</span>
</div>
) : accountFailed ? (
<div className="flex gap-4">
<span>LAST_UPDATE::--</span>
<span>EQ::--</span>
<span>PNL::--</span>
</div>
) : (
<div className="flex gap-4">
<span className="inline-block w-32 h-3 rounded bg-white/5 animate-pulse" />
@@ -501,37 +509,37 @@ export function TraderDashboardPage({
<div className="grid grid-cols-2 md:grid-cols-4 gap-4 mb-8">
<StatCard
title={t('totalEquity', language)}
value={`${account?.total_equity?.toFixed(2) || '0.00'}`}
value={accountFailed && !account ? '--' : `${account?.total_equity?.toFixed(2) ?? '--'}`}
unit="USDT"
change={account?.total_pnl_pct || 0}
change={account ? (account.total_pnl_pct || 0) : undefined}
positive={(account?.total_pnl ?? 0) > 0}
icon="💰"
loading={!account}
loading={!account && !accountFailed}
/>
<StatCard
title={t('availableBalance', language)}
value={`${account?.available_balance?.toFixed(2) || '0.00'}`}
value={accountFailed && !account ? '--' : `${account?.available_balance?.toFixed(2) ?? '--'}`}
unit="USDT"
subtitle={`${account?.available_balance && account?.total_equity ? ((account.available_balance / account.total_equity) * 100).toFixed(1) : '0.0'}% ${t('free', language)}`}
subtitle={accountFailed && !account ? '--' : `${account?.available_balance && account?.total_equity ? ((account.available_balance / account.total_equity) * 100).toFixed(1) : '--'}% ${t('free', language)}`}
icon="💳"
loading={!account}
loading={!account && !accountFailed}
/>
<StatCard
title={t('totalPnL', language)}
value={`${account?.total_pnl !== undefined && account.total_pnl >= 0 ? '+' : ''}${account?.total_pnl?.toFixed(2) || '0.00'}`}
value={accountFailed && !account ? '--' : `${account?.total_pnl !== undefined && account.total_pnl >= 0 ? '+' : ''}${account?.total_pnl?.toFixed(2) ?? '--'}`}
unit="USDT"
change={account?.total_pnl_pct || 0}
change={account ? (account.total_pnl_pct || 0) : undefined}
positive={(account?.total_pnl ?? 0) >= 0}
icon="📈"
loading={!account}
loading={!account && !accountFailed}
/>
<StatCard
title={t('positions', language)}
value={`${account?.position_count || 0}`}
value={accountFailed && !account ? '--' : `${account?.position_count ?? '--'}`}
unit="ACTIVE"
subtitle={`${t('margin', language)}: ${account?.margin_used_pct?.toFixed(1) || '0.0'}%`}
subtitle={accountFailed && !account ? `${t('margin', language)}: --` : `${t('margin', language)}: ${account?.margin_used_pct?.toFixed(1) ?? '--'}%`}
icon="📊"
loading={!account}
loading={!account && !accountFailed}
/>
</div>