fix: clear stale BTC data from portfolio and canvas when switching to USD/XAU
This commit is contained in:
@@ -39,6 +39,24 @@ function switchAsset(asset, btnEl) {
|
|||||||
addLog('SYS', `Ativo alterado para ${ASSET_LABELS[asset]} (${ASSET_PAIRS[asset]})`);
|
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 = `<div style="color:var(--text-secondary);font-size:0.8rem;padding:8px">Carregando ${ASSET_LABELS[currentAsset]}...</div>`;
|
||||||
|
// 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() {
|
function updatePipelineHeader() {
|
||||||
const h2 = document.querySelector('.pipeline-section h2');
|
const h2 = document.querySelector('.pipeline-section h2');
|
||||||
if (h2) {
|
if (h2) {
|
||||||
@@ -67,6 +85,9 @@ function loadAssetBrief() {
|
|||||||
return;
|
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 apiMap = { usd: '/api/usd/brief', xau: '/api/xau/brief' };
|
||||||
const api = apiMap[currentAsset];
|
const api = apiMap[currentAsset];
|
||||||
if (!api) return;
|
if (!api) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user