aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/gifts-wallet.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-07-06 11:12:31 -0700
committerAdam Soltys <[email protected]>2026-07-06 11:12:31 -0700
commitd071a09604599831d370b06563144cf4ba028902 (patch)
treecf5974694de768a5128f044d255b399fa3eb18dd /src/features/gifts-wallet.js
parentef1a901314cb667bc8a7c7ff5f080550edef2815 (diff)
downloadcoinosv3-d071a09604599831d370b06563144cf4ba028902.tar.gz
coinosv3-d071a09604599831d370b06563144cf4ba028902.zip
Gift cross-device sync, snapshot size cap, reliable SW updates, gift-detail layout
- Gifts now sync across devices: gift records + reserved/reclaimed coin sets ride the encrypted snapshot as a merge-safe extension (like ark), and every gift state change (create/reclaim/revoke) triggers a saveCache so it actually publishes. A gift made on one device now shows on the others. - Cap the published snapshot at ~40KB JSON (relay rejects >64KB events, nip44 expands ~1.5x): trim oldest on-chain txs when oversized; another device backfills via rescan. Typical wallets untouched. - Service worker: register with updateViaCache:'none' so a new build is detected immediately (not held by the 4h HTTP cache), and reload once on controllerchange so the fresh app runs without a manual second refresh. - Gift detail: View/Reclaim share a row, Revoke on its own full-width line so 'Revoke now' stops wrapping. Co-Authored-By: Claude Fable 5 <[email protected]>
Diffstat (limited to 'src/features/gifts-wallet.js')
-rw-r--r--src/features/gifts-wallet.js34
1 files changed, 33 insertions, 1 deletions
diff --git a/src/features/gifts-wallet.js b/src/features/gifts-wallet.js
index 52de0d0..96e4978 100644
--- a/src/features/gifts-wallet.js
+++ b/src/features/gifts-wallet.js
@@ -66,6 +66,7 @@ export function installGiftWallet(wallet) {
this.reclaimedSet().add(id);
this._saveReserved();
this._saveReclaimed();
+ try { this.saveCache(); } catch {} // publish the gift-state change to sync
},
// Truly revoke an unclaimed gift: spend its coin back into our own wallet,
@@ -79,12 +80,13 @@ export function installGiftWallet(wallet) {
this.reclaimedSet().delete(id);
this._saveReserved();
this._saveReclaimed();
+ try { this.saveCache(); } catch {}
return txid;
},
giftLink(id) { return this.giftRecords()[id] || null; },
- markGiftRevoked(id) { const r = this.giftRecords()[id]; if (r) { r.revoked = true; this._saveGiftRecords(); } },
+ markGiftRevoked(id) { const r = this.giftRecords()[id]; if (r) { r.revoked = true; this._saveGiftRecords(); try { this.saveCache(); } catch {} } },
giftRecords() {
if (!this._giftRecords) { try { this._giftRecords = JSON.parse(localStorage.getItem(this._giftRecordsKey()) || '{}'); } catch { this._giftRecords = {}; } }
@@ -250,6 +252,7 @@ export function installGiftWallet(wallet) {
if (!outpoints || !outpoints.length) return;
this.giftRecords()[outpoints[0]] = { id: outpoints[0], code, locked: !!locked, amount, claimCode: claimCode || null, outpoints, created: Date.now(), revoked: false };
this._saveGiftRecords();
+ try { this.saveCache(); } catch {} // publish the new gift to cross-device sync
},
// Sats that creating this gift right now would lock (the selected coins'
@@ -289,6 +292,35 @@ export function installGiftWallet(wallet) {
});
// reserved gift coins are excluded from spending + the spendable balance
wallet.registerCoinLock(() => wallet.reservedSet());
+
+ // Sync gift state across devices (like ark): the records + reserved/reclaimed
+ // coin sets are per-device localStorage, so a gift made on one device was
+ // invisible on another. Ride the encrypted snapshot as a merge-safe
+ // extension: union records (revoked/claimTxid flags sticky), union both coin
+ // sets. Each device's own scan then reconciles which coins are still live.
+ wallet.registerCacheExtension({
+ mergeAlways: true,
+ save: () => ({
+ giftState: {
+ records: wallet.giftRecords(),
+ reserved: [...wallet.reservedSet()],
+ reclaimed: [...wallet.reclaimedSet()],
+ },
+ }),
+ load: (d) => {
+ if (!d.giftState) return;
+ const recs = wallet.giftRecords();
+ for (const [id, r] of Object.entries(d.giftState.records || {})) {
+ const local = recs[id];
+ if (!local) recs[id] = r;
+ else { local.revoked = local.revoked || r.revoked; if (!local.claimTxid && r.claimTxid) local.claimTxid = r.claimTxid; }
+ }
+ wallet._saveGiftRecords();
+ const res = wallet.reservedSet(); for (const id of d.giftState.reserved || []) res.add(id);
+ const rec = wallet.reclaimedSet(); for (const id of d.giftState.reclaimed || []) rec.add(id);
+ wallet._saveReserved(); wallet._saveReclaimed();
+ },
+ });
}
// Gift-link claiming (sender side is Wallet.createGift). A gift code is a