Files
the-nexus/modules/data/bitcoin.js
Alexander Whitestone a1eb0ebb90
Some checks failed
CI / validate (pull_request) Failing after 14s
CI / auto-merge (pull_request) Has been skipped
[modularization] Phase 2: Extract data layer — gitea, weather, bitcoin, loaders
Created modules/data/ with 4 data modules:
- data/gitea.js: Centralized Gitea API (commits, PRs, agent status)
- data/weather.js: Open-Meteo weather data fetch
- data/bitcoin.js: Blockstream block height polling
- data/loaders.js: Static file loaders (portals.json, sovereignty-status.json, SOUL.md)

Updated consumers to use data modules instead of direct fetch():
- panels.js: Uses data/gitea.js for agent status
- heatmap.js: Uses data/gitea.js for commit data
- extras.js: Uses data/gitea.js for timelapse, data/bitcoin.js for block height
- portals.js: Uses data/loaders.js for portals.json
- effects.js: Uses data/loaders.js for sovereignty-status.json
- oath.js: Uses data/loaders.js for SOUL.md
- audio.js: Uses data/loaders.js for SOUL.md

Deduplication wins:
- Gitea token centralized (was hardcoded in 3 files)
- SOUL.md now cached (was fetched 3x independently)
- Nexus commits shared cache (was fetched 2x independently)

Refs #421
2026-03-24 17:25:51 -04:00

28 lines
735 B
JavaScript

// modules/data/bitcoin.js — Blockstream block height polling
// Writes to S: lastKnownBlockHeight, _starPulseIntensity
import { S } from '../state.js';
const BITCOIN_REFRESH_MS = 60 * 1000;
export async function fetchBlockHeight() {
try {
const res = await fetch('https://blockstream.info/api/blocks/tip/height');
if (!res.ok) return null;
const height = parseInt(await res.text(), 10);
if (isNaN(height)) return null;
const isNew = S.lastKnownBlockHeight !== null && height > S.lastKnownBlockHeight;
S.lastKnownBlockHeight = height;
if (isNew) {
S._starPulseIntensity = 1.0;
}
return { height, isNewBlock: isNew };
} catch {
return null;
}
}
export { BITCOIN_REFRESH_MS };