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/app.js | 145 ++++++++++++++++++++++++++++++++++++++++---------- src/features/ark.js | 60 ++++++++++++++++++--- src/features/names.js | 2 + src/i18n.js | 12 +++++ 4 files changed, 185 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/app.js b/src/app.js index 99cf565..e1df4e2 100644 --- a/src/app.js +++ b/src/app.js @@ -1886,6 +1886,12 @@ async function enterWallet(mnemonic, passphrase, opts = {}) { if (opts.spendingOnly && !acc.kind && !acc.deriveIndex && !acc.savingsAdded && acc.type === 'full') { acc.kind = 'spending'; acc.savingsLater = true; } else if (opts.signup && acc.kind === 'spending') acc.savingsLater = true; + // ...unless balances are one: then a sign-up is simply the account, its + // on-chain side there underneath for whenever someone pays on-chain + if (acc.kind === 'spending' && acc.savingsLater && !acc.deriveIndex && !separateBalances()) { + delete acc.kind; delete acc.savingsLater; + if (!acc.spendingSetup) acc.spendingSetup = Date.now(); + } await activateAccount(acc, { ...opts, fresh: true }); } @@ -3705,8 +3711,8 @@ function accountsScreen() { // has to say which identity. ...groupAccounts().flatMap(({ pk, rows }) => [ identityHeading(pk), - ...rows.flatMap((a) => viewsOf(a).map((view) => { - const isActive = a.id === activeId && accountSel() === view; + ...rows.flatMap((a) => (a.id === activeId && unifiedOn(a) ? ['all'] : viewsOf(a)).map((view) => { + const isActive = a.id === activeId && (view === 'all' || accountSel() === view); const netTag = a.network && a.network !== 'mainnet' ? ' · ' + a.network : ''; const seedTag = ''; const tag = (a.type === 'watch' ? ' · ' + t('watchOnlyTag') : '') + netTag + seedTag; @@ -3947,12 +3953,13 @@ function recoveryCard(a) { // cannot find this option" (Nils, 2026-11-12) about the Spending card's gear. function balanceSettingsCard(a) { if (a.id !== activeId) return null; - const views = a.kind ? [a.kind] : spendingActive() ? ['spending', 'savings'] : ['savings']; + const unified = unifiedOn(a); + const views = unified ? ['all'] : a.kind ? [a.kind] : spendingActive() ? ['spending', 'savings'] : ['savings']; // Each balance wears its own mark in a tinted tile — the bolt and the // bitcoin disc the balance card uses — rather than a gear beside one and a // coin beside the other (Adam, 2026-11-15: "Icons and padding need work"). const BOLT = ''; - const tile = (view) => h('span', { class: 'bs-tile ' + (view === 'spending' ? 'spend' : 'save'), html: view === 'spending' ? BOLT : BITCOIN_ICON(22) }); + const tile = (view) => h('span', { class: 'bs-tile ' + (view === 'savings' ? 'save' : 'spend'), html: view === 'savings' ? BITCOIN_ICON(22) : BOLT }); const rowOf = (attrs, view, title, desc, tail) => h('button', { class: 'balance-settings-row', ...attrs }, tile(view), h('span', { class: 'col bs-text' }, @@ -3960,13 +3967,20 @@ function balanceSettingsCard(a) { h('span', { class: 'small muted' }, desc)), h('span', { class: 'bs-tail', 'aria-hidden': 'true' }, tail)); const row = (view) => rowOf({ 'data-view': view, onClick: () => openWalletSettings(view) }, view, - viewLabel(a, view), t(view === 'spending' ? 'spendingSettingsDesc' : 'savingsSettingsDesc'), '›'); + viewLabel(a, view), t(view === 'all' ? 'allSettingsDesc' : view === 'spending' ? 'spendingSettingsDesc' : 'savingsSettingsDesc'), '›'); // a sign-up's Spending-only account: Savings is one tap away const addRow = a.kind === 'spending' && a.savingsLater && !a.deriveIndex ? rowOf({ id: 'add-savings', onClick: () => { addSavings(a); toast(t('savingsAddedToast')); } }, 'savings', t('addSavings'), t('addSavingsDesc'), '+') : null; - return h('div', { class: 'card col', style: 'gap:8px' }, h('h3', {}, t('balanceSettingsTitle')), ...views.map(row), addRow); + // one balance or two, per device: the same seed and coins either way + const apart = !a.kind && a.type === 'full' && spendingActive() + ? h('label', { class: 'row gap6', style: 'align-items:center;cursor:pointer;padding:6px 2px 0' }, + h('input', { type: 'checkbox', id: 'separate-balances', checked: separateBalances(), + onChange: (e) => { setSeparateBalances(e.target.checked); ui.recvOnchain = false; render(); } }), + h('span', { class: 'small' }, t('separateBalances'))) + : null; + return h('div', { class: 'card col', style: 'gap:8px' }, h('h3', {}, t('balanceSettingsTitle')), ...views.map(row), unified ? null : addRow, apart); } function walletNameCard(a) { const saveName = () => { @@ -4097,7 +4111,7 @@ function accountSettingsScreen() { const a = accounts.find((x) => x.id === ui.settingsId) || activeAccount(); if (!a) { ui.screen = 'accounts'; return accountsScreen(); } const view = ui.settingsView || accountSel(); - const spending = view === 'spending' && a.id === activeId; + const spending = (view === 'spending' || view === 'all') && a.id === activeId; const leave = () => { ui.editLabel = null; ui.revealShown = false; ui.pubkeyShown = false; ui.loadSeed = null; goBack(() => { ui.screen = 'wallet'; }); }; return h( 'div', @@ -4642,7 +4656,7 @@ function onboardScreen() { // A sign-up's name is the account itself — what people pay, follow and // message — so it's claimed here, not skipped. const signupAcc = activeAccount(); - const signup = !o.fromGift && !!(signupAcc && signupAcc.signupAt && signupAcc.kind === 'spending'); + const signup = !o.fromGift && !!(signupAcc && signupAcc.signupAt && (signupAcc.kind === 'spending' || !signupAcc.kind)); return page([ title(t(o.fromGift ? 'onbGiftNameTitle' : signup ? 'onbNameTitle' : 'onbSpendTitle')), h('p', { class: 'muted', style: 'margin:0' }, t(o.fromGift ? 'onbGiftNameBody' : signup ? 'onbNameBody' : 'onbSpendBody')), @@ -5007,6 +5021,8 @@ function addSavings(acc, { quiet = false } = {}) { function savingsEvident() { const a = activeAccount(); if (!a || a.kind !== 'spending' || !a.savingsLater || !wallet.loaded) return; + // one balance: on-chain is part of the account from the start, nothing to add + if (!separateBalances()) { addSavings(a, { quiet: true }); return; } if ((wallet.spendable || 0) > 0 || (wallet.pendingIncoming || 0) > 0 || (wallet.txs || []).length) addSavings(a, { quiet: true }); } // The shape rides the synced snapshot, so the phone opens the account the @@ -5024,7 +5040,7 @@ wallet.registerCacheExtension({ const a = activeAccount(); if (!d || !a || a.type !== 'full' || a.deriveIndex) return; if (d.savingsAdded) { if (addSavings(a, { quiet: true }) === false && !a.savingsAdded) { a.savingsAdded = d.savingsAdded; persistAccounts(); } return; } - if (d.spendingOnly && !a.kind && !a.savingsAdded && !(wallet.txs || []).length && !(wallet.spendable || 0)) { + if (d.spendingOnly && separateBalances() && !a.kind && !a.savingsAdded && !(wallet.txs || []).length && !(wallet.spendable || 0)) { a.kind = 'spending'; a.savingsLater = true; persistAccounts(); } @@ -5155,6 +5171,37 @@ function offlineBanner() { // Lightning) or Savings (on-chain). The balance card headline, the Receive // pane, and the gift source all follow it. const ACCOUNT_KEY = 'btc-wallet-account'; +// One balance (Adam, 2026-11-15: "combine the Ark and savings Bitcoin +// accounts into a single account … a combined history … the balance would +// be unified"). A seed with both sides shows ONE account: the total, one +// timeline (a move between the two is one row, priced at what it cost), and +// Receive leading with the payment address, an on-chain address a tap away. +// Money stays where it lands; a payment picks its coins by where it's going +// (Lightning/Ark from the Ark coins, an on-chain address from on-chain coins +// first). Settings → Wallet can still show the two apart, per device. +const SEPARATE_KEY = 'btc-wallet-separate-balances'; +function separateBalances() { + try { return localStorage.getItem(SEPARATE_KEY) === '1'; } catch { return false; } +} +function setSeparateBalances(on) { + try { on ? localStorage.setItem(SEPARATE_KEY, '1') : localStorage.removeItem(SEPARATE_KEY); } catch {} +} +function unifiedOn(a = activeAccount()) { + return !!a && !a.kind && a.type === 'full' && !separateBalances() && spendingActive(); +} +// History rows, both rails merged: on-chain transactions plus the features' +// entries. A feature row can stand in for an on-chain transaction +// (`replacesTxid` — a board or an offboard to our own address, told once). +function historyEntriesFor(sel) { + const all = sel === 'spending' ? [] : wallet.history || []; + const feat = featureAll('historyEntries', all, sel); + const replaced = new Set(feat.map((e) => e.replacesTxid).filter(Boolean)); + const txs = replaced.size ? all.filter((tx) => !replaced.has(tx.txid)) : all; + return [ + ...txs.map((tx) => ({ time: tx.confirmed ? (tx.blockTime || 0) * 1000 : Date.now(), render: () => txHistoryItem(tx) })), + ...feat, + ].sort((a, b) => b.time - a.time); +} // Spending is opt-in: a wallet is born on-chain only, and the second balance // (with its toggle, swipe, and Move money) appears once the user sets it up — // or the moment money is already there (a restored wallet, a claimed gift), @@ -5212,6 +5259,7 @@ function seedName(a) { } function viewLabel(a, view) { if (a && a.viewLabels && a.viewLabels[view]) return a.viewLabels[view]; + if (view === 'all') return t('balance'); return view === 'spending' ? t('spendingName') : t('savingsName'); } function switchToView(id, view) { @@ -5228,6 +5276,9 @@ function switchToView(id, view) { function accountSel() { const a = activeAccount(); if (a && a.kind) return a.kind; // single-purpose wallet: no other side + // one balance: payments start from the Ark coins; the send flow picks + // on-chain coins for an on-chain address itself (ark.js matchSend) + if (unifiedOn(a)) return 'spending'; if (!spendingActive()) return 'savings'; // one balance, no choice if (!ui.account) { let saved = null; @@ -5264,12 +5315,9 @@ function walletSide() { const toWallet = (tab) => { goHome(); ui.tab = tab; render(); }; const spending = featureHook('spendingSat') || 0; const saving = wallet.spendable || 0; - const sel = accountSel(); - const txs = sel === 'spending' ? [] : wallet.history || []; - const entries = wallet.loaded ? [ - ...txs.map((tx) => ({ time: tx.confirmed ? (tx.blockTime || 0) * 1000 : Date.now(), render: () => txHistoryItem(tx) })), - ...featureAll('historyEntries', txs, sel), - ].sort((a, b) => b.time - a.time).slice(0, 6) : []; + const unified = unifiedOn(); + const sel = unified ? 'all' : accountSel(); + const entries = wallet.loaded ? historyEntriesFor(sel).slice(0, 6) : []; const rows = entries.map((e) => { const row = e.render(); // a row opens its detail on the wallet page: go there first @@ -5284,8 +5332,8 @@ function walletSide() { h('button', { type: 'button', class: 'wallet-side-total', onClick: () => toWallet('history') }, h('span', { class: 'small muted' }, t('balance')), h('span', { class: 'wallet-side-amount' }, wallet.loaded ? fmtAmount(spending + saving) + ' ' + unitLabel() : '…')), - spendingActive() ? line(t('spendingLabel'), spending) : null, - spendingActive() ? line(t('savingLabel'), saving) : null, + spendingActive() && (!unified || (spending > 0 && saving > 0)) ? line(unified ? t('balInstant') : t('spendingLabel'), spending) : null, + spendingActive() && (!unified || (spending > 0 && saving > 0)) ? line(unified ? t('balOnchain') : t('savingLabel'), saving) : null, h('div', { class: 'row gap6' }, h('button', { type: 'button', class: 'btn-primary grow', onClick: () => toWallet('receive') }, t('tabReceive')), h('button', { type: 'button', class: 'btn-primary grow', onClick: () => toWallet('send') }, t('tabSend')))), @@ -5396,7 +5444,7 @@ function balanceCard() { try { localStorage.setItem(ACCOUNT_KEY, 'spending'); } catch {} } ui.arkMoveDir = 'toSpending'; ui.arkMoveOpen = true; render(); - } }, t('topUpFromSavings')) + } }, unifiedOn() ? t('topUpInstant') : t('topUpFromSavings')) : null, !hasSpending && !kindLocked && featureHook('arkReady') && !wallet.watchOnly && acc0 && acc0.type === 'full' && featureHook('namesSettled') !== 'pending' // a restoring name may prove Spending any second — don't flash the setup ask @@ -5421,6 +5469,32 @@ function balanceCard() { return w; })(), ]; + // One account: one face with everything on it. Where it sits shows only + // when it's in both places (instant Ark coins, on-chain coins) — and every + // line under the figure (pending, moving, locked in gifts) belongs to it. + if (unifiedOn()) { + const split = spending > 0 && saving > 0 + ? [{ label: t('balInstant'), sat: spending }, { label: t('balOnchain'), sat: saving }] : []; + const lines = split + .concat(pending > 0 ? [{ label: t('pending'), sat: pending, cls: 'v pending' }] : []) + .concat(featLines); + _accDir = null; + return h('div', { class: 'card balance balance-one' }, + h('div', { class: 'balance-face' }, + h('div', { class: 'row between', style: 'align-items:center' }, + h('div', { class: 'small faint', style: 'text-transform:uppercase;letter-spacing:.06em' }, + (acc0.viewLabels && acc0.viewLabels.all) || ''), + manageBtn('all')), + h('div', { class: 'amt', style: firstLoad ? 'opacity:.3' : '' }, + firstLoad ? h('span', { class: 'spinner sm', style: 'margin-right:8px' }) : null, + // mid-board money is still this account's: it counts, and its Moving line says where it is + animatedAmount('bal:all', spending + (saving || 0) + (featureHook('spendingBoardingSat') || 0)), ' ', unitTag('unit')), + lines.length + ? h('div', { class: 'split' }, + ...lines.map((l) => h('div', {}, h('div', { class: 'k' }, l.label), h('div', { class: l.cls || 'v' }, fmtAmount(l.sat), ' ', unitTag())))) + : null), + ...cardExtras('spending')); + } const carouselMode = hasSpending && !kindLocked; if (carouselMode) { // Two SEPARATE cards side by side — the neighbor card peeks past the @@ -5714,6 +5788,7 @@ function tabsBar() { tabBtn(label, ui.tab === id, () => { ui.tab = ui.tab === id ? 'history' : id; ui.sendError = ''; // a stale send error never survives a tab change + ui.recvOnchain = false; // Receive opens on the payment address again ui.revealShown = false; // re-mask the recovery phrase whenever tabs change ui.nostrExportStep = false; // and the exported nostr key ui.txDetail = null; // back to the history list when leaving/returning @@ -5808,6 +5883,11 @@ function iconGlyph(ic) { : h('span', { class: 'sel-ico' }, ic); } +// One account's Receive: the door to an on-chain address under the payment one. +function receiveOnchainBtn() { + if (!unifiedOn() || wallet.watchOnly) return null; + return h('button', { class: 'btn-block', id: 'recv-onchain', onClick: () => { ui.recvOnchain = true; render(); } }, t('recvOnchain')); +} function receiveTab() { // Feature takeovers: boarding success, Ark receive celebration, etc. const takeover = featureHook('receiveTakeover'); @@ -5846,6 +5926,17 @@ function receiveTab() { // (receives Ark and Lightning), Savings shows a fresh on-chain address. const fresh = wallet.freshReceive(); const nameMode = featureAll('receiveModes').find((m) => m.id === 'name'); + // One account: the payment address leads, an on-chain address is a tap + // away (and is all there is offline). What arrives on-chain stays on-chain. + if (unifiedOn() && (ui.recvOnchain || wallet.offline)) { + return h('div', { class: 'card col', style: 'align-items:center;gap:14px' }, + wallet.offline ? h('div', { class: 'notice info', style: 'width:100%' }, t('receiveOfflineOnchain')) : null, + h('div', { html: qrSvg(fresh.address) }), + h('div', { class: 'addr-box', style: 'width:100%' }, fresh.address), + copyBtn(fresh.address, t('copyAddress')), + h('div', { class: 'small muted', style: 'text-align:center' }, t('recvOnchainNote')), + wallet.offline ? null : h('button', { class: 'btn-block', id: 'recv-payaddr', onClick: () => { ui.recvOnchain = false; render(); } }, t('recvPaymentAddress'))); + } if (accountSel() === 'spending') { // Spending needs the network (registrar + ark); offline, offer the // on-chain path right here instead of an endless spinner. @@ -5869,7 +5960,8 @@ function receiveTab() { h('div', { html: qrSvg(ui.arkRecvAddr) }), h('div', { class: 'addr-box break', style: 'width:100%' }, ui.arkRecvAddr), copyBtn(ui.arkRecvAddr, t('copyAddress')), - featureHook('posAvailable') ? h('button', { class: 'btn-block', id: 'recv-amount', onClick: () => featureHook('openAmountRequest') }, t('recvAmount')) : null + featureHook('posAvailable') ? h('button', { class: 'btn-block', id: 'recv-amount', onClick: () => featureHook('openAmountRequest') }, t('recvAmount')) : null, + receiveOnchainBtn() ); } } @@ -6795,7 +6887,7 @@ function historyTab() { // ledger (BIP84 txs, silent-payment receipts, gift reservations), Spending // shows the ark side (receives, sends, boards, LN) — each card of the // carousel owns its own timeline. - const histSel = accountSel(); + const histSel = unifiedOn() ? 'all' : accountSel(); const txs = histSel === 'spending' ? [] : wallet.history; // newest first const featDetail = featureHook('historyDetail'); if (featDetail) return featDetail; @@ -6813,16 +6905,11 @@ function historyTab() { h('span', { class: 'spinner' }), wallet.historyLoading ? h('p', { class: 'small muted', style: 'margin:0' }, t('loadingHistory')) : null ); - const featEntries = featureAll('historyEntries', txs, histSel); + // Transactions and feature entries merge into one timeline. + const entries = historyEntriesFor(histSel); // nothing yet: no card at all, it appears with the first payment // (Adam, 2026-11-15: "let's not show an empty history section") - if (!txs.length && !featEntries.length) return null; - - // Transactions and feature entries merge into one timeline. - const entries = [ - ...txs.map((tx) => ({ time: tx.confirmed ? (tx.blockTime || 0) * 1000 : Date.now(), render: () => txHistoryItem(tx) })), - ...featEntries, - ].sort((a, b) => b.time - a.time); + if (!entries.length) return null; const txPages = Math.ceil(entries.length / PAGE_SIZE); const txPage = Math.min(ui.txPage, Math.max(0, txPages - 1)); const txSlice = entries.slice(txPage * PAGE_SIZE, txPage * PAGE_SIZE + PAGE_SIZE); @@ -7050,6 +7137,8 @@ const ctx = { shownPubkey: () => (featureHook('nostrLoginIdentity') || {}).pubkey || (wallet.nostrPubkey && wallet.nostrPubkey()) || (activeAccount() || {}).nostrPk || null, getAccount: () => accountSel(), + unifiedBalance: () => unifiedOn(), + receiveOnchainBtn: () => receiveOnchainBtn(), setAccount: (a, dir) => setAccountSel(a, dir), offerProfileSetup, pickConfirm, // the ways back in (Settings → Wallet): what's set up, and adding one 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()); } diff --git a/src/i18n.js b/src/i18n.js index bb82ed2..9dfc172 100644 --- a/src/i18n.js +++ b/src/i18n.js @@ -1679,6 +1679,18 @@ const STR = { settingsAdvancedDesc: 'Network, rarities, rescues', aboutTitle: 'About', recvAmount: 'Amount', + recvOnchain: 'Bitcoin address', + recvPaymentAddress: 'Payment address', + recvOnchainNote: 'For a payment on-chain, from an exchange or another wallet. It stays on-chain until you spend it.', + receiveOfflineOnchain: "You're offline. This on-chain address still takes payments.", + balInstant: 'Instant', + balOnchain: 'On-chain', + topUpInstant: 'Make on-chain bitcoin instant', + allSettingsDesc: 'Coins, renewals, lock, recovery phrase, public key', + separateBalances: 'Show Spending and Savings separately', + movedInstant: 'Made instant', + movingInstant: 'Making instant', + movedOnchain: 'Moved on-chain', recvAmountTitle: 'Request an amount', recvAmountNote: 'What it’s for (optional)', recvAmountGo: 'Create invoice', -- cgit v1.2.3