aboutsummaryrefslogtreecommitdiffstats
path: root/src/app.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-11-15 19:30:16 -0700
committerAdam Soltys <[email protected]>2026-11-15 19:30:16 -0700
commite883fefbc9baff516af25869560cf6198c603fab (patch)
tree5781667c93d057f04d42ce2af603635ec943fb4e /src/app.js
parent5554c7066113976b49c18c5c7505dd252769e72d (diff)
downloadcoinosv3-e883fefbc9baff516af25869560cf6198c603fab.tar.gz
coinosv3-e883fefbc9baff516af25869560cf6198c603fab.zip
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.HEADmaster
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VMan6SwkivduFDDkMmnXjZ
Diffstat (limited to 'src/app.js')
-rw-r--r--src/app.js145
1 files changed, 117 insertions, 28 deletions
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 = '<svg width="21" height="21" viewBox="0 0 24 24" fill="currentColor" style="display:block"><path d="M13.5 2 4 13.5h6.5L9.5 22 20 9.5h-6.6z"/></svg>';
- 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