@bsv/expo-wallet-toolbox 0.18.0 → 0.20.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 (135) hide show
  1. package/CHANGELOG.md +139 -30
  2. package/README.md +79 -79
  3. package/core/backup/RemoteSyncReader.ts +26 -24
  4. package/core/backup/appData.ts +9 -8
  5. package/core/backup/codec.ts +21 -18
  6. package/core/backup/constants.ts +5 -5
  7. package/core/backup/contactsBackup.ts +8 -8
  8. package/core/backup/cursor.ts +12 -7
  9. package/core/backup/derive.ts +3 -3
  10. package/core/backup/deviceId.ts +2 -2
  11. package/core/backup/erase.ts +2 -2
  12. package/core/backup/preference.ts +2 -2
  13. package/core/backup/push.ts +10 -12
  14. package/core/backup/restore.ts +22 -14
  15. package/core/backup/restoreOnImport.ts +3 -2
  16. package/core/config.tsx +17 -13
  17. package/core/constants.ts +34 -11
  18. package/core/contacts/contactsStore.ts +4 -3
  19. package/core/context/WalletConnectionContext.tsx +294 -212
  20. package/core/context/WalletContext.tsx +132 -97
  21. package/core/context/defaultWalletSettings.ts +4 -2
  22. package/core/demo/demoLedger.ts +1 -5
  23. package/core/directpay/DirectPayProvider.tsx +15 -24
  24. package/core/directpay/receive.ts +2 -1
  25. package/core/headers/checkpoints.ts +10 -1
  26. package/core/headers/headerStore.ts +13 -2
  27. package/core/hooks/useConfirmationSound.ts +3 -3
  28. package/core/hooks/useHaptics.ts +23 -6
  29. package/core/i18n/translations.tsx +303 -123
  30. package/core/index.ts +2 -0
  31. package/core/localpay/codec.ts +12 -6
  32. package/core/localpay/deviceCaps.ts +4 -14
  33. package/core/localpay/pending.ts +2 -1
  34. package/core/localpay/qr.ts +1 -1
  35. package/core/localpay/settlementAck.ts +1 -4
  36. package/core/localpay/transport/ble.ts +2 -2
  37. package/core/localpay/transport/socket.ts +1 -1
  38. package/core/mandala/abortGuard.ts +1 -1
  39. package/core/mandala/drain.ts +3 -0
  40. package/core/mandala/permissionModule.ts +3 -2
  41. package/core/mandala/resendTransfer.ts +4 -1
  42. package/core/mandala/runtime.ts +4 -4
  43. package/core/monitor/TaskBackupPush.ts +10 -13
  44. package/core/net/chainMatch.ts +8 -5
  45. package/core/networks.ts +145 -0
  46. package/core/parsePeerPayURI.ts +4 -1
  47. package/core/pay/beefRepair.ts +6 -3
  48. package/core/pay/creditErrors.ts +37 -1
  49. package/core/pay/rails/address.ts +10 -6
  50. package/core/pay/rails/handle.ts +84 -11
  51. package/core/pay/rails/index.ts +18 -2
  52. package/core/pay/receiveHistory.ts +8 -8
  53. package/core/peerpay/handleResendRequests.ts +11 -18
  54. package/core/peerpay/inboxAttempts.ts +1 -4
  55. package/core/peerpay/rebuildToken.ts +12 -9
  56. package/core/profiles/profileStore.ts +2 -1
  57. package/core/profiles/removalProblems.ts +3 -1
  58. package/core/services/arcTokenStorage.ts +2 -1
  59. package/core/services/arcadeBroadcastProvider.ts +7 -17
  60. package/core/services/secrets/envelope.ts +1 -6
  61. package/core/services/secrets/hkdf.ts +1 -6
  62. package/core/services/secrets/index.ts +3 -22
  63. package/core/services/usdFxRates.ts +1 -4
  64. package/core/services/vault/VaultKeyService.ts +2 -1
  65. package/core/services/vault/chainRecovery.ts +48 -21
  66. package/core/services/vault/metaAuthority.ts +4 -1
  67. package/core/services/vault/r1comb.ts +113 -51
  68. package/core/services/vault/session.ts +5 -1
  69. package/core/services/vault/transfers.ts +699 -576
  70. package/core/services/vault/vaultStore.ts +12 -10
  71. package/core/services/walletArgLimits.ts +1 -2
  72. package/core/services/walletConnectionValidation.ts +44 -28
  73. package/core/services/walletServiceConfig.ts +9 -40
  74. package/core/storage/StorageExpoSQLite.ts +7 -21
  75. package/core/storage/methods/listActionsSql.ts +81 -67
  76. package/core/storage/methods/listOutputsSql.ts +21 -16
  77. package/core/storage/methods/reviewStatusSql.ts +1 -4
  78. package/core/stores/ConnectionStore.ts +1 -1
  79. package/core/theme/ThemeContext.tsx +12 -16
  80. package/core/theme/motion.ts +3 -3
  81. package/core/theme/tokens.ts +6 -6
  82. package/core/toolboxConfig.ts +23 -0
  83. package/core/walletDbRegistry.ts +7 -5
  84. package/core/walletRepair/runWalletCheck.ts +1 -4
  85. package/package.json +2 -2
  86. package/ui/components/pay/AddressReceive.tsx +3 -3
  87. package/ui/components/pay/HandleReceive.tsx +58 -15
  88. package/ui/components/pay/MessageBoxConfig.tsx +46 -20
  89. package/ui/components/pay/NearbyFlow.tsx +575 -507
  90. package/ui/components/pay/OfflineNotice.tsx +1 -3
  91. package/ui/components/pay/PayCellRow.tsx +1 -4
  92. package/ui/components/pay/PayForm.tsx +1 -3
  93. package/ui/components/pay/RequestHub.tsx +14 -6
  94. package/ui/components/pay/UniversalSend.tsx +137 -40
  95. package/ui/components/pay/tokenSendCopy.ts +1 -2
  96. package/ui/components/pay/useRecipientInput.ts +2 -2
  97. package/ui/components/security/WalletLockNotice.tsx +1 -3
  98. package/ui/components/ui/AlertCard.tsx +44 -45
  99. package/ui/components/ui/BlurChrome.tsx +4 -15
  100. package/ui/components/ui/Celebration.tsx +3 -3
  101. package/ui/components/ui/ChoiceSheet.ts +1 -3
  102. package/ui/components/ui/ErrorBoundary.tsx +2 -6
  103. package/ui/components/ui/GroupedList.tsx +13 -31
  104. package/ui/components/ui/IconButton.tsx +6 -9
  105. package/ui/components/ui/ListRow.tsx +19 -25
  106. package/ui/components/ui/PresenceRow.tsx +4 -4
  107. package/ui/components/ui/PressableScale.tsx +24 -20
  108. package/ui/components/ui/Toast.tsx +23 -16
  109. package/ui/components/vault/KeyChooser.tsx +9 -6
  110. package/ui/components/vault/VaultBackdrop.tsx +1 -8
  111. package/ui/components/vault/VaultCeremonySheet.tsx +5 -5
  112. package/ui/components/wallet/ActivityRow.tsx +3 -2
  113. package/ui/components/wallet/BackupReminderSheet.tsx +1 -5
  114. package/ui/components/wallet/Balance.tsx +4 -1
  115. package/ui/components/wallet/ContactActivityList.tsx +7 -7
  116. package/ui/components/wallet/IconPickerSheet.tsx +1 -5
  117. package/ui/components/wallet/ProfileSwitcherPopover.tsx +6 -1
  118. package/ui/components/wallet/tokenEviction.ts +4 -1
  119. package/ui/hooks/useMandala.ts +1 -7
  120. package/ui/hooks/useOfflineNoticeActions.ts +21 -27
  121. package/ui/hooks/useSpendableBalance.ts +2 -2
  122. package/ui/hooks/useVaultCoverage.ts +7 -1
  123. package/ui/index.ts +9 -1
  124. package/ui/resolveIdentity.ts +20 -8
  125. package/ui/screens/ConnectionsScreen.tsx +44 -18
  126. package/ui/screens/LogsScreen.tsx +24 -22
  127. package/ui/screens/PairScreen.tsx +85 -54
  128. package/ui/screens/PayScreen.tsx +5 -1
  129. package/ui/screens/ProfileScreen.tsx +0 -3
  130. package/ui/screens/TrustScreen.tsx +125 -80
  131. package/ui/screens/VaultScreen.tsx +19 -7
  132. package/ui/screens/VaultTransferScreen.tsx +5 -1
  133. package/ui/screens/WalletCheckScreen.tsx +14 -17
  134. package/ui/screens/WalletConfigScreen.tsx +414 -376
  135. package/ui/screens/WalletHomeScreen.tsx +47 -42
@@ -1,12 +1,5 @@
1
1
  import React, { useEffect, useRef, useState } from 'react'
2
- import {
3
- View,
4
- Text,
5
- StyleSheet,
6
- TouchableOpacity,
7
- SafeAreaView,
8
- ActivityIndicator,
9
- } from 'react-native'
2
+ import { View, Text, StyleSheet, TouchableOpacity, SafeAreaView, ActivityIndicator } from 'react-native'
10
3
  import AsyncStorage from '@react-native-async-storage/async-storage'
11
4
  import { WalletClient } from '@bsv/sdk'
12
5
  import {
@@ -60,11 +53,7 @@ export function PairScreen() {
60
53
  reconnect?: string
61
54
  }>()
62
55
 
63
- const {
64
- status, sessionMeta, errorMsg,
65
- connect, disconnect,
66
- startNavTimer, cancelNavTimer,
67
- } = useWalletConnection()
56
+ const { status, sessionMeta, errorMsg, connect, disconnect, startNavTimer, cancelNavTimer } = useWalletConnection()
68
57
 
69
58
  // Pre-connection validation error (before connect() is called)
70
59
  const [preConnectError, setPreConnectError] = useState<string | null>(null)
@@ -80,7 +69,9 @@ export function PairScreen() {
80
69
  const [autoApproveThreshold, setAutoApproveThreshold] = useState(DEFAULT_AUTO_APPROVE_THRESHOLD)
81
70
  useEffect(() => {
82
71
  AsyncStorage.getItem(profileScopedKey(AUTO_APPROVE_STORAGE_KEY))
83
- .then(v => { if (v !== null) setAutoApproveThreshold(Number(v) || 0) })
72
+ .then(v => {
73
+ if (v !== null) setAutoApproveThreshold(Number(v) || 0)
74
+ })
84
75
  .catch(() => {})
85
76
  }, [])
86
77
 
@@ -89,7 +80,9 @@ export function PairScreen() {
89
80
 
90
81
  // Track current status for unmount cleanup without re-running the effect
91
82
  const statusRef = useRef(status)
92
- useEffect(() => { statusRef.current = status }, [status])
83
+ useEffect(() => {
84
+ statusRef.current = status
85
+ }, [status])
93
86
 
94
87
  // Reset error state when leaving this screen so the next scan starts fresh
95
88
  useEffect(() => {
@@ -127,7 +120,9 @@ export function PairScreen() {
127
120
  // Nav timer — start when leaving this screen, cancel when returning
128
121
  useEffect(() => {
129
122
  cancelNavTimer()
130
- return () => { if (status === 'connected') startNavTimer() }
123
+ return () => {
124
+ if (status === 'connected') startNavTimer()
125
+ }
131
126
  }, [status]) // eslint-disable-line react-hooks/exhaustive-deps
132
127
 
133
128
  async function handleApprove() {
@@ -163,21 +158,24 @@ export function PairScreen() {
163
158
  origin: external.origin,
164
159
  topic: params.topic,
165
160
  protocolID: params.protocolID,
166
- backendIdentityKey: params.backendIdentityKey,
161
+ backendIdentityKey: params.backendIdentityKey
167
162
  })
168
163
  connectionStore.stageAuthorityTag(params.topic, tag)
169
164
  } catch (err) {
170
165
  console.warn('[PairScreen] failed to compute connection authority tag', err)
171
166
  connectionStore.discardStagedAuthorityTag(params.topic)
172
167
  }
173
- await connect({
174
- topic: params.topic,
175
- backendIdentityKey: params.backendIdentityKey,
176
- protocolID: params.protocolID,
177
- origin: external.origin,
178
- expiry: params.expiry,
179
- sig: params.sig,
180
- }, wallet)
168
+ await connect(
169
+ {
170
+ topic: params.topic,
171
+ backendIdentityKey: params.backendIdentityKey,
172
+ protocolID: params.protocolID,
173
+ origin: external.origin,
174
+ expiry: params.expiry,
175
+ sig: params.sig
176
+ },
177
+ wallet
178
+ )
181
179
  } catch (err) {
182
180
  setPreConnectError(err instanceof Error ? err.message : 'Connection failed')
183
181
  }
@@ -198,7 +196,13 @@ export function PairScreen() {
198
196
  <View style={styles.centered}>
199
197
  <Text style={styles.errorTitle}>Connection Failed</Text>
200
198
  <Text style={styles.errorMsg}>{preConnectError}</Text>
201
- <TouchableOpacity style={styles.secondaryBtn} onPress={() => { disconnect(); router.back() }}>
199
+ <TouchableOpacity
200
+ style={styles.secondaryBtn}
201
+ onPress={() => {
202
+ disconnect()
203
+ router.back()
204
+ }}
205
+ >
202
206
  <Text style={styles.secondaryBtnText}>Go Back</Text>
203
207
  </TouchableOpacity>
204
208
  </View>
@@ -211,7 +215,13 @@ export function PairScreen() {
211
215
  <View style={styles.centered}>
212
216
  <Text style={styles.errorTitle}>Connection Failed</Text>
213
217
  <Text style={styles.errorMsg}>{errorMsg ?? 'Something went wrong'}</Text>
214
- <TouchableOpacity style={styles.secondaryBtn} onPress={() => { disconnect(); router.back() }}>
218
+ <TouchableOpacity
219
+ style={styles.secondaryBtn}
220
+ onPress={() => {
221
+ disconnect()
222
+ router.back()
223
+ }}
224
+ >
215
225
  <Text style={styles.secondaryBtnText}>Go Back</Text>
216
226
  </TouchableOpacity>
217
227
  </View>
@@ -247,7 +257,8 @@ export function PairScreen() {
247
257
  <View style={styles.infoRow}>
248
258
  <Text style={styles.infoLabel}>Auto-approve</Text>
249
259
  <Text style={styles.infoValue}>
250
- Up to {autoApproveThreshold.toLocaleString()} sats per request, {AUTO_APPROVE_DAILY_CAP_SATS.toLocaleString()} sats/24h total, without asking
260
+ Up to {autoApproveThreshold.toLocaleString()} sats per request,{' '}
261
+ {AUTO_APPROVE_DAILY_CAP_SATS.toLocaleString()} sats/24h total, without asking
251
262
  </Text>
252
263
  </View>
253
264
  </>
@@ -294,11 +305,7 @@ export function PairScreen() {
294
305
  )
295
306
  }
296
307
 
297
- return (
298
- <SafeAreaView style={styles.container}>
299
- {renderContent()}
300
- </SafeAreaView>
301
- )
308
+ return <SafeAreaView style={styles.container}>{renderContent()}</SafeAreaView>
302
309
  }
303
310
 
304
311
  function makeStyles(colors: ReturnType<typeof import('@bsv/expo-wallet-toolbox').useTheme>['colors']) {
@@ -307,9 +314,9 @@ function makeStyles(colors: ReturnType<typeof import('@bsv/expo-wallet-toolbox')
307
314
  flex: 1,
308
315
  backgroundColor: colors.backgroundSecondary,
309
316
  justifyContent: 'center',
310
- padding: spacing.xxl,
317
+ padding: spacing.xxl
311
318
  },
312
- centered: { alignItems: 'center' },
319
+ centered: { alignItems: 'center' },
313
320
  card: {
314
321
  backgroundColor: colors.backgroundElevated,
315
322
  borderRadius: radii.xl,
@@ -319,43 +326,67 @@ function makeStyles(colors: ReturnType<typeof import('@bsv/expo-wallet-toolbox')
319
326
  shadowColor: '#000',
320
327
  shadowOpacity: 0.08,
321
328
  shadowRadius: 12,
322
- elevation: 3,
329
+ elevation: 3
323
330
  },
324
- title: { ...typography.title2, color: colors.textPrimary, marginBottom: spacing.xs },
325
- subtitle: { ...typography.subhead, color: colors.textSecondary, marginBottom: spacing.xxl, textAlign: 'center' },
331
+ title: { ...typography.title2, color: colors.textPrimary, marginBottom: spacing.xs },
332
+ subtitle: { ...typography.subhead, color: colors.textSecondary, marginBottom: spacing.xxl, textAlign: 'center' },
326
333
  infoBox: {
327
334
  backgroundColor: colors.backgroundSecondary,
328
335
  borderRadius: radii.lg,
329
336
  borderWidth: StyleSheet.hairlineWidth,
330
337
  borderColor: colors.separator,
331
- marginBottom: spacing.xxl,
338
+ marginBottom: spacing.xxl
332
339
  },
333
- infoRow: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', padding: spacing.md },
334
- divider: { height: StyleSheet.hairlineWidth, backgroundColor: colors.separator },
340
+ infoRow: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', padding: spacing.md },
341
+ divider: { height: StyleSheet.hairlineWidth, backgroundColor: colors.separator },
335
342
  infoLabel: { ...typography.footnote, color: colors.textSecondary },
336
- infoValue: { ...typography.footnote, fontWeight: '500', color: colors.textPrimary, maxWidth: '60%', textAlign: 'right' },
343
+ infoValue: {
344
+ ...typography.footnote,
345
+ fontWeight: '500',
346
+ color: colors.textPrimary,
347
+ maxWidth: '60%',
348
+ textAlign: 'right'
349
+ },
337
350
  buttonRow: { flexDirection: 'row', gap: spacing.md },
338
351
  rejectBtn: {
339
- flex: 1, paddingVertical: spacing.md + 2, borderRadius: radii.lg,
340
- borderWidth: StyleSheet.hairlineWidth, borderColor: colors.separator,
341
- backgroundColor: colors.fillSecondary, alignItems: 'center',
352
+ flex: 1,
353
+ paddingVertical: spacing.md + 2,
354
+ borderRadius: radii.lg,
355
+ borderWidth: StyleSheet.hairlineWidth,
356
+ borderColor: colors.separator,
357
+ backgroundColor: colors.fillSecondary,
358
+ alignItems: 'center'
359
+ },
360
+ rejectBtnText: { ...typography.callout, fontWeight: '500', color: colors.textPrimary },
361
+ approveBtn: {
362
+ flex: 1,
363
+ paddingVertical: spacing.md + 2,
364
+ borderRadius: radii.lg,
365
+ backgroundColor: colors.accent,
366
+ alignItems: 'center'
342
367
  },
343
- rejectBtnText: { ...typography.callout, fontWeight: '500', color: colors.textPrimary },
344
- approveBtn: { flex: 1, paddingVertical: spacing.md + 2, borderRadius: radii.lg, backgroundColor: colors.accent, alignItems: 'center' },
345
368
  approveBtnText: { ...typography.callout, fontWeight: '600', color: colors.textOnAccent },
346
369
  secondaryBtn: {
347
- marginTop: spacing.xxl, paddingVertical: spacing.md, paddingHorizontal: spacing.xxl,
348
- borderRadius: radii.md, borderWidth: StyleSheet.hairlineWidth, borderColor: colors.separator,
370
+ marginTop: spacing.xxl,
371
+ paddingVertical: spacing.md,
372
+ paddingHorizontal: spacing.xxl,
373
+ borderRadius: radii.md,
374
+ borderWidth: StyleSheet.hairlineWidth,
375
+ borderColor: colors.separator
349
376
  },
350
377
  secondaryBtnText: { ...typography.subhead, color: colors.textSecondary },
351
- errorTitle: { ...typography.title3, color: colors.error, marginBottom: spacing.sm },
352
- errorMsg: { ...typography.subhead, color: colors.textSecondary, textAlign: 'center' },
378
+ errorTitle: { ...typography.title3, color: colors.error, marginBottom: spacing.sm },
379
+ errorMsg: { ...typography.subhead, color: colors.textSecondary, textAlign: 'center' },
353
380
  successIcon: {
354
- width: 64, height: 64, borderRadius: 32,
381
+ width: 64,
382
+ height: 64,
383
+ borderRadius: 32,
355
384
  backgroundColor: colors.fillTertiary,
356
- justifyContent: 'center', alignItems: 'center', marginBottom: spacing.lg,
385
+ justifyContent: 'center',
386
+ alignItems: 'center',
387
+ marginBottom: spacing.lg
357
388
  },
358
389
  successCheck: { fontSize: 28, color: colors.success, fontWeight: '700' },
359
- sessionId: { marginTop: spacing.lg, ...typography.caption2, color: colors.textTertiary },
390
+ sessionId: { marginTop: spacing.lg, ...typography.caption2, color: colors.textTertiary }
360
391
  })
361
392
  }
@@ -41,6 +41,7 @@ import {
41
41
  type OfflineActionRow,
42
42
  TaskSendOffline
43
43
  } from '@bsv/expo-wallet-toolbox'
44
+ import { NETWORKS } from '../../core/networks'
44
45
  import { getPendingCorruptNotice, readUnprocessedPending } from '../../core/localpay/pending'
45
46
  import { useAssetStatus, useMandala } from '../hooks/useMandala'
46
47
  import { formatTokenAmountWithUnit } from '../tokenFormat'
@@ -125,7 +126,8 @@ export function PayScreen({ dismissTo = '/' }: PayScreenProps = {}) {
125
126
  walletUserId,
126
127
  runMonitorTask,
127
128
  managers,
128
- adminOriginator
129
+ adminOriginator,
130
+ selectedNetwork
129
131
  } = useWallet()
130
132
  const [queued, setQueued] = useState(0)
131
133
  const [rejected, setRejected] = useState<OfflineActionRow[]>([])
@@ -412,6 +414,7 @@ export function PayScreen({ dismissTo = '/' }: PayScreenProps = {}) {
412
414
  storage,
413
415
  permissionsManager: managers?.permissionsManager,
414
416
  adminOriginator: adminOriginator ?? '',
417
+ network: selectedNetwork,
415
418
  online,
416
419
  rejected,
417
420
  t,
@@ -555,6 +558,7 @@ export function PayScreen({ dismissTo = '/' }: PayScreenProps = {}) {
555
558
  onChangeRequestSats={setRequestSats}
556
559
  onPick={setMethod}
557
560
  online={online}
561
+ addressAvailable={NETWORKS[selectedNetwork].woc !== undefined}
558
562
  balances={balances}
559
563
  selectedAssetId={selectedAssetId}
560
564
  onSelectAsset={setSelectedAssetId}
@@ -89,8 +89,6 @@ function loadExpoRouter(): ExpoRouterModule {
89
89
 
90
90
  const HANDLE_CHECK_DEBOUNCE_MS = 400
91
91
 
92
-
93
-
94
92
  /**
95
93
  * How long the switch cover takes to leave. A removal runs under it (a Modal on
96
94
  * the Home screen underneath this one), and it is dismissed in the same tick the
@@ -102,7 +100,6 @@ const HANDLE_CHECK_DEBOUNCE_MS = 400
102
100
  export const PROFILE_COVER_FADE_MS = 500
103
101
  const untilCoverGone = () => new Promise<void>(resolve => setTimeout(resolve, PROFILE_COVER_FADE_MS))
104
102
 
105
-
106
103
  export function ProfileScreen() {
107
104
  const { t } = useTranslation()
108
105
  const { colors } = useTheme()