@bsv/expo-wallet-toolbox 0.2.1 → 0.3.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/README.md +26 -1
- package/core/amountFormatHelpers.ts +16 -30
- package/core/context/WalletContext.tsx +15 -3
- package/core/index.ts +16 -5
- package/core/localpay/build.ts +4 -1
- package/core/localpay/pending.ts +5 -2
- package/core/pay/counterparty.ts +159 -0
- package/core/pay/creditInbox.ts +0 -3
- package/core/pay/patp.ts +181 -0
- package/core/pay/rails/address.ts +47 -7
- package/core/pay/rails/handle.ts +24 -14
- package/core/peerpay/handleResendRequests.ts +1 -2
- package/core/storage/StorageExpoSQLite.ts +37 -0
- package/core/storage/methods/listActionsSql.ts +9 -0
- package/core/theme/sigilPalette.ts +83 -0
- package/package.json +3 -1
- package/ui/components/pay/HandleReceive.tsx +4 -4
- package/ui/components/ui/AppLogo.tsx +9 -1
- package/ui/components/ui/Sigil.tsx +62 -0
- package/ui/components/wallet/ActivityRow.tsx +87 -24
- package/ui/isImageUrl.ts +16 -3
- package/ui/screens/TrustScreen.tsx +105 -23
- package/ui/screens/WalletCheckScreen.tsx +3 -3
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
type WalletProtocol
|
|
23
23
|
} from '@bsv/sdk'
|
|
24
24
|
import type { AppChain } from '../../config'
|
|
25
|
+
import { abbreviateKey, addressLabel, FROM_ADDRESS_LABEL_PREFIX, TO_ADDRESS_LABEL_PREFIX } from '../counterparty'
|
|
25
26
|
import { isValidBsvAddress } from './index'
|
|
26
27
|
|
|
27
28
|
export const BRC29_PROTOCOL_ID: WalletProtocol = [2, '3241645161d8']
|
|
@@ -215,14 +216,41 @@ export function parseWocBeefBody(resp: { ok: boolean; text: string }): number[]
|
|
|
215
216
|
}
|
|
216
217
|
}
|
|
217
218
|
|
|
219
|
+
/**
|
|
220
|
+
* The address a conventional wallet paid from, read off the zeroth input's
|
|
221
|
+
* P2PKH unlocking script: a signature push followed by a 33-byte compressed
|
|
222
|
+
* key. That is the only place the sweep can learn anything about the payer,
|
|
223
|
+
* since the remittance carries a sentinel sender rather than a real one.
|
|
224
|
+
* Anything else (coinbase, unsigned, multisig, a key that will not parse)
|
|
225
|
+
* yields undefined so the caller falls back to a generic description instead
|
|
226
|
+
* of guessing at a face; a throw here would count a good payment as failed.
|
|
227
|
+
*/
|
|
228
|
+
export function payerAddressOf(tx: Transaction, network: 'mainnet' | 'testnet' = 'mainnet'): string | undefined {
|
|
229
|
+
const chunks = tx.inputs[0]?.unlockingScript?.chunks
|
|
230
|
+
if (chunks === undefined || chunks.length !== 2) return undefined
|
|
231
|
+
const key = chunks[1].data
|
|
232
|
+
if (key === undefined || key.length !== 33 || (key[0] !== 0x02 && key[0] !== 0x03)) return undefined
|
|
233
|
+
try {
|
|
234
|
+
return PublicKey.fromString(Utils.toHex(key)).toAddress(network)
|
|
235
|
+
} catch {
|
|
236
|
+
return undefined
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
218
240
|
/**
|
|
219
241
|
* The sweep. Ported from legacy-payments.tsx's handleImportFunds with one
|
|
220
|
-
* change
|
|
242
|
+
* change to its trigger. What it writes has since grown a payer-facing
|
|
243
|
+
* description and a `from:` label so the activity list can name and draw the
|
|
244
|
+
* payer; both are additive and derived, and the dedup contract below is
|
|
245
|
+
* untouched. The label carries the address as hex (see addressLabel): the
|
|
246
|
+
* wallet lower-cases labels on the way in, which base58 does not survive.
|
|
221
247
|
*
|
|
222
248
|
* The sentinel sender key (PrivateKey(1)'s public key) and the label list are
|
|
223
249
|
* both load-bearing: the labels are how getInternalizedUtxos recognises what
|
|
224
|
-
* has already been imported, and the address label in particular is what
|
|
225
|
-
* a second sweep a no-op instead of a double credit.
|
|
250
|
+
* has already been imported, and the bare address label in particular is what
|
|
251
|
+
* makes a second sweep a no-op instead of a double credit. The `from:` label
|
|
252
|
+
* is a different string from the bare address, so the `labelQueryMode: 'all'`
|
|
253
|
+
* lookups and the `ts:` parse in getProcessedTransactions never see it.
|
|
226
254
|
*
|
|
227
255
|
* Each UTXO is fetched and internalized in its own try/catch so one bad BEEF
|
|
228
256
|
* cannot skip the rest of the address.
|
|
@@ -275,11 +303,21 @@ export async function sweepAddress(args: {
|
|
|
275
303
|
derivationSuffix: LEGACY_DERIVATION_SUFFIX
|
|
276
304
|
}
|
|
277
305
|
}))
|
|
306
|
+
// Same network the rail derives its own receive addresses on, so payer
|
|
307
|
+
// and payee addresses read consistently in one history.
|
|
308
|
+
const payerAddress = payerAddressOf(tx, woc.network)
|
|
278
309
|
const internalizeArgs: InternalizeActionArgs = {
|
|
279
310
|
tx: tx.toAtomicBEEF(),
|
|
280
|
-
description: 'Payment to your address',
|
|
311
|
+
description: payerAddress !== undefined ? abbreviateKey(payerAddress) : 'Payment to your address',
|
|
281
312
|
outputs,
|
|
282
|
-
labels: [
|
|
313
|
+
labels: [
|
|
314
|
+
'legacy',
|
|
315
|
+
'inbound',
|
|
316
|
+
'bsvbrowser',
|
|
317
|
+
address,
|
|
318
|
+
`ts:${nowSeconds}`,
|
|
319
|
+
...(payerAddress !== undefined ? [addressLabel(FROM_ADDRESS_LABEL_PREFIX, payerAddress)] : [])
|
|
320
|
+
]
|
|
283
321
|
}
|
|
284
322
|
const response = await wallet.internalizeAction(internalizeArgs, adminOriginator)
|
|
285
323
|
if (response?.accepted) importedSatoshis += relevant.reduce((sum, o) => sum + o.satoshis, 0)
|
|
@@ -313,9 +351,11 @@ export async function sendToAddress(args: {
|
|
|
313
351
|
const isSendMax = sats === 2099999999999999
|
|
314
352
|
const result = (await wallet.createAction(
|
|
315
353
|
{
|
|
316
|
-
|
|
354
|
+
// The recipient's address is the description so the activity list has a
|
|
355
|
+
// name for the row without a lookup; the to: label is what lets it draw a face.
|
|
356
|
+
description: abbreviateKey(address),
|
|
317
357
|
outputs: [{ lockingScript, satoshis: sats, outputDescription: 'BSV for recipient address' }],
|
|
318
|
-
labels: ['legacy', 'outbound'],
|
|
358
|
+
labels: ['legacy', 'outbound', addressLabel(TO_ADDRESS_LABEL_PREFIX, address)],
|
|
319
359
|
...(isSendMax ? { options: { randomizeOutputs: false } } : {})
|
|
320
360
|
},
|
|
321
361
|
adminOriginator
|
package/core/pay/rails/handle.ts
CHANGED
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
type OutboxEntry
|
|
21
21
|
} from '../../peerpay/outbox'
|
|
22
22
|
import type { CreditFailureKind } from '../creditErrors'
|
|
23
|
+
import { abbreviateKey } from '../counterparty'
|
|
23
24
|
import { isDuplicateMessageError, sendControlMessage, type ResendReason } from '../../peerpay/control'
|
|
24
25
|
import { TaskDrainOutbox } from '../../monitor/TaskDrainOutbox'
|
|
25
26
|
|
|
@@ -85,6 +86,12 @@ export function peerPayLinkFor(identityKey: string, sats?: number, messageBoxUrl
|
|
|
85
86
|
/**
|
|
86
87
|
* Credit an incoming payment, then acknowledge it. Never acknowledge first.
|
|
87
88
|
*
|
|
89
|
+
* The recorded description is the note the sender attached to the token or,
|
|
90
|
+
* failing that, the sender's abbreviated identity key: the same default the
|
|
91
|
+
* sending wallet wrote for the recipient, so both sides name one payment the
|
|
92
|
+
* same way. The sender is not added to the labels; the activity list recovers
|
|
93
|
+
* the counterparty from the output's senderIdentityKey instead.
|
|
94
|
+
*
|
|
88
95
|
* `repairBeef` is the second chance. The token's AtomicBEEF was minted at send
|
|
89
96
|
* time, and a reorg between then and now invalidates its merkle path without
|
|
90
97
|
* touching the transaction itself — the toolbox reports that as
|
|
@@ -97,13 +104,16 @@ export async function internalizeIncoming(
|
|
|
97
104
|
client: Pick<PeerPayClient, 'acknowledgeMessage'>,
|
|
98
105
|
adminOriginator: string,
|
|
99
106
|
payment: IncomingPayment,
|
|
100
|
-
description: string,
|
|
101
107
|
repairBeef?: (txid: string) => Promise<number[] | undefined>
|
|
102
108
|
): Promise<void> {
|
|
103
109
|
// A note the sender attached to the token becomes the description the
|
|
104
|
-
// recipient's wallet records
|
|
110
|
+
// recipient's wallet records, the same field the sender's action carries.
|
|
105
111
|
const note = (payment.token as { note?: unknown }).note
|
|
106
112
|
const noted = typeof note === 'string' && note.trim().length > 0 ? note.trim().slice(0, 500) : undefined
|
|
113
|
+
// Same rule as the sender's side: the note verbatim, space-padded to the
|
|
114
|
+
// 5-byte validation floor when it is shorter. The abbreviated key is 13
|
|
115
|
+
// characters, so it never needs padding.
|
|
116
|
+
const description = noted ? noted.padEnd(5) : abbreviateKey(payment.sender)
|
|
107
117
|
|
|
108
118
|
const argsFor = (tx: number[] | typeof payment.token.transaction) => ({
|
|
109
119
|
tx,
|
|
@@ -119,9 +129,7 @@ export async function internalizeIncoming(
|
|
|
119
129
|
}
|
|
120
130
|
],
|
|
121
131
|
labels: ['peerpay'],
|
|
122
|
-
|
|
123
|
-
// 5-byte validation floor when it is shorter.
|
|
124
|
-
description: noted ? noted.padEnd(5) : description
|
|
132
|
+
description
|
|
125
133
|
})
|
|
126
134
|
|
|
127
135
|
try {
|
|
@@ -185,15 +193,14 @@ export async function acceptWithRetry(
|
|
|
185
193
|
client: Pick<PeerPayClient, 'listIncomingPayments'>,
|
|
186
194
|
messageBoxUrl: string,
|
|
187
195
|
payment: IncomingPayment,
|
|
188
|
-
|
|
189
|
-
internalize: (p: IncomingPayment, d: string) => Promise<void>
|
|
196
|
+
internalize: (p: IncomingPayment) => Promise<void>
|
|
190
197
|
): Promise<void> {
|
|
191
198
|
void client
|
|
192
199
|
void messageBoxUrl
|
|
193
200
|
try {
|
|
194
|
-
await internalize(payment
|
|
201
|
+
await internalize(payment)
|
|
195
202
|
} catch {
|
|
196
|
-
await internalize(payment
|
|
203
|
+
await internalize(payment)
|
|
197
204
|
}
|
|
198
205
|
}
|
|
199
206
|
|
|
@@ -403,12 +410,15 @@ export async function sendViaHandle(args: {
|
|
|
403
410
|
// advertised host when there is one and otherwise falls back to the host this
|
|
404
411
|
// wallet is configured for, which is where both parties' apps look by default.
|
|
405
412
|
|
|
406
|
-
// The note IS the description when one was given
|
|
407
|
-
//
|
|
408
|
-
//
|
|
409
|
-
//
|
|
413
|
+
// The note IS the description when one was given, verbatim; otherwise the
|
|
414
|
+
// recipient's name, or their abbreviated key. No "Pay" prefix: the activity
|
|
415
|
+
// row already shows the direction, and the receive side records the sender
|
|
416
|
+
// the same way, so both wallets name one payment alike. BRC-100 requires
|
|
417
|
+
// 5-2000 bytes and the validator does not trim, so a very short note is
|
|
418
|
+
// padded with trailing spaces rather than decorated, and everything is
|
|
419
|
+
// clamped at the top end.
|
|
410
420
|
const note = args.note?.trim() || undefined
|
|
411
|
-
const description = (note ??
|
|
421
|
+
const description = (note ?? (recipientName?.trim() || abbreviateKey(recipient))).slice(0, 500).padEnd(5)
|
|
412
422
|
|
|
413
423
|
// Standard BRC-29: fresh prefix/suffix, key derived toward the recipient.
|
|
414
424
|
const derivationPrefix = Utils.toBase64(Random(8))
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Beef } from '@bsv/sdk'
|
|
2
|
+
import { PUBKEY_LABEL } from '../pay/counterparty'
|
|
2
3
|
import {
|
|
3
4
|
ackControlMessages,
|
|
4
5
|
isDuplicateMessageError,
|
|
@@ -14,8 +15,6 @@ const PAYMENT_INBOX = 'payment_inbox'
|
|
|
14
15
|
/** Stored unanswered `resend_request`s so Home can show a banner without re-listing. */
|
|
15
16
|
export const UNANSWERED_RESENDS_KEY = 'peerpay_unanswered_resends'
|
|
16
17
|
|
|
17
|
-
const PUBKEY_LABEL = /^(02|03)[0-9a-fA-F]{64}$/
|
|
18
|
-
|
|
19
18
|
/**
|
|
20
19
|
* Rail labels an outbound payment can carry. Both are resendable: each writes
|
|
21
20
|
* the payee's identity key as a label and BRC-29 derivation data as the
|
|
@@ -103,6 +103,13 @@ export interface StorageExpoSQLiteOptions extends StorageProviderOptions {
|
|
|
103
103
|
/** Per-connection wait before a lock contention becomes "database is locked". */
|
|
104
104
|
export const BUSY_TIMEOUT_MS = 5000
|
|
105
105
|
|
|
106
|
+
/**
|
|
107
|
+
* The lowest SQLITE_MAX_VARIABLE_NUMBER a shipped SQLite still enforces. Any
|
|
108
|
+
* IN (...) list built from caller data is split at this size so a large page
|
|
109
|
+
* can never turn into "too many SQL variables".
|
|
110
|
+
*/
|
|
111
|
+
const SQLITE_MAX_BOUND_VARIABLES = 999
|
|
112
|
+
|
|
106
113
|
/**
|
|
107
114
|
* The token `transaction()` hands its scope. Carrying the connection on the
|
|
108
115
|
* token is what lets `getDB(trx)` route a statement to the transaction without
|
|
@@ -1687,6 +1694,36 @@ export class StorageExpoSQLite extends StorageProvider {
|
|
|
1687
1694
|
return this.validateEntities(rows, undefined, ['isDeleted'])
|
|
1688
1695
|
}
|
|
1689
1696
|
|
|
1697
|
+
/**
|
|
1698
|
+
* The payer's identity key for each of a page of transactions, keyed by
|
|
1699
|
+
* transactionId. The key is recorded per output, not per transaction, so this
|
|
1700
|
+
* reads the whole page's outputs in one round trip and keeps the lowest-vout
|
|
1701
|
+
* non-empty key per transaction; transactions with no keyed output are absent
|
|
1702
|
+
* from the map. The sentinel key the address sweep writes is deliberately NOT
|
|
1703
|
+
* filtered here: what counts as a real counterparty is a presentation
|
|
1704
|
+
* decision that belongs to the caller.
|
|
1705
|
+
*/
|
|
1706
|
+
async getSenderIdentityKeysForTransactionIds(transactionIds: number[], trx?: TrxToken): Promise<Map<number, string>> {
|
|
1707
|
+
const keys = new Map<number, string>()
|
|
1708
|
+
if (transactionIds.length === 0) return keys
|
|
1709
|
+
const db = this.getDB(trx)
|
|
1710
|
+
type Row = { transactionId: number; senderIdentityKey: string }
|
|
1711
|
+
for (let i = 0; i < transactionIds.length; i += SQLITE_MAX_BOUND_VARIABLES) {
|
|
1712
|
+
const chunk = transactionIds.slice(i, i + SQLITE_MAX_BOUND_VARIABLES)
|
|
1713
|
+
const rows = (await db.getAllAsync(
|
|
1714
|
+
`SELECT transactionId, senderIdentityKey FROM outputs
|
|
1715
|
+
WHERE transactionId IN (${chunk.map(() => '?').join(',')})
|
|
1716
|
+
AND senderIdentityKey IS NOT NULL AND senderIdentityKey != ''
|
|
1717
|
+
ORDER BY transactionId, vout`,
|
|
1718
|
+
chunk
|
|
1719
|
+
)) as Row[]
|
|
1720
|
+
for (const row of rows) {
|
|
1721
|
+
if (!keys.has(row.transactionId)) keys.set(row.transactionId, row.senderIdentityKey)
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
return keys
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1690
1727
|
async getTagsForOutputId(outputId: number, trx?: TrxToken): Promise<TableOutputTag[]> {
|
|
1691
1728
|
const rows = await this.getDB(trx).getAllAsync(
|
|
1692
1729
|
`SELECT t.* FROM output_tags_map m JOIN output_tags t ON t.outputTagId = m.outputTagId
|
|
@@ -109,6 +109,11 @@ export async function listActionsSql(
|
|
|
109
109
|
await specOp.postProcess(storage, auth, vargs, specOpLabels, txs)
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
// The activity list identifies who paid us from the key stored on the
|
|
113
|
+
// transaction's outputs. One read covers the whole page rather than a
|
|
114
|
+
// findOutputs round trip per row.
|
|
115
|
+
const senderIdentityKeys = await storage.getSenderIdentityKeysForTransactionIds(txs.map(tx => tx.transactionId))
|
|
116
|
+
|
|
112
117
|
// Build action objects
|
|
113
118
|
for (const tx of txs) {
|
|
114
119
|
const wtx: any = {
|
|
@@ -126,6 +131,10 @@ export async function listActionsSql(
|
|
|
126
131
|
// `reference` already is.
|
|
127
132
|
created_at: tx.created_at
|
|
128
133
|
}
|
|
134
|
+
// Another extra, set only when a keyed output exists so consumers can tell
|
|
135
|
+
// "no sender recorded" from an empty string.
|
|
136
|
+
const senderIdentityKey = senderIdentityKeys.get(tx.transactionId)
|
|
137
|
+
if (senderIdentityKey !== undefined) wtx.senderIdentityKey = senderIdentityKey
|
|
129
138
|
r.actions.push(wtx)
|
|
130
139
|
}
|
|
131
140
|
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Colour for a counterparty's sigil tile. Every sigil used to be drawn in the
|
|
3
|
+
* text colour on a neutral tile, and at 38pt the shapes alone are too alike
|
|
4
|
+
* to tell one row from the next. A hue per counterparty gives each face its
|
|
5
|
+
* own tint, so the eye can pick out "the blue one" before it reads the glyph.
|
|
6
|
+
*
|
|
7
|
+
* The hue is whatever the caller derives (see counterpartyHue); this module
|
|
8
|
+
* only turns it into a pair of solids that stay readable at every hue in
|
|
9
|
+
* both themes. Saturation and lightness are fixed per theme rather than
|
|
10
|
+
* varied with the hue, so the tiles read as one family and not as a random
|
|
11
|
+
* scatter of swatches down the list.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export type SigilPalette = {
|
|
15
|
+
/** Symbol colour, six-digit lower-case hex. */
|
|
16
|
+
foreground: string
|
|
17
|
+
/**
|
|
18
|
+
* Tile colour, six-digit lower-case hex. Solid on purpose: sigil-js draws
|
|
19
|
+
* the cut-lines inside each glyph in this colour, so alpha would leave gaps.
|
|
20
|
+
*/
|
|
21
|
+
background: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type Tone = { s: number; l: number }
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Per-theme saturation and lightness, in percent. Light theme: a pale tint
|
|
28
|
+
* under a deep symbol. Dark theme: a deep tint under a bright symbol.
|
|
29
|
+
*
|
|
30
|
+
* The lightness values are pinned by the WCAG floor of 4.5:1 across all 360
|
|
31
|
+
* hues, which the palette test enforces. The weak spots are the hues whose
|
|
32
|
+
* luminance moves furthest for a given lightness: yellow (hue 60) is the
|
|
33
|
+
* brightest thing a light-theme symbol can be, so the foreground sits at 28%
|
|
34
|
+
* rather than 30% to keep 4.75:1 there; blue (hue 240) is the darkest thing a
|
|
35
|
+
* dark-theme symbol can be and clears 5.8:1 at 78%.
|
|
36
|
+
*/
|
|
37
|
+
const LIGHT: { background: Tone; foreground: Tone } = {
|
|
38
|
+
background: { s: 45, l: 92 },
|
|
39
|
+
foreground: { s: 55, l: 28 }
|
|
40
|
+
}
|
|
41
|
+
const DARK: { background: Tone; foreground: Tone } = {
|
|
42
|
+
background: { s: 35, l: 24 },
|
|
43
|
+
foreground: { s: 65, l: 78 }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Standard HSL to sRGB (CSS Color 3, section 4.2.4), then to `#rrggbb`. */
|
|
47
|
+
function hslToHex(hue: number, saturation: number, lightness: number): string {
|
|
48
|
+
const s = saturation / 100
|
|
49
|
+
const l = lightness / 100
|
|
50
|
+
const chroma = (1 - Math.abs(2 * l - 1)) * s
|
|
51
|
+
const sector = hue / 60
|
|
52
|
+
const x = chroma * (1 - Math.abs((sector % 2) - 1))
|
|
53
|
+
let r = 0
|
|
54
|
+
let g = 0
|
|
55
|
+
let b = 0
|
|
56
|
+
if (sector < 1) [r, g, b] = [chroma, x, 0]
|
|
57
|
+
else if (sector < 2) [r, g, b] = [x, chroma, 0]
|
|
58
|
+
else if (sector < 3) [r, g, b] = [0, chroma, x]
|
|
59
|
+
else if (sector < 4) [r, g, b] = [0, x, chroma]
|
|
60
|
+
else if (sector < 5) [r, g, b] = [x, 0, chroma]
|
|
61
|
+
else [r, g, b] = [chroma, 0, x]
|
|
62
|
+
const m = l - chroma / 2
|
|
63
|
+
const channel = (v: number) =>
|
|
64
|
+
Math.round((v + m) * 255)
|
|
65
|
+
.toString(16)
|
|
66
|
+
.padStart(2, '0')
|
|
67
|
+
return '#' + channel(r) + channel(g) + channel(b)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The symbol and tile colours for a hue in degrees. Any finite number is
|
|
72
|
+
* accepted and wrapped onto [0, 360), so -30 and 330 are the same tint; a
|
|
73
|
+
* non-finite hue (a NaN from a bad upstream parse) falls back to 0 rather than
|
|
74
|
+
* producing `#NaNNaNNaN` and a transparent tile.
|
|
75
|
+
*/
|
|
76
|
+
export function sigilPalette(hue: number, isDark: boolean): SigilPalette {
|
|
77
|
+
const h = Number.isFinite(hue) ? ((hue % 360) + 360) % 360 : 0
|
|
78
|
+
const tone = isDark ? DARK : LIGHT
|
|
79
|
+
return {
|
|
80
|
+
foreground: hslToHex(h, tone.foreground.s, tone.foreground.l),
|
|
81
|
+
background: hslToHex(h, tone.background.s, tone.background.l)
|
|
82
|
+
}
|
|
83
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bsv/expo-wallet-toolbox",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Wallet screens and P2P local-payment backend for Expo/React Native apps, extracted from BSV Wallet.",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"@react-native-async-storage/async-storage": "^2.2.0",
|
|
42
42
|
"@react-native-clipboard/clipboard": "^1.16.2",
|
|
43
43
|
"@react-native-community/netinfo": "^11.5.2",
|
|
44
|
+
"@urbit/sigil-js": "^2.2.0",
|
|
44
45
|
"date-fns": "^4.1.0",
|
|
45
46
|
"expo-audio": "~55.0.16",
|
|
46
47
|
"expo-blur": "~55.0.14",
|
|
@@ -51,6 +52,7 @@
|
|
|
51
52
|
"expo-document-picker": "~55.0.13",
|
|
52
53
|
"expo-file-system": "~55.0.20",
|
|
53
54
|
"expo-haptics": "~55.0.14",
|
|
55
|
+
"expo-image": "~55.0.11",
|
|
54
56
|
"expo-local-authentication": "~55.0.14",
|
|
55
57
|
"expo-localization": "~55.0.15",
|
|
56
58
|
"expo-print": "~55.0.15",
|
|
@@ -42,7 +42,7 @@ import { wocConfigFor } from '../../../core/pay/rails/address'
|
|
|
42
42
|
import { makeCreditClassifier } from '../../../core/pay/creditErrors'
|
|
43
43
|
import { satoshisFromToken } from '../../../core/pay/tokenAmount'
|
|
44
44
|
import { userFacingPayError } from '../../../core/pay/userError'
|
|
45
|
-
import { creditInboxOnce,
|
|
45
|
+
import { creditInboxOnce, type CreditInboxResult } from '../../../core/pay/creditInbox'
|
|
46
46
|
import { setReceiveInboxFocused } from '../../../core/pay/receiveFocus'
|
|
47
47
|
import { TaskCreditInbox } from '../../../core/monitor/TaskCreditInbox'
|
|
48
48
|
import { useOnline } from '../../hooks/useOnline'
|
|
@@ -468,10 +468,10 @@ export default function HandleReceive({
|
|
|
468
468
|
)
|
|
469
469
|
|
|
470
470
|
const internalize = useCallback(
|
|
471
|
-
async (payment: IncomingPayment
|
|
471
|
+
async (payment: IncomingPayment) => {
|
|
472
472
|
const client = peerPayClient
|
|
473
473
|
if (!client || !wallet) throw new Error(t('wallet_not_ready'))
|
|
474
|
-
await internalizeIncoming(wallet as any, client, adminOriginator, payment,
|
|
474
|
+
await internalizeIncoming(wallet as any, client, adminOriginator, payment, repairBeef)
|
|
475
475
|
},
|
|
476
476
|
[peerPayClient, wallet, adminOriginator, t, repairBeef]
|
|
477
477
|
)
|
|
@@ -510,7 +510,7 @@ export default function HandleReceive({
|
|
|
510
510
|
storage: storage ?? undefined,
|
|
511
511
|
force,
|
|
512
512
|
classify,
|
|
513
|
-
accept: payment => acceptWithRetry(client, messageBoxUrl, payment,
|
|
513
|
+
accept: payment => acceptWithRetry(client, messageBoxUrl, payment, internalize)
|
|
514
514
|
})
|
|
515
515
|
applyCreditResult(outcome)
|
|
516
516
|
return outcome
|
|
@@ -23,7 +23,15 @@ const AppLogo: React.FC<AppLogoProps> = ({ size = 150, color = '#2196F3', rotate
|
|
|
23
23
|
toValue: 1,
|
|
24
24
|
duration: 10000,
|
|
25
25
|
easing: Easing.linear,
|
|
26
|
-
useNativeDriver: true
|
|
26
|
+
useNativeDriver: true,
|
|
27
|
+
// A looped animation never ends, so without this the interaction
|
|
28
|
+
// handle Animated.timing registers is held for as long as this
|
|
29
|
+
// component is mounted — and while any handle is held,
|
|
30
|
+
// InteractionManager.runAfterInteractions never fires for anyone,
|
|
31
|
+
// process-wide. Balance renders this spinner whenever a balance is
|
|
32
|
+
// loading, so the deferred proof sweep in PayScreen (and any host
|
|
33
|
+
// that defers work the same way) would simply never run.
|
|
34
|
+
isInteraction: false
|
|
27
35
|
})
|
|
28
36
|
).start()
|
|
29
37
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Urbit sigil: a deterministic glyph for an @p name such as `~sampel-palnet`.
|
|
3
|
+
* The wallet uses it as the avatar for a counterparty it has no name or
|
|
4
|
+
* picture for, so two payments to the same key are recognisably the same
|
|
5
|
+
* person at a glance without showing them a hex string.
|
|
6
|
+
*/
|
|
7
|
+
import React, { useMemo } from 'react'
|
|
8
|
+
import type { StyleProp, ViewStyle } from 'react-native'
|
|
9
|
+
import { SvgXml } from 'react-native-svg'
|
|
10
|
+
// Only ever the `core` entry. The package root pulls in a DOM React renderer
|
|
11
|
+
// that touches `document` at import time, which does not exist on a device.
|
|
12
|
+
import sigil from '@urbit/sigil-js/core'
|
|
13
|
+
|
|
14
|
+
interface SigilProps {
|
|
15
|
+
/** A canonical @p, `~`-prefixed. */
|
|
16
|
+
point: string
|
|
17
|
+
/** Rendered edge in dp; the sigil is always square. */
|
|
18
|
+
size: number
|
|
19
|
+
/** Symbol colour. */
|
|
20
|
+
foreground: string
|
|
21
|
+
/**
|
|
22
|
+
* Tile colour. Must be a solid: sigil-js draws the cut-lines inside each
|
|
23
|
+
* glyph in this colour, so alpha would leave gaps in the shapes.
|
|
24
|
+
*/
|
|
25
|
+
background: string
|
|
26
|
+
/**
|
|
27
|
+
* sigil-js's own detail switch. `none` (the default) is the icon form: the
|
|
28
|
+
* inner lines that `default` adds are illegible at avatar size and just
|
|
29
|
+
* make every glyph look equally busy.
|
|
30
|
+
*/
|
|
31
|
+
detail?: 'none' | 'default'
|
|
32
|
+
style?: StyleProp<ViewStyle>
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// sigil-js emits this on the root <svg> for the browser, where an inline svg
|
|
36
|
+
// is otherwise `inline` and picks up line-height slop. Fabric has no such
|
|
37
|
+
// value and logs an error for it on every render, so it is cut before parsing.
|
|
38
|
+
const DOM_ONLY_STYLE = ' style="display: block;"'
|
|
39
|
+
|
|
40
|
+
export default function Sigil({
|
|
41
|
+
point,
|
|
42
|
+
size,
|
|
43
|
+
foreground,
|
|
44
|
+
background,
|
|
45
|
+
detail = 'none',
|
|
46
|
+
style
|
|
47
|
+
}: SigilProps): React.JSX.Element | null {
|
|
48
|
+
const xml = useMemo(() => {
|
|
49
|
+
try {
|
|
50
|
+
return sigil({ point, size, foreground, background, detail, space: 'default' }).replace(DOM_ONLY_STYLE, '')
|
|
51
|
+
} catch {
|
|
52
|
+
// A malformed @p (unknown syllable, odd length) throws inside sigil-js.
|
|
53
|
+
// One bad label must not take a whole activity list down with it.
|
|
54
|
+
return null
|
|
55
|
+
}
|
|
56
|
+
}, [point, size, foreground, background, detail])
|
|
57
|
+
|
|
58
|
+
if (xml === null) return null
|
|
59
|
+
// sigil-js writes `viewbox` in lower case, which the xml parser does not map
|
|
60
|
+
// onto the `viewBox` prop, so the box is restated here or nothing scales.
|
|
61
|
+
return <SvgXml xml={xml} width={size} height={size} viewBox={`0 0 ${size} ${size}`} style={style} />
|
|
62
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* One row of the wallet's activity list.
|
|
3
3
|
*
|
|
4
|
-
* Reading order is
|
|
5
|
-
*
|
|
4
|
+
* Reading order is who (a sigil avatar for the counterparty, with direction on
|
|
5
|
+
* the tile edge) → what it was → how much, then status and time underneath.
|
|
6
|
+
* The per-transaction utilities (status, explorer, resend, cancel)
|
|
6
7
|
* are NOT on the row: they used to sit permanently on the right, four icons
|
|
7
8
|
* deep, which made every row look equally busy whether or not anything needed
|
|
8
9
|
* doing. They now live behind a tap, and the expanded row lifts onto its own
|
|
@@ -12,13 +13,27 @@
|
|
|
12
13
|
* txid to a clipboard is not that — it is debugging, and it used to crowd out
|
|
13
14
|
* the two chips that actually resolve a stuck payment.
|
|
14
15
|
*/
|
|
15
|
-
import React, { memo, useContext } from 'react'
|
|
16
|
+
import React, { memo, useContext, useMemo } from 'react'
|
|
16
17
|
import { View, Text, StyleSheet, ActivityIndicator } from 'react-native'
|
|
17
18
|
import { useTranslation } from 'react-i18next'
|
|
18
19
|
import type { WalletAction } from '@bsv/sdk'
|
|
19
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
useTheme,
|
|
22
|
+
spacing,
|
|
23
|
+
radii,
|
|
24
|
+
typography,
|
|
25
|
+
useWallet,
|
|
26
|
+
ExchangeRateContext,
|
|
27
|
+
formatAmount,
|
|
28
|
+
formatAmountParts,
|
|
29
|
+
counterpartyOf,
|
|
30
|
+
counterpartyHue,
|
|
31
|
+
sigilPointOf,
|
|
32
|
+
sigilPalette
|
|
33
|
+
} from '@bsv/expo-wallet-toolbox'
|
|
20
34
|
import { txStatusView, toneColor } from '../../txStatus'
|
|
21
35
|
import PressableScale from '../ui/PressableScale'
|
|
36
|
+
import Sigil from '../ui/Sigil'
|
|
22
37
|
|
|
23
38
|
/**
|
|
24
39
|
* @expo/vector-icons' index barrel re-exports every icon set (AntDesign,
|
|
@@ -48,11 +63,14 @@ function loadMaterialCommunityIcons(): MaterialCommunityIconsComponent {
|
|
|
48
63
|
return materialCommunityIconsComponent
|
|
49
64
|
}
|
|
50
65
|
|
|
51
|
-
/** A row as storage actually returns it: `reference
|
|
52
|
-
* columns the SDK's WalletAction type does not
|
|
66
|
+
/** A row as storage actually returns it: `reference`, `created_at` and
|
|
67
|
+
* `senderIdentityKey` are real columns the SDK's WalletAction type does not
|
|
68
|
+
* declare. The sender key is what an inbound peer payment records about who
|
|
69
|
+
* paid, since nothing else on the row does. */
|
|
53
70
|
export type ActivityAction = WalletAction & {
|
|
54
71
|
reference?: string
|
|
55
72
|
created_at?: string | number | Date
|
|
73
|
+
senderIdentityKey?: string
|
|
56
74
|
}
|
|
57
75
|
|
|
58
76
|
interface Props {
|
|
@@ -117,7 +135,7 @@ function ActivityRowBase({
|
|
|
117
135
|
onCancelParked
|
|
118
136
|
}: Props & { currency: string }) {
|
|
119
137
|
const { t } = useTranslation()
|
|
120
|
-
const { colors } = useTheme()
|
|
138
|
+
const { colors, isDark } = useTheme()
|
|
121
139
|
const { satoshisPerUSD, usdToFiat = {} } = useContext(ExchangeRateContext)
|
|
122
140
|
const MaterialCommunityIcons = loadMaterialCommunityIcons()
|
|
123
141
|
|
|
@@ -144,6 +162,22 @@ function ActivityRowBase({
|
|
|
144
162
|
const amountColor = incoming ? colors.successAmount : colors.textPrimary
|
|
145
163
|
const unitColor = incoming ? colors.successAmount : colors.textSecondary
|
|
146
164
|
|
|
165
|
+
// Keyed on the label contents rather than on `action` or `labels`: every
|
|
166
|
+
// poll hands the row a fresh action object with a fresh labels array for the
|
|
167
|
+
// same transaction, so only a scalar key keeps the @p derivation from
|
|
168
|
+
// re-running per poll. Newline cannot appear in a stored label, so the join
|
|
169
|
+
// is unambiguous.
|
|
170
|
+
const { labels, senderIdentityKey, txid } = action
|
|
171
|
+
const labelsKey = labels?.join('\n') ?? ''
|
|
172
|
+
const face = useMemo(() => {
|
|
173
|
+
const cp = counterpartyOf({ labels: labelsKey === '' ? undefined : labelsKey.split('\n'), senderIdentityKey, txid })
|
|
174
|
+
return cp ? { point: sigilPointOf(cp), hue: counterpartyHue(cp) } : null
|
|
175
|
+
}, [labelsKey, senderIdentityKey, txid])
|
|
176
|
+
// Resolved outside the memo: the hue is a property of the counterparty, the
|
|
177
|
+
// colours it maps to are a property of the theme, and the theme can flip
|
|
178
|
+
// under a mounted row. Two HSL conversions per render are not worth a dep.
|
|
179
|
+
const palette = face ? sigilPalette(face.hue, !!isDark) : null
|
|
180
|
+
|
|
147
181
|
// A parked payment was built and shown as a code, but never released: it is
|
|
148
182
|
// not on chain and no task will put it there. An explorer link would 404 and
|
|
149
183
|
// a Refresh would ask the network about a transaction it has never seen, so
|
|
@@ -187,23 +221,50 @@ function ActivityRowBase({
|
|
|
187
221
|
accessibilityState={{ expanded }}
|
|
188
222
|
accessibilityLabel={action.description || t('transactions')}
|
|
189
223
|
>
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
224
|
+
{/* The sigil fills the tile, so direction moves to the border tint
|
|
225
|
+
alone: the same tints as the arrow tile, so a mixed list still
|
|
226
|
+
reads consistently down the left edge. The tile takes the
|
|
227
|
+
counterparty's own colour, and the sigil is drawn in exactly that
|
|
228
|
+
pair: sigil-js cuts its glyph lines in the background colour, so
|
|
229
|
+
the fill must be the same solid or the cuts show as a halo. */}
|
|
230
|
+
{face !== null && palette !== null ? (
|
|
231
|
+
<View
|
|
232
|
+
style={[
|
|
233
|
+
styles.glyph,
|
|
234
|
+
styles.avatar,
|
|
235
|
+
{
|
|
236
|
+
backgroundColor: palette.background,
|
|
237
|
+
borderColor: incoming ? colors.successStrong + '2E' : colors.surfaceSunkenBorder
|
|
238
|
+
}
|
|
239
|
+
]}
|
|
240
|
+
>
|
|
241
|
+
<Sigil
|
|
242
|
+
point={face.point}
|
|
243
|
+
size={38}
|
|
244
|
+
foreground={palette.foreground}
|
|
245
|
+
background={palette.background}
|
|
246
|
+
detail="default"
|
|
247
|
+
/>
|
|
248
|
+
</View>
|
|
249
|
+
) : (
|
|
250
|
+
<View
|
|
251
|
+
style={[
|
|
252
|
+
styles.glyph,
|
|
253
|
+
incoming
|
|
254
|
+
? {
|
|
255
|
+
backgroundColor: colors.successStrong + '1A',
|
|
256
|
+
borderColor: colors.successStrong + '2E'
|
|
257
|
+
}
|
|
258
|
+
: { backgroundColor: colors.surfaceSunken, borderColor: colors.surfaceSunkenBorder }
|
|
259
|
+
]}
|
|
260
|
+
>
|
|
261
|
+
<MaterialCommunityIcons
|
|
262
|
+
name={incoming ? 'arrow-bottom-left' : 'arrow-top-right'}
|
|
263
|
+
size={16}
|
|
264
|
+
color={incoming ? colors.successStrong : colors.textSecondary}
|
|
265
|
+
/>
|
|
266
|
+
</View>
|
|
267
|
+
)}
|
|
207
268
|
|
|
208
269
|
<View style={styles.middle}>
|
|
209
270
|
<Text style={[styles.description, { color: colors.textPrimary }]} numberOfLines={1}>
|
|
@@ -362,6 +423,8 @@ const styles = StyleSheet.create({
|
|
|
362
423
|
alignItems: 'center',
|
|
363
424
|
justifyContent: 'center'
|
|
364
425
|
},
|
|
426
|
+
// Clips the square sigil to the tile's rounded corners.
|
|
427
|
+
avatar: { overflow: 'hidden' },
|
|
365
428
|
middle: { flex: 1, minWidth: 0 },
|
|
366
429
|
// 14.5/500 rather than body 17/400: the row is scanned, not read, and at 17pt
|
|
367
430
|
// the description crowds the amount on narrow phones.
|