From e883fefbc9baff516af25869560cf6198c603fab Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sun, 15 Nov 2026 19:30:16 -0700 Subject: One balance: Spending and Savings on the same seed are one account. "Do you think we could combine the ARC and savings Bitcoin accounts into a single account? So if someone receives into a on-chain Bitcoin address, would hold it there, but they'd have a combined history, and it would select which coins to spend based on where you're paying out of, but the balance would be unified" … "Yeah go for it" (Adam, 2026-11-15). Step 1 of two: the wallet shows one balance card (the total, Ark and on-chain, with money mid-board still counted; an Instant / On-chain split appears only when there's some in both). History is one timeline, and a move between the two halves is one row priced at its cost: a board's on-chain Sent and its Boarded become "Made instant" (or "Making instant" while it confirms), and an offboard to our own address becomes "Moved on-chain". An offboard to someone else reads Sent. Receive leads with the payment address, with a Bitcoin address button for on-chain payers; the address stays on-chain and is all that's offered offline. Payments start from the Ark coins, and an on-chain address is paid from on-chain coins when there are any, leaving Ark only when there aren't. Accounts lists one row, Settings → Wallet has one balance row (Spending's coin settings plus the public key), and a per-device "Show Spending and Savings separately" brings the two-card carousel back as it was. Sign-ups are now this one account instead of Spending-only with Savings added later. Older Spending-only accounts are converted the same way, and the Add savings row only shows when the balances are shown apart. Not yet (step 2): covering a shortfall by boarding or offboarding automatically, and the "available now" split on the amount screen. New unified-balance-test (folded rows, their costs, the separate Spending timeline, on-chain-first routing) passes, along with signup-quick (one balance, Bitcoin address on Receive, separate toggle and back), balance-settings-row and send-enter-keys (both now opt into separate; send-enter-keys also enters through the seed-phrase door since Create became a sign-up), features-smoke, onboard-backup, gift-profile-setup, footer-support, pos, chat-layout, account-delete, lock-wallet, padlock-flow, profile-actions, gift-build, ark-ln-savings-small, carousel-flick, amber-dm-upgrade, send-lnaddr-advance, account-switch-leak and ark-offline-init. feed-choice-per-wallet fails at its second wallet's import, and fails the same way on 5554c70. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VMan6SwkivduFDDkMmnXjZ --- src/features/ark.js | 60 +++++++++++++++++++++++++++++++++++++++++++++------ src/features/names.js | 2 ++ 2 files changed, 56 insertions(+), 6 deletions(-) (limited to 'src/features') diff --git a/src/features/ark.js b/src/features/ark.js index 0456628..2c1a581 100644 --- a/src/features/ark.js +++ b/src/features/ark.js @@ -1516,13 +1516,27 @@ export function arkFeature(ctx) { : m.type === 'ln-send' && m.invoice ? zapNotes()['inv:' + m.invoice] : null; - function arkHistoryItem(m) { + // A move inside one account (on-chain ⇄ Ark): no money in or out, only + // what moving it cost. + function arkInternalMoveItem(m, feeSat, pending) { + const label = m.type === 'board' ? (pending ? t('movingInstant') : t('movedInstant')) : t('movedOnchain'); + return h('div', { class: 'item internal-move', style: m.id ? 'cursor:pointer' : '', onClick: m.id ? () => { ui.arkMoveDetail = m.id; render(); } : undefined }, + h('div', { class: 'ico' }, '\u21c4'), + h('div', { class: 'grow' }, + h('div', {}, label), + h('div', { class: 'small faint' }, (pending ? t('pending') + ' · ' : '') + fmtAmount(m.amountSat || 0) + ' ' + unitLabel() + ' · ' + timeAgo((m.ts || Date.now()) / 1000))), + h('div', { style: 'text-align:right' }, + feeSat > 0 ? h('div', { class: 'amount-neg' }, fmtAmount(feeSat)) : h('div', { class: 'small faint' }, t('arkDepthFree')))); + } + + function arkHistoryItem(m, labelAs) { const failed = m.status === 'failed'; const incoming = !['send', 'offboard', 'exit', 'ln-send', 'refresh'].includes(m.type); - const label = failed ? t('arkLnPayFailed') : m.type === 'receive' ? t('received') : m.type === 'board' ? t('arkBoarded') + let label = failed ? t('arkLnPayFailed') : m.type === 'receive' ? t('received') : m.type === 'board' ? t('arkBoarded') : m.type === 'ln-send' ? t('arkLnPaidHistory') : m.type === 'ln-receive' ? t('arkLnReceivedHistory') : m.type === 'offboard' ? t('arkOffboarded') : m.type === 'exit' ? t('arkExited') : m.type === 'refresh' ? t('arkRenewedHistory') : t('sent'); + if (labelAs) label = labelAs; // A spent input proves neither a payment amount nor its date: it can // contain change, an offboard, or a renewal this device has not synced. // Show the missing history explicitly until its records arrive. @@ -4270,7 +4284,11 @@ export function arkFeature(ctx) { } // In a Spending wallet an on-chain address means "exit ark to there": // the offboard happens right in the send flow, no Move money ceremony. - if (ctx.getAccount() === 'spending' && wallet.isOnchainAddress(inv) && arkAvailable()) { + // One balance: an on-chain address is paid from the on-chain coins + // when there are any — one ordinary transaction, nothing to move out + // of Ark first. Only without them does the payment leave Ark. + const onchainFirst = ctx.unifiedBalance && ctx.unifiedBalance() && (wallet.spendable || 0) > 0; + if (ctx.getAccount() === 'spending' && !onchainFirst && wallet.isOnchainAddress(inv) && arkAvailable()) { const b = arkBalance() || {}; if ((b.spendableSat || 0) > 0) { ui.arkOffboardSend = { address: inv, amount: '' }; @@ -4333,10 +4351,11 @@ export function arkFeature(ctx) { render(); } }, t('arkExitInFlightLink', { n: fmtAmount(acts.reduce((s2, a) => s2 + a.amountSat, 0)) })); }, - historyEntries(_txs, sel) { - if (sel && sel !== 'spending') return []; // ark movements are the Spending timeline + historyEntries(txs, sel) { + if (sel && sel !== 'spending' && sel !== 'all') return []; // ark movements are the Spending timeline const s = arkStateNow(); if (!s) return []; + if (sel === 'all') return this._histOne(s, txs || []); // Memoized on the state's REVISION, not a timer. This rebuild sorts and // dedupes every movement, resolves gifts, and touches secp256k1 — ~60ms // cold. A 1.5s TTL used to re-cool it between unhurried flicks, so every @@ -4349,6 +4368,35 @@ export function arkFeature(ctx) { this._histMemo = { key, val }; return val; }, + // One balance's timeline: a board, or an offboard to our own on-chain + // address, moves money between two halves of the same account. Its + // on-chain transaction and its Ark movement were two rows (Sent, then + // Boarded); here they're one, worth what the move cost. + _histOne(s, txs) { + const key = `${s._rev || 0}:${(s.movements || []).length}:${(s.actions || []).length}`; + if (!(this._histMemo && this._histMemo.key === key)) this._histMemo = { key, val: this._histBuild(s) }; + const own = new Map(txs.map((tx) => [tx.txid, tx])); + const rows = this._histMemo.val.map((e) => { + const m = e.m; + // with no Savings to move to, an offboard elsewhere is a payment + if (m && m.type === 'offboard' && !(m.txid && own.has(m.txid))) return { ...e, render: () => arkHistoryItem(m, t('sent')) }; + if (!m || !m.txid || !own.has(m.txid) || (m.type !== 'board' && m.type !== 'offboard')) return e; + const tx = own.get(m.txid); + const feeSat = m.type === 'board' ? Math.max(0, -(tx.net || 0) - (m.amountSat || 0)) : (m.feeSat || 0); + return { ...e, replacesTxid: m.txid, render: () => arkInternalMoveItem(m, feeSat, false) }; + }); + // a board still waiting on its funding transaction's confirmations + const told = new Set(rows.map((e) => e.replacesTxid).filter(Boolean)); + for (const a of s.actions || []) { + if (a.type !== 'board' || !a.fundingTxid || ['done', 'failed'].includes(a.step) || told.has(a.fundingTxid)) continue; + const tx = own.get(a.fundingTxid); + if (!tx) continue; + const m = { id: null, type: 'board', amountSat: (a.amountSat || 0) - (a.feeSat || 0), ts: exitStartedTs(a), txid: a.fundingTxid }; + const feeSat = Math.max(0, -(tx.net || 0) - m.amountSat); + rows.push({ time: m.ts, replacesTxid: a.fundingTxid, render: () => arkInternalMoveItem(m, feeSat, true) }); + } + return rows; + }, _histBuild(s) { // In-flight exits are payments the user made — they belong in history // as pending records, not on a monitoring page nobody thinks to visit. @@ -4432,7 +4480,7 @@ export function arkFeature(ctx) { } } this._histFolded = folded; // a folded row's detail shows the whole payment - return exits.concat(renewals, lnPending, out.map((m) => ({ time: m.ts, render: () => arkHistoryItem(m), csv: arkCsvRow(m) }))); + return exits.concat(renewals, lnPending, out.map((m) => ({ time: m.ts, m, render: () => arkHistoryItem(m), csv: arkCsvRow(m) }))); }, historyDetail() { if (ui.arkExitDetail) { diff --git a/src/features/names.js b/src/features/names.js index 81b64e6..e1f23ce 100644 --- a/src/features/names.js +++ b/src/features/names.js @@ -685,6 +685,8 @@ export function namesFeature(ctx) { }))), // ask for a sum: the point of sale's amount pad and invoice, simplified hook('posAvailable') ? h('button', { class: 'btn-block', id: 'recv-amount', onClick: () => hook('openAmountRequest') }, t('recvAmount')) : null, + // one balance: an on-chain address for the payers who need one + ctx.receiveOnchainBtn ? ctx.receiveOnchainBtn() : null, moreSection()); } -- cgit v1.2.3