@bsv/expo-wallet-toolbox 0.26.0 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/core/context/WalletContext.tsx +20 -1
- package/core/i18n/translations.tsx +24 -0
- package/core/identity/handleRegistry/classify.ts +74 -0
- package/core/identity/handleRegistry/resolver.ts +77 -34
- package/core/identity/handleRegistry/rules.ts +4 -0
- package/core/index.ts +7 -0
- package/core/monitor/TaskDrainOutbox.ts +13 -3
- package/core/pay/paymail/address.ts +19 -0
- package/core/pay/paymail/client.ts +177 -0
- package/core/pay/paymail/networkCheck.ts +56 -0
- package/core/pay/rails/handle.ts +46 -9
- package/core/pay/rails/paymail.ts +542 -0
- package/core/peerpay/handleResendRequests.ts +6 -6
- package/core/peerpay/outbox.ts +185 -17
- package/core/peerpay/rebuildToken.ts +2 -2
- package/package.json +1 -1
- package/ui/components/pay/ImportedOutboxApproval.tsx +23 -2
- package/ui/components/pay/UniversalSend.tsx +75 -4
- package/ui/screens/WalletHomeScreen.tsx +104 -4
- package/ui/txStatus.ts +1 -1
package/core/peerpay/outbox.ts
CHANGED
|
@@ -16,10 +16,14 @@
|
|
|
16
16
|
|
|
17
17
|
import { P2PKH, PublicKey, Transaction, type WalletInterface } from '@bsv/sdk'
|
|
18
18
|
import { BRC29_PROTOCOL_ID } from './brc29'
|
|
19
|
+
import { isPublicHttpsUrl } from '../net/publicDestination'
|
|
20
|
+
import { parsePaymail } from '../pay/paymail/address'
|
|
19
21
|
|
|
20
22
|
// ── Types ──────────────────────────────────────────────────────────────────────
|
|
21
23
|
|
|
22
|
-
export interface
|
|
24
|
+
export interface PeerPayOutboxEntry {
|
|
25
|
+
/** Absent on rows stored before the paymail kind existed; those are PeerPay rows. */
|
|
26
|
+
kind?: 'peerpay'
|
|
23
27
|
/** `${timestamp}_${recipientKey.slice(0, 8)}`, with a suffix on collision. */
|
|
24
28
|
id: string
|
|
25
29
|
/** ISO 8601 creation timestamp */
|
|
@@ -83,6 +87,46 @@ export interface OutboxEntry {
|
|
|
83
87
|
via?: 'direct'
|
|
84
88
|
}
|
|
85
89
|
|
|
90
|
+
/** A payment to a legacy paymail (P2P destination plus BEEF). */
|
|
91
|
+
export interface PaymailOutboxEntry {
|
|
92
|
+
kind: 'paymail'
|
|
93
|
+
id: string
|
|
94
|
+
createdAt: string
|
|
95
|
+
status: 'unsent' | 'sent' | 'import_hold'
|
|
96
|
+
lastAttemptAt?: string
|
|
97
|
+
lastError?: string
|
|
98
|
+
/** Our txid, 64 hex. */
|
|
99
|
+
txid: string
|
|
100
|
+
paymail: string
|
|
101
|
+
/** The BEEF URL, resolved at send time. */
|
|
102
|
+
endpoint: string
|
|
103
|
+
/** The receiver's reference, not the wallet action reference. */
|
|
104
|
+
paymailReference: string
|
|
105
|
+
/** Plain BEEF. */
|
|
106
|
+
beefHex: string
|
|
107
|
+
satoshis: number
|
|
108
|
+
/** The user's note. */
|
|
109
|
+
note?: string
|
|
110
|
+
/** Set just before the POST. */
|
|
111
|
+
delivering?: boolean
|
|
112
|
+
/** The receiver accepted. */
|
|
113
|
+
delivered?: boolean
|
|
114
|
+
receiverTxid?: string
|
|
115
|
+
receiverNote?: string
|
|
116
|
+
/** A retry saw a refusal and did not abort: only a user Cancel can finish it. */
|
|
117
|
+
refused?: boolean
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export type OutboxEntry = PeerPayOutboxEntry | PaymailOutboxEntry
|
|
121
|
+
|
|
122
|
+
export function isPaymailEntry(e: OutboxEntry): e is PaymailOutboxEntry {
|
|
123
|
+
return e.kind === 'paymail'
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function isPeerPayEntry(e: OutboxEntry): e is PeerPayOutboxEntry {
|
|
127
|
+
return e.kind !== 'paymail'
|
|
128
|
+
}
|
|
129
|
+
|
|
86
130
|
interface StorageLike {
|
|
87
131
|
getKeyValue: (key: string) => Promise<string | undefined>
|
|
88
132
|
setKeyValue: (key: string, value: string) => Promise<void>
|
|
@@ -172,17 +216,84 @@ export async function quarantineImportedOutbox(storage: StorageLike): Promise<nu
|
|
|
172
216
|
})
|
|
173
217
|
}
|
|
174
218
|
|
|
219
|
+
/** The most outputs a paymail transaction is allowed to have for the subset check. */
|
|
220
|
+
const MAX_SUBSET_OUTPUTS = 24
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* A loose check, and it is the most an offline import can do.
|
|
224
|
+
*
|
|
225
|
+
* The row holds the signed transaction, a display amount and a paymail, and
|
|
226
|
+
* nothing that says which output is the wallet's own change. So the amount must
|
|
227
|
+
* only equal the sum of SOME subset of the outputs (the rest being change); a
|
|
228
|
+
* transaction with no outputs, or none that add up to the amount, is refused.
|
|
229
|
+
*
|
|
230
|
+
* Limits: this does NOT bind the recipient to any output (the P2P destination
|
|
231
|
+
* script comes from the receiver's server and cannot be derived offline), and it
|
|
232
|
+
* does not prove that the subset is what the recipient is paid. A tampered
|
|
233
|
+
* backup could show one paymail and amount while the transaction pays another
|
|
234
|
+
* output. The approval screen therefore says these terms are unchecked.
|
|
235
|
+
*/
|
|
236
|
+
function outputsCanPay(tx: Transaction, satoshis: number): boolean {
|
|
237
|
+
const values = tx.outputs.map(o => o.satoshis)
|
|
238
|
+
if (values.length === 0 || values.length > MAX_SUBSET_OUTPUTS) return false
|
|
239
|
+
if (!values.every(v => typeof v === 'number' && Number.isSafeInteger(v) && v > 0)) return false
|
|
240
|
+
let sums = new Set<number>([0])
|
|
241
|
+
for (const v of values as number[]) {
|
|
242
|
+
const next = new Set(sums)
|
|
243
|
+
for (const s of sums) if (s + v <= satoshis) next.add(s + v)
|
|
244
|
+
sums = next
|
|
245
|
+
}
|
|
246
|
+
return sums.has(satoshis)
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function validateImportedPaymailEntry(entry: PaymailOutboxEntry): void {
|
|
250
|
+
let tx: Transaction
|
|
251
|
+
try {
|
|
252
|
+
if (typeof entry.beefHex !== 'string' || !entry.beefHex) throw new Error('empty')
|
|
253
|
+
tx = Transaction.fromHexBEEF(entry.beefHex)
|
|
254
|
+
} catch {
|
|
255
|
+
throw new Error('Imported payment has an invalid signed transaction')
|
|
256
|
+
}
|
|
257
|
+
if (
|
|
258
|
+
typeof entry.txid !== 'string' ||
|
|
259
|
+
!/^[0-9a-f]{64}$/i.test(entry.txid) ||
|
|
260
|
+
tx.id('hex').toLowerCase() !== entry.txid.toLowerCase()
|
|
261
|
+
) {
|
|
262
|
+
throw new Error('Imported payment transaction ID does not match its signed transaction')
|
|
263
|
+
}
|
|
264
|
+
if (!Number.isSafeInteger(entry.satoshis) || entry.satoshis <= 0) {
|
|
265
|
+
throw new Error('Imported payment has an invalid amount')
|
|
266
|
+
}
|
|
267
|
+
if (!parsePaymail(entry.paymail)) {
|
|
268
|
+
throw new Error('Imported payment has an invalid paymail')
|
|
269
|
+
}
|
|
270
|
+
if (!outputsCanPay(tx, entry.satoshis)) {
|
|
271
|
+
throw new Error('Imported payment amount does not match its signed outputs')
|
|
272
|
+
}
|
|
273
|
+
if (typeof entry.endpoint !== 'string' || !isPublicHttpsUrl(entry.endpoint)) {
|
|
274
|
+
throw new Error('Imported payment has an invalid endpoint')
|
|
275
|
+
}
|
|
276
|
+
if (typeof entry.paymailReference !== 'string' || !entry.paymailReference) {
|
|
277
|
+
throw new Error('Imported payment has no paymail reference')
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
175
281
|
/** Verify an imported snapshot before its amount or recipient is offered for
|
|
176
282
|
* approval. Only public-key derivation is needed; no payment is signed or sent. */
|
|
177
|
-
export async function validateImportedOutboxEntry(
|
|
178
|
-
entry:
|
|
283
|
+
export async function validateImportedOutboxEntry<E extends OutboxEntry>(
|
|
284
|
+
entry: E,
|
|
179
285
|
wallet: Pick<WalletInterface, 'getPublicKey'>,
|
|
180
286
|
adminOriginator: string
|
|
181
|
-
): Promise<
|
|
287
|
+
): Promise<E> {
|
|
182
288
|
// Separate the checked snapshot from the caller's mutable imported object
|
|
183
289
|
// before awaiting wallet derivation. Release still checks exact stored equality.
|
|
184
290
|
const reviewed = JSON.parse(JSON.stringify(entry)) as OutboxEntry
|
|
291
|
+
const result = reviewed as E
|
|
185
292
|
if (reviewed.status !== 'import_hold') throw new Error('Imported payment is not held for review')
|
|
293
|
+
if (isPaymailEntry(reviewed)) {
|
|
294
|
+
validateImportedPaymailEntry(reviewed)
|
|
295
|
+
return result
|
|
296
|
+
}
|
|
186
297
|
const token = reviewed.token
|
|
187
298
|
if (
|
|
188
299
|
!token ||
|
|
@@ -235,16 +346,16 @@ export async function validateImportedOutboxEntry(
|
|
|
235
346
|
if (output.lockingScript.toHex() !== expected) {
|
|
236
347
|
throw new Error('Imported payment recipient does not match its signed output')
|
|
237
348
|
}
|
|
238
|
-
return
|
|
349
|
+
return result
|
|
239
350
|
}
|
|
240
351
|
|
|
241
352
|
/** Called only after reviewing the displayed imported payment for a new send. */
|
|
242
|
-
export async function releaseImportedOutboxEntry(
|
|
353
|
+
export async function releaseImportedOutboxEntry<E extends OutboxEntry>(
|
|
243
354
|
storage: StorageLike,
|
|
244
|
-
reviewed:
|
|
355
|
+
reviewed: E,
|
|
245
356
|
wallet: Pick<WalletInterface, 'getPublicKey'>,
|
|
246
357
|
adminOriginator: string
|
|
247
|
-
): Promise<
|
|
358
|
+
): Promise<E> {
|
|
248
359
|
return withOutboxLock(storage, async () => {
|
|
249
360
|
const all = await readEntries(storage)
|
|
250
361
|
const index = all.findIndex(entry => entry.id === reviewed.id)
|
|
@@ -253,10 +364,26 @@ export async function releaseImportedOutboxEntry(
|
|
|
253
364
|
throw new Error('Imported payment changed; review it again')
|
|
254
365
|
}
|
|
255
366
|
const validated = await validateImportedOutboxEntry(current, wallet, adminOriginator)
|
|
256
|
-
|
|
367
|
+
let approved: OutboxEntry
|
|
368
|
+
if (isPaymailEntry(validated)) {
|
|
369
|
+
// An imported row must not claim a delivery this wallet did not see.
|
|
370
|
+
const {
|
|
371
|
+
delivered: _d,
|
|
372
|
+
delivering: _g,
|
|
373
|
+
refused: _r,
|
|
374
|
+
receiverTxid: _t,
|
|
375
|
+
receiverNote: _n,
|
|
376
|
+
lastAttemptAt: _a,
|
|
377
|
+
lastError: _e,
|
|
378
|
+
...rest
|
|
379
|
+
} = validated
|
|
380
|
+
approved = { ...rest, status: 'unsent' as const }
|
|
381
|
+
} else {
|
|
382
|
+
approved = { ...validated, status: 'unsent' as const }
|
|
383
|
+
}
|
|
257
384
|
all[index] = approved
|
|
258
385
|
await writeEntries(storage, all)
|
|
259
|
-
return approved
|
|
386
|
+
return approved as E
|
|
260
387
|
})
|
|
261
388
|
}
|
|
262
389
|
|
|
@@ -268,16 +395,16 @@ export async function saveOutboxEntry(
|
|
|
268
395
|
storage: StorageLike,
|
|
269
396
|
params: {
|
|
270
397
|
recipient: string
|
|
271
|
-
token:
|
|
398
|
+
token: PeerPayOutboxEntry['token']
|
|
272
399
|
messageBoxUrl: string
|
|
273
400
|
txid?: string
|
|
274
401
|
recipientHost?: string
|
|
275
|
-
via?:
|
|
402
|
+
via?: PeerPayOutboxEntry['via']
|
|
276
403
|
}
|
|
277
404
|
): Promise<string> {
|
|
278
405
|
const { recipient, token, messageBoxUrl, txid, recipientHost, via } = params
|
|
279
406
|
const id = `${Date.now()}_${recipient.slice(0, 8)}`
|
|
280
|
-
const entry:
|
|
407
|
+
const entry: PeerPayOutboxEntry = {
|
|
281
408
|
id,
|
|
282
409
|
createdAt: new Date().toISOString(),
|
|
283
410
|
recipient,
|
|
@@ -302,6 +429,45 @@ export async function saveOutboxEntry(
|
|
|
302
429
|
})
|
|
303
430
|
}
|
|
304
431
|
|
|
432
|
+
/** Persist a paymail payment before the POST. Returns the generated entry ID. */
|
|
433
|
+
export async function savePaymailOutboxEntry(
|
|
434
|
+
storage: StorageLike,
|
|
435
|
+
params: {
|
|
436
|
+
paymail: string
|
|
437
|
+
endpoint: string
|
|
438
|
+
paymailReference: string
|
|
439
|
+
beefHex: string
|
|
440
|
+
satoshis: number
|
|
441
|
+
txid: string
|
|
442
|
+
note?: string
|
|
443
|
+
}
|
|
444
|
+
): Promise<string> {
|
|
445
|
+
const { paymail, endpoint, paymailReference, beefHex, satoshis, txid, note } = params
|
|
446
|
+
const id = `${Date.now()}_pm_${txid.slice(0, 8)}`
|
|
447
|
+
const entry: PaymailOutboxEntry = {
|
|
448
|
+
kind: 'paymail',
|
|
449
|
+
id,
|
|
450
|
+
createdAt: new Date().toISOString(),
|
|
451
|
+
status: 'unsent',
|
|
452
|
+
txid,
|
|
453
|
+
paymail,
|
|
454
|
+
endpoint,
|
|
455
|
+
paymailReference,
|
|
456
|
+
beefHex,
|
|
457
|
+
satoshis,
|
|
458
|
+
...(note ? { note } : {})
|
|
459
|
+
}
|
|
460
|
+
return withOutboxLock(storage, async () => {
|
|
461
|
+
const all = await readEntries(storage)
|
|
462
|
+
const usedIds = new Set(all.map(e => e.id))
|
|
463
|
+
let suffix = 0
|
|
464
|
+
while (usedIds.has(entry.id)) entry.id = `${id}_${++suffix}`
|
|
465
|
+
all.push(entry)
|
|
466
|
+
await writeEntries(storage, all)
|
|
467
|
+
return entry.id
|
|
468
|
+
})
|
|
469
|
+
}
|
|
470
|
+
|
|
305
471
|
/**
|
|
306
472
|
* Mark an entry as successfully delivered.
|
|
307
473
|
* Called immediately after `sendMessage()` returns without error.
|
|
@@ -321,12 +487,14 @@ export async function markOutboxSent(storage: StorageLike, id: string): Promise<
|
|
|
321
487
|
* Merge a partial update into an entry.
|
|
322
488
|
* Used to record `lastAttemptAt` and `lastError` on failed retry attempts.
|
|
323
489
|
*/
|
|
324
|
-
export async function updateOutboxEntry(storage: StorageLike, id: string,
|
|
490
|
+
export async function updateOutboxEntry(storage: StorageLike, id: string,
|
|
491
|
+
patch: Partial<PeerPayOutboxEntry> | Partial<PaymailOutboxEntry>
|
|
492
|
+
): Promise<void> {
|
|
325
493
|
return withOutboxLock(storage, async () => {
|
|
326
494
|
const all = await readEntries(storage)
|
|
327
495
|
const idx = all.findIndex(e => e.id === id)
|
|
328
496
|
if (idx !== -1) {
|
|
329
|
-
all[idx] = { ...all[idx], ...patch }
|
|
497
|
+
all[idx] = { ...all[idx], ...patch } as OutboxEntry
|
|
330
498
|
await writeEntries(storage, all)
|
|
331
499
|
}
|
|
332
500
|
})
|
|
@@ -372,12 +540,12 @@ export async function pruneExpiredSent(storage: StorageLike, now: number = Date.
|
|
|
372
540
|
}
|
|
373
541
|
|
|
374
542
|
/** Only explicitly authorized unsent entries may enter automatic delivery. */
|
|
375
|
-
export function unsentEntries(entries:
|
|
543
|
+
export function unsentEntries<E extends OutboxEntry>(entries: E[]): E[] {
|
|
376
544
|
return entries.filter(e => e.status === 'unsent')
|
|
377
545
|
}
|
|
378
546
|
|
|
379
547
|
/** Held or unrecognized history still needs retention, even though it cannot
|
|
380
548
|
* be automatically delivered. Only sent entries are terminal. */
|
|
381
|
-
export function unresolvedOutboxEntries(entries:
|
|
549
|
+
export function unresolvedOutboxEntries<E extends OutboxEntry>(entries: E[]): E[] {
|
|
382
550
|
return entries.filter(e => e.status !== 'sent')
|
|
383
551
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PeerPayOutboxEntry } from './outbox'
|
|
2
2
|
|
|
3
3
|
export function instructionsFromOutput(customInstructions: unknown):
|
|
4
4
|
| {
|
|
@@ -54,7 +54,7 @@ export async function rebuildPeerPayToken(args: {
|
|
|
54
54
|
action: { txid?: string; outputs?: RebuildOutput[] }
|
|
55
55
|
recipient: string
|
|
56
56
|
refetch: (txid: string) => Promise<number[] | undefined>
|
|
57
|
-
}): Promise<{ token:
|
|
57
|
+
}): Promise<{ token: PeerPayOutboxEntry['token']; recipient: string } | undefined> {
|
|
58
58
|
const { action, recipient, refetch } = args
|
|
59
59
|
if (!action.txid) return undefined
|
|
60
60
|
|
package/package.json
CHANGED
|
@@ -3,7 +3,20 @@ import { ActivityIndicator, StyleSheet, Text, View } from 'react-native'
|
|
|
3
3
|
import type { WalletInterface } from '@bsv/sdk'
|
|
4
4
|
import type { ThemeColors } from '../../../core/theme/ThemeContext'
|
|
5
5
|
import { hitTargets, spacing, typography } from '../../../core/theme/tokens'
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
isPaymailEntry,
|
|
8
|
+
releaseImportedOutboxEntry,
|
|
9
|
+
validateImportedOutboxEntry,
|
|
10
|
+
type OutboxEntry
|
|
11
|
+
} from '../../../core/peerpay/outbox'
|
|
12
|
+
|
|
13
|
+
function hostOf(url: string): string {
|
|
14
|
+
try {
|
|
15
|
+
return new URL(url).host
|
|
16
|
+
} catch {
|
|
17
|
+
return url
|
|
18
|
+
}
|
|
19
|
+
}
|
|
7
20
|
import { TaskDrainOutbox } from '../../../core/monitor/TaskDrainOutbox'
|
|
8
21
|
import PressableScale from '../ui/PressableScale'
|
|
9
22
|
|
|
@@ -96,7 +109,15 @@ export default function ImportedOutboxApproval({
|
|
|
96
109
|
<View>
|
|
97
110
|
{reviewed && (
|
|
98
111
|
<Text style={[styles.detail, { color: colors.textPrimary }]}>
|
|
99
|
-
{
|
|
112
|
+
{isPaymailEntry(reviewed)
|
|
113
|
+
? // The paymail destination script cannot be derived offline, so the
|
|
114
|
+
// recipient and amount cannot be checked against the signed
|
|
115
|
+
// outputs. Say so; do not present them as verified terms.
|
|
116
|
+
t('review_imported_paymail_detail', {
|
|
117
|
+
amount: reviewed.satoshis,
|
|
118
|
+
recipient: `${reviewed.paymail} (${hostOf(reviewed.endpoint)})`
|
|
119
|
+
})
|
|
120
|
+
: t('review_imported_payment_detail', { amount: reviewed.token.amount, recipient: reviewed.recipient })}
|
|
100
121
|
</Text>
|
|
101
122
|
)}
|
|
102
123
|
<View style={[styles.buttons, { borderTopColor: colors.separator }]}>
|
|
@@ -50,6 +50,10 @@ import { formatTokenAmount, formatTokenAmountWithUnit, shortAssetId, tokenUnitsF
|
|
|
50
50
|
import { abbreviateKey } from '../../../core/pay/counterparty'
|
|
51
51
|
import type { ContactRow } from '../../../core/contacts/contactsStore'
|
|
52
52
|
import { createHandleRegistryClient } from '../../../core/identity/handleRegistry/client'
|
|
53
|
+
import { createRegistryResolver } from '../../../core/identity/handleRegistry/resolver'
|
|
54
|
+
import { cancelPaymailPayment, retryPaymailDelivery } from '../../../core/pay/rails/paymail'
|
|
55
|
+
import { createLegacyPaymailClient } from '../../../core/pay/paymail/client'
|
|
56
|
+
import { statusFnFromStorage } from '../../../core/pay/paymail/networkCheck'
|
|
53
57
|
import type { RegistryProfile } from '../../../core/identity/handleRegistry/profileCert'
|
|
54
58
|
import {
|
|
55
59
|
useTheme,
|
|
@@ -74,6 +78,7 @@ import {
|
|
|
74
78
|
sendToAddress,
|
|
75
79
|
getOutboxEntries,
|
|
76
80
|
pruneExpiredSent,
|
|
81
|
+
isPaymailEntry,
|
|
77
82
|
type OutboxEntry,
|
|
78
83
|
type Session,
|
|
79
84
|
haptics,
|
|
@@ -174,7 +179,9 @@ function OutgoingSection({
|
|
|
174
179
|
const truncated =
|
|
175
180
|
entry.status === 'import_hold'
|
|
176
181
|
? t('review_imported_payment')
|
|
177
|
-
:
|
|
182
|
+
: isPaymailEntry(entry)
|
|
183
|
+
? entry.paymail
|
|
184
|
+
: `${entry.recipient.slice(0, 8)}…${entry.recipient.slice(-4)}`
|
|
178
185
|
return (
|
|
179
186
|
<View
|
|
180
187
|
key={entry.id}
|
|
@@ -192,7 +199,7 @@ function OutgoingSection({
|
|
|
192
199
|
</Text>
|
|
193
200
|
{entry.status !== 'import_hold' && (
|
|
194
201
|
<Text style={[styles.outgoingAmount, { color: accentColor }]}>
|
|
195
|
-
<AmountDisplay>{entry.token.amount}</AmountDisplay>
|
|
202
|
+
<AmountDisplay>{isPaymailEntry(entry) ? entry.satoshis : entry.token.amount}</AmountDisplay>
|
|
196
203
|
</Text>
|
|
197
204
|
)}
|
|
198
205
|
</View>
|
|
@@ -369,6 +376,17 @@ function UniversalSendInner(
|
|
|
369
376
|
[registryDomain, registryUrl]
|
|
370
377
|
)
|
|
371
378
|
|
|
379
|
+
// The paymail rail's resolver and client, one per screen.
|
|
380
|
+
const paymailClient = useMemo(
|
|
381
|
+
() =>
|
|
382
|
+
createLegacyPaymailClient({
|
|
383
|
+
resolver: createRegistryResolver({
|
|
384
|
+
pinned: registryDomain && registryUrl ? { domain: registryDomain, url: registryUrl } : undefined
|
|
385
|
+
})
|
|
386
|
+
}),
|
|
387
|
+
[registryDomain, registryUrl]
|
|
388
|
+
)
|
|
389
|
+
|
|
372
390
|
// ── the asset axis ──────────────────────────────────────────────────
|
|
373
391
|
// Every line below is gated on `asset`: with no token held, `balances` is
|
|
374
392
|
// empty, `asset` is null, the picker renders nothing and this form is
|
|
@@ -1184,6 +1202,31 @@ function UniversalSendInner(
|
|
|
1184
1202
|
async (entry: OutboxEntry) => {
|
|
1185
1203
|
// Held rows can become actionable only through the validated inline approval.
|
|
1186
1204
|
if (entry.status !== 'unsent') return
|
|
1205
|
+
if (isPaymailEntry(entry)) {
|
|
1206
|
+
if (!storage || !wallet) return
|
|
1207
|
+
if (entry.refused === true) {
|
|
1208
|
+
showToast('The receiver refused this payment. Cancel it to free the funds.', { type: 'error' })
|
|
1209
|
+
return
|
|
1210
|
+
}
|
|
1211
|
+
setRetryingId(entry.id)
|
|
1212
|
+
try {
|
|
1213
|
+
await retryPaymailDelivery({
|
|
1214
|
+
wallet: wallet as never,
|
|
1215
|
+
adminOriginator,
|
|
1216
|
+
storage,
|
|
1217
|
+
client: paymailClient,
|
|
1218
|
+
getStatusForTxids: statusFnFromStorage(storage as never),
|
|
1219
|
+
entry
|
|
1220
|
+
})
|
|
1221
|
+
} catch (e: any) {
|
|
1222
|
+
const reason = e?.message || t('unknown_error')
|
|
1223
|
+
showToast(`${t('retry_failed')}: ${reason}`, { type: 'error' })
|
|
1224
|
+
} finally {
|
|
1225
|
+
setRetryingId(null)
|
|
1226
|
+
await loadOutbox()
|
|
1227
|
+
}
|
|
1228
|
+
return
|
|
1229
|
+
}
|
|
1187
1230
|
// `peerPayClient` is built from the CURRENT setting, so it wins: the
|
|
1188
1231
|
// configured host may have changed since this entry was minted, and the
|
|
1189
1232
|
// client re-resolves the recipient's advertised inbox on every send
|
|
@@ -1214,12 +1257,40 @@ function UniversalSendInner(
|
|
|
1214
1257
|
await loadOutbox()
|
|
1215
1258
|
}
|
|
1216
1259
|
},
|
|
1217
|
-
[peerPayClient, storage, loadOutbox, wallet, adminOriginator, t, handleRetryError, selectedNetwork]
|
|
1260
|
+
[peerPayClient, paymailClient, storage, loadOutbox, wallet, adminOriginator, t, handleRetryError, selectedNetwork]
|
|
1218
1261
|
)
|
|
1219
1262
|
|
|
1220
1263
|
const handleCancel = useCallback(
|
|
1221
1264
|
async (entry: OutboxEntry) => {
|
|
1222
1265
|
if (!storage || !wallet) return
|
|
1266
|
+
if (isPaymailEntry(entry)) {
|
|
1267
|
+
// No abandon sheet and no delivered branch: the network decides.
|
|
1268
|
+
const choice = await showAlert({
|
|
1269
|
+
title: t('cancel_this_payment'),
|
|
1270
|
+
buttons: [
|
|
1271
|
+
{ text: t('cancel'), style: 'cancel', key: 'cancel' },
|
|
1272
|
+
{ text: t('cancel_payment'), style: 'destructive', key: 'cancel_payment' }
|
|
1273
|
+
]
|
|
1274
|
+
})
|
|
1275
|
+
if (choice !== 'cancel_payment') return
|
|
1276
|
+
setRetryingId(entry.id)
|
|
1277
|
+
try {
|
|
1278
|
+
await cancelPaymailPayment({
|
|
1279
|
+
wallet: wallet as never,
|
|
1280
|
+
adminOriginator,
|
|
1281
|
+
storage,
|
|
1282
|
+
client: paymailClient,
|
|
1283
|
+
getStatusForTxids: statusFnFromStorage(storage as never),
|
|
1284
|
+
entry
|
|
1285
|
+
})
|
|
1286
|
+
} catch (e: any) {
|
|
1287
|
+
showToast(e?.message || t('unknown_error'), { type: 'error' })
|
|
1288
|
+
} finally {
|
|
1289
|
+
setRetryingId(null)
|
|
1290
|
+
await loadOutbox()
|
|
1291
|
+
}
|
|
1292
|
+
return
|
|
1293
|
+
}
|
|
1223
1294
|
const deliveredOrUncertain = entry.delivered === true || entry.delivering === true
|
|
1224
1295
|
if (deliveredOrUncertain) {
|
|
1225
1296
|
const key = await showChoiceSheet({
|
|
@@ -1270,7 +1341,7 @@ function UniversalSendInner(
|
|
|
1270
1341
|
await loadOutbox()
|
|
1271
1342
|
}
|
|
1272
1343
|
},
|
|
1273
|
-
[storage, wallet, adminOriginator, peerPayClient, handleRetry, loadOutbox, t]
|
|
1344
|
+
[storage, wallet, adminOriginator, peerPayClient, paymailClient, handleRetry, loadOutbox, t]
|
|
1274
1345
|
)
|
|
1275
1346
|
|
|
1276
1347
|
// Token mode: an exact bigint figure (a number would round past 2^53).
|
|
@@ -62,6 +62,7 @@ import {
|
|
|
62
62
|
getOnline,
|
|
63
63
|
haptics,
|
|
64
64
|
getOutboxEntries,
|
|
65
|
+
isPeerPayEntry,
|
|
65
66
|
unsentEntries,
|
|
66
67
|
retryDelivery,
|
|
67
68
|
makePeerPayClient,
|
|
@@ -75,6 +76,12 @@ import {
|
|
|
75
76
|
type PendingResend
|
|
76
77
|
} from '@bsv/expo-wallet-toolbox'
|
|
77
78
|
import { NETWORKS } from '../../core/networks'
|
|
79
|
+
import { isPaymailEntry } from '../../core/peerpay/outbox'
|
|
80
|
+
import { getHandleRegistryConfig } from '../../core/toolboxConfig'
|
|
81
|
+
import { cancelPaymailPayment, resolveOrphanPaymailAction, retryPaymailDelivery } from '../../core/pay/rails/paymail'
|
|
82
|
+
import { createLegacyPaymailClient } from '../../core/pay/paymail/client'
|
|
83
|
+
import { statusFnFromStorage } from '../../core/pay/paymail/networkCheck'
|
|
84
|
+
import { createRegistryResolver } from '../../core/identity/handleRegistry/resolver'
|
|
78
85
|
import { bindMessageBoxNetwork, readMessageBoxUrl } from '../../core/pay/rails/handle'
|
|
79
86
|
import ActivityRow, { type ActivityAction } from '../components/wallet/ActivityRow'
|
|
80
87
|
import { FitAmount } from '../components/wallet/FitAmount'
|
|
@@ -1017,6 +1024,11 @@ export function WalletHomeScreen({ topLeft }: WalletHomeScreenProps = {}) {
|
|
|
1017
1024
|
[busyRow, refreshProof, t]
|
|
1018
1025
|
)
|
|
1019
1026
|
|
|
1027
|
+
const paymailClient = useMemo(() => {
|
|
1028
|
+
const registry = getHandleRegistryConfig(selectedNetwork)
|
|
1029
|
+
return createLegacyPaymailClient({ resolver: createRegistryResolver({ pinned: registry }) })
|
|
1030
|
+
}, [selectedNetwork])
|
|
1031
|
+
|
|
1020
1032
|
/**
|
|
1021
1033
|
* Abort a still-local transaction, releasing the inputs it reserved.
|
|
1022
1034
|
*
|
|
@@ -1032,12 +1044,68 @@ export function WalletHomeScreen({ topLeft }: WalletHomeScreenProps = {}) {
|
|
|
1032
1044
|
if (!managers.permissionsManager || busyRow) return
|
|
1033
1045
|
setBusyRow(reference)
|
|
1034
1046
|
try {
|
|
1035
|
-
if (action?.labels?.
|
|
1047
|
+
if (action?.labels?.some(l => l === 'peerpay' || l === 'paymail')) {
|
|
1036
1048
|
const entries = storage ? await getOutboxEntries(storage) : []
|
|
1049
|
+
const isPaymail = action.labels?.includes('paymail') === true
|
|
1050
|
+
const hasRow = action.txid != null && entries.some(e => e.txid === action.txid)
|
|
1051
|
+
if (isPaymail && !hasRow) {
|
|
1052
|
+
// A noSend paymail action with no row (a crash or a restore): the
|
|
1053
|
+
// network decides, and abortAction is never called directly.
|
|
1054
|
+
if (!action.txid || !storage) {
|
|
1055
|
+
showToast(t('tx_abort_maybe_delivered'), { type: 'error' })
|
|
1056
|
+
return
|
|
1057
|
+
}
|
|
1058
|
+
try {
|
|
1059
|
+
const r = await resolveOrphanPaymailAction({
|
|
1060
|
+
wallet: managers.permissionsManager as never,
|
|
1061
|
+
adminOriginator,
|
|
1062
|
+
getStatusForTxids: statusFnFromStorage(storage as never),
|
|
1063
|
+
txid: action.txid
|
|
1064
|
+
})
|
|
1065
|
+
if (r.aborted) {
|
|
1066
|
+
showToast(t('tx_abort_success'), { type: 'success' })
|
|
1067
|
+
await onRefresh()
|
|
1068
|
+
} else {
|
|
1069
|
+
showToast(t('tx_abort_maybe_delivered'), { type: 'error' })
|
|
1070
|
+
}
|
|
1071
|
+
} catch (e) {
|
|
1072
|
+
showToast(e instanceof Error ? e.message : t('tx_abort_failed'), { type: 'error' })
|
|
1073
|
+
}
|
|
1074
|
+
return
|
|
1075
|
+
}
|
|
1037
1076
|
if (!isAbortSafe(action, entries).aborted) {
|
|
1038
1077
|
showToast(t('tx_abort_maybe_delivered'), { type: 'error' })
|
|
1039
1078
|
return
|
|
1040
1079
|
}
|
|
1080
|
+
const paymailRow = isPaymail ? entries.find(e => e.txid === action.txid && isPaymailEntry(e)) : undefined
|
|
1081
|
+
if (paymailRow && isPaymailEntry(paymailRow)) {
|
|
1082
|
+
// A paymail row survives a plain abort and the drain would re-POST
|
|
1083
|
+
// its BEEF over freed inputs. Network decides; abort removes the row.
|
|
1084
|
+
if (!storage) {
|
|
1085
|
+
showToast(t('tx_abort_maybe_delivered'), { type: 'error' })
|
|
1086
|
+
return
|
|
1087
|
+
}
|
|
1088
|
+
try {
|
|
1089
|
+
const r = await cancelPaymailPayment({
|
|
1090
|
+
wallet: managers.permissionsManager as never,
|
|
1091
|
+
adminOriginator,
|
|
1092
|
+
storage,
|
|
1093
|
+
client: paymailClient,
|
|
1094
|
+
getStatusForTxids: statusFnFromStorage(storage as never),
|
|
1095
|
+
entry: paymailRow
|
|
1096
|
+
})
|
|
1097
|
+
if (r.aborted) {
|
|
1098
|
+
showToast(t('tx_abort_success'), { type: 'success' })
|
|
1099
|
+
await onRefresh()
|
|
1100
|
+
} else {
|
|
1101
|
+
showToast(t('tx_abort_maybe_delivered'), { type: 'error' })
|
|
1102
|
+
await onRefresh()
|
|
1103
|
+
}
|
|
1104
|
+
} catch (e) {
|
|
1105
|
+
showToast(e instanceof Error ? e.message : t('tx_abort_failed'), { type: 'error' })
|
|
1106
|
+
}
|
|
1107
|
+
return
|
|
1108
|
+
}
|
|
1041
1109
|
}
|
|
1042
1110
|
const r = (await managers.permissionsManager.abortAction({ reference }, adminOriginator)) as
|
|
1043
1111
|
| { aborted?: boolean }
|
|
@@ -1055,7 +1123,7 @@ export function WalletHomeScreen({ topLeft }: WalletHomeScreenProps = {}) {
|
|
|
1055
1123
|
setBusyLabel(undefined)
|
|
1056
1124
|
}
|
|
1057
1125
|
},
|
|
1058
|
-
[managers.permissionsManager, adminOriginator, busyRow, onRefresh, storage, t]
|
|
1126
|
+
[managers.permissionsManager, adminOriginator, busyRow, onRefresh, storage, t, paymailClient]
|
|
1059
1127
|
)
|
|
1060
1128
|
|
|
1061
1129
|
const onResendPending = useCallback(async () => {
|
|
@@ -1202,11 +1270,43 @@ export function WalletHomeScreen({ topLeft }: WalletHomeScreenProps = {}) {
|
|
|
1202
1270
|
]
|
|
1203
1271
|
)
|
|
1204
1272
|
|
|
1273
|
+
// The paymail rail's resolver and client, one per screen.
|
|
1205
1274
|
const onFailedSendAgain = useCallback(
|
|
1206
1275
|
async (action: ActivityAction) => {
|
|
1207
1276
|
if (busyRow) return
|
|
1208
1277
|
if (action.txid && storage && managers.permissionsManager) {
|
|
1209
|
-
const
|
|
1278
|
+
const paymailRow = unsentEntries(await getOutboxEntries(storage))
|
|
1279
|
+
.filter(isPaymailEntry)
|
|
1280
|
+
.find(e => e.txid === action.txid)
|
|
1281
|
+
if (paymailRow?.refused === true) {
|
|
1282
|
+
// The retry is a no-op for a refused row. Say so, do not fake success.
|
|
1283
|
+
showToast(t('paymail_refused_cancel_hint', { defaultValue: 'The receiver refused this payment. Cancel it to free the funds.' }), { type: 'error' })
|
|
1284
|
+
return
|
|
1285
|
+
}
|
|
1286
|
+
if (paymailRow) {
|
|
1287
|
+
// A paymail row has no message box: never build a PeerPay client for it.
|
|
1288
|
+
setBusyRow(action.txid)
|
|
1289
|
+
try {
|
|
1290
|
+
await retryPaymailDelivery({
|
|
1291
|
+
wallet: managers.permissionsManager as never,
|
|
1292
|
+
adminOriginator,
|
|
1293
|
+
storage,
|
|
1294
|
+
client: paymailClient,
|
|
1295
|
+
getStatusForTxids: statusFnFromStorage(storage as never),
|
|
1296
|
+
entry: paymailRow
|
|
1297
|
+
})
|
|
1298
|
+
haptics.success()
|
|
1299
|
+
await onRefresh()
|
|
1300
|
+
} catch (e: unknown) {
|
|
1301
|
+
showToast(e instanceof Error ? e.message : t('unknown_error'), { type: 'error' })
|
|
1302
|
+
} finally {
|
|
1303
|
+
setBusyRow(null)
|
|
1304
|
+
}
|
|
1305
|
+
return
|
|
1306
|
+
}
|
|
1307
|
+
const entry = unsentEntries(await getOutboxEntries(storage))
|
|
1308
|
+
.filter(isPeerPayEntry)
|
|
1309
|
+
.find(e => e.txid === action.txid)
|
|
1210
1310
|
if (entry) {
|
|
1211
1311
|
setBusyRow(action.txid)
|
|
1212
1312
|
try {
|
|
@@ -1252,7 +1352,7 @@ export function WalletHomeScreen({ topLeft }: WalletHomeScreenProps = {}) {
|
|
|
1252
1352
|
const sats = Math.abs(action.satoshis)
|
|
1253
1353
|
router.push(sats > 0 ? `/pay?sats=${sats}` : '/pay')
|
|
1254
1354
|
},
|
|
1255
|
-
[busyRow, storage, managers.permissionsManager, adminOriginator, selectedNetwork, onRefresh, t]
|
|
1355
|
+
[busyRow, storage, managers.permissionsManager, adminOriginator, selectedNetwork, onRefresh, paymailClient, t]
|
|
1256
1356
|
)
|
|
1257
1357
|
|
|
1258
1358
|
const toggleRow = useCallback((key: string) => {
|
package/ui/txStatus.ts
CHANGED
|
@@ -32,7 +32,7 @@ export interface TxStatusView {
|
|
|
32
32
|
* without one was made by a connected app or the wallet itself (an identity
|
|
33
33
|
* certificate, say), so it reads "Spent", not "Sent".
|
|
34
34
|
*/
|
|
35
|
-
const PAYMENT_LABELS = new Set(['peerpay', 'localpay', 'legacy', 'mandala'])
|
|
35
|
+
const PAYMENT_LABELS = new Set(['peerpay', 'localpay', 'legacy', 'mandala', 'paymail'])
|
|
36
36
|
|
|
37
37
|
export function isPaymentAction(labels?: readonly string[]): boolean {
|
|
38
38
|
return Boolean(labels?.some(l => PAYMENT_LABELS.has(l)))
|