Fix: Add null safety checks to Debug Info section in frontend

Previously fixed StatCard components but missed the Debug Info section,
causing "Cannot read properties of undefined (reading 'total_pnl')" error
when account data is loading or incomplete.

Root cause:
- Frontend uses SWR with async data fetching (5s refresh interval)
- During initial load or API delays, account object may exist but fields undefined
- Previous fix (93e331a) only covered StatCard section (lines 369-384)
- Debug Info section (lines 360-362) still used direct property access

Changes:
- Add optional chaining (?.) to all account field accesses in Debug Info
- Add fallback values ('0.00') for undefined fields
- Ensures consistent null safety across all account data displays

This prevents runtime errors during data loading and API failures.

Fixes: TypeError: Cannot read properties of undefined (reading 'total_pnl')

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
PorunC
2025-10-29 20:39:28 +08:00
parent 75b106d439
commit 0cb1f37b55

View File

@@ -357,9 +357,9 @@ function TraderDetailsPage({
{account && (
<div className="mb-4 p-3 rounded text-xs font-mono" style={{ background: '#1E2329', border: '1px solid #2B3139' }}>
<div style={{ color: '#848E9C' }}>
🔄 Last Update: {lastUpdate} | Total Equity: {account.total_equity.toFixed(2)} |
Available: {account.available_balance.toFixed(2)} | P&L: {account.total_pnl.toFixed(2)}{' '}
({account.total_pnl_pct.toFixed(2)}%)
🔄 Last Update: {lastUpdate} | Total Equity: {account.total_equity?.toFixed(2) || '0.00'} |
Available: {account.available_balance?.toFixed(2) || '0.00'} | P&L: {account.total_pnl?.toFixed(2) || '0.00'}{' '}
({account.total_pnl_pct?.toFixed(2) || '0.00'}%)
</div>
</div>
)}