@bsv/expo-wallet-toolbox 0.27.0 → 0.29.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.
@@ -109,7 +109,7 @@ import {
109
109
  import Animated, { FadeIn, FadeInDown, useReducedMotion } from 'react-native-reanimated'
110
110
  import { useSafeAreaInsets } from 'react-native-safe-area-context'
111
111
  import { useTranslation } from 'react-i18next'
112
- import { Beef, createNonce, type ChainTracker, type WalletInterface } from '@bsv/sdk'
112
+ import { Beef, WERR_INSUFFICIENT_FUNDS, createNonce, type ChainTracker, type WalletInterface } from '@bsv/sdk'
113
113
  import { finalizeDelivery } from '../../../core/localpay/build'
114
114
  import { queuePendingAbort, queueDeclinedAbortWatch } from '../../../core/localpay/pendingAborts'
115
115
  import type { PendingAbortTagWallet } from '../../../core/localpay/pendingAbortAuthority'
@@ -323,6 +323,10 @@ type Phase =
323
323
  | 'failed'
324
324
 
325
325
  interface Failure {
326
+ /** The cause as a stable code, named where the failure is created (never read off `detail`). */
327
+ cause: NearbyFailureCause
328
+ /** The payee's own decline code, when the cause is a decline. */
329
+ declineReason?: string
326
330
  /** Human-readable cause, shown under the generic failure title. */
327
331
  detail: string
328
332
  /** Local Network access is off — offer a route to Settings. */
@@ -379,6 +383,21 @@ const DECLINE_KEYS: Record<DeclineReason, string> = {
379
383
  root_unverified: 'local_pay_declined_root_unverified'
380
384
  }
381
385
 
386
+ /**
387
+ * Decline codes as a failure cause. Only `root_unverified` has a remedy of its
388
+ * own (the payee goes online, the same code works again), so it alone gets its
389
+ * own cause. Every other code is a plain refusal; the code itself goes out as
390
+ * `NearbyFailed.declineReason` for a host that wants finer copy.
391
+ */
392
+ const DECLINE_CAUSES: Record<DeclineReason, NearbyFailureCause> = {
393
+ session_mismatch: 'declined',
394
+ already_paid: 'declined',
395
+ save_failed: 'declined',
396
+ decode_failed: 'declined',
397
+ not_covered: 'declined',
398
+ root_unverified: 'unverified'
399
+ }
400
+
382
401
  /**
383
402
  * Why the payer is on the fountain, as one sentence they can act on. Only ever
384
403
  * rendered when selectTransport() chose QR (spec §5) — this is what the hint
@@ -407,6 +426,18 @@ function messageOf(e: unknown): string {
407
426
  return text === '[object Object]' ? '' : text
408
427
  }
409
428
 
429
+ /**
430
+ * A wallet's refusal for a short balance, by class, name or code, never by its
431
+ * sentence. The toolbox's own errors expose `code` as the `WERR_*` name; the
432
+ * SDK class uses the number 7 (see core/bridge/protocol/errorCodec.ts).
433
+ */
434
+ function isInsufficientFunds(e: unknown): boolean {
435
+ if (e instanceof WERR_INSUFFICIENT_FUNDS) return true
436
+ if (typeof e !== 'object' || e === null) return false
437
+ const { name, code } = e as { name?: unknown; code?: unknown }
438
+ return name === 'WERR_INSUFFICIENT_FUNDS' || code === 'WERR_INSUFFICIENT_FUNDS' || code === 7
439
+ }
440
+
410
441
  /**
411
442
  * iOS surfaces a Local Network denial through Network.framework as a policy or
412
443
  * routing error rather than a typed permission result, so this is a match on the
@@ -557,7 +588,13 @@ export interface NearbyConfirm {
557
588
  holding?: bigint
558
589
  note: string
559
590
  setNote: (note: string) => void
560
- recipient: { name: string; detail?: string }
591
+ /**
592
+ * Who is being paid. `identityKey` is their wallet identity, for a host
593
+ * that draws a face from it: it is the same key the payment is addressed
594
+ * to, so the person on screen is provably the person being paid, and a
595
+ * host showing one elsewhere (an activity row, a contact) shows the same.
596
+ */
597
+ recipient: { name: string; detail?: string; identityKey?: string }
561
598
  /** A merchant's sale + tip breakdown, as a sentence. */
562
599
  tipText?: string
563
600
  /** The nearby link's state, as the presence row would say it. */
@@ -580,7 +617,7 @@ export interface NearbySending {
580
617
  /** Token session: `units` formatted in `asset`. */
581
618
  amountText?: string
582
619
  asset?: { ticker: string; decimals: number }
583
- recipient: { name: string; detail?: string }
620
+ recipient: { name: string; detail?: string; identityKey?: string }
584
621
  presence: { state: PresenceState; label: string } | null
585
622
  }
586
623
 
@@ -597,7 +634,7 @@ export interface NearbyShowCode {
597
634
  /** Token session: `units` formatted in `asset`. */
598
635
  amountText?: string
599
636
  asset?: { ticker: string; decimals: number }
600
- recipient: { name: string; detail?: string }
637
+ recipient: { name: string; detail?: string; identityKey?: string }
601
638
  presence: { state: PresenceState; label: string } | null
602
639
  /** Why it fell back to a code, when a radio was tried first. */
603
640
  notice?: { text: string; tone: 'success' | 'info' | 'warning' }
@@ -614,6 +651,8 @@ export interface NearbyDone {
614
651
  amountText?: string
615
652
  statusNote?: string
616
653
  recipientName?: string
654
+ /** Who was paid, as a wallet identity: the face on this screen is theirs. */
655
+ recipientKey?: string
617
656
  /** Back to the wallet; ends the flow. */
618
657
  dismiss: () => void
619
658
  }
@@ -630,10 +669,96 @@ export interface NearbyReceived {
630
669
  verification: 'pending' | 'verified' | 'not-credited'
631
670
  /** Who paid, when their name is known. */
632
671
  payerName?: string
672
+ /** Who paid, as a wallet identity: it is read off the payment frame they sent. */
673
+ payerKey?: string
633
674
  /** Back to the wallet; ends the flow. */
634
675
  dismiss: () => void
635
676
  }
636
677
 
678
+ /**
679
+ * Why a nearby payment did not go through, as a code a host can switch on.
680
+ *
681
+ * - `insufficient-funds`: the payer's wallet refused the build for a short BSV
682
+ * balance (`WERR_INSUFFICIENT_FUNDS`).
683
+ * - `network-permission`: Local Network access is off on this device.
684
+ * - `wrong-network`: the two wallets are on different networks.
685
+ * - `declined`: the payee's device refused the payment. `declineReason` on
686
+ * NearbyFailed says which refusal.
687
+ * - `unverified`: the payee's device could not check the payment against the
688
+ * chain, usually because it is offline and its headers are behind. The
689
+ * request stays live, so the same code works when the payee is online.
690
+ * - `unsaved`: a payment reached this device (the payee) and was not saved.
691
+ * - `too-large`: the payment's data is too large to hand over as a code.
692
+ * - `unknown`: none of the above, or a site that cannot name its cause
693
+ * without a guess. `detail` still carries the sentence.
694
+ */
695
+ export type NearbyFailureCause =
696
+ | 'insufficient-funds'
697
+ | 'network-permission'
698
+ | 'wrong-network'
699
+ | 'declined'
700
+ | 'unverified'
701
+ | 'unsaved'
702
+ | 'too-large'
703
+ | 'unknown'
704
+
705
+ /**
706
+ * Either side's dead end: the payment did not go through.
707
+ *
708
+ * `detail` is the core's own sentence for the cause, handed over raw so a host
709
+ * can write its own copy from it (and keep this as the fallback for a cause it
710
+ * does not recognise). Every action is optional except `cancel`: which ones are
711
+ * set is what the cause allows, so a host shows exactly the ones it is given.
712
+ */
713
+ export interface NearbyFailed {
714
+ /**
715
+ * The cause as a stable code. It is set where the failure is created, so it
716
+ * does not change when `detail` is translated or reworded: a host that writes
717
+ * its own copy switches on this, not on the sentence.
718
+ */
719
+ cause: NearbyFailureCause
720
+ /**
721
+ * The payee's own decline code, on a failure that is a decline (`cause` is
722
+ * `declined` or `unverified`). The known codes are `session_mismatch`,
723
+ * `already_paid`, `save_failed`, `decode_failed`, `not_covered` and
724
+ * `root_unverified`; a payee on another build can send one not listed here.
725
+ */
726
+ declineReason?: string
727
+ /** The core's own sentence for the cause. */
728
+ detail: string
729
+ /** Which side of the exchange this device is on: the causes differ. */
730
+ role: 'payer' | 'payee'
731
+ /** Satoshis the payer was sending; 0 on a token payment, where `amountText` is the figure. */
732
+ amount: number
733
+ amountText?: string
734
+ /** The token being sent, where it isn't BSV. */
735
+ asset?: { ticker: string; decimals: number }
736
+ /** Who was being paid, when their name is known. */
737
+ recipientName?: string
738
+ /** Set when the fix is in Settings (Local Network access is off). */
739
+ openSettings?: () => void
740
+ /** Set when this cause is one the core's wallet check can look into. */
741
+ checkWallet?: () => void
742
+ /** Set when a payment reached this device but never reached storage: retries the SAME session. */
743
+ retrySave?: () => void
744
+ /** Set when the payment can still be handed over as a code. */
745
+ showCode?: () => void
746
+ /** Start again from the top. Unset while a frame is still in hand, where `retrySave` is the way on. */
747
+ retry?: () => void
748
+ /** Give up: ends this payment (with a frame in hand, abandons it). */
749
+ cancel: () => void
750
+ }
751
+
752
+ /**
753
+ * The ways on from a failure, and nothing else. Derived once per render
754
+ * (`failedActions` in NearbyFlow) and read by both the built-in failure screen
755
+ * and `renderFailed`, so the two cannot offer different actions for one cause.
756
+ */
757
+ type NearbyFailedActions = Pick<
758
+ NearbyFailed,
759
+ 'openSettings' | 'checkWallet' | 'retrySave' | 'showCode' | 'retry' | 'cancel'
760
+ >
761
+
637
762
  export interface NearbyFlowProps {
638
763
  /** Which side of the exchange this device is on. Set by the cell that mounted it. */
639
764
  role: 'payer' | 'payee'
@@ -688,6 +813,24 @@ export interface NearbyFlowProps {
688
813
  * presents it full screen (a Modal) and plays its own sound.
689
814
  */
690
815
  renderReceived?: (received: NearbyReceived) => React.ReactNode
816
+ /**
817
+ * Either role: draw the failure yourself instead of the built-in screen. It
818
+ * is handed what went wrong and only the actions that cause allows
819
+ * (NearbyFailed). When `embedded`, the host presents it full screen itself (a
820
+ * Modal), exactly as `renderReceived` is presented.
821
+ */
822
+ renderFailed?: (failed: NearbyFailed) => React.ReactNode
823
+ /**
824
+ * A radio gave up and the payee is being told so. Given, each of those
825
+ * notices carries an (i) that calls `onPress` with the radio that stopped,
826
+ * so the host can say why in its own words; without it the notice is only
827
+ * the notice, exactly as before. `label` is what a screen reader announces
828
+ * for that button, and is the host's because the explanation behind it is:
829
+ * no wording for a sheet this component never draws belongs in its own
830
+ * translations. The flow is unaffected either way — a radio is an optional
831
+ * fast path, and the pairing code carries the payment whatever they do.
832
+ */
833
+ explainRadio?: { label: string; onPress: (kind: RadioKind) => void }
691
834
  }
692
835
 
693
836
  function NearbyFlow({
@@ -698,7 +841,9 @@ function NearbyFlow({
698
841
  dismissTo = '/',
699
842
  embedded,
700
843
  renderPayer,
701
- renderReceived
844
+ renderReceived,
845
+ renderFailed,
846
+ explainRadio
702
847
  }: NearbyFlowProps) {
703
848
  const { t } = useTranslation()
704
849
  const { colors } = useTheme()
@@ -1105,14 +1250,21 @@ function NearbyFlow({
1105
1250
  }, [])
1106
1251
 
1107
1252
  const fail = useCallback(
1108
- (kind: 'network' | 'generic', detail?: string, offerWalletCheck = false) => {
1253
+ (
1254
+ cause: NearbyFailureCause,
1255
+ detail?: string,
1256
+ { offerWalletCheck = false, declineReason }: { offerWalletCheck?: boolean; declineReason?: string } = {}
1257
+ ) => {
1109
1258
  setFailure(
1110
- kind === 'network'
1111
- ? { detail: t('local_pay_network_denied'), settings: true }
1259
+ // The one cause whose sentence and Settings route are fixed.
1260
+ cause === 'network-permission'
1261
+ ? { cause, detail: t('local_pay_network_denied'), settings: true }
1112
1262
  : {
1263
+ cause,
1113
1264
  detail: detail && detail.length > 0 ? detail : t('local_pay_failed'),
1114
1265
  settings: false,
1115
- offerWalletCheck
1266
+ offerWalletCheck,
1267
+ ...(declineReason ? { declineReason } : {})
1116
1268
  }
1117
1269
  )
1118
1270
  setPhase('failed')
@@ -1367,7 +1519,7 @@ function NearbyFlow({
1367
1519
  void confirm?.(false, 'save_failed')
1368
1520
  settlingRef.current = false
1369
1521
  setUnsettled(confirm ? null : { frame, session })
1370
- fail('generic', t('wallet_not_ready'))
1522
+ fail('unsaved', t('wallet_not_ready'))
1371
1523
  return
1372
1524
  }
1373
1525
 
@@ -1415,7 +1567,7 @@ function NearbyFlow({
1415
1567
  void confirm?.(false, 'save_failed')
1416
1568
  settlingRef.current = false
1417
1569
  setUnsettled(confirm ? null : { frame, session })
1418
- fail('generic', messageOf(e))
1570
+ fail('unsaved', messageOf(e))
1419
1571
  return
1420
1572
  }
1421
1573
 
@@ -1643,7 +1795,7 @@ function NearbyFlow({
1643
1795
  // means a payer can deliver a frame the payee then cannot persist, after the
1644
1796
  // transport has already acked it as accepted.
1645
1797
  if (!wallet || !storage) {
1646
- fail('generic', t('wallet_not_ready'))
1798
+ fail('unknown', t('wallet_not_ready'))
1647
1799
  return
1648
1800
  }
1649
1801
  setPhase('receive_minting')
@@ -1706,7 +1858,7 @@ function NearbyFlow({
1706
1858
  setHostedSession(session)
1707
1859
  setPhase('receive_wait')
1708
1860
  } catch (e) {
1709
- fail('generic', messageOf(e))
1861
+ fail('unknown', messageOf(e))
1710
1862
  }
1711
1863
  },
1712
1864
  [wallet, storage, adminOriginator, supportsAwdl, nearbyReady, blePermitted, walletNetwork, fail, t]
@@ -1770,7 +1922,7 @@ function NearbyFlow({
1770
1922
  const mismatch = walletNetwork === undefined ? null : sessionNetworkMismatch(session, walletNetwork)
1771
1923
  if (mismatch) {
1772
1924
  fail(
1773
- 'generic',
1925
+ 'wrong-network',
1774
1926
  t('local_pay_wrong_network', {
1775
1927
  theirs: networkName(mismatch.theirs, t),
1776
1928
  mine: networkName(mismatch.mine, t)
@@ -1800,14 +1952,14 @@ function NearbyFlow({
1800
1952
  if (data.startsWith(POS_PREFIX)) {
1801
1953
  void decodePaymentRequest(data)
1802
1954
  .then(adoptSession)
1803
- .catch(() => fail('generic', t('invalid_qr_code')))
1955
+ .catch(() => fail('unknown', t('invalid_qr_code')))
1804
1956
  return
1805
1957
  }
1806
1958
  let session: Session
1807
1959
  try {
1808
1960
  session = decodeSession(data)
1809
1961
  } catch {
1810
- fail('generic', t('invalid_qr_code'))
1962
+ fail('unknown', t('invalid_qr_code'))
1811
1963
  return
1812
1964
  }
1813
1965
  adoptSession(session)
@@ -2090,7 +2242,7 @@ function NearbyFlow({
2090
2242
  // and buildPaymentFrame would refuse it anyway.
2091
2243
  if (session.asset ? payUnits <= 0n : payAmount <= 0) return
2092
2244
  if (!wallet) {
2093
- fail('generic', t('wallet_not_ready'))
2245
+ fail('unknown', t('wallet_not_ready'))
2094
2246
  return
2095
2247
  }
2096
2248
  if (session.merchantChain) {
@@ -2098,11 +2250,15 @@ function NearbyFlow({
2098
2250
  const network = await wallet.getNetwork({})
2099
2251
  const expected = session.merchantChain === 'main' ? 'mainnet' : 'testnet'
2100
2252
  if (network.network !== expected || !session.merchantExpires || session.merchantExpires <= Date.now()) {
2101
- fail('generic', 'Merchant request expired or uses a different network.')
2253
+ // One sentence for two causes; the code says which one it was.
2254
+ fail(
2255
+ network.network !== expected ? 'wrong-network' : 'unknown',
2256
+ 'Merchant request expired or uses a different network.'
2257
+ )
2102
2258
  return
2103
2259
  }
2104
2260
  } catch {
2105
- fail('generic', 'Could not verify the merchant payment network.')
2261
+ fail('unknown', 'Could not verify the merchant payment network.')
2106
2262
  return
2107
2263
  }
2108
2264
  }
@@ -2147,7 +2303,7 @@ function NearbyFlow({
2147
2303
  const runtime = mandala.runtime
2148
2304
  const known = (mandala.balances ?? []).find(b => b.asset.assetId === session.asset?.id)
2149
2305
  if (!runtime || !known) {
2150
- fail('generic', t('pay_asset_nearby_wrong_overlay'))
2306
+ fail('unknown', t('pay_asset_nearby_wrong_overlay'))
2151
2307
  return
2152
2308
  }
2153
2309
  }
@@ -2194,7 +2350,11 @@ function NearbyFlow({
2194
2350
  // built, so there is nothing to abort.
2195
2351
  if (!controller.signal.aborted) {
2196
2352
  const facing = userFacingPayError(e)
2197
- fail('generic', facing.offerWalletCheck ? t(facing.key) : messageOf(e), facing.offerWalletCheck)
2353
+ fail(
2354
+ isInsufficientFunds(e) ? 'insufficient-funds' : 'unknown',
2355
+ facing.offerWalletCheck ? t(facing.key) : messageOf(e),
2356
+ { offerWalletCheck: facing.offerWalletCheck }
2357
+ )
2198
2358
  }
2199
2359
  return
2200
2360
  }
@@ -2215,7 +2375,7 @@ function NearbyFlow({
2215
2375
  if (sealed.length > MAX_MESSAGE_BYTES) {
2216
2376
  abortBuild(built.reference, session.asset ? built.txid : undefined)
2217
2377
  setPaymentQr(null)
2218
- fail('generic', t('local_pay_too_large'))
2378
+ fail('too-large', t('local_pay_too_large'))
2219
2379
  return
2220
2380
  }
2221
2381
  builtRef.current = built
@@ -2282,7 +2442,7 @@ function NearbyFlow({
2282
2442
  // than left as an untracked orphan reachable only by the
2283
2443
  // unrestricted generic Abort action.
2284
2444
  await parkUncertainDelivery(built, sealedToQr(sealed))
2285
- fail(looksLikeLocalNetworkDenial(message) ? 'network' : 'generic', t('local_pay_too_large'))
2445
+ fail(looksLikeLocalNetworkDenial(message) ? 'network-permission' : 'too-large', t('local_pay_too_large'))
2286
2446
  return
2287
2447
  }
2288
2448
  builtRef.current = built
@@ -2394,7 +2554,12 @@ function NearbyFlow({
2394
2554
  // considers free invites a double-spend. Clearing paymentQr also drops
2395
2555
  // any stale QR left by an earlier attempt.
2396
2556
  setPaymentQr(null)
2397
- fail('generic', declineMessage(outcome.reason))
2557
+ fail(
2558
+ // A code this build does not know is still a refusal by the payee.
2559
+ outcome.reason && isDeclineReason(outcome.reason) ? DECLINE_CAUSES[outcome.reason] : 'declined',
2560
+ declineMessage(outcome.reason),
2561
+ { declineReason: outcome.reason }
2562
+ )
2398
2563
  return
2399
2564
  }
2400
2565
 
@@ -2652,12 +2817,33 @@ function NearbyFlow({
2652
2817
  const onPaymentQrError = useCallback(() => {
2653
2818
  void Promise.resolve().then(() => {
2654
2819
  setPaymentQr(null)
2655
- fail('generic', t('local_pay_too_large'))
2820
+ fail('too-large', t('local_pay_too_large'))
2656
2821
  })
2657
2822
  }, [fail, t])
2658
2823
 
2659
2824
  // ── Derived ──
2660
2825
 
2826
+ // What the failure allows. The one place these rules live: the built-in
2827
+ // failure screen and a host's `renderFailed` both read this value.
2828
+ const failedActions: NearbyFailedActions = {
2829
+ ...(failure?.settings ? { openSettings: () => void Linking.openSettings() } : {}),
2830
+ ...(failure?.offerWalletCheck ? { checkWallet: () => router.push('/wallet-check' as never) } : {}),
2831
+ // A frame reached this device but never reached storage. Retry the SAME
2832
+ // session: reset() would mint one that can never receive it, and with the
2833
+ // frame only in memory, starting again is abandoning it — so there is no
2834
+ // `retry` while it is in hand.
2835
+ ...(unsettled ? { retrySave: retrySettle } : { retry }),
2836
+ ...(paymentQr
2837
+ ? {
2838
+ showCode: () => {
2839
+ setFailure(null)
2840
+ setPhase('send_qr')
2841
+ }
2842
+ }
2843
+ : {}),
2844
+ cancel: reset
2845
+ }
2846
+
2661
2847
  // Source blocks in the payment code. One block renders as a still QR, so the
2662
2848
  // "hold steady while it animates" hint would be wrong copy for it.
2663
2849
  const paymentQrBlocks = useMemo(() => {
@@ -3046,18 +3232,20 @@ function NearbyFlow({
3046
3232
  {radioFailures.map(([kind, err]) => (
3047
3233
  <React.Fragment key={kind}>
3048
3234
  <View style={styles.gapLg} />
3049
- <Animated.View
3050
- entering={fadeIn}
3051
- style={[styles.notice, { backgroundColor: colors.fillTertiary, borderColor: colors.separator }]}
3052
- >
3053
- <Info size={16} color={colors.textSecondary} />
3054
- <Text style={[styles.noticeText, { color: colors.textSecondary }]}>
3055
- {err.networkDenied
3056
- ? t('local_pay_network_denied')
3057
- : kind === 'ble'
3058
- ? t('local_pay_ble_unavailable')
3059
- : t('local_pay_nearby_unavailable')}
3060
- </Text>
3235
+ <Animated.View entering={fadeIn} style={styles.stretch}>
3236
+ <RadioNotice
3237
+ styles={styles}
3238
+ colors={colors}
3239
+ label={
3240
+ err.networkDenied
3241
+ ? t('local_pay_network_denied')
3242
+ : kind === 'ble'
3243
+ ? t('local_pay_ble_unavailable')
3244
+ : t('local_pay_nearby_unavailable')
3245
+ }
3246
+ explainLabel={explainRadio?.label ?? ''}
3247
+ {...(explainRadio && !err.networkDenied ? { onExplain: () => explainRadio.onPress(kind) } : {})}
3248
+ />
3061
3249
  </Animated.View>
3062
3250
  </React.Fragment>
3063
3251
  ))}
@@ -3327,69 +3515,9 @@ function NearbyFlow({
3327
3515
  </Text>
3328
3516
  <View style={styles.gapXl} />
3329
3517
 
3330
- {/* A frame reached this device but never reached storage. Retry the
3331
- SAME session — reset() would mint one that can never receive it. */}
3332
- {unsettled && (
3333
- <>
3334
- <PrimaryButton
3335
- styles={styles}
3336
- colors={colors}
3337
- icon="refresh"
3338
- label={t('local_pay_retry_save')}
3339
- onPress={retrySettle}
3340
- />
3341
- <View style={styles.gapMd} />
3342
- </>
3343
- )}
3344
-
3345
- {failure?.settings && (
3346
- <>
3347
- <SecondaryButton
3348
- styles={styles}
3349
- colors={colors}
3350
- icon="settings-outline"
3351
- label={t('open_settings')}
3352
- onPress={() => void Linking.openSettings()}
3353
- />
3354
- <View style={styles.gapMd} />
3355
- </>
3356
- )}
3357
-
3358
- {failure?.offerWalletCheck && (
3359
- <>
3360
- <SecondaryButton
3361
- styles={styles}
3362
- colors={colors}
3363
- label={t('check_wallet')}
3364
- onPress={() => router.push('/wallet-check' as never)}
3365
- />
3366
- <View style={styles.gapMd} />
3367
- </>
3368
- )}
3369
-
3370
- {paymentQr && (
3371
- <>
3372
- <SecondaryButton
3373
- styles={styles}
3374
- colors={colors}
3375
- icon="qr-code-outline"
3376
- label={t('local_pay_show_qr_instead')}
3377
- onPress={() => {
3378
- setFailure(null)
3379
- setPhase('send_qr')
3380
- }}
3381
- />
3382
- <View style={styles.gapMd} />
3383
- </>
3384
- )}
3385
-
3386
- {/* With a frame in hand, reset() means abandoning it — the frame lives
3387
- only in memory — so it is demoted to the secondary action. */}
3388
- {unsettled ? (
3389
- <CancelButton styles={styles} colors={colors} label={t('cancel')} onPress={reset} />
3390
- ) : (
3391
- <PrimaryButton styles={styles} colors={colors} label={t('retry')} onPress={retry} />
3392
- )}
3518
+ {/* The buttons are drawn from failedActions, the same value a host's
3519
+ renderFailed is handed. */}
3520
+ <FailedActionButtons styles={styles} colors={colors} actions={failedActions} />
3393
3521
  </Animated.View>
3394
3522
  )}
3395
3523
  </ScrollView>
@@ -3487,16 +3615,19 @@ function NearbyFlow({
3487
3615
  radioFailures.map(([kind, err]) => (
3488
3616
  <React.Fragment key={kind}>
3489
3617
  <View style={styles.gapMd} />
3490
- <View style={[styles.notice, { backgroundColor: colors.fillTertiary, borderColor: colors.separator }]}>
3491
- <Info size={16} color={colors.textSecondary} />
3492
- <Text style={[styles.noticeText, { color: colors.textSecondary }]}>
3493
- {err.networkDenied
3618
+ <RadioNotice
3619
+ styles={styles}
3620
+ colors={colors}
3621
+ label={
3622
+ err.networkDenied
3494
3623
  ? t('local_pay_network_denied')
3495
3624
  : kind === 'ble'
3496
3625
  ? t('local_pay_ble_unavailable')
3497
- : t('local_pay_nearby_unavailable')}
3498
- </Text>
3499
- </View>
3626
+ : t('local_pay_nearby_unavailable')
3627
+ }
3628
+ explainLabel={explainRadio?.label ?? ''}
3629
+ {...(explainRadio && !err.networkDenied ? { onExplain: () => explainRadio.onPress(kind) } : {})}
3630
+ />
3500
3631
  </React.Fragment>
3501
3632
  ))}
3502
3633
  {phase === 'receive_wait' && radioFailures.some(([, err]) => err.networkDenied) && (
@@ -3511,22 +3642,19 @@ function NearbyFlow({
3511
3642
  />
3512
3643
  </>
3513
3644
  )}
3514
- {/* the payer's radios failed and it shows its own code instead */}
3645
+ {/* the payer's radios failed and it shows its own code instead: the one
3646
+ thing left to do on this step, so it is the step's button, the same
3647
+ one the full-screen flow gives it rather than a line of small text */}
3515
3648
  {phase === 'receive_wait' && (
3516
3649
  <>
3517
- <View style={styles.gapMd} />
3518
- <PressableScale
3650
+ <View style={styles.gapLg} />
3651
+ <SecondaryButton
3652
+ styles={styles}
3653
+ colors={colors}
3654
+ icon="scan-outline"
3655
+ label={t('local_pay_scan_payer_qr')}
3519
3656
  onPress={() => openScanner('receive_scan')}
3520
- haptic="tap"
3521
- style={styles.embeddedScan}
3522
- accessibilityRole="button"
3523
- accessibilityLabel={t('local_pay_scan_payer_qr')}
3524
- >
3525
- <ScanLine size={16} color={colors.textSecondary} />
3526
- <Text style={[styles.embeddedScanText, { color: colors.textSecondary }]}>
3527
- {t('local_pay_scan_payer_qr')}
3528
- </Text>
3529
- </PressableScale>
3657
+ />
3530
3658
  </>
3531
3659
  )}
3532
3660
  </View>
@@ -3539,116 +3667,137 @@ function NearbyFlow({
3539
3667
  ? `Merchant · ${abbreviateKey(scannedSession.identityKey)}`
3540
3668
  : peerName
3541
3669
  ? abbreviateKey(scannedSession.identityKey)
3542
- : undefined
3670
+ : undefined,
3671
+ identityKey: scannedSession.identityKey
3543
3672
  }
3544
3673
  : { name: '' }
3545
3674
  // wrapped, so a host that renders nothing still replaces the built-in step
3546
3675
  const hosted: { node: React.ReactNode } | null =
3547
- role !== 'payer' || !renderPayer
3548
- ? null
3549
- : phase === 'send_confirm' && scannedSession && renderPayer.confirm
3550
- ? {
3551
- node: (
3552
- <Hosted
3553
- render={renderPayer.confirm}
3554
- value={{
3555
- session: scannedSession,
3556
- fixedAmount,
3557
- amount: payAmount,
3558
- ...(scannedSession.asset ? { fixedUnits, units: payUnits, amountText: payAmountText } : {}),
3559
- setAmount: amount =>
3560
- setSendAmount(
3561
- typeof amount === 'bigint'
3562
- ? amount > 0n
3563
- ? amount.toString()
3564
- : ''
3565
- : amount !== undefined && amount > 0
3566
- ? String(Math.round(amount))
3567
- : ''
3568
- ),
3569
- asset: scannedAssetUnits,
3570
- holding: scannedHolding && !unitsUnknown ? scannedHolding.units : undefined,
3571
- note,
3572
- setNote,
3573
- recipient: payerRecipient,
3574
- tipText: scannedSession.merchantTip
3575
- ? t('merchant_tip_breakdown', {
3576
- defaultValue: '{{subtotal}} sats sale + {{tip}} sats tip',
3577
- subtotal: scannedSession.merchantSubtotal?.toLocaleString(),
3578
- tip: scannedSession.merchantTip.toLocaleString()
3579
- })
3580
- : undefined,
3581
- presence,
3582
- advisories: [
3583
- ...(floorReason !== 'none' ? [t(FLOOR_KEYS[floorReason])] : []),
3584
- ...(overHolding && scannedAssetUnits && !unitsUnknown
3585
- ? [t('pay_asset_over_balance', { ticker: scannedAssetUnits.ticker })]
3586
- : []),
3587
- ...(unitsUnknown ? [t('pay_asset_unidentified')] : [])
3588
- ],
3589
- openSettings: floorReason === 'local_ble_denied' ? () => void Linking.openSettings() : undefined,
3590
- canSend,
3591
- send: () => void executeSend(),
3592
- cancel: reset
3593
- }}
3594
- />
3595
- )
3596
- }
3597
- : phase === 'send_working' && renderPayer.sending
3676
+ phase === 'failed' && failure && role && renderFailed
3677
+ ? {
3678
+ node: (
3679
+ <Hosted
3680
+ render={renderFailed}
3681
+ value={{
3682
+ cause: failure.cause,
3683
+ ...(failure.declineReason ? { declineReason: failure.declineReason } : {}),
3684
+ detail: failure.detail,
3685
+ role,
3686
+ amount: payAmount,
3687
+ ...(scannedSession?.asset ? { amountText: payAmountText } : {}),
3688
+ asset: scannedAssetUnits,
3689
+ recipientName: payerRecipient.name || undefined,
3690
+ ...failedActions
3691
+ }}
3692
+ />
3693
+ )
3694
+ }
3695
+ : role !== 'payer' || !renderPayer
3696
+ ? null
3697
+ : phase === 'send_confirm' && scannedSession && renderPayer.confirm
3598
3698
  ? {
3599
3699
  node: (
3600
3700
  <Hosted
3601
- render={renderPayer.sending}
3701
+ render={renderPayer.confirm}
3602
3702
  value={{
3703
+ session: scannedSession,
3704
+ fixedAmount,
3603
3705
  amount: payAmount,
3604
- ...(scannedSession?.asset ? { units: payUnits, amountText: payAmountText } : {}),
3706
+ ...(scannedSession.asset ? { fixedUnits, units: payUnits, amountText: payAmountText } : {}),
3707
+ setAmount: amount =>
3708
+ setSendAmount(
3709
+ typeof amount === 'bigint'
3710
+ ? amount > 0n
3711
+ ? amount.toString()
3712
+ : ''
3713
+ : amount !== undefined && amount > 0
3714
+ ? String(Math.round(amount))
3715
+ : ''
3716
+ ),
3605
3717
  asset: scannedAssetUnits,
3718
+ holding: scannedHolding && !unitsUnknown ? scannedHolding.units : undefined,
3719
+ note,
3720
+ setNote,
3606
3721
  recipient: payerRecipient,
3607
- presence
3722
+ tipText: scannedSession.merchantTip
3723
+ ? t('merchant_tip_breakdown', {
3724
+ defaultValue: '{{subtotal}} sats sale + {{tip}} sats tip',
3725
+ subtotal: scannedSession.merchantSubtotal?.toLocaleString(),
3726
+ tip: scannedSession.merchantTip.toLocaleString()
3727
+ })
3728
+ : undefined,
3729
+ presence,
3730
+ advisories: [
3731
+ ...(floorReason !== 'none' ? [t(FLOOR_KEYS[floorReason])] : []),
3732
+ ...(overHolding && scannedAssetUnits && !unitsUnknown
3733
+ ? [t('pay_asset_over_balance', { ticker: scannedAssetUnits.ticker })]
3734
+ : []),
3735
+ ...(unitsUnknown ? [t('pay_asset_unidentified')] : [])
3736
+ ],
3737
+ openSettings: floorReason === 'local_ble_denied' ? () => void Linking.openSettings() : undefined,
3738
+ canSend,
3739
+ send: () => void executeSend(),
3740
+ cancel: reset
3608
3741
  }}
3609
3742
  />
3610
3743
  )
3611
3744
  }
3612
- : phase === 'send_qr' && paymentQr && renderPayer.showCode
3745
+ : phase === 'send_working' && renderPayer.sending
3613
3746
  ? {
3614
3747
  node: (
3615
3748
  <Hosted
3616
- render={renderPayer.showCode}
3749
+ render={renderPayer.sending}
3617
3750
  value={{
3618
- code: size => <PaymentQrDisplay frameQr={paymentQr} size={size} onError={onPaymentQrError} />,
3619
- animated: paymentQrBlocks > 1,
3620
3751
  amount: payAmount,
3621
3752
  ...(scannedSession?.asset ? { units: payUnits, amountText: payAmountText } : {}),
3622
3753
  asset: scannedAssetUnits,
3623
3754
  recipient: payerRecipient,
3624
- presence,
3625
- notice: notice ?? undefined,
3626
- done: () => void completeQrDelivery(),
3627
- back: () => void handleSendQrExit(false)
3755
+ presence
3628
3756
  }}
3629
3757
  />
3630
3758
  )
3631
3759
  }
3632
- : phase === 'done' && renderPayer.done
3760
+ : phase === 'send_qr' && paymentQr && renderPayer.showCode
3633
3761
  ? {
3634
3762
  node: (
3635
3763
  <Hosted
3636
- render={renderPayer.done}
3764
+ render={renderPayer.showCode}
3637
3765
  value={{
3638
- amount: settledAmount,
3639
- amountText: settledTokenText ?? undefined,
3640
- statusNote: settledStatusNote ?? undefined,
3641
- recipientName:
3642
- peerName ?? (scannedSession ? abbreviateKey(scannedSession.identityKey) : undefined),
3643
- dismiss: () => {
3644
- goBack()
3645
- router.dismissTo(dismissTo)
3646
- }
3766
+ code: size => <PaymentQrDisplay frameQr={paymentQr} size={size} onError={onPaymentQrError} />,
3767
+ animated: paymentQrBlocks > 1,
3768
+ amount: payAmount,
3769
+ ...(scannedSession?.asset ? { units: payUnits, amountText: payAmountText } : {}),
3770
+ asset: scannedAssetUnits,
3771
+ recipient: payerRecipient,
3772
+ presence,
3773
+ notice: notice ?? undefined,
3774
+ done: () => void completeQrDelivery(),
3775
+ back: () => void handleSendQrExit(false)
3647
3776
  }}
3648
3777
  />
3649
3778
  )
3650
3779
  }
3651
- : null
3780
+ : phase === 'done' && renderPayer.done
3781
+ ? {
3782
+ node: (
3783
+ <Hosted
3784
+ render={renderPayer.done}
3785
+ value={{
3786
+ amount: settledAmount,
3787
+ amountText: settledTokenText ?? undefined,
3788
+ statusNote: settledStatusNote ?? undefined,
3789
+ recipientName:
3790
+ peerName ?? (scannedSession ? abbreviateKey(scannedSession.identityKey) : undefined),
3791
+ recipientKey: scannedSession?.identityKey,
3792
+ dismiss: () => {
3793
+ goBack()
3794
+ router.dismissTo(dismissTo)
3795
+ }
3796
+ }}
3797
+ />
3798
+ )
3799
+ }
3800
+ : null
3652
3801
 
3653
3802
  return (
3654
3803
  <View
@@ -3713,6 +3862,7 @@ function NearbyFlow({
3713
3862
  broadcast: settledTokenText ? undefined : receivedBroadcast,
3714
3863
  verification: receivedVerification,
3715
3864
  payerName: peerName ?? undefined,
3865
+ payerKey: peerKey ?? undefined,
3716
3866
  dismiss: () => {
3717
3867
  goBack()
3718
3868
  router.dismissTo(dismissTo)
@@ -3799,6 +3949,120 @@ function PrimaryButton({
3799
3949
  )
3800
3950
  }
3801
3951
 
3952
+ /**
3953
+ * The built-in failure screen's buttons, one per entry of the actions it is
3954
+ * given. It decides nothing: which actions exist is NearbyFlow's
3955
+ * `failedActions`, the value a host's `renderFailed` also receives.
3956
+ */
3957
+ function FailedActionButtons({
3958
+ styles,
3959
+ colors,
3960
+ actions
3961
+ }: {
3962
+ styles: Styles
3963
+ colors: Colors
3964
+ actions: NearbyFailedActions
3965
+ }) {
3966
+ const { t } = useTranslation()
3967
+ return (
3968
+ <>
3969
+ {/* A frame reached this device but never reached storage. Retry the
3970
+ SAME session — reset() would mint one that can never receive it. */}
3971
+ {actions.retrySave && (
3972
+ <>
3973
+ <PrimaryButton
3974
+ styles={styles}
3975
+ colors={colors}
3976
+ icon="refresh"
3977
+ label={t('local_pay_retry_save')}
3978
+ onPress={actions.retrySave}
3979
+ />
3980
+ <View style={styles.gapMd} />
3981
+ </>
3982
+ )}
3983
+
3984
+ {actions.openSettings && (
3985
+ <>
3986
+ <SecondaryButton
3987
+ styles={styles}
3988
+ colors={colors}
3989
+ icon="settings-outline"
3990
+ label={t('open_settings')}
3991
+ onPress={actions.openSettings}
3992
+ />
3993
+ <View style={styles.gapMd} />
3994
+ </>
3995
+ )}
3996
+
3997
+ {actions.checkWallet && (
3998
+ <>
3999
+ <SecondaryButton styles={styles} colors={colors} label={t('check_wallet')} onPress={actions.checkWallet} />
4000
+ <View style={styles.gapMd} />
4001
+ </>
4002
+ )}
4003
+
4004
+ {actions.showCode && (
4005
+ <>
4006
+ <SecondaryButton
4007
+ styles={styles}
4008
+ colors={colors}
4009
+ icon="qr-code-outline"
4010
+ label={t('local_pay_show_qr_instead')}
4011
+ onPress={actions.showCode}
4012
+ />
4013
+ <View style={styles.gapMd} />
4014
+ </>
4015
+ )}
4016
+
4017
+ {/* With a frame in hand there is no `retry`, and reset() means
4018
+ abandoning the frame — it lives only in memory — so the way out
4019
+ is the demoted Cancel. */}
4020
+ {actions.retry ? (
4021
+ <PrimaryButton styles={styles} colors={colors} label={t('retry')} onPress={actions.retry} />
4022
+ ) : (
4023
+ <CancelButton styles={styles} colors={colors} label={t('cancel')} onPress={actions.cancel} />
4024
+ )}
4025
+ </>
4026
+ )
4027
+ }
4028
+
4029
+ /**
4030
+ * A radio that gave up: what stopped, and an (i) for why when the host offers
4031
+ * one. The text takes the width (noticeText is flex: 1), so the button sits
4032
+ * against the right edge without a spacer.
4033
+ */
4034
+ function RadioNotice({
4035
+ styles,
4036
+ colors,
4037
+ label,
4038
+ explainLabel,
4039
+ onExplain
4040
+ }: {
4041
+ styles: Styles
4042
+ colors: Colors
4043
+ label: string
4044
+ explainLabel: string
4045
+ onExplain?: () => void
4046
+ }) {
4047
+ return (
4048
+ <View style={[styles.notice, { backgroundColor: colors.fillTertiary, borderColor: colors.separator }]}>
4049
+ <Info size={16} color={colors.textSecondary} />
4050
+ <Text style={[styles.noticeText, { color: colors.textSecondary }]}>{label}</Text>
4051
+ {!!onExplain && (
4052
+ <PressableScale
4053
+ onPress={onExplain}
4054
+ haptic="tap"
4055
+ hitSlop={8}
4056
+ accessibilityRole="button"
4057
+ accessibilityLabel={explainLabel}
4058
+ >
4059
+ <Info size={18} color={colors.accent} />
4060
+ </PressableScale>
4061
+ )}
4062
+ </View>
4063
+ )
4064
+ }
4065
+
3802
4066
  function SecondaryButton({
3803
4067
  styles,
3804
4068
  colors,
@@ -3875,8 +4139,6 @@ function makeStyles() {
3875
4139
  container: { flex: 1 },
3876
4140
  embedded: { alignItems: 'center', alignSelf: 'stretch' },
3877
4141
  embeddedPending: { alignItems: 'center', justifyContent: 'center' },
3878
- embeddedScan: { flexDirection: 'row', alignItems: 'center', gap: 6, paddingVertical: 6, paddingHorizontal: 12 },
3879
- embeddedScanText: { fontFamily: 'Nunito', fontSize: 13, lineHeight: 18 },
3880
4142
  header: {
3881
4143
  flexDirection: 'row',
3882
4144
  alignItems: 'center',
@@ -3987,6 +4249,7 @@ function makeStyles() {
3987
4249
  paddingVertical: spacing.md
3988
4250
  },
3989
4251
 
4252
+ stretch: { alignSelf: 'stretch' },
3990
4253
  notice: {
3991
4254
  flexDirection: 'row',
3992
4255
  alignItems: 'center',