From 7b432bc96486a808acb32b87a560bfa50f958bdd Mon Sep 17 00:00:00 2001 From: dekun Date: Sun, 4 Oct 2026 21:50:50 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=A6=E6=88=B7=E5=BF=AB=E7=85=A7=E7=BC=BA?= =?UTF-8?q?=E5=A4=B1=E5=90=8E=E6=94=B9=E4=B8=BA=2010=20=E7=A7=92=E8=A1=A5?= =?UTF-8?q?=E6=89=93=E4=B8=80=E6=AC=A1=EF=BC=8C=E9=81=BF=E5=85=8D=E7=9F=AD?= =?UTF-8?q?=E9=97=B4=E9=9A=94=20force=20=E6=92=9E=E9=A2=91=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- .../templates/embed_boot_scripts.html | 38 +++++++++++++------ lib/instance/templates/index.html | 38 +++++++++++++------ 2 files changed, 54 insertions(+), 22 deletions(-) diff --git a/lib/instance/templates/embed_boot_scripts.html b/lib/instance/templates/embed_boot_scripts.html index acc8003..a72b47a 100644 --- a/lib/instance/templates/embed_boot_scripts.html +++ b/lib/instance/templates/embed_boot_scripts.html @@ -1200,7 +1200,23 @@ function accountSnapshotFundingMissing(data){ const hasTrading = data.current_capital != null && data.current_capital !== ""; return !hasFunding && !hasTotal && !hasTrading; } -let accountSnapshotRetryCount = 0; +let accountSnapshotMissRetryTimer = null; +let accountSnapshotMissRetryDone = false; +function clearAccountSnapshotMissRetry(){ + accountSnapshotMissRetryDone = false; + if(accountSnapshotMissRetryTimer){ + clearTimeout(accountSnapshotMissRetryTimer); + accountSnapshotMissRetryTimer = null; + } +} +function scheduleAccountSnapshotMissRetry(){ + if(accountSnapshotMissRetryDone || accountSnapshotMissRetryTimer) return; + accountSnapshotMissRetryTimer = setTimeout(function(){ + accountSnapshotMissRetryTimer = null; + accountSnapshotMissRetryDone = true; + refreshAccountSnapshot({ silent: true, force: true, missRetry: true }); + }, 10000); +} function applyAccountSnapshot(data){ if(!data || typeof data !== "object") return; const coinMode = String(data.options_margin_mode || "coin").toLowerCase() === "coin"; @@ -1329,20 +1345,20 @@ function applyAccountSnapshot(data){ } function refreshAccountSnapshot(opts){ const options = opts || {}; - const qs = options.force ? "?force=1" : ""; + let useForce = !!options.force; + if(useForce && !options.missRetry && (accountSnapshotMissRetryTimer || accountSnapshotMissRetryDone)){ + useForce = false; + } + const qs = useForce ? "?force=1" : ""; fetch("/api/account_snapshot" + qs).then(r=>r.json()).then(data=>{ applyAccountSnapshot(data); - if(accountSnapshotFundingMissing(data) && !options.force && accountSnapshotRetryCount < 3){ - accountSnapshotRetryCount += 1; - setTimeout(() => refreshAccountSnapshot({ silent: true, force: accountSnapshotRetryCount >= 2 }), 1200 * accountSnapshotRetryCount); - }else if(!accountSnapshotFundingMissing(data)){ - accountSnapshotRetryCount = 0; + if(!accountSnapshotFundingMissing(data)){ + clearAccountSnapshotMissRetry(); + return; } + scheduleAccountSnapshotMissRetry(); }).catch(()=>{ - if(!options.silent && accountSnapshotRetryCount < 3){ - accountSnapshotRetryCount += 1; - setTimeout(() => refreshAccountSnapshot({ silent: true }), 1200 * accountSnapshotRetryCount); - } + scheduleAccountSnapshotMissRetry(); }); } diff --git a/lib/instance/templates/index.html b/lib/instance/templates/index.html index 46fd47b..63605e1 100644 --- a/lib/instance/templates/index.html +++ b/lib/instance/templates/index.html @@ -1686,7 +1686,23 @@ function accountSnapshotFundingMissing(data){ const hasTrading = data.current_capital != null && data.current_capital !== ""; return !hasFunding && !hasTotal && !hasTrading; } -let accountSnapshotRetryCount = 0; +let accountSnapshotMissRetryTimer = null; +let accountSnapshotMissRetryDone = false; +function clearAccountSnapshotMissRetry(){ + accountSnapshotMissRetryDone = false; + if(accountSnapshotMissRetryTimer){ + clearTimeout(accountSnapshotMissRetryTimer); + accountSnapshotMissRetryTimer = null; + } +} +function scheduleAccountSnapshotMissRetry(){ + if(accountSnapshotMissRetryDone || accountSnapshotMissRetryTimer) return; + accountSnapshotMissRetryTimer = setTimeout(function(){ + accountSnapshotMissRetryTimer = null; + accountSnapshotMissRetryDone = true; + refreshAccountSnapshot({ silent: true, force: true, missRetry: true }); + }, 10000); +} function applyAccountSnapshot(data){ if(!data || typeof data !== "object") return; const coinMode = String(data.options_margin_mode || "coin").toLowerCase() === "coin"; @@ -1824,20 +1840,20 @@ function applyAccountSnapshot(data){ } function refreshAccountSnapshot(opts){ const options = opts || {}; - const qs = options.force ? "?force=1" : ""; + let useForce = !!options.force; + if(useForce && !options.missRetry && (accountSnapshotMissRetryTimer || accountSnapshotMissRetryDone)){ + useForce = false; + } + const qs = useForce ? "?force=1" : ""; fetch("/api/account_snapshot" + qs).then(r=>r.json()).then(data=>{ applyAccountSnapshot(data); - if(accountSnapshotFundingMissing(data) && !options.force && accountSnapshotRetryCount < 3){ - accountSnapshotRetryCount += 1; - setTimeout(() => refreshAccountSnapshot({ silent: true, force: accountSnapshotRetryCount >= 2 }), 1200 * accountSnapshotRetryCount); - }else if(!accountSnapshotFundingMissing(data)){ - accountSnapshotRetryCount = 0; + if(!accountSnapshotFundingMissing(data)){ + clearAccountSnapshotMissRetry(); + return; } + scheduleAccountSnapshotMissRetry(); }).catch(()=>{ - if(!options.silent && accountSnapshotRetryCount < 3){ - accountSnapshotRetryCount += 1; - setTimeout(() => refreshAccountSnapshot({ silent: true }), 1200 * accountSnapshotRetryCount); - } + scheduleAccountSnapshotMissRetry(); }); }