aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/ark.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/features/ark.js')
-rw-r--r--src/features/ark.js60
1 files changed, 54 insertions, 6 deletions
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) {