aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/sp-wallet.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-07-05 23:16:30 -0700
committerAdam Soltys <[email protected]>2026-07-05 23:16:30 -0700
commit81a55be4ea07d4dee4a83a3728c8ba0914744cd5 (patch)
treea0fe2ab8fd1b69aa92375459b0c6a9faf4684ef3 /src/features/sp-wallet.js
parenteb89b9e3681d9eea331b6471ecc576f39a0fd5ec (diff)
downloadcoinosv3-81a55be4ea07d4dee4a83a3728c8ba0914744cd5.tar.gz
coinosv3-81a55be4ea07d4dee4a83a3728c8ba0914744cd5.zip
Stop pointless SP catch-up scans
A gift-claimed wallet is a brand-new seed but the claim flow never passed generated:true, so every gift wallet ground through the indexer's full history (~336k tweaks) hunting silent payments it could not have received — the CPU burn seen with a fresh gift wallet open. Fresh claim wallets now fast-forward their scan watermark to the tip like any other generated wallet. And two tabs on the same wallet no longer duplicate a catch-up: a localStorage lease, refreshed per chunk, lets the second tab yield. Co-Authored-By: Claude Fable 5 <[email protected]>
Diffstat (limited to 'src/features/sp-wallet.js')
-rw-r--r--src/features/sp-wallet.js10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/features/sp-wallet.js b/src/features/sp-wallet.js
index e72532c..116f2e0 100644
--- a/src/features/sp-wallet.js
+++ b/src/features/sp-wallet.js
@@ -198,6 +198,15 @@ export function installSpWallet(wallet) {
try { this.lastSpScan = (await (await fetch(`${indexer}/height`)).json()).height || 0; this.saveCache(); } catch {}
return { fresh: true };
}
+ // Two tabs on the same wallet must not both grind the catch-up: a
+ // localStorage lease (refreshed per chunk) lets the second tab yield.
+ const leaseKey = this._cacheKey() + ':spscan-lease';
+ try {
+ if (!rescan && Date.now() - (parseInt(localStorage.getItem(leaseKey), 10) || 0) < 30000) {
+ return { busy: true };
+ }
+ localStorage.setItem(leaseKey, String(Date.now()));
+ } catch {}
this._spScanBusy = true;
// Only a manual scan shows the visible "Scanning…" state; auto-scans are
// invisible (setting spScanning for them left the card stuck on "Scanning…").
@@ -237,6 +246,7 @@ export function installSpWallet(wallet) {
}
const maxH = slice[slice.length - 1].height;
if (maxH > (this.lastSpScan || 0)) { this.lastSpScan = maxH; this.saveCache(); } // checkpoint
+ try { localStorage.setItem(leaseKey, String(Date.now())); } catch {} // keep the lease
await new Promise((r) => setTimeout(r, 0)); // let the UI breathe
}
if (tip > (this.lastSpScan || 0)) this.lastSpScan = tip;