diff options
| author | Adam Soltys <[email protected]> | 2026-06-29 07:22:30 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-06-29 07:22:30 -0700 |
| commit | 729690e58a2601ec9c96f5b4431944c1d8f999c7 (patch) | |
| tree | b6270e661f914c136c5db08e1b71254c01080b03 /src | |
| parent | 0baf4cf55daa1ed33c2b276f40a6fd8aa922ee34 (diff) | |
| download | coinosv3-729690e58a2601ec9c96f5b4431944c1d8f999c7.tar.gz coinosv3-729690e58a2601ec9c96f5b4431944c1d8f999c7.zip | |
Dev: proxy all regtest backends through the dev server for LAN/phone testing
The dev server already binds 0.0.0.0, but the app's regtest data source + SP
indexer pointed at localhost, which on a phone means the phone's own localhost.
Proxy them all through the dev server (same-origin), like /boltz already was:
HTTP by prefix (/boltz, /esplora, /sp) and WebSocket by exact path (/electrum →
Fulcrum, /sp/ws → SP indexer), with a Bun websocket relay. The regtest presets
become relative paths, and a small absWsUrl() resolves '/path' WS URLs to
ws(s)://<page-host>/path so they work from any device hitting the dev server.
No per-device config, no CORS. Verified: /electrum relays Fulcrum 2.1.1, /esplora
returns the tip height, and the desktop wallet still loads (balance 98,444) and
connects through the proxy with no errors.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Diffstat (limited to 'src')
| -rw-r--r-- | src/api.js | 6 | ||||
| -rw-r--r-- | src/wallet.js | 15 |
2 files changed, 16 insertions, 5 deletions
@@ -76,8 +76,8 @@ const DATA_SOURCES_BY_NET = { { id: 'custom', label: 'Custom', type: 'auto', url: '' }, ], regtest: [ - { id: 'local', label: 'Local Fulcrum', type: 'electrum', url: 'ws://localhost:50003' }, - { id: 'localesplora', label: 'Local Esplora', type: 'esplora', base: 'http://localhost:3000', web: 'http://localhost:3000', kind: 'esplora' }, + { id: 'local', label: 'Local Fulcrum', type: 'electrum', url: '/electrum' }, + { id: 'localesplora', label: 'Local Esplora', type: 'esplora', base: '/esplora', web: 'http://localhost:3000', kind: 'esplora' }, { id: 'custom', label: 'Custom', type: 'auto', url: '' }, ], }; @@ -185,7 +185,7 @@ const SP_INDEXER_PRESETS_BY_NET = { mainnet: [{ id: 'coinos', label: 'coinos', url: 'https://sp.coinos.io' }, { id: 'custom', label: 'Custom', url: '' }], testnet: [{ id: 'custom', label: 'Custom', url: '' }], mutinynet: [{ id: 'custom', label: 'Custom', url: '' }], - regtest: [{ id: 'local', label: 'Local (localhost:8888)', url: 'http://localhost:8888' }, { id: 'custom', label: 'Custom', url: '' }], + regtest: [{ id: 'local', label: 'Local (proxied)', url: '/sp' }, { id: 'custom', label: 'Custom', url: '' }], }; const SP_INDEXER_DEFAULT = { mainnet: 'coinos', testnet: 'custom', mutinynet: 'custom', regtest: 'local' }; const SP_INDEXER_KEY = 'btc-wallet-sp-indexer'; diff --git a/src/wallet.js b/src/wallet.js index bc70561..519e3e1 100644 --- a/src/wallet.js +++ b/src/wallet.js @@ -27,6 +27,17 @@ import { NostrSync, getSyncConfig, encryptGiftPayload, npubOf } from './nostr.js import { isSilentPaymentAddress, decodeSilentPaymentAddress, silentPaymentScripts, silentPaymentPlaceholder, deriveSilentPaymentKeys, encodeSilentPaymentAddress, silentPaymentScan, silentPaymentOutputPrivKey, silentPaymentCandidate, bloomHas } from './silentpay.js'; import { schnorr } from '@noble/curves/secp256k1'; +// Resolve a same-origin '/path' WebSocket URL to an absolute ws(s):// URL against +// the page. The regtest backends are proxied through the dev server as relative +// paths (e.g. '/electrum') so the app works from a phone over the LAN/Tailscale; +// absolute URLs (real deployments, tests) pass through untouched. +function absWsUrl(u) { + if (u && u[0] === '/' && typeof location !== 'undefined') { + return (location.protocol === 'https:' ? 'wss://' : 'ws://') + location.host + u; + } + return u; +} + // No look-ahead: stop scanning a chain at the first unused address. This wallet // only ever exposes ONE unused address at a time (freshReceive = first unused; // there is no "generate another address" button), so used addresses stay @@ -528,7 +539,7 @@ export class Wallet { this._spDisconnect(); this._spWsUrl = url; let ws; - try { ws = new WebSocket(url); } catch { return; } + try { ws = new WebSocket(absWsUrl(url)); } catch { return; } this._spWs = ws; ws.onopen = () => { this.spLive = true; @@ -1772,7 +1783,7 @@ export class Wallet { if (getBackend() === 'electrum') { if (!this._wsCandidates || !this._wsCandidates.length) { this._wsCandidates = electrumCandidates(this.netName); this._wsCandIdx = 0; } const list = this._wsCandidates; - return list.length ? list[(this._wsCandIdx || 0) % list.length] : null; + return list.length ? absWsUrl(list[(this._wsCandIdx || 0) % list.length]) : null; } return null; } |
