From fb0bd13f51ebc5e6ab78401f19de83e591202119 Mon Sep 17 00:00:00 2001 From: shinchan-zhai Date: Mon, 30 Mar 2026 14:02:50 +0800 Subject: [PATCH] fix: division by zero guard, logout redirect, onboarding close button - auto_trader_risk: skip drawdown check when entryPrice <= 0 - AuthContext: redirect to / on logout - App.tsx: simplify data page navigation - BeginnerOnboardingPage: add close button to overlay --- trader/auto_trader_risk.go | 6 ++++++ web/src/App.tsx | 14 +------------- web/src/contexts/AuthContext.tsx | 2 ++ web/src/pages/BeginnerOnboardingPage.tsx | 9 +++++++++ 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/trader/auto_trader_risk.go b/trader/auto_trader_risk.go index b8c94fb3..937b1839 100644 --- a/trader/auto_trader_risk.go +++ b/trader/auto_trader_risk.go @@ -49,6 +49,12 @@ func (at *AutoTrader) checkPositionDrawdown() { quantity = -quantity // Short position quantity is negative, convert to positive } + // Guard: skip if entry price is zero (prevents division by zero panic) + if entryPrice <= 0 { + logger.Warnf("⚠️ Drawdown monitoring: %s %s has zero entry price, skipping", symbol, side) + continue + } + // Calculate current P&L percentage leverage := 10 // Default value if lev, ok := pos["leverage"].(float64); ok { diff --git a/web/src/App.tsx b/web/src/App.tsx index 34fbef5c..df4afab2 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -451,19 +451,7 @@ function App() { // Data page - publicly accessible with embedded dashboard if (route === '/data') { const dataPageNavigate = (page: Page) => { - const pathMap: Record = { - 'data': '/data', - 'competition': '/competition', - 'strategy-market': '/strategy-market', - 'traders': '/traders', - 'trader': '/dashboard', - 'strategy': '/strategy', - 'faq': '/faq', - } - const path = pathMap[page] - if (path) { - window.location.href = path - } + navigateToPage(page) } return (
+