From e99748ac9622ac3a7b10eac87e1b5f06412a0f12 Mon Sep 17 00:00:00 2001 From: admtracksteel Date: Tue, 16 Jun 2026 00:24:30 +0000 Subject: [PATCH] fix: clear stale BTC data from portfolio and canvas when switching to USD/XAU --- static/script.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/static/script.js b/static/script.js index a8df166..47c23cd 100644 --- a/static/script.js +++ b/static/script.js @@ -39,6 +39,24 @@ function switchAsset(asset, btnEl) { addLog('SYS', `Ativo alterado para ${ASSET_LABELS[asset]} (${ASSET_PAIRS[asset]})`); } +function clearAssetData() { + // Clear portfolio stale BTC data + const pfTrades = document.getElementById('portfolioTrades'); + if (pfTrades) pfTrades.innerHTML = `
Carregando ${ASSET_LABELS[currentAsset]}...
`; + // Clear portfolio header values + const pfPnl = document.getElementById('pfPnl'); + if (pfPnl) { pfPnl.textContent = 'P&L: —'; pfPnl.style.color = 'var(--text-secondary)'; } + const pfTrades2 = document.getElementById('pfTrades'); + if (pfTrades2) pfTrades2.textContent = '—'; + const pfTotal = document.getElementById('pfTotal'); + if (pfTotal) pfTotal.textContent = ASSET_PAIRS[currentAsset]; + const pfDays = document.getElementById('pfDays'); + if (pfDays) pfDays.textContent = ASSET_LABELS[currentAsset]; + // Clear multi-strat canvas + const canvas = document.getElementById('multiStratCanvas'); + if (canvas) { const ctx = canvas.getContext('2d'); ctx.clearRect(0, 0, canvas.width, canvas.height); } +} + function updatePipelineHeader() { const h2 = document.querySelector('.pipeline-section h2'); if (h2) { @@ -67,6 +85,9 @@ function loadAssetBrief() { return; } + // Clear stale BTC data from portfolio/timeline when switching to USD/XAU + clearAssetData(); + const apiMap = { usd: '/api/usd/brief', xau: '/api/xau/brief' }; const api = apiMap[currentAsset]; if (!api) return;