fix(web): prevent NaN% display in competition gap calculation (#633) (#670)

**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
Co-authored-by: tinkle-community <tinklefund@gmail.com>
This commit is contained in:
0xYYBB | ZYY | Bobo
2025-11-07 09:35:58 +08:00
committed by GitHub
parent 36365a3b30
commit b98a438843

View File

@@ -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 (
<div