From 88d93de66b9ba713c5cc1a8fc5b1528ea1d74fb8 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sat, 1 Aug 2026 22:56:13 -0700 Subject: Stop the Ark card flickering on the settings page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every synced snapshot re-ran initArk() while Ark was unconnected, and initArk() calls stopArk() first — so each arriving snapshot tore down and restarted the connection, flashing 'Connecting to the Ark server…' and jittering the page. Automatic re-inits are now skipped while a connection exists or is in flight, and rate-limited to one per 20s; user-driven reconnects (switching servers, the connect button) are unaffected. Co-Authored-By: Claude Fable 5 --- src/features/ark.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/features') diff --git a/src/features/ark.js b/src/features/ark.js index 8229ead..0981918 100644 --- a/src/features/ark.js +++ b/src/features/ark.js @@ -235,7 +235,7 @@ export function arkFeature(ctx) { // is what resolves it: the manager learns the server's pubkey and // adopts the held state if it matches — a seed imported on a new // device would otherwise show no ark balance until some manual poke. - if (!mine) setTimeout(() => initArk(), 0); + if (!mine) setTimeout(() => maybeInitArk(), 0); return; } const local = wallet.loadArkState(cfg.ark); @@ -251,7 +251,7 @@ export function arkFeature(ctx) { // The merge brought vtxos our live manager doesn't have — (re)connect so // the balance actually shows. const novel = mergedN > localN || (mergedN && (!ark || !ark.state)); - if (mergedN && novel) setTimeout(() => initArk(), 0); + if (mergedN && novel) setTimeout(() => maybeInitArk(), 0); }, }); @@ -288,9 +288,22 @@ export function arkFeature(ctx) { function initArk() { stopArk(); ui.arkError = ''; + lastAutoInit = Date.now(); if (arkAvailable() && arkWanted()) connectArk().catch(() => {}); } + // Automatic re-inits (a synced snapshot arriving) must not restart a + // connection that is already in flight, or retry in a tight loop when the + // server is unreachable: each one calls stopArk() first, so the settings + // card's "connecting" indicator flickers on every snapshot. User-driven + // calls to initArk() stay immediate. + let lastAutoInit = 0; + function maybeInitArk() { + if (ark || arkConnectPromise) return; + if (Date.now() - lastAutoInit < 20000) return; + initArk(); + } + function connectArk() { if (ark) return Promise.resolve(ark); if (arkConnectPromise) return arkConnectPromise; -- cgit v1.2.3