From 0cb1f37b55ef50e0e1bd5901861b19a1126d15cb Mon Sep 17 00:00:00 2001 From: PorunC <09982.misaka@gmail.com> Date: Wed, 29 Oct 2025 20:39:28 +0800 Subject: [PATCH] Fix: Add null safety checks to Debug Info section in frontend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- web/src/App.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/web/src/App.tsx b/web/src/App.tsx index 57c2e2f5..70761155 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -357,9 +357,9 @@ function TraderDetailsPage({ {account && (
- 🔄 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'}%)
)}