@bsv/expo-wallet-toolbox 0.19.0 → 0.21.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 (141) hide show
  1. package/CHANGELOG.md +154 -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/DirectPayManager.ts +148 -29
  24. package/core/directpay/DirectPayProvider.tsx +26 -26
  25. package/core/directpay/payFlow.ts +10 -1
  26. package/core/directpay/receive.ts +2 -1
  27. package/core/directpay/settings.ts +56 -9
  28. package/core/directpay/types.ts +11 -2
  29. package/core/directpay/webrtpay.ts +4 -0
  30. package/core/headers/checkpoints.ts +10 -1
  31. package/core/headers/headerStore.ts +13 -2
  32. package/core/hooks/useConfirmationSound.ts +3 -3
  33. package/core/hooks/useHaptics.ts +23 -6
  34. package/core/i18n/translations.tsx +382 -209
  35. package/core/index.ts +2 -0
  36. package/core/localpay/codec.ts +12 -6
  37. package/core/localpay/deviceCaps.ts +4 -14
  38. package/core/localpay/pending.ts +2 -1
  39. package/core/localpay/qr.ts +1 -1
  40. package/core/localpay/settlementAck.ts +1 -4
  41. package/core/localpay/transport/ble.ts +2 -2
  42. package/core/localpay/transport/socket.ts +1 -1
  43. package/core/mandala/abortGuard.ts +1 -1
  44. package/core/mandala/drain.ts +3 -0
  45. package/core/mandala/permissionModule.ts +3 -2
  46. package/core/mandala/resendTransfer.ts +4 -1
  47. package/core/mandala/runtime.ts +4 -4
  48. package/core/monitor/TaskBackupPush.ts +10 -13
  49. package/core/net/chainMatch.ts +8 -5
  50. package/core/networks.ts +145 -0
  51. package/core/parsePeerPayURI.ts +4 -1
  52. package/core/pay/beefRepair.ts +6 -3
  53. package/core/pay/creditErrors.ts +37 -1
  54. package/core/pay/rails/address.ts +10 -6
  55. package/core/pay/rails/direct.ts +6 -2
  56. package/core/pay/rails/handle.ts +84 -11
  57. package/core/pay/rails/index.ts +18 -2
  58. package/core/pay/receiveHistory.ts +8 -8
  59. package/core/peerpay/handleResendRequests.ts +11 -18
  60. package/core/peerpay/inboxAttempts.ts +1 -4
  61. package/core/peerpay/rebuildToken.ts +12 -9
  62. package/core/profiles/profileStore.ts +2 -1
  63. package/core/profiles/removalProblems.ts +3 -1
  64. package/core/services/arcTokenStorage.ts +2 -1
  65. package/core/services/arcadeBroadcastProvider.ts +7 -17
  66. package/core/services/secrets/envelope.ts +1 -6
  67. package/core/services/secrets/hkdf.ts +1 -6
  68. package/core/services/secrets/index.ts +3 -22
  69. package/core/services/usdFxRates.ts +1 -4
  70. package/core/services/vault/VaultKeyService.ts +2 -1
  71. package/core/services/vault/chainRecovery.ts +48 -21
  72. package/core/services/vault/metaAuthority.ts +4 -1
  73. package/core/services/vault/r1comb.ts +113 -51
  74. package/core/services/vault/session.ts +5 -1
  75. package/core/services/vault/transfers.ts +699 -576
  76. package/core/services/vault/vaultStore.ts +12 -10
  77. package/core/services/walletArgLimits.ts +1 -2
  78. package/core/services/walletConnectionValidation.ts +44 -28
  79. package/core/services/walletServiceConfig.ts +9 -40
  80. package/core/storage/StorageExpoSQLite.ts +7 -21
  81. package/core/storage/methods/listActionsSql.ts +81 -67
  82. package/core/storage/methods/listOutputsSql.ts +21 -16
  83. package/core/storage/methods/reviewStatusSql.ts +1 -4
  84. package/core/stores/ConnectionStore.ts +1 -1
  85. package/core/theme/ThemeContext.tsx +12 -16
  86. package/core/theme/motion.ts +3 -3
  87. package/core/theme/tokens.ts +6 -6
  88. package/core/toolboxConfig.ts +23 -0
  89. package/core/walletDbRegistry.ts +7 -5
  90. package/core/walletRepair/runWalletCheck.ts +1 -4
  91. package/package.json +2 -2
  92. package/ui/components/pay/AddressReceive.tsx +3 -3
  93. package/ui/components/pay/HandleReceive.tsx +21 -15
  94. package/ui/components/pay/MessageBoxConfig.tsx +46 -20
  95. package/ui/components/pay/NearbyFlow.tsx +575 -507
  96. package/ui/components/pay/OfflineNotice.tsx +1 -3
  97. package/ui/components/pay/PayCellRow.tsx +1 -4
  98. package/ui/components/pay/PayForm.tsx +1 -3
  99. package/ui/components/pay/RequestHub.tsx +14 -6
  100. package/ui/components/pay/UniversalSend.tsx +79 -27
  101. package/ui/components/pay/tokenSendCopy.ts +1 -2
  102. package/ui/components/pay/useRecipientInput.ts +2 -2
  103. package/ui/components/security/WalletLockNotice.tsx +1 -3
  104. package/ui/components/ui/AlertCard.tsx +44 -45
  105. package/ui/components/ui/BlurChrome.tsx +4 -15
  106. package/ui/components/ui/Celebration.tsx +3 -3
  107. package/ui/components/ui/ChoiceSheet.ts +1 -3
  108. package/ui/components/ui/ErrorBoundary.tsx +2 -6
  109. package/ui/components/ui/GroupedList.tsx +13 -31
  110. package/ui/components/ui/IconButton.tsx +6 -9
  111. package/ui/components/ui/ListRow.tsx +19 -25
  112. package/ui/components/ui/PresenceRow.tsx +4 -4
  113. package/ui/components/ui/PressableScale.tsx +24 -20
  114. package/ui/components/ui/Toast.tsx +23 -16
  115. package/ui/components/vault/KeyChooser.tsx +9 -6
  116. package/ui/components/vault/VaultBackdrop.tsx +1 -8
  117. package/ui/components/vault/VaultCeremonySheet.tsx +5 -5
  118. package/ui/components/wallet/ActivityRow.tsx +3 -2
  119. package/ui/components/wallet/BackupReminderSheet.tsx +1 -5
  120. package/ui/components/wallet/Balance.tsx +4 -1
  121. package/ui/components/wallet/ContactActivityList.tsx +7 -7
  122. package/ui/components/wallet/IconPickerSheet.tsx +1 -5
  123. package/ui/components/wallet/ProfileSwitcherPopover.tsx +6 -1
  124. package/ui/components/wallet/tokenEviction.ts +4 -1
  125. package/ui/hooks/useMandala.ts +1 -7
  126. package/ui/hooks/useOfflineNoticeActions.ts +21 -27
  127. package/ui/hooks/useSpendableBalance.ts +2 -2
  128. package/ui/hooks/useVaultCoverage.ts +7 -1
  129. package/ui/index.ts +9 -1
  130. package/ui/resolveIdentity.ts +20 -8
  131. package/ui/screens/ConnectionsScreen.tsx +44 -18
  132. package/ui/screens/LogsScreen.tsx +24 -22
  133. package/ui/screens/PairScreen.tsx +85 -54
  134. package/ui/screens/PayScreen.tsx +5 -1
  135. package/ui/screens/ProfileScreen.tsx +0 -3
  136. package/ui/screens/TrustScreen.tsx +125 -80
  137. package/ui/screens/VaultScreen.tsx +19 -7
  138. package/ui/screens/VaultTransferScreen.tsx +5 -1
  139. package/ui/screens/WalletCheckScreen.tsx +14 -17
  140. package/ui/screens/WalletConfigScreen.tsx +414 -376
  141. package/ui/screens/WalletHomeScreen.tsx +47 -42
@@ -1,9 +1,6 @@
1
1
  import React, { createContext, useContext, useEffect, useMemo } from 'react'
2
2
  import { useColorScheme } from 'react-native'
3
- import {
4
- lightColors as tokenLightColors,
5
- darkColors as tokenDarkColors
6
- } from './tokens'
3
+ import { lightColors as tokenLightColors, darkColors as tokenDarkColors } from './tokens'
7
4
  import { assertThemeContrast } from './assertThemeContrast'
8
5
 
9
6
  // Theme type definitions
@@ -137,7 +134,7 @@ const darkColors: ThemeColors = {
137
134
  basketApproval: tokenDarkColors.permissionBasket,
138
135
  identityApproval: tokenDarkColors.permissionIdentity,
139
136
  renewalApproval: tokenDarkColors.accentSecondary,
140
- gold: '#92811f',
137
+ gold: '#92811f'
141
138
  }
142
139
 
143
140
  // Create the context with default values
@@ -167,16 +164,15 @@ export const ThemeProvider: React.FC<ThemeProviderProps> = ({ children }) => {
167
164
  assertThemeContrast(colors, isDark ? 'dark' : 'light')
168
165
  }, [colors, isDark])
169
166
 
170
- const value = useMemo(() => ({
171
- mode: 'system' as ThemeMode,
172
- setThemeMode: () => {},
173
- colors,
174
- isDark
175
- }), [colors, isDark])
176
-
177
- return (
178
- <ThemeContext.Provider value={value}>
179
- {children}
180
- </ThemeContext.Provider>
167
+ const value = useMemo(
168
+ () => ({
169
+ mode: 'system' as ThemeMode,
170
+ setThemeMode: () => {},
171
+ colors,
172
+ isDark
173
+ }),
174
+ [colors, isDark]
181
175
  )
176
+
177
+ return <ThemeContext.Provider value={value}>{children}</ThemeContext.Provider>
182
178
  }
@@ -29,14 +29,14 @@ import type { WithSpringConfig } from 'react-native-reanimated'
29
29
  */
30
30
  export const easings = {
31
31
  /** cubic-bezier(0.23, 1, 0.32, 1) — a long, soft deceleration. */
32
- out: Easing.bezier(0.23, 1, 0.32, 1),
32
+ out: Easing.bezier(0.23, 1, 0.32, 1)
33
33
  } as const
34
34
 
35
35
  export const springs = {
36
36
  /** Buttons, small elements, alert cards. Custom-tuned — NOT Reanimated's built-in presets. */
37
37
  snappy: { mass: 1, stiffness: 380, damping: 36 } satisfies WithSpringConfig,
38
38
  /** Larger surfaces: sheets, popovers, dropdowns. */
39
- settle: { mass: 1, stiffness: 280, damping: 32 } satisfies WithSpringConfig,
39
+ settle: { mass: 1, stiffness: 280, damping: 32 } satisfies WithSpringConfig
40
40
  } as const
41
41
 
42
42
  /** All values in milliseconds. */
@@ -46,5 +46,5 @@ export const durations = {
46
46
  /** Small movements, toasts. */
47
47
  quick: 250,
48
48
  /** Largest allowed — full-surface transitions. */
49
- moderate: 350,
49
+ moderate: 350
50
50
  } as const
@@ -26,7 +26,7 @@ export const spacing = {
26
26
  lg: 16,
27
27
  xl: 20,
28
28
  xxl: 24,
29
- xxxl: 32,
29
+ xxxl: 32
30
30
  } as const
31
31
 
32
32
  /* --------------------------------- Radii --------------------------------- */
@@ -42,7 +42,7 @@ export const radii = {
42
42
  md: 12,
43
43
  lg: 14,
44
44
  xl: 24,
45
- pill: 999,
45
+ pill: 999
46
46
  } as const
47
47
 
48
48
  /* ------------------------------- Typography ------------------------------ */
@@ -68,7 +68,7 @@ export const typography = {
68
68
  subhead: { fontSize: 15, fontWeight: '400' as const, lineHeight: 20 },
69
69
  footnote: { fontSize: 13, fontWeight: '400' as const, lineHeight: 18 },
70
70
  caption1: { fontSize: 12, fontWeight: '400' as const, lineHeight: 16 },
71
- caption2: { fontSize: 11, fontWeight: '400' as const, lineHeight: 13 },
71
+ caption2: { fontSize: 11, fontWeight: '400' as const, lineHeight: 13 }
72
72
  } as const
73
73
 
74
74
  /* --------------------------------- Colors -------------------------------- */
@@ -151,7 +151,7 @@ export const lightColors = {
151
151
  permissionProtocol: '#34C759',
152
152
  permissionBasket: '#34C759',
153
153
  permissionIdentity: '#007AFF',
154
- permissionSpending: '#FF9500',
154
+ permissionSpending: '#FF9500'
155
155
  } as const
156
156
 
157
157
  export const darkColors = {
@@ -222,11 +222,11 @@ export const darkColors = {
222
222
  permissionProtocol: '#1fae4378',
223
223
  permissionBasket: '#1fae4378',
224
224
  permissionIdentity: '#24588dff',
225
- permissionSpending: '#FF9F0A',
225
+ permissionSpending: '#FF9F0A'
226
226
  } as const
227
227
 
228
228
  /* ------------------------------ Hit Targets ------------------------------ */
229
229
 
230
230
  export const hitTargets = {
231
- minimum: 44, // iOS HIG minimum touch target
231
+ minimum: 44 // iOS HIG minimum touch target
232
232
  } as const
@@ -16,6 +16,11 @@ export interface ToolboxServiceConfig {
16
16
  chaintracksUrl?: string
17
17
  whatsOnChainApiKey?: string
18
18
  taalApiKey?: string
19
+ /**
20
+ * The chain's default MessageBox origin. A user's own choice in Settings
21
+ * still wins; this only replaces the built-in default in `NETWORKS`.
22
+ */
23
+ messageBoxUrl?: string
19
24
  }
20
25
 
21
26
  /**
@@ -299,6 +304,24 @@ export function getServiceConfig(chain: AppChain): ToolboxServiceConfig {
299
304
  return current.services[chain] ?? {}
300
305
  }
301
306
 
307
+ /**
308
+ * The host's default MessageBox origin for a chain, or undefined to use the
309
+ * built-in one. Never throws, like `getMandalaEndpoints`: it is read while
310
+ * rendering, and an unconfigured or malformed value must look like "no
311
+ * override" rather than crash.
312
+ */
313
+ export function getMessageBoxUrlOverride(chain: AppChain): string | undefined {
314
+ const url = trimTrailingSlashes(current?.services[chain]?.messageBoxUrl?.trim() ?? '')
315
+ if (url === '') return undefined
316
+ let parsed: URL
317
+ try {
318
+ parsed = new URL(url)
319
+ } catch {
320
+ return undefined
321
+ }
322
+ return isAllowedServiceOrigin(parsed) ? url : undefined
323
+ }
324
+
302
325
  const COMPRESSED_KEY = /^0[23][0-9a-fA-F]{64}$/
303
326
 
304
327
  /**
@@ -11,6 +11,8 @@
11
11
  * Current : wallet-<keySuffix>-<chain>net-<unix_s>.db → timestamp = <unix_s>
12
12
  */
13
13
 
14
+ import { APP_CHAINS } from './networks'
15
+
14
16
  // ── Filename parsing ────────────────────────────────────────────────────────
15
17
 
16
18
  /**
@@ -18,14 +20,14 @@
18
20
  *
19
21
  * Groups:
20
22
  * 1 – keySuffix (8 hex chars from the end of the identityKey)
21
- * 2 – chain (main | test | teratest)
23
+ * 2 – chain (main | test | teratest | scaletest)
22
24
  * 3 – timestamp (digits, optional)
23
25
  */
24
- const DB_FILENAME_RE = /^wallet-([a-fA-F0-9]{8})-(main|test|teratest)net(?:-(\d+))?\.db$/
26
+ const DB_FILENAME_RE = /^wallet-([a-fA-F0-9]{8})-(main|test|teratest|scaletest)net(?:-(\d+))?\.db$/
25
27
 
26
28
  export interface ParsedDbFilename {
27
29
  keySuffix: string
28
- chain: string // 'main' | 'test' | 'teratest'
30
+ chain: string // an AppChain
29
31
  timestamp: number // 0 for legacy files without a timestamp segment
30
32
  }
31
33
 
@@ -85,7 +87,7 @@ export function selectLatestDb(filenames: string[]): string {
85
87
  // the barrel, which breaks a plain `jest` host that never touches the
86
88
  // registry (no native module to resolve). Same class of issue documented on
87
89
  // useHaptics.ts and services/vault/driver.ts/random.ts's lazy requires.
88
- type AsyncStorageModule = typeof import('@react-native-async-storage/async-storage')['default']
90
+ type AsyncStorageModule = (typeof import('@react-native-async-storage/async-storage'))['default']
89
91
  let asyncStorage: AsyncStorageModule | undefined
90
92
  function getAsyncStorage(): AsyncStorageModule {
91
93
  if (!asyncStorage) {
@@ -114,7 +116,7 @@ export async function getRegisteredDbs(keySuffix: string, chain: string): Promis
114
116
  }
115
117
 
116
118
  /** The networks a wallet database can belong to. */
117
- const WALLET_DB_CHAINS = ['main', 'test', 'teratest'] as const
119
+ const WALLET_DB_CHAINS = APP_CHAINS
118
120
 
119
121
  /**
120
122
  * Every registered wallet DB filename for an identity, on every network. Unlike
@@ -98,7 +98,6 @@ function pushStatus(
98
98
  onStepDone?.(id, status)
99
99
  }
100
100
 
101
-
102
101
  export async function runWalletCheck(
103
102
  ports: WalletCheckPorts,
104
103
  onStep: (id: WalletCheckStepId) => void,
@@ -161,9 +160,7 @@ export async function runWalletCheck(
161
160
  )
162
161
 
163
162
  onStep('proofs')
164
- const proofs = await guard(skips, 'proofs', { repaired: 0 }, () =>
165
- settle(() => ports.checkProofs(), { repaired: 0 })
166
- )
163
+ const proofs = await guard(skips, 'proofs', { repaired: 0 }, () => settle(() => ports.checkProofs(), { repaired: 0 }))
167
164
  record('proofs', proofs, () => ((proofs as { ok?: boolean }).ok === true ? 'ok' : 'error'))
168
165
 
169
166
  onStep('backup')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsv/expo-wallet-toolbox",
3
- "version": "0.19.0",
3
+ "version": "0.21.0",
4
4
  "private": false,
5
5
  "description": "Wallet screens and P2P local-payment backend for Expo/React Native apps, extracted from BSV Wallet.",
6
6
  "license": "SEE LICENSE IN LICENSE.txt",
@@ -38,7 +38,7 @@
38
38
  "@bsv/sdk": "^2.8.11",
39
39
  "@bsv/templates": "^2.0.0",
40
40
  "@bsv/webrtpay": "^0.2.1",
41
- "@bsv/wallet-toolbox-mobile": "^2.14.3",
41
+ "@bsv/wallet-toolbox-mobile": "^2.14.9",
42
42
  "@expo/vector-icons": "^15.0.3",
43
43
  "@noble/curves": "^2.3.0",
44
44
  "@react-native-async-storage/async-storage": "^2.2.0",
@@ -174,7 +174,7 @@ export default function AddressReceive({
174
174
 
175
175
  const load = useCallback(
176
176
  async (offset: number) => {
177
- if (!wallet) return
177
+ if (!wallet || !woc) return
178
178
  setLoading(true)
179
179
  try {
180
180
  const date = getCurrentDate(offset)
@@ -202,7 +202,7 @@ export default function AddressReceive({
202
202
  setLoading(false)
203
203
  }
204
204
  },
205
- [wallet, adminOriginator, woc.network, storage, t]
205
+ [wallet, adminOriginator, woc?.network, storage, t]
206
206
  )
207
207
 
208
208
  useEffect(() => {
@@ -273,7 +273,7 @@ export default function AddressReceive({
273
273
  * screen precisely because they want an answer immediately.
274
274
  */
275
275
  const handleSweepNow = useCallback(async () => {
276
- if (!wallet || !address) return
276
+ if (!wallet || !address || !woc) return
277
277
  setSweeping(true)
278
278
  try {
279
279
  const { importedSatoshis } = await sweepAddress({
@@ -43,6 +43,7 @@ import PressableScale from '../ui/PressableScale'
43
43
  import { showAlert } from '../ui/AlertCard'
44
44
  import { showToast } from '../ui/Toast'
45
45
  import { makeIdentityClient, resolveIdentity } from '../../resolveIdentity'
46
+ import { bindMessageBoxNetwork } from '../../../core/pay/rails/handle'
46
47
  import { makeBeefRepair } from '../../../core/pay/beefRepair'
47
48
  import { wocConfigFor } from '../../../core/pay/rails/address'
48
49
  import { makeCreditClassifier } from '../../../core/pay/creditErrors'
@@ -421,7 +422,7 @@ export default function HandleReceive({
421
422
  const mandala = useMandala()
422
423
  const [identityError, setIdentityError] = useState(false)
423
424
  const [copied, setCopied] = useState(false)
424
- const { messageBoxUrl } = useMessageBoxConfig(t)
425
+ const { messageBoxUrl } = useMessageBoxConfig(t, selectedNetwork)
425
426
  const isConfigured = !!messageBoxUrl && messageBoxUrl !== NO_MESSAGE_BOX
426
427
 
427
428
  const [payments, setPayments] = useState<IncomingPayment[]>([])
@@ -494,18 +495,27 @@ export default function HandleReceive({
494
495
  }, [identityKey, loadIdentityKey])
495
496
  )
496
497
 
498
+ // Live payments are answered only while this screen is focused, and only for BSV (a token
499
+ // always arrives by message box): the rest of the time payers use the message box.
500
+ const { openReceiveScreen } = directPay
501
+ const liveReceive = !asset
502
+ useFocusEffect(useCallback(() => (liveReceive ? openReceiveScreen() : undefined), [liveReceive, openReceiveScreen]))
503
+
497
504
  const newPeerPayClient = useCallback((): PeerPayClient | null => {
498
505
  if (!isConfigured || !messageBoxUrl || !wallet) return null
499
506
  try {
500
- return new PeerPayClient({
501
- messageBoxHost: messageBoxUrl,
502
- walletClient: wallet as any,
503
- originator: adminOriginator
504
- })
507
+ return bindMessageBoxNetwork(
508
+ new PeerPayClient({
509
+ messageBoxHost: messageBoxUrl,
510
+ walletClient: wallet as any,
511
+ originator: adminOriginator
512
+ }),
513
+ selectedNetwork
514
+ )
505
515
  } catch {
506
516
  return null
507
517
  }
508
- }, [isConfigured, messageBoxUrl, wallet, adminOriginator])
518
+ }, [isConfigured, messageBoxUrl, wallet, adminOriginator, selectedNetwork])
509
519
  /** The client every inbox read, accept and discard goes through. */
510
520
  const peerPayClient = useMemo(() => newPeerPayClient(), [newPeerPayClient])
511
521
 
@@ -690,9 +700,7 @@ export default function HandleReceive({
690
700
  // receipt says both rather than claiming a settlement nobody has.
691
701
  statusNote: arrival.status === 'settled' ? undefined : t('local_pay_token_not_cleared', { issuer }),
692
702
  // Disclosure at the one moment the user is definitely looking.
693
- firstHoldNote: firstHold
694
- ? t('token_first_hold', { ticker: arrival.asset.ticker, issuer })
695
- : undefined
703
+ firstHoldNote: firstHold ? t('token_first_hold', { ticker: arrival.asset.ticker, issuer }) : undefined
696
704
  })
697
705
  } catch {
698
706
  // A drain that could not run is not news on this screen: the monitor task
@@ -995,11 +1003,9 @@ export default function HandleReceive({
995
1003
  would actually deliver. Advisory: the code below still works for
996
1004
  every OTHER rail, and the mismatch may resolve itself (a Settings
997
1005
  change, a fresh registry read) before anyone acts on it. */}
998
- {asset &&
999
- !admission &&
1000
- !!assetMessageBoxUrl &&
1001
- isConfigured &&
1002
- assetMessageBoxUrl !== messageBoxUrl && <ConsequenceNote textKey="token_messagebox_mismatch" />}
1006
+ {asset && !admission && !!assetMessageBoxUrl && isConfigured && assetMessageBoxUrl !== messageBoxUrl && (
1007
+ <ConsequenceNote textKey="token_messagebox_mismatch" />
1008
+ )}
1003
1009
  {admission && asset ? (
1004
1010
  <AdmissionNotice
1005
1011
  ticker={asset.ticker}
@@ -16,13 +16,14 @@ import {
16
16
  typography,
17
17
  radii,
18
18
  isAllowedServiceOrigin,
19
- DEFAULT_MESSAGE_BOX_URL,
20
19
  LEGACY_MESSAGE_BOX_URL,
21
20
  MESSAGE_BOX_URL_KEY,
22
21
  NO_MESSAGE_BOX
23
22
  } from '@bsv/expo-wallet-toolbox'
24
23
  import { profileScopedKey } from '../../../core/profiles/profileStore'
25
24
  import { trimTrailingSlashes } from '../../../core/net/trimTrailingSlashes'
25
+ import { defaultMessageBoxUrlFor, resolveMessageBoxUrl } from '../../../core/pay/rails/handle'
26
+ import type { AppChain } from '../../../core/networks'
26
27
 
27
28
  /**
28
29
  * @expo/vector-icons' index barrel re-exports every icon set (AntDesign,
@@ -41,9 +42,14 @@ function loadIonicons(): IoniconsComponent {
41
42
  return ioniconsComponent
42
43
  }
43
44
 
44
- export function useMessageBoxConfig(t: ReturnType<typeof import('react-i18next').useTranslation>['t']) {
45
- const [messageBoxUrl, setMessageBoxUrl] = useState(DEFAULT_MESSAGE_BOX_URL)
46
- const [urlInput, setUrlInput] = useState(DEFAULT_MESSAGE_BOX_URL)
45
+ export function useMessageBoxConfig(
46
+ t: ReturnType<typeof import('react-i18next').useTranslation>['t'],
47
+ /** Each network has its own server: the default, and what a saved preference resolves to, follow it. */
48
+ selectedNetwork: AppChain
49
+ ) {
50
+ const defaultUrl = defaultMessageBoxUrlFor(selectedNetwork)
51
+ const [messageBoxUrl, setMessageBoxUrl] = useState(defaultUrl)
52
+ const [urlInput, setUrlInput] = useState(defaultUrl)
47
53
  const [isSaving, setIsSaving] = useState(false)
48
54
  const [showConfig, setShowConfig] = useState(false)
49
55
 
@@ -53,15 +59,13 @@ export function useMessageBoxConfig(t: ReturnType<typeof import('react-i18next')
53
59
  // deliberate choice of that server — follow the new default instead.
54
60
  if (saved === LEGACY_MESSAGE_BOX_URL) {
55
61
  void AsyncStorage.removeItem(profileScopedKey(MESSAGE_BOX_URL_KEY))
56
- return
57
- }
58
- if (saved) {
59
- setMessageBoxUrl(saved)
60
- setUrlInput(saved)
61
- if (saved === NO_MESSAGE_BOX) setShowConfig(true)
62
62
  }
63
+ const resolved = resolveMessageBoxUrl(saved, selectedNetwork) ?? NO_MESSAGE_BOX
64
+ setMessageBoxUrl(resolved)
65
+ setUrlInput(resolved)
66
+ if (resolved === NO_MESSAGE_BOX) setShowConfig(true)
63
67
  })
64
- }, [])
68
+ }, [selectedNetwork])
65
69
 
66
70
  const handleSave = useCallback(
67
71
  async (input: string) => {
@@ -87,8 +91,17 @@ export function useMessageBoxConfig(t: ReturnType<typeof import('react-i18next')
87
91
  }
88
92
  setIsSaving(true)
89
93
  try {
90
- await AsyncStorage.setItem(profileScopedKey(MESSAGE_BOX_URL_KEY), trimmed)
91
- setMessageBoxUrl(trimmed)
94
+ // Saved the way every reader will resolve it: a network default (any
95
+ // network's) means "the default", so it is stored as no preference at
96
+ // all, and this screen shows the host the rails will actually use.
97
+ const resolved = resolveMessageBoxUrl(trimmed, selectedNetwork) ?? trimmed
98
+ if (resolved === trimmed) {
99
+ await AsyncStorage.setItem(profileScopedKey(MESSAGE_BOX_URL_KEY), trimmed)
100
+ } else {
101
+ await AsyncStorage.removeItem(profileScopedKey(MESSAGE_BOX_URL_KEY))
102
+ }
103
+ setMessageBoxUrl(resolved)
104
+ setUrlInput(resolved)
92
105
  setShowConfig(false)
93
106
  showToast(t('message_box_saved'), { type: 'success' })
94
107
  } catch (error: any) {
@@ -97,16 +110,16 @@ export function useMessageBoxConfig(t: ReturnType<typeof import('react-i18next')
97
110
  setIsSaving(false)
98
111
  }
99
112
  },
100
- [t]
113
+ [t, selectedNetwork]
101
114
  )
102
115
 
103
116
  const handleReset = useCallback(async () => {
104
117
  await AsyncStorage.removeItem(profileScopedKey(MESSAGE_BOX_URL_KEY))
105
- setMessageBoxUrl(DEFAULT_MESSAGE_BOX_URL)
106
- setUrlInput(DEFAULT_MESSAGE_BOX_URL)
118
+ setMessageBoxUrl(defaultUrl)
119
+ setUrlInput(defaultUrl)
107
120
  setShowConfig(false)
108
121
  showToast(t('message_box_removed'), { type: 'success' })
109
- }, [t])
122
+ }, [t, defaultUrl])
110
123
 
111
124
  const handleNone = useCallback(async () => {
112
125
  const noneValue = NO_MESSAGE_BOX
@@ -126,6 +139,7 @@ export function useMessageBoxConfig(t: ReturnType<typeof import('react-i18next')
126
139
 
127
140
  return {
128
141
  messageBoxUrl,
142
+ defaultUrl,
129
143
  urlInput,
130
144
  setUrlInput,
131
145
  isSaving,
@@ -139,6 +153,8 @@ export function useMessageBoxConfig(t: ReturnType<typeof import('react-i18next')
139
153
 
140
154
  interface ConfigPanelProps {
141
155
  readonly urlInput: string
156
+ /** This network's default server: the placeholder, and what "reset" returns to. */
157
+ readonly defaultUrl: string
142
158
  readonly isSaving: boolean
143
159
  readonly colors: ReturnType<typeof import('@bsv/expo-wallet-toolbox').useTheme>['colors']
144
160
  readonly t: ReturnType<typeof import('react-i18next').useTranslation>['t']
@@ -148,10 +164,20 @@ interface ConfigPanelProps {
148
164
  readonly onNone: () => void
149
165
  }
150
166
 
151
- export function ConfigPanel({ urlInput, isSaving, colors, t, onChangeUrl, onSave, onReset, onNone }: ConfigPanelProps) {
167
+ export function ConfigPanel({
168
+ urlInput,
169
+ defaultUrl,
170
+ isSaving,
171
+ colors,
172
+ t,
173
+ onChangeUrl,
174
+ onSave,
175
+ onReset,
176
+ onNone
177
+ }: ConfigPanelProps) {
152
178
  const Ionicons = loadIonicons()
153
179
  const hasUrl = !!urlInput.trim()
154
- const isNonDefault = urlInput.trim() !== DEFAULT_MESSAGE_BOX_URL && urlInput !== NO_MESSAGE_BOX
180
+ const isNonDefault = urlInput.trim() !== defaultUrl && urlInput !== NO_MESSAGE_BOX
155
181
  return (
156
182
  <View style={[styles.configPanel, { backgroundColor: colors.backgroundSecondary }]}>
157
183
  <Text style={[styles.configTitle, { color: colors.textPrimary }]}>{t('message_box_server')}</Text>
@@ -159,7 +185,7 @@ export function ConfigPanel({ urlInput, isSaving, colors, t, onChangeUrl, onSave
159
185
  <TextInput
160
186
  value={urlInput}
161
187
  onChangeText={onChangeUrl}
162
- placeholder={DEFAULT_MESSAGE_BOX_URL}
188
+ placeholder={defaultUrl}
163
189
  placeholderTextColor={colors.textTertiary}
164
190
  autoCapitalize="none"
165
191
  autoCorrect={false}