[claude] Re-implement Bitcoin block height counter (#480) (#495)
Some checks failed
Deploy Nexus / deploy (push) Has been cancelled
Some checks failed
Deploy Nexus / deploy (push) Has been cancelled
This commit was merged in pull request #495.
This commit is contained in:
32
app.js
32
app.js
@@ -1695,4 +1695,36 @@ function triggerHarnessPulse() {
|
||||
}
|
||||
}
|
||||
|
||||
// === BITCOIN BLOCK HEIGHT ===
|
||||
(function initBitcoin() {
|
||||
const blockHeightDisplay = document.getElementById('block-height-display');
|
||||
const blockHeightValue = document.getElementById('block-height-value');
|
||||
if (!blockHeightDisplay || !blockHeightValue) return;
|
||||
|
||||
let lastKnownBlockHeight = null;
|
||||
|
||||
async function fetchBlockHeight() {
|
||||
try {
|
||||
const res = await fetch('https://blockstream.info/api/blocks/tip/height');
|
||||
if (!res.ok) return;
|
||||
const height = parseInt(await res.text(), 10);
|
||||
if (isNaN(height)) return;
|
||||
|
||||
if (lastKnownBlockHeight !== null && height !== lastKnownBlockHeight) {
|
||||
blockHeightDisplay.classList.remove('fresh');
|
||||
void blockHeightDisplay.offsetWidth;
|
||||
blockHeightDisplay.classList.add('fresh');
|
||||
}
|
||||
|
||||
lastKnownBlockHeight = height;
|
||||
blockHeightValue.textContent = height.toLocaleString();
|
||||
} catch (_) {
|
||||
// Network unavailable
|
||||
}
|
||||
}
|
||||
|
||||
fetchBlockHeight();
|
||||
setInterval(fetchBlockHeight, 60000);
|
||||
})();
|
||||
|
||||
init();
|
||||
|
||||
Reference in New Issue
Block a user