diff --git a/app/static/app.js b/app/static/app.js index ef788f5..9ba8b2c 100644 --- a/app/static/app.js +++ b/app/static/app.js @@ -159,11 +159,36 @@ const CHAIN_STATUS_KEYS = { paying_out: 'chain.status.paying_out', }; +// The bar is rendered from remembered state rather than straight from the +// response that triggered it, so a language switch can repaint it immediately +// instead of waiting for the next poll. That wait used to make it lie: with the +// connection down, switching language reset the label to "connecting" until a +// further fetch failed. +let lastChainData = null; +let chainOffline = false; + function updateChainStatusBar(data) { + lastChainData = data; + chainOffline = false; + renderChainStatusBar(); +} + +function renderChainStatusBar() { const dot = document.getElementById('chain-status-dot'); const label = document.getElementById('chain-status-label'); const block = document.getElementById('chain-block'); + if (chainOffline) { + dot.className = 'status-dot status-offline'; + label.textContent = t('chain.connectionLost'); + return; // block height deliberately left showing its last known value + } + if (lastChainData === null) { + label.textContent = t('chain.connecting'); + return; + } + const data = lastChainData; + // The dot's color/pulse only distinguishes waiting/open/drawing (that's all // the CSS defines) — closing and paying_out both pulse like drawing, they // just get their own text label below. @@ -189,8 +214,8 @@ const STALE_AFTER_FAILURES = 2; let consecutiveFetchFailures = 0; function showConnectionLost() { - document.getElementById('chain-status-dot').className = 'status-dot status-offline'; - document.getElementById('chain-status-label').textContent = t('chain.connectionLost'); + chainOffline = true; + renderChainStatusBar(); } function noteFetchOutcome(ok) { @@ -575,7 +600,12 @@ function resetToLoggedOutUI() { } function logout() { + // The chosen language is a device preference, not session state — clearing it + // on logout would drop the user back to the browser-detected default on the + // very screen where they'd have to find the switcher again. + const lang = localStorage.getItem(LANG_STORAGE_KEY); localStorage.clear(); + if (lang) localStorage.setItem(LANG_STORAGE_KEY, lang); resetToLoggedOutUI(); } @@ -774,6 +804,7 @@ function connectRoundEvents() { // those are built from server data + t() rather than fixed markup. function onLanguageChange() { renderBetButton(); + renderChainStatusBar(); // repaints from remembered state, without waiting for the next poll if (token) { refreshRound(); refreshMe(); @@ -787,5 +818,6 @@ function onLanguageChange() { } renderBetButton(); +renderChainStatusBar(); connectRoundEvents(); initAuthState(); diff --git a/app/static/index.html b/app/static/index.html index 2048b22..28a55e1 100644 --- a/app/static/index.html +++ b/app/static/index.html @@ -59,7 +59,10 @@