From b7c5abd93868b97c25f52610510544764a3e44eb Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sat, 4 Jul 2026 09:33:52 -0700 Subject: Features phase 2: gift/swap/ark primitives leave the core wallet MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit wallet.js drops from 2,762 to 2,374 lines and now exposes two generic seams instead of feature code: - registerCoinLock()/lockedCoinIds(): features contribute coin ids that spending and the balance treat as unavailable (gift reservations). - loadFeatureState()/saveFeatureState(): namespaced per-wallet persisted state. src/features/gifts-wallet.js takes the whole gift engine — reservation sets, gift records, coin selection, the SIGHASH_SINGLE/NONE PSBT builder, the compact codec, claim building, nostr-locked gifts — as an installGiftWallet(wallet) instance install plus standalone exports. Swap storage/key helpers (loadSwaps/saveSwaps/swapNode/nextSwapIndex) install from swap.js; ark state storage installs from the ark feature. The silent-payment scan worker only embeds when the sp feature ships (wallet.js already tolerated its absence). Minimal profile: 412KB, down from 476KB (full: 578KB). All suites pass: ark UI e2e, ArkManager crash-resume, gift lifecycle, minimal smoke. SP's engine (scanning, BIP-352 signing) stays in wallet.js — extracting it safely wants an SP e2e harness on this stack first. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01QFAcD4V284DvYZZHP7Rxxy --- src/features/ark.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/features/ark.js') diff --git a/src/features/ark.js b/src/features/ark.js index 24acfea..868192a 100644 --- a/src/features/ark.js +++ b/src/features/ark.js @@ -11,8 +11,27 @@ import { shortAddr, shortTxid, timeAgo } from '../format.js'; // t?ark1… bech32m — an Ark address for this or another ASP. export function isArkAddress(a) { return /^t?ark1[a-z0-9]{20,}$/i.test((a || '').trim()); } +// Wallet storage/key helpers for this feature, installed onto the core +// wallet instance so a build without the feature ships none of it. +export function installArkWallet(wallet) { + if (wallet.loadArkState) return; // already installed + Object.assign(wallet, { + // ---- Ark support ------------------------------------------------------- + // Persisted ArkManager state (vtxos, in-flight action checkpoints, movement + // history — no secrets: vtxo keys are re-derived from the seed). + _arkKey() { return this._cacheKey() + ':ark'; }, + loadArkState() { + try { return JSON.parse(localStorage.getItem(this._arkKey()) || 'null'); } catch { return null; } + }, + saveArkState(state) { + try { localStorage.setItem(this._arkKey(), JSON.stringify(state)); } catch {} + }, + }); +} + export function arkFeature(ctx) { const { h, ui, render, wallet, blankSend, fmtAmount, unitLabel, unitTag, copyBtn, toast, openExternal } = ctx; + installArkWallet(wallet); // ark state storage lives outside the core wallet // One manager per open wallet; null when Ark is off in Settings, watch-only, // or not yet dialed (lazy: fresh wallets connect on first use). -- cgit v1.2.3