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.js71
1 files changed, 61 insertions, 10 deletions
diff --git a/src/features/ark.js b/src/features/ark.js
index 1b8c591..2c1a581 100644
--- a/src/features/ark.js
+++ b/src/features/ark.js
@@ -1,4 +1,4 @@
-import { momentTags } from '../media-timeline.js';
+import { momentTags, momentToggle, mediaClock } from '../media-timeline.js';
// Ark feature — off-chain payments via an ASP (Second's bark/captaind
// protocol, spoken natively by ../ark). Receive address + boarding, instant
// sends, history entries, refresh/consolidation, server settings.
@@ -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.
@@ -1892,7 +1906,8 @@ export function arkFeature(ctx) {
// 3. an on-chain address from the BIP-353 record
const NAMES_REGISTRAR = 'https://names.coinos.io';
function startNpubPay(pk, npub, eventId = null, autoSat = 0, moment = null) {
- const z = { npub, pk, eventId, moment, amount: '', comment: '', status: 'lookup', autoSat };
+ // `moment`: where the clip was — offered in the sheet, tied only when ticked
+ const z = { npub, pk, eventId, momentOffer: moment, moment: null, amount: '', comment: '', status: 'lookup', autoSat };
// A one-tap post zap has no card: it resolves and pays off-screen, so a
// second tap — the same post again, or another — never evicts the one
// already in the air. Everything else takes the send screen's zap slot.
@@ -1974,7 +1989,7 @@ export function arkFeature(ctx) {
z.lnOk = true;
await connectArk().catch(() => {});
if (!live()) return;
- if (ctx.hook('canLnZap')) { if (ui.arkZap === z) ui.arkZap = null; ctx.hook('lnZapNpub', pk, npub, z.eventId, z.autoSat, z.moment); return; }
+ if (ctx.hook('canLnZap')) { if (ui.arkZap === z) ui.arkZap = null; ctx.hook('lnZapNpub', pk, npub, z.eventId, z.autoSat, z.moment || (z.autoSat ? null : z.momentOffer)); return; }
}
// 3. on-chain fallback (a one-tap zap can't take the send form)
if (onchain && !(z.autoSat && z.eventId)) {
@@ -2227,6 +2242,8 @@ export function arkFeature(ctx) {
h('div', { style: 'display:flex;align-items:center' }, unitTag())),
h('input', { type: 'text', class: 'mono-input', placeholder: t('arkZapCommentPh'), value: z.comment,
onInput: (e) => { z.comment = e.target.value; } }),
+ z.momentOffer ? h('div', { class: 'row' }, momentToggle(h, z.momentOffer, !!z.moment, (on) => { z.moment = on ? z.momentOffer : null; render(); },
+ t('mediaTieTo', { time: mediaClock(z.momentOffer.seconds) }))) : null,
h('div', { class: 'small faint' }, hint));
return h('div', { class: 'card col', style: 'gap:12px' },
h('h3', {}, '⚡ ' + t('zapTitle')),
@@ -2237,7 +2254,7 @@ export function arkFeature(ctx) {
// Only someone with a Lightning address gets the Lightning door (the
// lookup normally hands such a person straight to the zaps feature).
noAddr && z.lnOk && ctx.hook('canLnZap')
- ? h('button', { class: 'btn-block', disabled: !!ui.busy, onClick: () => { ctx.hook('lnZapNpub', z.pk, z.npub, z.eventId, 0, z.moment); } }, '⚡ ' + t('lnZapFallback'))
+ ? h('button', { class: 'btn-block', disabled: !!ui.busy, onClick: () => { ctx.hook('lnZapNpub', z.pk, z.npub, z.eventId, 0, z.moment || z.momentOffer); } }, '⚡ ' + t('lnZapFallback'))
: null,
payable && spendable < 330
? h('div', { class: 'notice info' }, t(spendable + renewingSat() >= 330 ? 'spendingRenewingPayment' : 'zapNoBalance'))
@@ -4267,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: '' };
@@ -4330,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
@@ -4346,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.
@@ -4429,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) {