aboutsummaryrefslogtreecommitdiffstats
path: root/src/api.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-06-26 09:03:49 -0700
committerAdam Soltys <[email protected]>2026-06-26 09:03:49 -0700
commiteef3193729ccea2c3d712cda9381c24325fac260 (patch)
treedd22d714a3667773a73fc42e3b0a88b3171bdbae /src/api.js
parent190c849cf9ce1c09501fedea33020098c8026c1d (diff)
downloadcoinosv3-eef3193729ccea2c3d712cda9381c24325fac260.tar.gz
coinosv3-eef3193729ccea2c3d712cda9381c24325fac260.zip
Fold the coinos opt-out into a single Data source picker
Replace the Esplora|Electrum backend toggle plus the separate 'Instant notifications' on/off with one 'Data source' selector: • coinos (instant) — default; explorer data + coinos push • Block explorer — REST + polling, nothing sent to coinos (the opt-out) • Electrum server — one WS server for data + push (your node / public) Picking a non-coinos source IS the privacy opt-out, so the standalone toggle is gone. A single 'mode' setting drives getBackend()/getRealtimeEnabled(), so the wallet/wsUrl logic is unchanged; existing per-feature settings migrate in (realtime=off → explorer, backend=electrum → electrum). coinos⇄explorer just flips the watcher (no rescan); to/from electrum rebuilds the backend. Sets up cleanly for a future coinos Fulcrum: 'coinos' mode upgrades from REST+watcher to a full Electrum backend transparently. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Diffstat (limited to 'src/api.js')
-rw-r--r--src/api.js41
1 files changed, 23 insertions, 18 deletions
diff --git a/src/api.js b/src/api.js
index 4d4212f..03db6b9 100644
--- a/src/api.js
+++ b/src/api.js
@@ -60,26 +60,31 @@ export function getElectrumWsUrl() {
return 'wss://coinos.io/electrum';
}
-// Privacy opt-out: turning this off means the app never connects to coinos's
-// watcher (so it can't see your addresses) and relies on polling your explorer
-// instead. On by default.
-const REALTIME_KEY = 'btc-wallet-realtime';
-export function getRealtimeEnabled() {
- try { return localStorage.getItem(REALTIME_KEY) !== 'off'; } catch { return true; }
-}
-export function setRealtimeEnabled(on) {
- try { localStorage.setItem(REALTIME_KEY, on ? 'on' : 'off'); } catch {}
-}
-
-// Data backend: the default Esplora REST (`Api`) or a full Electrum-over-WS
-// server (`ElectrumApi`) that serves data AND notifications over one connection.
-const BACKEND_KEY = 'btc-wallet-backend';
-export function getBackend() {
- try { return localStorage.getItem(BACKEND_KEY) === 'electrum' ? 'electrum' : 'esplora'; } catch { return 'esplora'; }
+// One "data source" setting drives both where chain data comes from and whether
+// coinos sees your addresses for instant push:
+// coinos — block-explorer data + coinos instant-payment notifications (default)
+// explorer — block-explorer data only; polls for payments, nothing sent to coinos
+// electrum — a single Electrum-over-WS server for both data and push (your node)
+// getBackend()/getRealtimeEnabled() derive from it, so the rest of the code (and
+// the wsUrl logic) is unchanged. Existing per-feature settings migrate in.
+const DATA_MODE_KEY = 'btc-wallet-mode';
+const BACKEND_KEY = 'btc-wallet-backend'; // legacy (migration only)
+const REALTIME_KEY = 'btc-wallet-realtime'; // legacy (migration only)
+export function getDataMode() {
+ try {
+ const m = localStorage.getItem(DATA_MODE_KEY);
+ if (m === 'coinos' || m === 'explorer' || m === 'electrum') return m;
+ if (localStorage.getItem(BACKEND_KEY) === 'electrum') return 'electrum';
+ if (localStorage.getItem(REALTIME_KEY) === 'off') return 'explorer';
+ } catch {}
+ return 'coinos';
}
-export function setBackend(b) {
- try { localStorage.setItem(BACKEND_KEY, b === 'electrum' ? 'electrum' : 'esplora'); } catch {}
+export function setDataMode(m) {
+ try { localStorage.setItem(DATA_MODE_KEY, m === 'electrum' || m === 'explorer' ? m : 'coinos'); } catch {}
}
+export function getBackend() { return getDataMode() === 'electrum' ? 'electrum' : 'esplora'; }
+// The coinos watcher is used only in 'coinos' mode; 'explorer' polls instead.
+export function getRealtimeEnabled() { return getDataMode() === 'coinos'; }
// Electrum servers that accept WebSocket connections. blockstream.info is
// electrs (validated); the point, though, is pointing at your own Fulcrum/electrs.