@bsv/expo-wallet-toolbox 0.5.0 → 0.9.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.
Files changed (200) hide show
  1. package/CHANGELOG.md +2000 -0
  2. package/README.md +66 -1
  3. package/core/amountFormatHelpers.ts +258 -36
  4. package/core/backup/RemoteSyncReader.ts +133 -24
  5. package/core/backup/appData.ts +157 -0
  6. package/core/backup/client.ts +15 -1
  7. package/core/backup/codec.ts +149 -11
  8. package/core/backup/constants.ts +30 -1
  9. package/core/backup/cursor.ts +31 -2
  10. package/core/backup/push.ts +71 -5
  11. package/core/backup/restore.ts +104 -16
  12. package/core/backup/restoreOnImport.ts +94 -30
  13. package/core/backup/status.ts +13 -8
  14. package/core/config.tsx +12 -5
  15. package/core/constants.ts +14 -1
  16. package/core/contacts/contactActivity.ts +153 -0
  17. package/core/contacts/contactCache.ts +41 -0
  18. package/core/contacts/contactsStore.ts +183 -0
  19. package/core/context/ExchangeRateContext.tsx +34 -27
  20. package/core/context/LocalStorageProvider.tsx +43 -40
  21. package/core/context/UserContext.tsx +18 -7
  22. package/core/context/VaultContext.tsx +49 -2
  23. package/core/context/WalletConnectionContext.tsx +203 -11
  24. package/core/context/WalletContext.tsx +685 -171
  25. package/core/demo/demoAssets.ts +60 -0
  26. package/core/demo/demoLedger.ts +240 -0
  27. package/core/demo/demoMandalaRuntime.ts +96 -0
  28. package/core/demo/demoMode.ts +38 -0
  29. package/core/demo/demoWallet.ts +25 -0
  30. package/core/demo/index.ts +26 -0
  31. package/core/demo/useDemo.ts +59 -0
  32. package/core/headers/OfflineFirstChaintracks.ts +99 -17
  33. package/core/headers/headerStore.ts +33 -14
  34. package/core/headers/syncHeaders.ts +12 -1
  35. package/core/i18n/translations.tsx +2186 -98
  36. package/core/identity/contactLink.ts +36 -0
  37. package/core/identity/handleRegistry/client.ts +314 -0
  38. package/core/identity/handleRegistry/keyPinStore.ts +70 -0
  39. package/core/identity/handleRegistry/profileCert.ts +254 -0
  40. package/core/identity/handleRegistry/registration.ts +559 -0
  41. package/core/identity/handleRegistry/resolver.ts +315 -0
  42. package/core/identity/handleRegistry/rules.ts +104 -0
  43. package/core/index.ts +53 -5
  44. package/core/localpay/build.ts +225 -24
  45. package/core/localpay/pending.ts +110 -7
  46. package/core/localpay/pendingAbortAuthority.ts +95 -0
  47. package/core/localpay/pendingAborts.ts +266 -26
  48. package/core/localpay/session.ts +42 -17
  49. package/core/localpay/settlementAck.ts +10 -1
  50. package/core/localpay/transport/socket.ts +52 -3
  51. package/core/localpay/verify.ts +100 -10
  52. package/core/mandala/abortGuard.ts +96 -20
  53. package/core/mandala/createRuntime.ts +206 -33
  54. package/core/mandala/drain.ts +89 -11
  55. package/core/mandala/inboxPrehold.ts +186 -0
  56. package/core/mandala/permissionModule.ts +202 -20
  57. package/core/mandala/settlementStore.ts +24 -2
  58. package/core/mandala/types.ts +40 -5
  59. package/core/monitor/MonitorSupervisor.ts +121 -0
  60. package/core/monitor/TaskBackupPush.ts +15 -1
  61. package/core/monitor/TaskCreditInbox.ts +1 -1
  62. package/core/monitor/TaskDrainOutbox.ts +15 -1
  63. package/core/monitor/TaskSendOffline.ts +15 -1
  64. package/core/net/online.ts +49 -0
  65. package/core/net/publicDestination.ts +91 -0
  66. package/core/net/validateArcUrl.ts +22 -0
  67. package/core/numberFormat.ts +19 -0
  68. package/core/offline/cancelParked.ts +134 -13
  69. package/core/offline/payerHold.ts +100 -24
  70. package/core/offline/plan.ts +37 -8
  71. package/core/pay/beefRepair.ts +6 -2
  72. package/core/pay/damagedInbox.ts +24 -0
  73. package/core/pay/rails/address.ts +107 -12
  74. package/core/pay/rails/handle.ts +117 -22
  75. package/core/pay/rails/index.ts +45 -7
  76. package/core/pay/rails/nativeIntent.ts +61 -0
  77. package/core/pay/receiveHistory.ts +93 -0
  78. package/core/pay/recordProof.ts +21 -7
  79. package/core/pay/refreshProofGuard.ts +42 -1
  80. package/core/pay/watchlist.ts +5 -2
  81. package/core/peerpay/control.ts +17 -18
  82. package/core/peerpay/handleResendRequests.ts +58 -4
  83. package/core/peerpay/outbox.ts +3 -1
  84. package/core/recovery/backupMaterial.ts +61 -0
  85. package/core/recovery/createWallet.ts +95 -0
  86. package/core/recovery/recoverWallet.ts +120 -0
  87. package/core/recovery/restoreWallet.ts +170 -0
  88. package/core/recovery/secret.ts +92 -0
  89. package/core/recovery/shareCollector.ts +71 -0
  90. package/core/recovery/shareParsing.ts +87 -0
  91. package/core/recovery/shares.ts +116 -0
  92. package/core/recovery/useRecoveryDeps.ts +70 -0
  93. package/core/services/arcTokenStorage.ts +52 -0
  94. package/core/services/arcadeBroadcastProvider.ts +233 -52
  95. package/core/services/autoApprovePolicy.ts +105 -0
  96. package/core/services/callbackToken.ts +19 -0
  97. package/core/services/capWalletArgs.ts +14 -2
  98. package/core/services/connectionAuthority.ts +98 -0
  99. package/core/services/exchangeRate.ts +36 -13
  100. package/core/services/externalOrigin.ts +16 -2
  101. package/core/services/secrets/kek.ts +126 -29
  102. package/core/services/secrets/migration.ts +16 -4
  103. package/core/services/secrets/store.ts +42 -14
  104. package/core/services/vault/VaultKeyService.ts +228 -45
  105. package/core/services/vault/chainRecovery.ts +483 -0
  106. package/core/services/vault/driver.ts +9 -1
  107. package/core/services/vault/enrolledSerialRegistry.ts +150 -0
  108. package/core/services/vault/guard.ts +218 -32
  109. package/core/services/vault/hardwareLease.ts +19 -0
  110. package/core/services/vault/metaAuthority.ts +210 -0
  111. package/core/services/vault/pivReset.ts +64 -23
  112. package/core/services/vault/r1comb.ts +139 -3
  113. package/core/services/vault/session.ts +25 -4
  114. package/core/services/vault/transfers.ts +868 -172
  115. package/core/services/vault/types.ts +19 -4
  116. package/core/services/vault/vaultStore.ts +256 -29
  117. package/core/services/walletArgLimits.ts +45 -2
  118. package/core/services/walletConnectionValidation.ts +76 -6
  119. package/core/services/walletServiceConfig.ts +40 -27
  120. package/core/storage/StorageExpoSQLite.ts +88 -47
  121. package/core/storage/methods/findSql.ts +24 -2
  122. package/core/storage/methods/listActionsSql.ts +8 -5
  123. package/core/storage/methods/listOutputsSql.ts +2 -2
  124. package/core/storage/methods/offlineActions.ts +10 -1
  125. package/core/storage/methods/processOfflineActions.ts +117 -25
  126. package/core/storage/methods/reviewStatusSql.ts +7 -2
  127. package/core/storage/schema/createTables.ts +155 -2
  128. package/core/stores/ConnectionStore.ts +34 -0
  129. package/core/toolboxConfig.ts +104 -0
  130. package/core/toolboxTypes.ts +40 -0
  131. package/core/userAvatar.ts +79 -0
  132. package/core/walletDbRegistry.ts +63 -0
  133. package/core/walletMonitor.ts +25 -4
  134. package/core/walletRepair/releaseStuckReservations.ts +72 -0
  135. package/core/walletRepair/shouldMarkUnspendable.ts +20 -0
  136. package/core/walletRepair/spenderConsumesOutpoint.ts +29 -0
  137. package/package.json +7 -7
  138. package/ui/activityFilter.ts +115 -0
  139. package/ui/backupShares.ts +26 -169
  140. package/ui/components/pay/AddressReceive.tsx +13 -6
  141. package/ui/components/pay/AssetPicker.tsx +30 -9
  142. package/ui/components/pay/MessageBoxConfig.tsx +16 -0
  143. package/ui/components/pay/NearbyFlow.tsx +480 -243
  144. package/ui/components/pay/PaymentSuccessOverlay.tsx +85 -10
  145. package/ui/components/pay/RecipientField.tsx +84 -70
  146. package/ui/components/pay/StepBar.tsx +32 -0
  147. package/ui/components/pay/UniversalSend.tsx +827 -205
  148. package/ui/components/ui/AlertCard.tsx +38 -5
  149. package/ui/components/ui/PencilEditField.tsx +109 -0
  150. package/ui/components/ui/PermissionSheet.tsx +197 -66
  151. package/ui/components/ui/SlideOverFromRight.tsx +86 -0
  152. package/ui/components/vault/EnrollWizard.tsx +61 -13
  153. package/ui/components/vault/vaultErrorCopy.ts +3 -1
  154. package/ui/components/wallet/ActivityRow.tsx +227 -123
  155. package/ui/components/wallet/AmountInput.tsx +26 -8
  156. package/ui/components/wallet/AssetSwitcherDropdown.tsx +22 -2
  157. package/ui/components/wallet/Balance.tsx +42 -23
  158. package/ui/components/wallet/BiometricAdvisoryModal.tsx +16 -3
  159. package/ui/components/wallet/ContactActivityList.tsx +149 -0
  160. package/ui/components/wallet/ContactSigil.tsx +49 -0
  161. package/ui/components/wallet/EditPictureSheet.tsx +99 -0
  162. package/ui/components/wallet/FitAmount.tsx +148 -0
  163. package/ui/components/wallet/IconPickerSheet.tsx +168 -0
  164. package/ui/components/wallet/IdentifierRow.tsx +69 -0
  165. package/ui/components/wallet/ImportFromBackupPrompt.tsx +35 -13
  166. package/ui/components/wallet/ProfileButton.tsx +62 -0
  167. package/ui/components/wallet/UserAvatar.tsx +85 -0
  168. package/ui/components/wallet/avatarIcons.ts +122 -0
  169. package/ui/exportTransactions.ts +36 -4
  170. package/ui/hooks/useContactsStore.ts +10 -0
  171. package/ui/hooks/useExportWalletData.ts +25 -2
  172. package/ui/hooks/useMandala.ts +18 -1
  173. package/ui/hooks/useOnline.ts +65 -20
  174. package/ui/importDatabases.ts +339 -24
  175. package/ui/index.ts +33 -2
  176. package/ui/isImageUrl.ts +6 -0
  177. package/ui/printRecoveryShares.ts +9 -10
  178. package/ui/recoveryPrompts.ts +91 -0
  179. package/ui/resolveIdentity.ts +31 -9
  180. package/ui/screens/ConnectionsScreen.tsx +86 -19
  181. package/ui/screens/ContactScreen.tsx +289 -0
  182. package/ui/screens/ContactsScreen.tsx +373 -0
  183. package/ui/screens/IdentifierScreen.tsx +256 -0
  184. package/ui/screens/NewContactScreen.tsx +362 -0
  185. package/ui/screens/PairScreen.tsx +74 -2
  186. package/ui/screens/PayScreen.tsx +20 -7
  187. package/ui/screens/ProfileScreen.tsx +783 -0
  188. package/ui/screens/SettingsScreen.tsx +10 -4
  189. package/ui/screens/TransactionDetailScreen.tsx +419 -0
  190. package/ui/screens/TrustScreen.tsx +100 -5
  191. package/ui/screens/VaultScreen.tsx +410 -61
  192. package/ui/screens/VaultTransferScreen.tsx +59 -7
  193. package/ui/screens/WalletCheckScreen.tsx +17 -6
  194. package/ui/screens/WalletConfigScreen.tsx +124 -28
  195. package/ui/screens/WalletHomeScreen.tsx +640 -104
  196. package/ui/screens/detailActionKeys.ts +55 -0
  197. package/ui/tokenFormat.ts +44 -4
  198. package/ui/tokenStatus.ts +21 -0
  199. package/ui/txStatus.ts +48 -5
  200. package/core/storage/LocalStorageAdapter.ts +0 -58
@@ -41,6 +41,7 @@ import { vaultErrorCopy } from './vaultErrorCopy'
41
41
  import { vaultKeyLabel } from './KeyChooser'
42
42
  import {
43
43
  useTheme,
44
+ useWallet,
44
45
  spacing,
45
46
  radii,
46
47
  typography,
@@ -62,7 +63,8 @@ import {
62
63
  type VaultEnrollmentQuarantine,
63
64
  type VaultScopeToken,
64
65
  type VaultErrorCode,
65
- type EnrollPhase
66
+ type EnrollPhase,
67
+ type VaultWalletAuthority
66
68
  } from '@bsv/expo-wallet-toolbox'
67
69
 
68
70
  const t = (k: string, o?: Record<string, unknown>) => i18n.t(k, o) as string
@@ -264,6 +266,23 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
264
266
  if (!scopeTokenRef.current) scopeTokenRef.current = vaultStore.captureScopeToken()
265
267
  const scopeToken = scopeTokenRef.current
266
268
 
269
+ // XR-001: the admin-scoped wallet capability every draft/meta authority tag
270
+ // in this wizard is computed and verified with (metaAuthority.ts). The
271
+ // wizard is only ever reached once a wallet is built (VaultScreen gates
272
+ // every door into it), so a missing permissions manager here is treated as
273
+ // the same programmer error `pm as unknown as VaultWallet` casts elsewhere
274
+ // in the vault UI already assume, not a recoverable runtime state.
275
+ const { managers, adminOriginator } = useWallet()
276
+ const authority: VaultWalletAuthority | null = managers?.permissionsManager
277
+ ? { wallet: managers.permissionsManager as unknown as VaultWalletAuthority['wallet'], adminOriginator }
278
+ : null
279
+ const requireAuthority = useCallback((): VaultWalletAuthority => {
280
+ if (!authority) {
281
+ throw new VaultError('driver-unavailable', 'Wallet is not ready for a vault enrollment operation')
282
+ }
283
+ return authority
284
+ }, [authority])
285
+
267
286
  const [step, setStep] = useState<Step>(mode === 'enroll' ? 'intro' : 'key')
268
287
  const [sub, setSub] = useState<KeySub>('pin')
269
288
  const [ack, setAck] = useState(false)
@@ -375,7 +394,7 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
375
394
  setBusy(true)
376
395
  setStepError(null)
377
396
  try {
378
- await addVaultKey(record, scopeToken)
397
+ await addVaultKey(record, scopeToken, requireAuthority())
379
398
  clearKeyInputs()
380
399
  haptics.success()
381
400
  showToast(t('vault_key_added_toast'), { type: 'success' })
@@ -398,7 +417,7 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
398
417
  setBusy(false)
399
418
  }
400
419
  },
401
- [k, mode, onCancel, scopeToken]
420
+ [k, mode, onCancel, scopeToken, requireAuthority]
402
421
  )
403
422
 
404
423
  /**
@@ -436,10 +455,31 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
436
455
  return [...current, ...ready.map(entry => entry.record).filter(record => !serials.has(record.serial))]
437
456
  })
438
457
  } else if (ready[0]) {
439
- // A ready draft's card already holds its key, and its name was
440
- // settled when it was drafted: there is nothing left to ask, so
441
- // restoring it means writing it.
442
- void saveKeyRef.current(ready[0].record)
458
+ // A ready draft is a persisted claim, not proof: nothing here
459
+ // re-verifies it against the card, so a draft never tapped in this
460
+ // run (crash-resumed, or — XR-001 — written straight to storage by
461
+ // something other than a live enrollment challenge) must not gain
462
+ // vault spend authority in an already-funded vault with zero user
463
+ // action. Name it and require an explicit choice before writing it.
464
+ const entry = ready[0]
465
+ void showAlert({
466
+ title: t('vault_resume_draft_confirm_title'),
467
+ message: t('vault_resume_draft_confirm_body', {
468
+ nickname: entry.record.nickname,
469
+ tail: entry.record.serial.slice(-4)
470
+ }),
471
+ buttons: [
472
+ { text: t('vault_resume_draft_confirm_use'), key: 'use' },
473
+ { text: t('vault_resume_draft_confirm_discard'), key: 'discard', style: 'destructive' }
474
+ ]
475
+ }).then(choice => {
476
+ if (!alive) return
477
+ if (choice === 'use') {
478
+ void saveKeyRef.current(entry.record)
479
+ } else {
480
+ void vaultStore.discardEnrollmentDraft(entry.record.serial, scopeToken).catch(() => {})
481
+ }
482
+ })
443
483
  }
444
484
  })
445
485
  .catch(e => {
@@ -553,6 +593,7 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
553
593
  const known = [...metaKeys.map(r => r.serial), ...pending.map(r => r.serial)]
554
594
  try {
555
595
  const record = await enrollKey({
596
+ ...requireAuthority(),
556
597
  scopeToken,
557
598
  acknowledgeDedicatedPivApplication: true,
558
599
  pendingSerials: known,
@@ -681,7 +722,7 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
681
722
  tapInFlight.current = false
682
723
  }
683
724
  },
684
- [k, metaKeys, pending, newPin, newPuk, onCancel, pivAck, saveKey, scopeToken, reloadDraftLists]
725
+ [k, metaKeys, pending, newPin, newPuk, onCancel, pivAck, saveKey, scopeToken, reloadDraftLists, requireAuthority]
685
726
  )
686
727
 
687
728
  /** Resume only the non-mutating possession challenge for a protected draft.
@@ -698,6 +739,7 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
698
739
  clearResetConsent()
699
740
  try {
700
741
  const record = await resumeEnrollmentDraft({
742
+ ...requireAuthority(),
701
743
  entry,
702
744
  scopeToken,
703
745
  onPhase: setPhase,
@@ -753,7 +795,7 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
753
795
  tapInFlight.current = false
754
796
  }
755
797
  },
756
- [onCancel, newPin, pinOk, pivAck, saveKey, scopeToken]
798
+ [onCancel, newPin, pinOk, pivAck, saveKey, scopeToken, requireAuthority]
757
799
  )
758
800
 
759
801
  // ── finish (enroll mode) ────────────────────────────────────────────
@@ -762,7 +804,7 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
762
804
  setBusy(true)
763
805
  setStepError(null)
764
806
  try {
765
- await finalizeEnrollment(pending, scopeToken)
807
+ await finalizeEnrollment(pending, scopeToken, requireAuthority())
766
808
  // No tone here (see useConfirmationSound): vaultDeposit/vaultWithdraw
767
809
  // name an actual transfer, and enrolling isn't one.
768
810
  haptics.success()
@@ -774,7 +816,7 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
774
816
  } finally {
775
817
  setBusy(false)
776
818
  }
777
- }, [pending, busy, scopeToken])
819
+ }, [pending, busy, scopeToken, requireAuthority])
778
820
 
779
821
  const addAnother = useCallback(() => {
780
822
  setStepError(null)
@@ -1410,6 +1452,9 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
1410
1452
  }
1411
1453
 
1412
1454
  // ── done ────────────────────────────────────────────────────────────
1455
+ // A sixth key is one more than a lock holds: the next step is removing the
1456
+ // key it replaces, not a re-lock (which would be refused).
1457
+ const overLockLimit = mode === 'add-key' && enrolledCount + 1 > VAULT_MAX_KEYS
1413
1458
  return (
1414
1459
  <View style={[styles.body, styles.doneBody]}>
1415
1460
  <Ionicons name="checkmark-circle" size={56} color={colors.success} style={styles.hero} />
@@ -1419,9 +1464,12 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({ mode, onDone, onCanc
1419
1464
  <Text style={[styles.p, { color: colors.textSecondary }]}>
1420
1465
  {mode === 'enroll'
1421
1466
  ? t('vault_done_body', { count: pending.length })
1422
- : t('vault_add_key_done', { nickname: addedNickname })}
1467
+ : t(overLockLimit ? 'vault_add_key_done_over_limit' : 'vault_add_key_done', { nickname: addedNickname })}
1423
1468
  </Text>
1424
- <ActionButton label={mode === 'enroll' ? t('vault_done_cta') : t('vault_relock_now')} onPress={onDone} />
1469
+ <ActionButton
1470
+ label={mode === 'enroll' || overLockLimit ? t('vault_done_cta') : t('vault_relock_now')}
1471
+ onPress={onDone}
1472
+ />
1425
1473
  </View>
1426
1474
  )
1427
1475
  }
@@ -84,13 +84,15 @@ const KEY: Record<VaultErrorCode, string> = {
84
84
  'key-already-enrolled': 'vault_err_key_already_enrolled',
85
85
  'key-not-adopted': 'vault_err_key_not_adopted',
86
86
  'too-many-keys': 'vault_err_too_many_keys',
87
+ 'too-many-active-keys': 'vault_err_too_many_active_keys',
87
88
  'last-keys': 'vault_err_last_keys',
88
89
  'relock-required': 'vault_err_relock_required',
89
90
  'action-pending': 'vault_err_action_pending',
90
91
  'key-not-committed': 'vault_err_key_not_committed',
91
92
  'key-cannot-cover': 'vault_err_key_cannot_cover',
92
93
  'too-small-to-relock': 'vault_err_too_small_to_relock',
93
- 'bad-version': 'vault_err_bad_version'
94
+ 'bad-version': 'vault_err_bad_version',
95
+ 'chain-scan-failed': 'vault_err_chain_scan_failed'
94
96
  }
95
97
 
96
98
  /**
@@ -13,7 +13,7 @@
13
13
  * txid to a clipboard is not that — it is debugging, and it used to crowd out
14
14
  * the two chips that actually resolve a stuck payment.
15
15
  */
16
- import React, { memo, useContext, useMemo } from 'react'
16
+ import React, { memo, useCallback, useContext, useEffect, useMemo, useState } from 'react'
17
17
  import { View, Text, StyleSheet, ActivityIndicator } from 'react-native'
18
18
  import { useTranslation } from 'react-i18next'
19
19
  import type { WalletAction } from '@bsv/sdk'
@@ -32,9 +32,28 @@ import {
32
32
  sigilPalette,
33
33
  type Counterparty
34
34
  } from '@bsv/expo-wallet-toolbox'
35
- import { txStatusView, toneColor } from '../../txStatus'
35
+ import { txStatusView, toneColor, type TxStatusView } from '../../txStatus'
36
36
  import PressableScale from '../ui/PressableScale'
37
37
  import Sigil from '../ui/Sigil'
38
+ import type { ContactsStore } from '../../../core/contacts/contactsStore'
39
+
40
+ /**
41
+ * expo-router is required lazily rather than imported at module scope: this
42
+ * file is barrel-exported from the package's `ui` entry point, and a static
43
+ * top-level `import` of expo-router pulls in its own untransformed JSX
44
+ * source, which Jest cannot parse for any consumer of the barrel, even one
45
+ * that never navigates. Same pattern as every other screen/component in this
46
+ * package that needs the router.
47
+ */
48
+ type ExpoRouterModule = typeof import('expo-router')
49
+ let expoRouterMod: ExpoRouterModule | undefined
50
+ function loadExpoRouter(): ExpoRouterModule {
51
+ if (!expoRouterMod) {
52
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
53
+ expoRouterMod = require('expo-router') as ExpoRouterModule
54
+ }
55
+ return expoRouterMod
56
+ }
38
57
 
39
58
  /**
40
59
  * @expo/vector-icons' index barrel re-exports every icon set (AntDesign,
@@ -57,9 +76,8 @@ function loadIonicons(): IoniconsComponent {
57
76
  }
58
77
  function loadMaterialCommunityIcons(): MaterialCommunityIconsComponent {
59
78
  if (!materialCommunityIconsComponent) {
60
- materialCommunityIconsComponent = require('@expo/vector-icons')
61
- // eslint-disable-next-line @typescript-eslint/no-require-imports
62
- .MaterialCommunityIcons as MaterialCommunityIconsComponent
79
+ materialCommunityIconsComponent = // eslint-disable-next-line @typescript-eslint/no-require-imports
80
+ require('@expo/vector-icons').MaterialCommunityIcons as MaterialCommunityIconsComponent
63
81
  }
64
82
  return materialCommunityIconsComponent
65
83
  }
@@ -77,6 +95,20 @@ export type ActivityAction = WalletAction & {
77
95
  interface Props {
78
96
  /** Pass the screen currency to avoid subscribing every row to wallet updates. */
79
97
  currency?: string
98
+ /**
99
+ * Pass this alongside `currency` for the same reason: without it the row
100
+ * would call `useWallet()` itself just to scope the contact lookup below,
101
+ * subscribing every row to wallet updates again. `undefined`/`null` simply
102
+ * means the tappable-contact-face feature never activates for this row.
103
+ */
104
+ walletUserId?: number | null
105
+ /**
106
+ * Same reason as `walletUserId`: built once at the screen and passed down
107
+ * rather than resolved per row via `useContactsStore()`, which reaches
108
+ * `useWallet()` internally — exactly the subscription `currency` above
109
+ * already exists to avoid.
110
+ */
111
+ contactsStore?: ContactsStore | null
80
112
  action: ActivityAction
81
113
  /** Identity of this row in the list's expanded/busy bookkeeping. Passed back
82
114
  * to `onToggle` so the handler can stay referentially stable across renders —
@@ -90,9 +122,15 @@ interface Props {
90
122
  * question ("is it sending? cancelling?") the row can answer. */
91
123
  busyLabel?: string
92
124
  onToggle: (rowKey: string) => void
125
+ /**
126
+ * Open this row's detail view. When present it REPLACES the expand-in-place
127
+ * tap: a row means one thing, and the utilities that used to unfold
128
+ * underneath it are the detail screen's overflow menu.
129
+ */
130
+ onOpen?: (action: ActivityAction) => void
93
131
  onExplorer: (txid: string) => void
94
132
  onRefreshTx: (txid: string) => void
95
- onAbort: (reference: string) => void
133
+ onAbort: (reference: string, action?: ActivityAction) => void
96
134
  /** Rebuild and re-deliver a PeerPay token without waiting for a NACK. */
97
135
  onSendPaymentDetails?: (txid: string) => void
98
136
  /** Start a new payment (or retryDelivery) for a failed outbound row. */
@@ -132,6 +170,8 @@ interface Props {
132
170
  counterpartyKey?: string
133
171
  /** Settlement status line, in place of the chain-status words. */
134
172
  statusText?: string
173
+ /** Settlement status as a tone + label; drives the dot as a BSV row's does. */
174
+ status?: TxStatusView
135
175
  }
136
176
  }
137
177
 
@@ -155,6 +195,8 @@ export function formatRowTime(value?: string | number | Date): string {
155
195
 
156
196
  function ActivityRowBase({
157
197
  currency,
198
+ walletUserId,
199
+ contactsStore,
158
200
  action,
159
201
  rowKey,
160
202
  offlineStatus,
@@ -162,6 +204,7 @@ function ActivityRowBase({
162
204
  busy,
163
205
  busyLabel,
164
206
  onToggle,
207
+ onOpen,
165
208
  onExplorer,
166
209
  onRefreshTx,
167
210
  onAbort,
@@ -175,13 +218,16 @@ function ActivityRowBase({
175
218
  const { satoshisPerUSD, usdToFiat = {} } = useContext(ExchangeRateContext)
176
219
  const MaterialCommunityIcons = loadMaterialCommunityIcons()
177
220
 
178
- const view = txStatusView(action.status, offlineStatus)
221
+ const incoming = token ? token.incoming : action.satoshis >= 0
222
+ // Direction decides the settled wording ("Received" vs "Sent"), so it has to
223
+ // be known before the status view is built.
224
+ const view = token?.status ?? txStatusView(action.status, offlineStatus, incoming, action.labels)
179
225
  const settled = view.tone === 'settled'
180
226
  const tone = toneColor(view.tone, colors as unknown as Record<string, string>)
181
- const incoming = token ? token.incoming : action.satoshis >= 0
182
227
 
183
228
  const { value, unit } = formatAmountParts(action.satoshis, currency, satoshisPerUSD, {
184
229
  abbreviate: true,
230
+ compact: true,
185
231
  showPlus: true,
186
232
  usdToFiat
187
233
  })
@@ -190,6 +236,7 @@ function ActivityRowBase({
190
236
  // reason a sats-denominated wallet needs a fiat line at all.
191
237
  const secondary = formatAmount(action.satoshis, currency === 'BSV' ? 'USD' : 'BSV', satoshisPerUSD, {
192
238
  abbreviate: true,
239
+ compact: true,
193
240
  showPlus: true,
194
241
  usdToFiat
195
242
  })
@@ -228,6 +275,41 @@ function ActivityRowBase({
228
275
  // under a mounted row. Two HSL conversions per render are not worth a dep.
229
276
  const palette = face ? sigilPalette(face.hue, !!isDark) : null
230
277
 
278
+ // The counterparty's own identity key, when the row can name one at all —
279
+ // an address or a bare txid (the other two `counterpartyOf` kinds) can
280
+ // never be a saved contact. Recomputed independently of `face` above: that
281
+ // memo only keeps what the sigil needs (point/hue), and duplicating the
282
+ // (pure, cheap) `counterpartyOf` call here is simpler than threading a
283
+ // second value out of it.
284
+ const counterpartyIdentityKey = useMemo(() => {
285
+ if (isTokenRow) return tokenCounterpartyKey
286
+ const cp = counterpartyOf({ labels: labelsKey === '' ? undefined : labelsKey.split('\n'), senderIdentityKey, txid })
287
+ return cp?.kind === 'identityKey' ? cp.value : undefined
288
+ }, [labelsKey, senderIdentityKey, txid, isTokenRow, tokenCounterpartyKey])
289
+
290
+ // Whether the face is tappable, expanded or not (2026-09-18) — only for a
291
+ // counterparty already saved as a contact; nobody this row cannot name a
292
+ // saved contact for gets a tap that opens nothing.
293
+ const [isContact, setIsContact] = useState(false)
294
+ useEffect(() => {
295
+ if (!counterpartyIdentityKey || !contactsStore || walletUserId == null) {
296
+ setIsContact(false)
297
+ return
298
+ }
299
+ let cancelled = false
300
+ void contactsStore.getContact(walletUserId, counterpartyIdentityKey).then(c => {
301
+ if (!cancelled) setIsContact(!!c)
302
+ })
303
+ return () => {
304
+ cancelled = true
305
+ }
306
+ }, [counterpartyIdentityKey, contactsStore, walletUserId])
307
+ const faceTappable = isContact && !!counterpartyIdentityKey
308
+ const onPressFace = useCallback(() => {
309
+ if (!counterpartyIdentityKey) return
310
+ loadExpoRouter().router.push({ pathname: '/contact', params: { identityKey: counterpartyIdentityKey } } as never)
311
+ }, [counterpartyIdentityKey])
312
+
231
313
  // A parked payment was built and shown as a code, but never released: it is
232
314
  // not on chain and no task will put it there. An explorer link would 404 and
233
315
  // a Refresh would ask the network about a transaction it has never seen, so
@@ -237,7 +319,9 @@ function ActivityRowBase({
237
319
  // they are not, the remote rail is the only one that can still reach them.
238
320
  const parked = offlineStatus === 'parked'
239
321
  const canCancelParked = parked && !!action.txid && !!onCancelParked
240
- const canAbort = !parked && ABORTABLE_STATUSES.has(action.status) && !!action.reference
322
+ // Same rule as the detail sheet (detailActionKeysFor): no plain Cancel once
323
+ // this device recorded handing the payment over — the payee may hold it.
324
+ const canAbort = offlineStatus === undefined && ABORTABLE_STATUSES.has(action.status) && !!action.reference
241
325
  // Any outgoing payment this wallet can re-deliver over the message box: both
242
326
  // rails write the payee's identity key as a label and the derivation data as
243
327
  // customInstructions, so the details can be sent again whether the payment
@@ -265,121 +349,140 @@ function ActivityRowBase({
265
349
  }
266
350
  ]}
267
351
  >
268
- <PressableScale
269
- scaleTo={0.99}
270
- onPress={hasUtilities ? () => onToggle(rowKey) : undefined}
271
- style={styles.row}
272
- accessibilityRole="button"
273
- accessibilityState={{ expanded }}
274
- accessibilityLabel={
275
- token
276
- ? // Never the lib's developer description, which carries a raw
277
- // 36-byte token id, and never silence for a figure we could not
278
- // recover: "Sent USDX, amount unavailable" is the honest read.
279
- `${token.title}, ${
280
- token.amount ? `${token.amount.value} ${token.amount.unit}` : t('token_row_amount_pending')
281
- }`
282
- : action.description || t('transactions')
283
- }
284
- >
352
+ <View style={styles.row}>
285
353
  {/* The sigil fills the tile, so direction moves to the border tint
286
354
  alone: the same tints as the arrow tile, so a mixed list still
287
355
  reads consistently down the left edge. The tile takes the
288
356
  counterparty's own colour, and the sigil is drawn in exactly that
289
357
  pair: sigil-js cuts its glyph lines in the background colour, so
290
- the fill must be the same solid or the cuts show as a halo. */}
291
- {face !== null && palette !== null ? (
292
- <View
293
- style={[
294
- styles.glyph,
295
- styles.avatar,
296
- {
297
- backgroundColor: palette.background,
298
- borderColor: incoming ? colors.successStrong + '2E' : colors.surfaceSunkenBorder
299
- }
300
- ]}
301
- >
302
- <Sigil
303
- point={face.point}
304
- size={38}
305
- foreground={palette.foreground}
306
- background={palette.background}
307
- detail="default"
308
- />
309
- </View>
310
- ) : (
311
- <View
312
- style={[
313
- styles.glyph,
314
- incoming
315
- ? {
316
- backgroundColor: colors.successStrong + '1A',
317
- borderColor: colors.successStrong + '2E'
318
- }
319
- : { backgroundColor: colors.surfaceSunken, borderColor: colors.surfaceSunkenBorder }
320
- ]}
321
- >
322
- <MaterialCommunityIcons
323
- name={incoming ? 'arrow-bottom-left' : 'arrow-top-right'}
324
- size={16}
325
- color={incoming ? colors.successStrong : colors.textSecondary}
326
- />
327
- </View>
328
- )}
358
+ the fill must be the same solid or the cuts show as a halo.
329
359
 
330
- <View style={styles.middle}>
331
- <Text style={[styles.description, { color: colors.textPrimary }]} numberOfLines={1}>
332
- {token ? token.title : action.description || t('transactions')}
333
- </Text>
334
- <View style={styles.statusLine}>
335
- <View
336
- style={[
337
- styles.dot,
338
- { backgroundColor: settled ? colors.successStrong : tone }
339
- ]}
340
- />
341
- <Text
342
- style={[styles.statusText, { color: settled ? colors.textSecondary : tone }]}
343
- numberOfLines={1}
344
- >
345
- {(() => {
346
- const words = token?.statusText ?? t(view.key)
347
- return time ? `${words} · ${time}` : words
348
- })()}
349
- </Text>
350
- </View>
351
- </View>
352
-
353
- <View style={styles.amounts}>
354
- {token ? (
355
- token.amount ? (
356
- // No secondary denomination line: this wallet has no price for a
357
- // token, and a converted figure would be invented.
358
- <Text
359
- style={[styles.amount, { color: amountColor }]}
360
- accessibilityLabel={`${token.amount.value} ${token.amount.unit}`}
360
+ A separate pressable from the row below it (2026-09-18), expanded
361
+ or not: tapping a face that names a saved contact opens their
362
+ contact page, while tapping the rest of the row still toggles the
363
+ chips — two touch targets, not one nested inside the other. No
364
+ visual affordance on the tile itself (a highlight ring was tried
365
+ and dropped) — the row already reads as tappable as a whole. */}
366
+ {(() => {
367
+ const tile =
368
+ face !== null && palette !== null ? (
369
+ <View
370
+ style={[
371
+ styles.glyph,
372
+ styles.avatar,
373
+ {
374
+ backgroundColor: palette.background,
375
+ borderColor: incoming ? colors.successStrong + '2E' : colors.surfaceSunkenBorder
376
+ }
377
+ ]}
361
378
  >
362
- {token.amount.value}
363
- <Text style={[styles.amountUnit, { color: unitColor }]}> {token.amount.unit}</Text>
364
- </Text>
379
+ <Sigil
380
+ point={face.point}
381
+ size={38}
382
+ foreground={palette.foreground}
383
+ background={palette.background}
384
+ detail="default"
385
+ />
386
+ </View>
365
387
  ) : (
366
- <Text style={[styles.amountSecondary, { color: colors.textTertiary }]}>
367
- {t('token_row_amount_pending')}
368
- </Text>
388
+ <View
389
+ style={[
390
+ styles.glyph,
391
+ incoming
392
+ ? {
393
+ backgroundColor: colors.successStrong + '1A',
394
+ borderColor: colors.successStrong + '2E'
395
+ }
396
+ : { backgroundColor: colors.surfaceSunken, borderColor: colors.surfaceSunkenBorder }
397
+ ]}
398
+ >
399
+ <MaterialCommunityIcons
400
+ name={incoming ? 'arrow-bottom-left' : 'arrow-top-right'}
401
+ size={16}
402
+ color={incoming ? colors.successStrong : colors.textSecondary}
403
+ />
404
+ </View>
369
405
  )
406
+ return faceTappable ? (
407
+ <PressableScale
408
+ onPress={onPressFace}
409
+ scaleTo={0.92}
410
+ accessibilityRole="button"
411
+ accessibilityLabel={t('activity_view_contact')}
412
+ >
413
+ {tile}
414
+ </PressableScale>
370
415
  ) : (
371
- <>
372
- <Text style={[styles.amount, { color: amountColor }]}>
373
- {value}
374
- {unit ? <Text style={[styles.amountUnit, { color: unitColor }]}> {unit}</Text> : null}
416
+ tile
417
+ )
418
+ })()}
419
+
420
+ <PressableScale
421
+ scaleTo={0.99}
422
+ onPress={onOpen ? () => onOpen(action) : hasUtilities ? () => onToggle(rowKey) : undefined}
423
+ style={styles.rowRest}
424
+ accessibilityRole="button"
425
+ accessibilityState={onOpen ? undefined : { expanded }}
426
+ accessibilityLabel={
427
+ token
428
+ ? // Never the lib's developer description, which carries a raw
429
+ // 36-byte token id, and never silence for a figure we could not
430
+ // recover: "Sent USDX, amount unavailable" is the honest read.
431
+ `${token.title}, ${
432
+ token.amount ? `${token.amount.value} ${token.amount.unit}` : t('token_row_amount_pending')
433
+ }`
434
+ : action.description || t('transactions')
435
+ }
436
+ >
437
+ <View style={styles.middle}>
438
+ <Text style={[styles.description, { color: colors.textPrimary }]} numberOfLines={1}>
439
+ {token ? token.title : action.description || t('transactions')}
440
+ </Text>
441
+ <View style={styles.statusLine}>
442
+ {/* A dot only where the tone carries a warning. A settled row is
443
+ the normal case, and marking every normal row green made the
444
+ list a wall of confirmation the eye had to read past. */}
445
+ {settled ? null : <View style={[styles.dot, { backgroundColor: tone }]} />}
446
+ <Text style={[styles.statusText, { color: settled ? colors.textSecondary : tone }]} numberOfLines={1}>
447
+ {(() => {
448
+ const words = token?.status ? t(view.key) : (token?.statusText ?? t(view.key))
449
+ return time ? `${words} · ${time}` : words
450
+ })()}
375
451
  </Text>
376
- <Text style={[styles.amountSecondary, { color: colors.textTertiary }]}>{secondary}</Text>
377
- </>
378
- )}
379
- </View>
380
- </PressableScale>
452
+ </View>
453
+ </View>
381
454
 
382
- {expanded && hasUtilities ? (
455
+ <View style={styles.amounts}>
456
+ {token ? (
457
+ token.amount ? (
458
+ // No secondary denomination line: this wallet has no price for a
459
+ // token, and a converted figure would be invented.
460
+ <Text
461
+ style={[styles.amount, { color: amountColor }]}
462
+ accessibilityLabel={`${token.amount.value} ${token.amount.unit}`}
463
+ >
464
+ {token.amount.value}
465
+ <Text style={[styles.amountUnit, { color: unitColor }]}> {token.amount.unit}</Text>
466
+ </Text>
467
+ ) : (
468
+ <Text style={[styles.amountSecondary, { color: colors.textTertiary }]}>
469
+ {t('token_row_amount_pending')}
470
+ </Text>
471
+ )
472
+ ) : (
473
+ <>
474
+ <Text style={[styles.amount, { color: amountColor }]}>
475
+ {value}
476
+ {unit ? <Text style={[styles.amountUnit, { color: unitColor }]}> {unit}</Text> : null}
477
+ </Text>
478
+ <Text style={[styles.amountSecondary, { color: colors.textTertiary }]}>{secondary}</Text>
479
+ </>
480
+ )}
481
+ </View>
482
+ </PressableScale>
483
+ </View>
484
+
485
+ {!onOpen && expanded && hasUtilities ? (
383
486
  <View style={styles.chips}>
384
487
  {busy ? (
385
488
  <View style={styles.busyRow}>
@@ -414,7 +517,7 @@ function ActivityRowBase({
414
517
  label={t('cancel')}
415
518
  accessibilityLabel={t('tx_action_abort')}
416
519
  danger
417
- onPress={() => onAbort(action.reference!)}
520
+ onPress={() => onAbort(action.reference!, action)}
418
521
  />
419
522
  ) : null}
420
523
  {canResendDetails ? (
@@ -450,9 +553,7 @@ function ActivityRowBase({
450
553
  {/* Inset to the description, not the screen edge: the rule separates the
451
554
  text columns, and the glyph tiles already read as separate objects. An
452
555
  expanded row is bounded by its own surface, so it needs no rule. */}
453
- {expanded ? null : (
454
- <View style={[styles.separator, { backgroundColor: colors.hairline }]} />
455
- )}
556
+ {expanded ? null : <View style={[styles.separator, { backgroundColor: colors.hairline }]} />}
456
557
  </View>
457
558
  )
458
559
  }
@@ -477,10 +578,7 @@ function Chip({
477
578
  <PressableScale
478
579
  onPress={onPress}
479
580
  haptic="tap"
480
- style={[
481
- styles.chip,
482
- { backgroundColor: colors.surfaceRaised, borderColor: colors.surfaceRaisedBorder }
483
- ]}
581
+ style={[styles.chip, { backgroundColor: colors.surfaceRaised, borderColor: colors.surfaceRaisedBorder }]}
484
582
  accessibilityRole="button"
485
583
  accessibilityLabel={accessibilityLabel}
486
584
  >
@@ -499,6 +597,10 @@ const styles = StyleSheet.create({
499
597
  paddingTop: 13,
500
598
  paddingBottom: 11
501
599
  },
600
+ // The face's touch target and the rest of the row's are two separate
601
+ // pressables side by side; `rowRest` reproduces `row`'s own inner spacing
602
+ // for the middle/amounts pair so splitting them changes no spacing.
603
+ rowRest: { flex: 1, flexDirection: 'row', alignItems: 'center', gap: spacing.md },
502
604
  glyph: {
503
605
  width: 38,
504
606
  height: 38,
@@ -556,7 +658,9 @@ function ConnectedActivityRow(props: Props) {
556
658
  /** Preserve the existing package API for hosts that omit currency; the home
557
659
  * screen supplies it so background wallet updates cannot invalidate each row. */
558
660
  export default function ActivityRow(props: Props) {
559
- return props.currency === undefined
560
- ? <ConnectedActivityRow {...props} />
561
- : <MemoActivityRow {...props} currency={props.currency} />
661
+ return props.currency === undefined ? (
662
+ <ConnectedActivityRow {...props} />
663
+ ) : (
664
+ <MemoActivityRow {...props} currency={props.currency} />
665
+ )
562
666
  }