@bsv/expo-wallet-toolbox 0.15.1 → 0.16.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 +174 -0
- package/core/backup/appData.ts +5 -1
- package/core/backup/codec.ts +9 -3
- package/core/backup/contactsBackup.ts +145 -0
- package/core/backup/push.ts +14 -0
- package/core/backup/restoreOnImport.ts +15 -0
- package/core/contacts/contactsStore.ts +47 -3
- package/core/context/LocalStorageProvider.tsx +3 -1
- package/core/context/WalletContext.tsx +5 -2
- package/core/context/startupPrewarm.ts +54 -0
- package/core/hooks/useConfirmationSound.ts +7 -0
- package/core/identity/handleRegistry/client.ts +2 -1
- package/core/identity/handleRegistry/profileKeys.ts +16 -0
- package/core/identity/handleRegistry/resolver.ts +2 -1
- package/core/identity/handleRegistry/rules.ts +7 -3
- package/core/index.ts +2 -1
- package/core/localpay/build.ts +4 -3
- package/core/localpay/session.ts +6 -0
- package/core/localpay/transport/select.ts +64 -3
- package/core/localpay/verify.ts +2 -1
- package/core/mandala/permissionModule.ts +19 -3
- package/core/net/trimTrailingSlashes.ts +13 -0
- package/core/parsePeerPayURI.ts +25 -2
- package/core/pay/creditInbox.ts +31 -1
- package/core/pay/rails/address.ts +3 -2
- package/core/pay/rails/handle.ts +8 -2
- package/core/pay/rails/index.ts +6 -4
- package/core/pos/protocol.ts +172 -0
- package/core/profiles/removalProblems.ts +41 -0
- package/core/push/registration.ts +2 -1
- package/core/services/revokeConnection.ts +98 -0
- package/core/storage/schema/createTables.ts +24 -0
- package/core/toolboxConfig.ts +22 -4
- package/package.json +2 -2
- package/ui/components/pay/MessageBoxConfig.tsx +2 -1
- package/ui/components/pay/NearbyFlow.tsx +410 -7
- package/ui/exportTransactions.ts +26 -13
- package/ui/index.ts +2 -2
- package/ui/screens/ConnectionsScreen.tsx +8 -63
- package/ui/screens/ProfileScreen.tsx +2 -40
- package/ui/screens/WalletConfigScreen.tsx +57 -51
|
@@ -93,6 +93,7 @@
|
|
|
93
93
|
* easings.out. Nothing eases in; nothing starts from scale(0).
|
|
94
94
|
*/
|
|
95
95
|
|
|
96
|
+
import { POS_PREFIX, decodePaymentRequest } from '../../../core/pos/protocol'
|
|
96
97
|
import React, { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
|
97
98
|
import {
|
|
98
99
|
ActivityIndicator,
|
|
@@ -149,6 +150,8 @@ import {
|
|
|
149
150
|
frameBytesFromQr,
|
|
150
151
|
holdSentPaymentOffline,
|
|
151
152
|
parkSentPaymentOffline,
|
|
153
|
+
failedBeforeConnect,
|
|
154
|
+
fallbackRadio,
|
|
152
155
|
isAirGapPart,
|
|
153
156
|
isDeclineReason,
|
|
154
157
|
localSupportsAwdl,
|
|
@@ -451,6 +454,93 @@ function assetUnits(asset: SessionAsset, held?: { ticker: string; decimals: numb
|
|
|
451
454
|
|
|
452
455
|
// ── Screen ──
|
|
453
456
|
|
|
457
|
+
/**
|
|
458
|
+
* Everything the payer's confirm step shows and does, for a host that draws
|
|
459
|
+
* it in its own style (NearbyFlowProps.renderConfirm). The logic stays here:
|
|
460
|
+
* the host only renders these values and calls these actions.
|
|
461
|
+
*/
|
|
462
|
+
export interface NearbyConfirm {
|
|
463
|
+
session: Session
|
|
464
|
+
/** The payee's own figure, which the payer cannot change; undefined is an open request. */
|
|
465
|
+
fixedAmount?: number
|
|
466
|
+
/** What will be paid: satoshis, or base units of `asset`. 0 until usable. */
|
|
467
|
+
amount: number
|
|
468
|
+
/** Open request only: set the payer's figure (satoshis or base units); undefined clears it. */
|
|
469
|
+
setAmount: (units: number | undefined) => void
|
|
470
|
+
/** Token session: the unit every figure is in. Undefined on BSV. */
|
|
471
|
+
asset?: { ticker: string; decimals: number }
|
|
472
|
+
/** Token session: this wallet's holding of it, in base units. */
|
|
473
|
+
holding?: number
|
|
474
|
+
note: string
|
|
475
|
+
setNote: (note: string) => void
|
|
476
|
+
recipient: { name: string; detail?: string }
|
|
477
|
+
/** A merchant's sale + tip breakdown, as a sentence. */
|
|
478
|
+
tipText?: string
|
|
479
|
+
/** The nearby link's state, as the presence row would say it. */
|
|
480
|
+
presence: { state: PresenceState; label: string } | null
|
|
481
|
+
/** Plain sentences the confirm must show (why it's on the QR code, over balance, unknown unit). */
|
|
482
|
+
advisories: string[]
|
|
483
|
+
/** Set when the fix is in Settings (Bluetooth permission denied). */
|
|
484
|
+
openSettings?: () => void
|
|
485
|
+
canSend: boolean
|
|
486
|
+
send: () => void
|
|
487
|
+
cancel: () => void
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/** The payer's "Delivering…" step, while the radio carries the payment. */
|
|
491
|
+
export interface NearbySending {
|
|
492
|
+
/** Satoshis, or base units of `asset`. */
|
|
493
|
+
amount: number
|
|
494
|
+
asset?: { ticker: string; decimals: number }
|
|
495
|
+
recipient: { name: string; detail?: string }
|
|
496
|
+
presence: { state: PresenceState; label: string } | null
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/** The payer's fallback: the payment itself as a code the payee scans. */
|
|
500
|
+
export interface NearbyShowCode {
|
|
501
|
+
/** The payment code at `size` points: an animated fountain when it spans several frames. */
|
|
502
|
+
code: (size: number) => React.ReactNode
|
|
503
|
+
/** True when the code cycles through frames. */
|
|
504
|
+
animated: boolean
|
|
505
|
+
amount: number
|
|
506
|
+
asset?: { ticker: string; decimals: number }
|
|
507
|
+
recipient: { name: string; detail?: string }
|
|
508
|
+
presence: { state: PresenceState; label: string } | null
|
|
509
|
+
/** Why it fell back to a code, when a radio was tried first. */
|
|
510
|
+
notice?: { text: string; tone: 'success' | 'info' | 'warning' }
|
|
511
|
+
/** The payee has scanned it: keep the payment and finish. */
|
|
512
|
+
done: () => void
|
|
513
|
+
/** Leave without confirming: the payment is kept exactly as Done keeps it. */
|
|
514
|
+
back: () => void
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
/** The payer's finish: the payment went. */
|
|
518
|
+
export interface NearbyDone {
|
|
519
|
+
/** Satoshis; with `amountText` set it's a token payment and that is the figure. */
|
|
520
|
+
amount: number
|
|
521
|
+
amountText?: string
|
|
522
|
+
statusNote?: string
|
|
523
|
+
recipientName?: string
|
|
524
|
+
/** Back to the wallet; ends the flow. */
|
|
525
|
+
dismiss: () => void
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
/** The payee's finish: a nearby payment arrived and is durably queued. */
|
|
529
|
+
export interface NearbyReceived {
|
|
530
|
+
/** Satoshis; with `amountText` set it's a token payment and that is the figure. */
|
|
531
|
+
amount: number
|
|
532
|
+
amountText?: string
|
|
533
|
+
statusNote?: string
|
|
534
|
+
/** False when it was accepted offline and no broadcaster has seen it yet. */
|
|
535
|
+
broadcast?: boolean
|
|
536
|
+
/** 'pending' while the wallet credits it, then 'verified' or 'not-credited'. */
|
|
537
|
+
verification: 'pending' | 'verified' | 'not-credited'
|
|
538
|
+
/** Who paid, when their name is known. */
|
|
539
|
+
payerName?: string
|
|
540
|
+
/** Back to the wallet; ends the flow. */
|
|
541
|
+
dismiss: () => void
|
|
542
|
+
}
|
|
543
|
+
|
|
454
544
|
export interface NearbyFlowProps {
|
|
455
545
|
/** Which side of the exchange this device is on. Set by the cell that mounted it. */
|
|
456
546
|
role: 'payer' | 'payee'
|
|
@@ -469,9 +559,48 @@ export interface NearbyFlowProps {
|
|
|
469
559
|
initialRequest?: { sats?: number; asset?: SessionAsset }
|
|
470
560
|
/** Where the post-payment overlay and an exited QR flow send the user. Defaults to `/`. */
|
|
471
561
|
dismissTo?: DismissTarget
|
|
562
|
+
/**
|
|
563
|
+
* Payee with `initialRequest` only: render inline inside a host screen
|
|
564
|
+
* instead of taking it over. While the request is live (minting, waiting,
|
|
565
|
+
* the payer's-code scanner, saving, the paid overlay) only the pairing code
|
|
566
|
+
* and its status show, sized `qrSize`; the host already shows the amount.
|
|
567
|
+
* A failed or already-paid outcome opens full screen in a modal, and its
|
|
568
|
+
* Cancel calls `onExit` — the host remounts for a fresh request.
|
|
569
|
+
*
|
|
570
|
+
* `onBusy` reports when a payment is in hand (the payer's-code scanner,
|
|
571
|
+
* saving, the paid overlay, a failure): the host must not remount or
|
|
572
|
+
* unmount the flow then — no new amount, no switching away.
|
|
573
|
+
*/
|
|
574
|
+
embedded?: { qrSize?: number; onBusy?: (busy: boolean) => void }
|
|
575
|
+
/**
|
|
576
|
+
* Payer only: draw these steps yourself, in the host's own style. Each is
|
|
577
|
+
* optional; a step without one shows the built-in screen. The logic stays
|
|
578
|
+
* here — the host renders the values and calls the actions it is handed.
|
|
579
|
+
*/
|
|
580
|
+
renderPayer?: {
|
|
581
|
+
confirm?: (confirm: NearbyConfirm) => React.ReactNode
|
|
582
|
+
sending?: (sending: NearbySending) => React.ReactNode
|
|
583
|
+
showCode?: (showCode: NearbyShowCode) => React.ReactNode
|
|
584
|
+
done?: (done: NearbyDone) => React.ReactNode
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Payee only: draw the "payment received" moment yourself instead of the
|
|
588
|
+
* built-in overlay. It is shown in place of that overlay, so the host
|
|
589
|
+
* presents it full screen (a Modal) and plays its own sound.
|
|
590
|
+
*/
|
|
591
|
+
renderReceived?: (received: NearbyReceived) => React.ReactNode
|
|
472
592
|
}
|
|
473
593
|
|
|
474
|
-
function NearbyFlow({
|
|
594
|
+
function NearbyFlow({
|
|
595
|
+
role: initialRole,
|
|
596
|
+
onExit,
|
|
597
|
+
initialSession,
|
|
598
|
+
initialRequest,
|
|
599
|
+
dismissTo = '/',
|
|
600
|
+
embedded,
|
|
601
|
+
renderPayer,
|
|
602
|
+
renderReceived
|
|
603
|
+
}: NearbyFlowProps) {
|
|
475
604
|
const { t } = useTranslation()
|
|
476
605
|
const { colors } = useTheme()
|
|
477
606
|
const Ionicons = loadIonicons()
|
|
@@ -1512,6 +1641,10 @@ function NearbyFlow({ role: initialRole, onExit, initialSession, initialRequest,
|
|
|
1512
1641
|
(data: string) => {
|
|
1513
1642
|
if (scanLatchRef.current) return
|
|
1514
1643
|
scanLatchRef.current = true
|
|
1644
|
+
if (data.startsWith(POS_PREFIX)) {
|
|
1645
|
+
void decodePaymentRequest(data).then(adoptSession).catch(() => fail('generic', t('invalid_qr_code')))
|
|
1646
|
+
return
|
|
1647
|
+
}
|
|
1515
1648
|
let session: Session
|
|
1516
1649
|
try {
|
|
1517
1650
|
session = decodeSession(data)
|
|
@@ -1756,6 +1889,19 @@ function NearbyFlow({ role: initialRole, onExit, initialSession, initialRequest,
|
|
|
1756
1889
|
fail('generic', t('wallet_not_ready'))
|
|
1757
1890
|
return
|
|
1758
1891
|
}
|
|
1892
|
+
if (session.merchantChain) {
|
|
1893
|
+
try {
|
|
1894
|
+
const network = await wallet.getNetwork({})
|
|
1895
|
+
const expected = session.merchantChain === 'main' ? 'mainnet' : 'testnet'
|
|
1896
|
+
if (network.network !== expected || !session.merchantExpires || session.merchantExpires <= Date.now()) {
|
|
1897
|
+
fail('generic', 'Merchant request expired or uses a different network.')
|
|
1898
|
+
return
|
|
1899
|
+
}
|
|
1900
|
+
} catch {
|
|
1901
|
+
fail('generic', 'Could not verify the merchant payment network.')
|
|
1902
|
+
return
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1759
1905
|
setPhase('send_working')
|
|
1760
1906
|
|
|
1761
1907
|
const registry = abortsRef.current
|
|
@@ -1888,7 +2034,19 @@ function NearbyFlow({ role: initialRole, onExit, initialSession, initialRequest,
|
|
|
1888
2034
|
if (sendKind === 'ble' && Platform.OS === 'android' && !(await requestBlePermissions())) {
|
|
1889
2035
|
throw new Error('bluetooth permission not granted')
|
|
1890
2036
|
}
|
|
1891
|
-
|
|
2037
|
+
try {
|
|
2038
|
+
ack = await radio.send(session, built.frame, controller.signal)
|
|
2039
|
+
} catch (e) {
|
|
2040
|
+
// Graceful degradation, AWDL → BLE → QR. Only a failure that proves
|
|
2041
|
+
// the frame never left this device (the link never came up) may try
|
|
2042
|
+
// the next radio; anything later — a lost ack — may already have
|
|
2043
|
+
// delivered, and goes to the fountain below exactly as before
|
|
2044
|
+
// (failedBeforeConnect explains why a second radio would be unsafe).
|
|
2045
|
+
const next = controller.signal.aborted || !failedBeforeConnect(e) ? null : fallbackRadio(session, sendKind)
|
|
2046
|
+
if (next !== 'ble') throw e
|
|
2047
|
+
console.warn('[localpay] awdl never connected, trying BLE:', messageOf(e))
|
|
2048
|
+
ack = await bleTransport.send(session, built.frame, controller.signal)
|
|
2049
|
+
}
|
|
1892
2050
|
} catch (e) {
|
|
1893
2051
|
if (controller.signal.aborted) {
|
|
1894
2052
|
// XR-096: the screen blurred or unmounted while this native send
|
|
@@ -2539,8 +2697,7 @@ function NearbyFlow({ role: initialRole, onExit, initialSession, initialRequest,
|
|
|
2539
2697
|
)
|
|
2540
2698
|
}
|
|
2541
2699
|
|
|
2542
|
-
|
|
2543
|
-
<View style={[styles.container, { backgroundColor: colors.backgroundSecondary }]}>
|
|
2700
|
+
const flowBody = (
|
|
2544
2701
|
<ScrollView
|
|
2545
2702
|
style={{ flex: 1, backgroundColor: colors.background }}
|
|
2546
2703
|
contentContainerStyle={[styles.scroll, { paddingBottom: insets.bottom + spacing.xxxl }]}
|
|
@@ -2849,10 +3006,14 @@ function NearbyFlow({ role: initialRole, onExit, initialSession, initialRequest,
|
|
|
2849
3006
|
</PayField>
|
|
2850
3007
|
|
|
2851
3008
|
<RecipientSummary
|
|
2852
|
-
name={peerName ?? abbreviateKey(scannedSession.identityKey)}
|
|
2853
|
-
detail={peerName ? abbreviateKey(scannedSession.identityKey) : undefined}
|
|
3009
|
+
name={peerName ?? scannedSession.merchantName ?? abbreviateKey(scannedSession.identityKey)}
|
|
3010
|
+
detail={scannedSession.merchantName ? `Merchant · ${abbreviateKey(scannedSession.identityKey)}` : peerName ? abbreviateKey(scannedSession.identityKey) : undefined}
|
|
2854
3011
|
/>
|
|
2855
3012
|
|
|
3013
|
+
{!!scannedSession.merchantTip && supportText(t('merchant_tip_breakdown', {
|
|
3014
|
+
defaultValue: '{{subtotal}} sats sale + {{tip}} sats tip',
|
|
3015
|
+
subtotal: scannedSession.merchantSubtotal?.toLocaleString(), tip: scannedSession.merchantTip.toLocaleString()
|
|
3016
|
+
}))}
|
|
2856
3017
|
<View style={styles.gapLg} />
|
|
2857
3018
|
{presenceBlock}
|
|
2858
3019
|
{floorReason !== 'none' && (
|
|
@@ -3058,6 +3219,222 @@ function NearbyFlow({ role: initialRole, onExit, initialSession, initialRequest,
|
|
|
3058
3219
|
</Animated.View>
|
|
3059
3220
|
)}
|
|
3060
3221
|
</ScrollView>
|
|
3222
|
+
)
|
|
3223
|
+
|
|
3224
|
+
/**
|
|
3225
|
+
* Embedded (see NearbyFlowProps.embedded): every phase of a live request
|
|
3226
|
+
* stays inline, so the scanner and the paid overlay — both modals of their
|
|
3227
|
+
* own — never stack on a second one. Only the outcomes that need the full
|
|
3228
|
+
* failure copy and its buttons open full screen.
|
|
3229
|
+
*/
|
|
3230
|
+
const inlinePhase =
|
|
3231
|
+
phase === 'entry' ||
|
|
3232
|
+
phase === 'receive_minting' ||
|
|
3233
|
+
phase === 'receive_wait' ||
|
|
3234
|
+
phase === 'receive_scan' ||
|
|
3235
|
+
phase === 'receive_settling' ||
|
|
3236
|
+
phase === 'done'
|
|
3237
|
+
const embeddedQrSize = embedded?.qrSize ?? 196
|
|
3238
|
+
const onBusy = embedded?.onBusy
|
|
3239
|
+
const busy = !(phase === 'entry' || phase === 'receive_minting' || phase === 'receive_wait')
|
|
3240
|
+
useEffect(() => {
|
|
3241
|
+
onBusy?.(busy)
|
|
3242
|
+
}, [onBusy, busy])
|
|
3243
|
+
useEffect(() => () => onBusy?.(false), [onBusy])
|
|
3244
|
+
|
|
3245
|
+
const inlineBody = (
|
|
3246
|
+
<View style={styles.embedded}>
|
|
3247
|
+
{phase === 'receive_wait' && hostedSession && sessionQr && !sessionQrBroken ? (
|
|
3248
|
+
<View style={[styles.qrCard, { shadowColor: colors.textPrimary }]}>
|
|
3249
|
+
<View style={styles.qrPlate}>
|
|
3250
|
+
<QRCode
|
|
3251
|
+
value={sessionQr}
|
|
3252
|
+
size={embeddedQrSize}
|
|
3253
|
+
ecl="M"
|
|
3254
|
+
color="#000"
|
|
3255
|
+
backgroundColor="#fff"
|
|
3256
|
+
onError={onSessionQrError}
|
|
3257
|
+
/>
|
|
3258
|
+
</View>
|
|
3259
|
+
</View>
|
|
3260
|
+
) : phase === 'receive_wait' && hostedSession ? (
|
|
3261
|
+
<View
|
|
3262
|
+
style={[styles.qrError, { width: embeddedQrSize, height: embeddedQrSize, backgroundColor: colors.fillTertiary, borderColor: colors.separator }]}
|
|
3263
|
+
accessibilityRole="alert"
|
|
3264
|
+
>
|
|
3265
|
+
<Ionicons name="alert-circle-outline" size={28} color={colors.error} />
|
|
3266
|
+
<View style={styles.gapSm} />
|
|
3267
|
+
<Text style={[styles.support, { color: colors.textSecondary }]}>{t('local_pay_qr_unavailable')}</Text>
|
|
3268
|
+
</View>
|
|
3269
|
+
) : (
|
|
3270
|
+
// the code's own footprint, so the host's layout does not jump
|
|
3271
|
+
<View
|
|
3272
|
+
style={[styles.embeddedPending, { width: embeddedQrSize + spacing.lg * 2, height: embeddedQrSize + spacing.lg * 2 }]}
|
|
3273
|
+
accessibilityRole="progressbar"
|
|
3274
|
+
accessibilityLabel={phase === 'receive_settling' ? t('local_pay_saving') : t('local_pay_preparing')}
|
|
3275
|
+
>
|
|
3276
|
+
<ActivityIndicator size="large" color={colors.textSecondary} />
|
|
3277
|
+
<View style={styles.gapMd} />
|
|
3278
|
+
{supportText(phase === 'receive_settling' ? t('local_pay_saving') : t('local_pay_preparing'))}
|
|
3279
|
+
</View>
|
|
3280
|
+
)}
|
|
3281
|
+
<View style={styles.gapMd} />
|
|
3282
|
+
{presenceBlock}
|
|
3283
|
+
{phase === 'receive_wait' && sessionMismatch && (
|
|
3284
|
+
<>
|
|
3285
|
+
<View style={styles.gapMd} />
|
|
3286
|
+
{notice ? (
|
|
3287
|
+
noticeBlock(notice)
|
|
3288
|
+
) : (
|
|
3289
|
+
<View
|
|
3290
|
+
style={[styles.notice, { backgroundColor: colors.error + '15', borderColor: colors.error + '40' }]}
|
|
3291
|
+
accessibilityRole="alert"
|
|
3292
|
+
>
|
|
3293
|
+
<Ionicons name="alert-circle-outline" size={16} color={colors.error} />
|
|
3294
|
+
<Text style={[styles.noticeText, { color: colors.error }]}>{t('local_pay_wrong_session')}</Text>
|
|
3295
|
+
</View>
|
|
3296
|
+
)}
|
|
3297
|
+
</>
|
|
3298
|
+
)}
|
|
3299
|
+
{phase === 'receive_wait' &&
|
|
3300
|
+
radioFailures.map(([kind, err]) => (
|
|
3301
|
+
<React.Fragment key={kind}>
|
|
3302
|
+
<View style={styles.gapMd} />
|
|
3303
|
+
<View style={[styles.notice, { backgroundColor: colors.fillTertiary, borderColor: colors.separator }]}>
|
|
3304
|
+
<Ionicons name="information-circle-outline" size={16} color={colors.textSecondary} />
|
|
3305
|
+
<Text style={[styles.noticeText, { color: colors.textSecondary }]}>
|
|
3306
|
+
{err.networkDenied
|
|
3307
|
+
? t('local_pay_network_denied')
|
|
3308
|
+
: kind === 'ble'
|
|
3309
|
+
? t('local_pay_ble_unavailable')
|
|
3310
|
+
: t('local_pay_nearby_unavailable')}
|
|
3311
|
+
</Text>
|
|
3312
|
+
</View>
|
|
3313
|
+
</React.Fragment>
|
|
3314
|
+
))}
|
|
3315
|
+
{phase === 'receive_wait' && radioFailures.some(([, err]) => err.networkDenied) && (
|
|
3316
|
+
<>
|
|
3317
|
+
<View style={styles.gapMd} />
|
|
3318
|
+
<SecondaryButton
|
|
3319
|
+
styles={styles}
|
|
3320
|
+
colors={colors}
|
|
3321
|
+
icon="settings-outline"
|
|
3322
|
+
label={t('open_settings')}
|
|
3323
|
+
onPress={() => void Linking.openSettings()}
|
|
3324
|
+
/>
|
|
3325
|
+
</>
|
|
3326
|
+
)}
|
|
3327
|
+
{/* the payer's radios failed and it shows its own code instead */}
|
|
3328
|
+
{phase === 'receive_wait' && (
|
|
3329
|
+
<>
|
|
3330
|
+
<View style={styles.gapMd} />
|
|
3331
|
+
<PressableScale
|
|
3332
|
+
onPress={() => openScanner('receive_scan')}
|
|
3333
|
+
haptic="tap"
|
|
3334
|
+
style={styles.embeddedScan}
|
|
3335
|
+
accessibilityRole="button"
|
|
3336
|
+
accessibilityLabel={t('local_pay_scan_payer_qr')}
|
|
3337
|
+
>
|
|
3338
|
+
<Ionicons name="scan-outline" size={16} color={colors.textSecondary} />
|
|
3339
|
+
<Text style={[styles.embeddedScanText, { color: colors.textSecondary }]}>{t('local_pay_scan_payer_qr')}</Text>
|
|
3340
|
+
</PressableScale>
|
|
3341
|
+
</>
|
|
3342
|
+
)}
|
|
3343
|
+
</View>
|
|
3344
|
+
)
|
|
3345
|
+
|
|
3346
|
+
const payerRecipient = scannedSession
|
|
3347
|
+
? {
|
|
3348
|
+
name: peerName ?? scannedSession.merchantName ?? abbreviateKey(scannedSession.identityKey),
|
|
3349
|
+
detail: scannedSession.merchantName
|
|
3350
|
+
? `Merchant · ${abbreviateKey(scannedSession.identityKey)}`
|
|
3351
|
+
: peerName
|
|
3352
|
+
? abbreviateKey(scannedSession.identityKey)
|
|
3353
|
+
: undefined
|
|
3354
|
+
}
|
|
3355
|
+
: { name: '' }
|
|
3356
|
+
// wrapped, so a host that renders nothing still replaces the built-in step
|
|
3357
|
+
const hosted: { node: React.ReactNode } | null =
|
|
3358
|
+
role !== 'payer' || !renderPayer
|
|
3359
|
+
? null
|
|
3360
|
+
: phase === 'send_confirm' && scannedSession && renderPayer.confirm
|
|
3361
|
+
? { node: <Hosted render={renderPayer.confirm} value={{
|
|
3362
|
+
session: scannedSession,
|
|
3363
|
+
fixedAmount: scannedSession.amount,
|
|
3364
|
+
amount: payAmount,
|
|
3365
|
+
setAmount: units => setSendAmount(units !== undefined && units > 0 ? String(Math.round(units)) : ''),
|
|
3366
|
+
asset: scannedAssetUnits,
|
|
3367
|
+
holding: scannedHolding && !unitsUnknown ? scannedHolding.baseUnits : undefined,
|
|
3368
|
+
note,
|
|
3369
|
+
setNote,
|
|
3370
|
+
recipient: payerRecipient,
|
|
3371
|
+
tipText: scannedSession.merchantTip
|
|
3372
|
+
? t('merchant_tip_breakdown', {
|
|
3373
|
+
defaultValue: '{{subtotal}} sats sale + {{tip}} sats tip',
|
|
3374
|
+
subtotal: scannedSession.merchantSubtotal?.toLocaleString(),
|
|
3375
|
+
tip: scannedSession.merchantTip.toLocaleString()
|
|
3376
|
+
})
|
|
3377
|
+
: undefined,
|
|
3378
|
+
presence,
|
|
3379
|
+
advisories: [
|
|
3380
|
+
...(floorReason !== 'none' ? [t(FLOOR_KEYS[floorReason])] : []),
|
|
3381
|
+
...(overHolding && scannedAssetUnits && !unitsUnknown
|
|
3382
|
+
? [t('pay_asset_over_balance', { ticker: scannedAssetUnits.ticker })]
|
|
3383
|
+
: []),
|
|
3384
|
+
...(unitsUnknown ? [t('pay_asset_unidentified')] : [])
|
|
3385
|
+
],
|
|
3386
|
+
openSettings: floorReason === 'local_ble_denied' ? () => void Linking.openSettings() : undefined,
|
|
3387
|
+
canSend,
|
|
3388
|
+
send: () => void executeSend(),
|
|
3389
|
+
cancel: reset
|
|
3390
|
+
}} /> }
|
|
3391
|
+
: phase === 'send_working' && renderPayer.sending
|
|
3392
|
+
? { node: <Hosted render={renderPayer.sending} value={{ amount: payAmount, asset: scannedAssetUnits, recipient: payerRecipient, presence }} /> }
|
|
3393
|
+
: phase === 'send_qr' && paymentQr && renderPayer.showCode
|
|
3394
|
+
? { node: <Hosted render={renderPayer.showCode} value={{
|
|
3395
|
+
code: size => <PaymentQrDisplay frameQr={paymentQr} size={size} onError={onPaymentQrError} />,
|
|
3396
|
+
animated: paymentQrBlocks > 1,
|
|
3397
|
+
amount: payAmount,
|
|
3398
|
+
asset: scannedAssetUnits,
|
|
3399
|
+
recipient: payerRecipient,
|
|
3400
|
+
presence,
|
|
3401
|
+
notice: notice ?? undefined,
|
|
3402
|
+
done: () => void completeQrDelivery(),
|
|
3403
|
+
back: () => void handleSendQrExit(false)
|
|
3404
|
+
}} /> }
|
|
3405
|
+
: phase === 'done' && renderPayer.done
|
|
3406
|
+
? { node: <Hosted render={renderPayer.done} value={{
|
|
3407
|
+
amount: settledAmount,
|
|
3408
|
+
amountText: settledTokenText ?? undefined,
|
|
3409
|
+
statusNote: settledStatusNote ?? undefined,
|
|
3410
|
+
recipientName:
|
|
3411
|
+
peerName ?? (scannedSession ? abbreviateKey(scannedSession.identityKey) : undefined),
|
|
3412
|
+
dismiss: () => {
|
|
3413
|
+
goBack()
|
|
3414
|
+
router.dismissTo(dismissTo)
|
|
3415
|
+
}
|
|
3416
|
+
}} /> }
|
|
3417
|
+
: null
|
|
3418
|
+
|
|
3419
|
+
return (
|
|
3420
|
+
<View
|
|
3421
|
+
style={
|
|
3422
|
+
hosted ? styles.container : embedded ? undefined : [styles.container, { backgroundColor: colors.backgroundSecondary }]
|
|
3423
|
+
}
|
|
3424
|
+
>
|
|
3425
|
+
{hosted ? (
|
|
3426
|
+
hosted.node
|
|
3427
|
+
) : !embedded ? (
|
|
3428
|
+
flowBody
|
|
3429
|
+
) : inlinePhase ? (
|
|
3430
|
+
inlineBody
|
|
3431
|
+
) : (
|
|
3432
|
+
<Modal visible animationType="slide" onRequestClose={reset} statusBarTranslucent>
|
|
3433
|
+
<View style={[styles.container, { backgroundColor: colors.backgroundSecondary, paddingTop: insets.top }]}>
|
|
3434
|
+
{flowBody}
|
|
3435
|
+
</View>
|
|
3436
|
+
</Modal>
|
|
3437
|
+
)}
|
|
3061
3438
|
|
|
3062
3439
|
{/* ══ Scanner ══ */}
|
|
3063
3440
|
<Modal visible={scannerOpen} animationType="slide" onRequestClose={closeScanner} statusBarTranslucent>
|
|
@@ -3088,7 +3465,24 @@ function NearbyFlow({ role: initialRole, onExit, initialSession, initialRequest,
|
|
|
3088
3465
|
the write cannot be lost at that point, and background internalizing
|
|
3089
3466
|
catches up on its own; surfacing that separately (if it ever fails)
|
|
3090
3467
|
is a job for the activity list, not for withholding this screen. */}
|
|
3091
|
-
{phase === 'done' && (
|
|
3468
|
+
{phase === 'done' && !hosted && role === 'payee' && renderReceived && (
|
|
3469
|
+
<Hosted
|
|
3470
|
+
render={renderReceived}
|
|
3471
|
+
value={{
|
|
3472
|
+
amount: settledAmount,
|
|
3473
|
+
amountText: settledTokenText ?? undefined,
|
|
3474
|
+
statusNote: settledStatusNote ?? undefined,
|
|
3475
|
+
broadcast: settledTokenText ? undefined : receivedBroadcast,
|
|
3476
|
+
verification: receivedVerification,
|
|
3477
|
+
payerName: peerName ?? undefined,
|
|
3478
|
+
dismiss: () => {
|
|
3479
|
+
goBack()
|
|
3480
|
+
router.dismissTo(dismissTo)
|
|
3481
|
+
}
|
|
3482
|
+
}}
|
|
3483
|
+
/>
|
|
3484
|
+
)}
|
|
3485
|
+
{phase === 'done' && !hosted && !(role === 'payee' && renderReceived) && (
|
|
3092
3486
|
<ReceivedOverlay
|
|
3093
3487
|
amount={settledAmount}
|
|
3094
3488
|
amountText={settledTokenText ?? undefined}
|
|
@@ -3116,6 +3510,11 @@ function NearbyFlow({ role: initialRole, onExit, initialSession, initialRequest,
|
|
|
3116
3510
|
)
|
|
3117
3511
|
}
|
|
3118
3512
|
|
|
3513
|
+
/** A host's own drawing of one payer step (NearbyFlowProps.renderPayer), run in its own render. */
|
|
3514
|
+
function Hosted<T>({ render, value }: { render: (value: T) => React.ReactNode; value: T }) {
|
|
3515
|
+
return <>{render(value)}</>
|
|
3516
|
+
}
|
|
3517
|
+
|
|
3119
3518
|
// ── Small components ──
|
|
3120
3519
|
//
|
|
3121
3520
|
// Every control below covers the full interaction set RN can express: default,
|
|
@@ -3234,6 +3633,10 @@ function CancelButton({
|
|
|
3234
3633
|
function makeStyles() {
|
|
3235
3634
|
return StyleSheet.create({
|
|
3236
3635
|
container: { flex: 1 },
|
|
3636
|
+
embedded: { alignItems: 'center', alignSelf: 'stretch' },
|
|
3637
|
+
embeddedPending: { alignItems: 'center', justifyContent: 'center' },
|
|
3638
|
+
embeddedScan: { flexDirection: 'row', alignItems: 'center', gap: 6, paddingVertical: 6, paddingHorizontal: 12 },
|
|
3639
|
+
embeddedScanText: { fontSize: 13, lineHeight: 18 },
|
|
3237
3640
|
header: {
|
|
3238
3641
|
flexDirection: 'row',
|
|
3239
3642
|
alignItems: 'center',
|
package/ui/exportTransactions.ts
CHANGED
|
@@ -58,18 +58,8 @@ function csvEscapeUntrusted(v: unknown): string {
|
|
|
58
58
|
return csvEscape(neutralizeFormula(String(v)))
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
/**
|
|
62
|
-
|
|
63
|
-
* Columns: txid, satoshis (signed), description, status, blockHeight,
|
|
64
|
-
* tags (semi-colon), labels (semi-colon), outputDescriptions (semi-colon).
|
|
65
|
-
*
|
|
66
|
-
* Returns the number of rows exported.
|
|
67
|
-
*/
|
|
68
|
-
export async function exportTransactionsAsCsv(
|
|
69
|
-
wallet: WalletInterface,
|
|
70
|
-
storage: StorageExpoSQLite | null,
|
|
71
|
-
adminOriginator: string
|
|
72
|
-
): Promise<number> {
|
|
61
|
+
/** Every action in this wallet, page by page, with its labels and outputs. */
|
|
62
|
+
export async function listAllActions(wallet: WalletInterface, adminOriginator: string): Promise<WalletAction[]> {
|
|
73
63
|
const actions: WalletAction[] = []
|
|
74
64
|
let offset = 0
|
|
75
65
|
let total = Infinity
|
|
@@ -89,6 +79,29 @@ export async function exportTransactionsAsCsv(
|
|
|
89
79
|
actions.push(...r.actions)
|
|
90
80
|
offset += r.actions.length
|
|
91
81
|
}
|
|
82
|
+
return actions
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Exports all wallet transactions as a CSV file via the OS share dialog.
|
|
87
|
+
* Columns: txid, satoshis (signed), description, status, blockHeight,
|
|
88
|
+
* tags (semi-colon), labels (semi-colon), outputDescriptions (semi-colon).
|
|
89
|
+
*
|
|
90
|
+
* `select`, when given, keeps only the actions it returns true for (a period,
|
|
91
|
+
* a direction).
|
|
92
|
+
*
|
|
93
|
+
* Returns the number of rows exported.
|
|
94
|
+
*/
|
|
95
|
+
export async function exportTransactionsAsCsv(
|
|
96
|
+
wallet: WalletInterface,
|
|
97
|
+
storage: StorageExpoSQLite | null,
|
|
98
|
+
adminOriginator: string,
|
|
99
|
+
select?: (action: WalletAction) => boolean,
|
|
100
|
+
/** the file's name, with its .csv; bsv-transactions-<unix time>.csv when not given */
|
|
101
|
+
fileName?: string
|
|
102
|
+
): Promise<number> {
|
|
103
|
+
const all = await listAllActions(wallet, adminOriginator)
|
|
104
|
+
const actions = select ? all.filter(select) : all
|
|
92
105
|
|
|
93
106
|
if (actions.length === 0) return 0
|
|
94
107
|
|
|
@@ -138,7 +151,7 @@ export async function exportTransactionsAsCsv(
|
|
|
138
151
|
const { shareAsync } = loadExpoSharing()
|
|
139
152
|
|
|
140
153
|
const ts = Math.floor(Date.now() / 1000)
|
|
141
|
-
const outName = `bsv-transactions-${ts}.csv`
|
|
154
|
+
const outName = fileName ?? `bsv-transactions-${ts}.csv`
|
|
142
155
|
const tempDir = new Directory(Paths.cache, 'bsv-tx-export')
|
|
143
156
|
if (tempDir.exists) tempDir.delete()
|
|
144
157
|
tempDir.create({ intermediates: true })
|
package/ui/index.ts
CHANGED
|
@@ -39,7 +39,7 @@ export type { WalletHomeScreenProps } from './screens/WalletHomeScreen'
|
|
|
39
39
|
|
|
40
40
|
// Wallet-screen support utilities, moved alongside the screen (Task 20)
|
|
41
41
|
export * from './txStatus'
|
|
42
|
-
export { exportTransactionsAsCsv } from './exportTransactions'
|
|
42
|
+
export { exportTransactionsAsCsv, listAllActions } from './exportTransactions'
|
|
43
43
|
|
|
44
44
|
// Identity resolution and spendable-balance helpers, promoted here (Task 21)
|
|
45
45
|
// as hard dependencies of the pay UI below — same flat-at-root treatment as
|
|
@@ -57,7 +57,7 @@ export { default as AddressReceive } from './components/pay/AddressReceive'
|
|
|
57
57
|
export { default as AvailableBalance } from './components/pay/AvailableBalance'
|
|
58
58
|
export { default as HandleReceive } from './components/pay/HandleReceive'
|
|
59
59
|
export { useMessageBoxConfig, ConfigPanel } from './components/pay/MessageBoxConfig'
|
|
60
|
-
export { default as NearbyFlow, type NearbyFlowProps } from './components/pay/NearbyFlow'
|
|
60
|
+
export { default as NearbyFlow, type NearbyConfirm, type NearbyDone, type NearbyFlowProps, type NearbyReceived, type NearbySending, type NearbyShowCode } from './components/pay/NearbyFlow'
|
|
61
61
|
export { NearbyAdvisoryModal } from './components/pay/NearbyAdvisoryModal'
|
|
62
62
|
export { NotificationAdvisoryModal } from './components/pay/NotificationAdvisoryModal'
|
|
63
63
|
export { default as OfflineNotice, offlineActionDetails, type OfflineNoticeProps } from './components/pay/OfflineNotice'
|
|
@@ -25,15 +25,9 @@ import {
|
|
|
25
25
|
useWalletConnection,
|
|
26
26
|
lastSeqKey
|
|
27
27
|
} from '@bsv/expo-wallet-toolbox'
|
|
28
|
-
import {
|
|
29
|
-
buildRelayWebSocketUrl,
|
|
30
|
-
validateMobileIdentityKey,
|
|
31
|
-
validateRelayUrl,
|
|
32
|
-
validateStoredConnectionAuthorityTag,
|
|
33
|
-
validateStoredConnectionFields,
|
|
34
|
-
validateStoredConnectionSequence
|
|
35
|
-
} from '../../core/services/walletConnectionValidation'
|
|
28
|
+
import { validateStoredConnectionAuthorityTag } from '../../core/services/walletConnectionValidation'
|
|
36
29
|
import { computeConnectionAuthorityTag, verifyConnectionAuthorityTag } from '../../core/services/connectionAuthority'
|
|
30
|
+
import { revokeConnection } from '../../core/services/revokeConnection'
|
|
37
31
|
|
|
38
32
|
/**
|
|
39
33
|
* expo-clipboard ships an untransformed ESM build (its Clipboard.js imports
|
|
@@ -214,61 +208,12 @@ export const ConnectionsScreen = observer(function ConnectionsScreen() {
|
|
|
214
208
|
}
|
|
215
209
|
|
|
216
210
|
async function handleDisconnect(conn: Connection) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
connectionStore.setStatus(conn.sessionId, 'disconnected')
|
|
224
|
-
|
|
225
|
-
if (!managers.permissionsManager) return
|
|
226
|
-
try {
|
|
227
|
-
const validated = validateStoredConnectionFields(conn)
|
|
228
|
-
const relay = validateRelayUrl(conn.relay)
|
|
229
|
-
const storedSeq = await SecureStore.getItemAsync(lastSeqKey(validated.topic))
|
|
230
|
-
const initialSeq = validateStoredConnectionSequence(storedSeq)
|
|
231
|
-
const wallet = new WalletClient(
|
|
232
|
-
capWalletArgs(guardVaultAccess(managers.permissionsManager as any, ADMIN_ORIGINATOR)),
|
|
233
|
-
validated.external.originator
|
|
234
|
-
)
|
|
235
|
-
const identityResult = await wallet.getPublicKey({ identityKey: true })
|
|
236
|
-
const currentMobileIdentityKey = validateMobileIdentityKey(identityResult.publicKey)
|
|
237
|
-
if (currentMobileIdentityKey !== validated.mobileIdentityKey) {
|
|
238
|
-
throw new Error('Stored connection belongs to a different wallet identity')
|
|
239
|
-
}
|
|
240
|
-
const ws = new WebSocket(buildRelayWebSocketUrl(relay, validated.topic))
|
|
241
|
-
|
|
242
|
-
ws.onopen = async () => {
|
|
243
|
-
try {
|
|
244
|
-
const seq = initialSeq + 1
|
|
245
|
-
const payload = JSON.stringify({
|
|
246
|
-
id: crypto.randomUUID(),
|
|
247
|
-
seq,
|
|
248
|
-
method: 'session_revoke',
|
|
249
|
-
params: {}
|
|
250
|
-
})
|
|
251
|
-
const plaintext = Array.from(new TextEncoder().encode(payload))
|
|
252
|
-
const { ciphertext } = await wallet.encrypt({
|
|
253
|
-
protocolID: validated.protocolID,
|
|
254
|
-
keyID: validated.topic,
|
|
255
|
-
counterparty: validated.backendIdentityKey,
|
|
256
|
-
plaintext
|
|
257
|
-
})
|
|
258
|
-
ws.send(
|
|
259
|
-
JSON.stringify({
|
|
260
|
-
topic: validated.topic,
|
|
261
|
-
ciphertext: Buffer.from(ciphertext).toString('base64url')
|
|
262
|
-
})
|
|
263
|
-
)
|
|
264
|
-
} finally {
|
|
265
|
-
ws.close()
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
ws.onerror = () => ws.close()
|
|
269
|
-
} catch (e) {
|
|
270
|
-
console.warn('[connections] session_revoke failed:', e)
|
|
271
|
-
}
|
|
211
|
+
await revokeConnection(
|
|
212
|
+
conn,
|
|
213
|
+
managers.permissionsManager,
|
|
214
|
+
{ liveTopic: sessionMeta?.topic, disconnect },
|
|
215
|
+
{ store: connectionStore, guard: guardVaultAccess, cap: capWalletArgs, adminOriginator: ADMIN_ORIGINATOR, seqKey: lastSeqKey }
|
|
216
|
+
)
|
|
272
217
|
}
|
|
273
218
|
|
|
274
219
|
async function handleReconnect(conn: Connection) {
|