aboutsummaryrefslogtreecommitdiffstats
path: root/src/nwc-bg.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-08-03 14:02:25 -0700
committerAdam Soltys <[email protected]>2026-08-03 14:02:25 -0700
commitcdd34e88be8a58c1cc9fa3d0cfbbd02b23439629 (patch)
treeeca597b57765aa6adbfbbe36dffb00087713b413 /src/nwc-bg.js
parentda13a93a3852eb15156a5a84a73a8200d1344685 (diff)
downloadcoinosv3-cdd34e88be8a58c1cc9fa3d0cfbbd02b23439629.tar.gz
coinosv3-cdd34e88be8a58c1cc9fa3d0cfbbd02b23439629.zip
Auto-withdraw runs with the app closed; fix the dead Back on the legacy step
The service worker can't watch a relay, so it doesn't try: the app resolves the destination to something concrete (ark address, LNURL endpoint, or on-chain script) and mirrors it beside the keys the background NWC payer already uses. On a push wake-up — which is exactly when money has just landed — the worker re-checks the same gate and sends, writing the outcome back into the mirror for the app to absorb on next open. A partial on-chain forward still waits for the app, since carving an exact vtxo needs more round trips than a worker is promised. writeBgMirror now carries forward the NWC connections and offer when another caller refreshes the mirror, instead of blanking them. And onboarding's legacy step loses its Back: the wallet exists by then, so returning to the nostr question just bounced straight forward again and the link looked broken. Its copy no longer promises a rename either. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Wvj4aoeMZwA7VUGdJP9Swi
Diffstat (limited to 'src/nwc-bg.js')
-rw-r--r--src/nwc-bg.js5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/nwc-bg.js b/src/nwc-bg.js
index af0bb6d..b22c36e 100644
--- a/src/nwc-bg.js
+++ b/src/nwc-bg.js
@@ -84,7 +84,7 @@ export const BG_KEY_LOOKAHEAD = 25;
// module). Chain 3 covers coins + change, chain 4/0 the mailbox, chain 5 a
// window of receive preimages — everything the worker needs to pay AND to
// mint invoices while the app is closed.
-export function buildBg({ ark, mgrState, keyFor, connections, offer }) {
+export function buildBg({ ark, mgrState, keyFor, connections, offer, autowithdraw }) {
const keys = {};
const idx = new Set((mgrState.vtxos || []).filter((v) => v.state !== 'spent').map((v) => v.keyIndex));
for (let i = 0; i < BG_KEY_LOOKAHEAD; i++) idx.add((mgrState.nextKeyIndex || 1) + i);
@@ -104,6 +104,9 @@ export function buildBg({ ark, mgrState, keyFor, connections, offer }) {
keys5,
key4: keyFor(4, 0),
offer: offer || null, // { sk, pk } — the CLINK offer service keypair
+ // { on, threshold, keep, target: { kind, address, url?, spkHex? } } — the
+ // destination is resolved by the app, so the worker never needs a relay
+ autowithdraw: autowithdraw || null,
connections: (connections || []).map((c) => ({
id: c.id, servicePk: c.servicePk, serviceSk: c.serviceSk, clientPk: c.clientPk,
maxSat: c.maxSat, dailySat: c.dailySat,