From 8db6dc3b061bd044abb7e3bdb995c01a2bc6c78f Mon Sep 17 00:00:00 2001 From: 0xYYBB | ZYY | Bobo <128128010+zhouyongyou@users.noreply.github.com> Date: Fri, 7 Nov 2025 09:35:58 +0800 Subject: [PATCH] fix(web): prevent NaN% display in competition gap calculation (#633) (#670) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Problem:** Competition page shows "NaN%" for gap difference when trader P&L percentages are null/undefined. **Root Cause:** Line 227: `const gap = trader.total_pnl_pct - opponent.total_pnl_pct` - If either value is `undefined` or `null`, result is `NaN` - Display shows "领先 NaN%" or "落后 NaN%" **Solution:** Add null coalescing to default undefined/null values to 0: ```typescript const gap = (trader.total_pnl_pct ?? 0) - (opponent.total_pnl_pct ?? 0) ``` **Impact:** - ✅ Gap calculation returns 0 when data is missing (shows 0.00%) - ✅ Prevents confusing "NaN%" display - ✅ Graceful degradation for incomplete data Fixes #633 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude --- web/src/components/CompetitionPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/components/CompetitionPage.tsx b/web/src/components/CompetitionPage.tsx index 2c1effd2..b9d1946e 100644 --- a/web/src/components/CompetitionPage.tsx +++ b/web/src/components/CompetitionPage.tsx @@ -392,7 +392,7 @@ export function CompetitionPage() { {sortedTraders.map((trader, index) => { const isWinning = index === 0 const opponent = sortedTraders[1 - index] - const gap = trader.total_pnl_pct - opponent.total_pnl_pct + const gap = (trader.total_pnl_pct ?? 0) - (opponent.total_pnl_pct ?? 0) return (