@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
@@ -140,6 +140,7 @@ const MANDALA_OUTPOINT_LIST_MAX_PAGES = 1000
140
140
 
141
141
  import type { AppChain } from '../config'
142
142
  import { DEFAULT_STORAGE_URL, DEFAULT_CHAIN, ADMIN_ORIGINATOR, toWalletChain } from '../config'
143
+ import { NETWORKS, isAppChain } from '../networks'
143
144
  import { getBackupUrl, getHandleRegistryConfig, getMandalaEndpoints, getPushAdapter } from '../toolboxConfig'
144
145
  import { inboxSeenStore } from '../directpay/receive'
145
146
  import {
@@ -293,11 +294,9 @@ import { spenderConsumesOutpoint } from '../walletRepair/spenderConsumesOutpoint
293
294
  import { releaseStuckReservationsOnDb } from '../walletRepair/releaseStuckReservations'
294
295
  import {
295
296
  acceptWithRetry,
296
- DEFAULT_MESSAGE_BOX_URL,
297
+ bindMessageBoxNetwork,
297
298
  internalizeIncoming,
298
- LEGACY_MESSAGE_BOX_URL,
299
- MESSAGE_BOX_URL_KEY,
300
- NO_MESSAGE_BOX,
299
+ readMessageBoxUrl,
301
300
  retryDelivery
302
301
  } from '../pay/rails/handle'
303
302
  import { getOutboxEntries, pruneExpiredSent, unsentEntries } from '../peerpay/outbox'
@@ -354,7 +353,10 @@ async function reloadAutoApproveLedger(): Promise<void> {
354
353
  autoApprovePolicy.loadLedger(Array.isArray(entries) ? entries : [])
355
354
  }
356
355
  function persistAutoApproveLedger(): void {
357
- AsyncStorage.setItem(profileScopedKey(AUTO_APPROVE_LEDGER_STORAGE_KEY), JSON.stringify(autoApprovePolicy.getLedger())).catch(() => {})
356
+ AsyncStorage.setItem(
357
+ profileScopedKey(AUTO_APPROVE_LEDGER_STORAGE_KEY),
358
+ JSON.stringify(autoApprovePolicy.getLedger())
359
+ ).catch(() => {})
358
360
  }
359
361
 
360
362
  /**
@@ -790,7 +792,12 @@ async function probeForLegacyDb(legacyName: string): Promise<boolean> {
790
792
  }
791
793
 
792
794
  /** The i18n key naming each network to the user. */
793
- const NETWORK_LABEL_KEYS: Record<AppChain, string> = { main: 'mainnet', test: 'testnet', teratest: 'teratest' }
795
+ const NETWORK_LABEL_KEYS: Record<AppChain, string> = {
796
+ main: 'mainnet',
797
+ test: 'testnet',
798
+ teratest: 'teratest',
799
+ scaletest: 'scaletest'
800
+ }
794
801
 
795
802
  /**
796
803
  * Minimal shape of the app's toast function. `core` must never import a `ui`
@@ -936,7 +943,7 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
936
943
  * its own; `getBackupPseudonym` also refuses to answer for any OTHER chain, so a stale
937
944
  * entry from a network switch can never be misread as the current one's.
938
945
  */
939
- const backupIdentityRef = useRef<{ chain: BackupChain, pseudonym: string } | null>(null)
946
+ const backupIdentityRef = useRef<{ chain: BackupChain; pseudonym: string } | null>(null)
940
947
  const getBackupPseudonym = useCallback(
941
948
  (chain: BackupChain): string | undefined =>
942
949
  backupIdentityRef.current?.chain === chain ? backupIdentityRef.current.pseudonym : undefined,
@@ -1362,7 +1369,7 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
1362
1369
 
1363
1370
  const finalizeConfig = useCallback((wabConfig: WABConfig): boolean => {
1364
1371
  const { method, network, storageUrl } = wabConfig
1365
- if (!network) {
1372
+ if (!isAppChain(network)) {
1366
1373
  console.error('Network selection is required')
1367
1374
  return false
1368
1375
  }
@@ -1414,7 +1421,12 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
1414
1421
  // The network lives on the active profile, not in finalConfig.
1415
1422
  finalizeConfig({ ...config, network: getActiveProfile().network })
1416
1423
  } catch {
1417
- finalizeConfig({ wabUrl: 'noWAB', method: 'mnemonic', network: getActiveProfile().network, storageUrl: 'local' })
1424
+ finalizeConfig({
1425
+ wabUrl: 'noWAB',
1426
+ method: 'mnemonic',
1427
+ network: getActiveProfile().network,
1428
+ storageUrl: 'local'
1429
+ })
1418
1430
  await setItem(
1419
1431
  'finalConfig',
1420
1432
  JSON.stringify({ wabUrl: 'noWAB', method: 'mnemonic', network: DEFAULT_CHAIN, storageUrl: 'local' })
@@ -1422,7 +1434,12 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
1422
1434
  }
1423
1435
  } else {
1424
1436
  // First launch: auto-configure with defaults
1425
- finalizeConfig({ wabUrl: 'noWAB', method: 'mnemonic', network: getActiveProfile().network, storageUrl: 'local' })
1437
+ finalizeConfig({
1438
+ wabUrl: 'noWAB',
1439
+ method: 'mnemonic',
1440
+ network: getActiveProfile().network,
1441
+ storageUrl: 'local'
1442
+ })
1426
1443
  await setItem(
1427
1444
  'finalConfig',
1428
1445
  JSON.stringify({ wabUrl: 'noWAB', method: 'mnemonic', network: DEFAULT_CHAIN, storageUrl: 'local' })
@@ -1476,10 +1493,10 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
1476
1493
  const mandalaEndpoints = getMandalaEndpoints(chain)
1477
1494
  // Toolbox chain id ('teratest' -> 'ttn'). App keeps 'teratest' for AsyncStorage keys / env / UI.
1478
1495
  const walletChain = toWalletChain(chain)
1496
+ const network = NETWORKS[chain]
1479
1497
  // The backup log's network name. Distinct from walletChain ('ttn' for teratest):
1480
1498
  // the backup derivation is frozen on the app-level names.
1481
- const backupChain =
1482
- chain === 'main' ? ('main' as const) : chain === 'test' ? ('test' as const) : ('teratest' as const)
1499
+ const backupChain: BackupChain = chain
1483
1500
  // See getBackupPseudonym's own docs: this is what lets Wallet Check scope its
1484
1501
  // cursor lookup to THIS identity without the primary key itself leaving this scope.
1485
1502
  backupIdentityRef.current = { chain: backupChain, pseudonym: backupPseudonym(primaryKey, backupChain) }
@@ -1531,7 +1548,9 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
1531
1548
 
1532
1549
  // Replace all default broadcast providers with EF/rawtx-only services.
1533
1550
  // Order: Arcade → Taal → GorillaPool → WoC → Bitails. UntilSuccess stops at first success.
1534
- // Taal runs on main + test only, GorillaPool on main only; teratest has no public ARC.
1551
+ // Each fallback is registered only where NETWORKS says it serves the
1552
+ // network: Taal on main + test, GorillaPool on main, WhatsOnChain where
1553
+ // one exists, Bitails on main + test.
1535
1554
  // 'ArcadeBeef' is the toolbox's own Arcade broadcaster, registered
1536
1555
  // because serviceOptions now carries arcadeUrl (needed for Arcade-first
1537
1556
  // proofs and SSE). Our createArcadeBroadcastService replaces it here so
@@ -1543,15 +1562,16 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
1543
1562
  services.postBeefServices.remove('Bitails')
1544
1563
  services.postBeefServices.remove('WhatsOnChain')
1545
1564
  services.postBeefServices.add(createArcadeBroadcastService(serviceOptions.arcUrl!, callbackToken))
1546
- if (chain === 'main' || chain === 'test') {
1547
- const taalArcUrl = chain === 'main' ? 'https://arc.taal.com' : 'https://arc-test.taal.com'
1548
- services.postBeefServices.add(createTaalBroadcastService(taalArcUrl, serviceOptions.taalApiKey))
1565
+ if (network.taalArcUrl) {
1566
+ services.postBeefServices.add(createTaalBroadcastService(network.taalArcUrl, serviceOptions.taalApiKey))
1549
1567
  }
1550
- if (chain === 'main') {
1551
- services.postBeefServices.add(createGorillaPoolBroadcastService('https://arc.gorillapool.io'))
1568
+ if (network.gorillaPoolArcUrl) {
1569
+ services.postBeefServices.add(createGorillaPoolBroadcastService(network.gorillaPoolArcUrl))
1552
1570
  }
1553
- services.postBeefServices.add(createWocBroadcastService(walletChain, serviceOptions.whatsOnChainApiKey))
1554
- if (bitailsService) {
1571
+ if (network.woc) {
1572
+ services.postBeefServices.add(createWocBroadcastService(network.woc, serviceOptions.whatsOnChainApiKey))
1573
+ }
1574
+ if (bitailsService && network.bitails) {
1555
1575
  services.postBeefServices.add({ name: 'Bitails', service: bitailsService.postBeef.bind(bitailsService) })
1556
1576
  }
1557
1577
 
@@ -1560,48 +1580,49 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
1560
1580
  // Every tx this wallet sends goes through Arcade, so GET /tx/{txid}
1561
1581
  // there is the one lookup that can answer as soon as it is mined. WoC
1562
1582
  // BUMP and Bitails are re-added after it as fallbacks, in that order.
1563
- const wocBumpBase =
1564
- chain === 'main'
1565
- ? 'https://api.whatsonchain.com/v1/bsv/main'
1566
- : chain === 'test'
1567
- ? 'https://api.whatsonchain.com/v1/bsv/test'
1568
- : 'https://api.woc-ttn.bsvblockchain.tech/v1/bsv/test'
1569
1583
  const wocApiKey = serviceOptions.whatsOnChainApiKey
1570
1584
  const chaintracksClient = serviceOptions.chaintracks as any
1571
1585
  const getMerklePathSvc = (services as any).getMerklePathServices
1572
1586
  const bitailsGetMerklePath = (services as any).bitails?.getMerklePath?.bind((services as any).bitails)
1573
1587
  getMerklePathSvc.remove('WhatsOnChain')
1574
1588
  getMerklePathSvc.remove('Bitails')
1575
- getMerklePathSvc.add({
1576
- name: 'WhatsOnChain',
1577
- service: async (txid: string): Promise<any> => {
1578
- const r: any = { name: 'WhatsOnChain', notes: [] }
1579
- try {
1580
- const headers: Record<string, string> = {}
1581
- if (wocApiKey) headers['woc-api-key'] = wocApiKey
1582
- const res = await fetch(`${wocBumpBase}/tx/${txid}/proof/bump`, { headers })
1583
- if (res.status === 404) {
1584
- r.notes.push({ what: 'getMerklePathNoData', when: new Date().toISOString() })
1585
- return r
1586
- }
1587
- if (!res.ok) {
1588
- r.notes.push({ what: 'getMerklePathBadStatus', httpStatus: res.status, when: new Date().toISOString() })
1589
- return r
1589
+ const wocBumpBase = network.woc ? `${network.woc.apiBase}/v1/bsv/${network.woc.segment}` : undefined
1590
+ if (wocBumpBase) {
1591
+ getMerklePathSvc.add({
1592
+ name: 'WhatsOnChain',
1593
+ service: async (txid: string): Promise<any> => {
1594
+ const r: any = { name: 'WhatsOnChain', notes: [] }
1595
+ try {
1596
+ const headers: Record<string, string> = {}
1597
+ if (wocApiKey) headers['woc-api-key'] = wocApiKey
1598
+ const res = await fetch(`${wocBumpBase}/tx/${txid}/proof/bump`, { headers })
1599
+ if (res.status === 404) {
1600
+ r.notes.push({ what: 'getMerklePathNoData', when: new Date().toISOString() })
1601
+ return r
1602
+ }
1603
+ if (!res.ok) {
1604
+ r.notes.push({
1605
+ what: 'getMerklePathBadStatus',
1606
+ httpStatus: res.status,
1607
+ when: new Date().toISOString()
1608
+ })
1609
+ return r
1610
+ }
1611
+ const bumpHex = (await res.text()).trim()
1612
+ r.merklePath = MerklePath.fromHex(bumpHex)
1613
+ const height = r.merklePath.blockHeight
1614
+ const header = await chaintracksClient.findHeaderForHeight(height)
1615
+ if (header) r.header = { ...header, height }
1616
+ r.notes.push({ what: 'getMerklePathSuccess', when: new Date().toISOString() })
1617
+ } catch (eu: any) {
1618
+ r.error = eu
1619
+ r.notes.push({ what: 'getMerklePathError', description: eu?.message, when: new Date().toISOString() })
1590
1620
  }
1591
- const bumpHex = (await res.text()).trim()
1592
- r.merklePath = MerklePath.fromHex(bumpHex)
1593
- const height = r.merklePath.blockHeight
1594
- const header = await chaintracksClient.findHeaderForHeight(height)
1595
- if (header) r.header = { ...header, height }
1596
- r.notes.push({ what: 'getMerklePathSuccess', when: new Date().toISOString() })
1597
- } catch (eu: any) {
1598
- r.error = eu
1599
- r.notes.push({ what: 'getMerklePathError', description: eu?.message, when: new Date().toISOString() })
1621
+ return r
1600
1622
  }
1601
- return r
1602
- }
1603
- })
1604
- if (bitailsGetMerklePath) {
1623
+ })
1624
+ }
1625
+ if (bitailsGetMerklePath && network.bitails) {
1605
1626
  getMerklePathSvc.add({ name: 'Bitails', service: bitailsGetMerklePath })
1606
1627
  }
1607
1628
 
@@ -2139,14 +2160,20 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
2139
2160
  // never touches stablecoins never opens a MessageBox connection.
2140
2161
  messageBox: mandalaEndpoints
2141
2162
  ? async () =>
2142
- new MessageBoxClient({
2143
- host: mandalaEndpoints.messageBoxUrl,
2144
- // The client calls getPublicKey / createSignature itself;
2145
- // those must carry the admin originator or the vault guard
2146
- // refuses them ("Originator is required for permission checks").
2147
- walletClient: bindOriginator(newManagers.permissionsManager as object, adminOriginator) as never,
2148
- enableLogging: false
2149
- }) as unknown as MandalaMessageBox
2163
+ bindMessageBoxNetwork(
2164
+ new MessageBoxClient({
2165
+ host: mandalaEndpoints.messageBoxUrl,
2166
+ // The client calls getPublicKey / createSignature itself;
2167
+ // those must carry the admin originator or the vault guard
2168
+ // refuses them ("Originator is required for permission checks").
2169
+ walletClient: bindOriginator(
2170
+ newManagers.permissionsManager as object,
2171
+ adminOriginator
2172
+ ) as never,
2173
+ enableLogging: false
2174
+ }),
2175
+ chain
2176
+ ) as unknown as MandalaMessageBox
2150
2177
  : undefined,
2151
2178
  // The payer's own frames are sealed with a nearby session PSK the
2152
2179
  // drain never persists; this opens the ones whose session this
@@ -2206,15 +2233,12 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
2206
2233
  // and the push registration below, so a device token is always
2207
2234
  // registered on exactly the host the inbox reads. The push
2208
2235
  // registration names the profile it is asking about; the inbox task
2209
- // reads the open profile's.
2210
- const readMessageBoxHost = async (index?: number): Promise<string | undefined> => {
2211
- const saved = await AsyncStorage.getItem(profileScopedKey(MESSAGE_BOX_URL_KEY, index))
2212
- return saved === NO_MESSAGE_BOX
2213
- ? undefined
2214
- : !saved || saved === LEGACY_MESSAGE_BOX_URL
2215
- ? DEFAULT_MESSAGE_BOX_URL
2216
- : saved
2217
- }
2236
+ // reads the open profile's. Each network has its own server, so a
2237
+ // profile's host follows that profile's network, not this build's.
2238
+ const networkOfProfile = (index?: number): AppChain =>
2239
+ index === undefined ? chain : (getProfilesState().profiles[index]?.network ?? chain)
2240
+ const readMessageBoxHost = async (index?: number): Promise<string | undefined> =>
2241
+ readMessageBoxUrl(networkOfProfile(index), index)
2218
2242
 
2219
2243
  // Release held offline transactions when signal returns — registered
2220
2244
  // BEFORE the defaults, and the order matters. Monitor.runOnce collects
@@ -2307,11 +2331,14 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
2307
2331
  if (!messageBoxUrl) return { accepted: 0, attention: 0, pending: false }
2308
2332
  let client: PeerPayClient
2309
2333
  try {
2310
- client = new PeerPayClient({
2311
- messageBoxHost: messageBoxUrl,
2312
- walletClient: permissionsManager as never,
2313
- originator: adminOriginator
2314
- })
2334
+ client = bindMessageBoxNetwork(
2335
+ new PeerPayClient({
2336
+ messageBoxHost: messageBoxUrl,
2337
+ walletClient: permissionsManager as never,
2338
+ originator: adminOriginator
2339
+ }),
2340
+ chain
2341
+ )
2315
2342
  } catch {
2316
2343
  return { accepted: 0, attention: 0, pending: false }
2317
2344
  }
@@ -2366,11 +2393,14 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
2366
2393
  return drainUnsentEntries({
2367
2394
  entries,
2368
2395
  retry: async entry => {
2369
- const client = new PeerPayClient({
2370
- messageBoxHost: entry.messageBoxUrl,
2371
- walletClient: permissionsManager as never,
2372
- originator: adminOriginator
2373
- })
2396
+ const client = bindMessageBoxNetwork(
2397
+ new PeerPayClient({
2398
+ messageBoxHost: entry.messageBoxUrl,
2399
+ walletClient: permissionsManager as never,
2400
+ originator: adminOriginator
2401
+ }),
2402
+ chain
2403
+ )
2374
2404
  await retryDelivery({
2375
2405
  wallet: permissionsManager as never,
2376
2406
  adminOriginator,
@@ -2651,12 +2681,16 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
2651
2681
  profiles,
2652
2682
  retired,
2653
2683
  activeIndex: profileIndex,
2654
- readHost: readMessageBoxHost,
2684
+ // Only a server that sends push notifications can take a
2685
+ // registration (mainnet's, today): a profile on any other
2686
+ // network has no host to register at.
2687
+ readHost: async index => (NETWORKS[networkOfProfile(index)].push ? readMessageBoxHost(index) : undefined),
2655
2688
  // Still this build's, and not removed: a removal tombstones its profile
2656
2689
  // right after the switch to profile 0, whose build holds the key.
2657
2690
  isCurrent: index => stillWanted() && !isRemoved(index),
2658
2691
  isRemoved,
2659
- makeClient: (wallet, host) => new MessageBoxClient({ host, walletClient: wallet as never }),
2692
+ makeClient: (wallet, host) =>
2693
+ bindMessageBoxNetwork(new MessageBoxClient({ host, walletClient: wallet as never }), chain),
2660
2694
  makePost: authPostFor
2661
2695
  })
2662
2696
  profilePushRef.current = profilePush
@@ -2709,7 +2743,7 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
2709
2743
  // a store) that belongs to a different build.
2710
2744
  const stillCurrent = () => offlineChaintracksRef.current === offlineChaintracks
2711
2745
  try {
2712
- const anchor = HEADER_CHECKPOINTS[walletChain as 'main' | 'test' | 'ttn']
2746
+ const anchor = HEADER_CHECKPOINTS[network.walletChain]
2713
2747
  if (!anchor) return
2714
2748
 
2715
2749
  const openStart = Date.now()
@@ -3672,13 +3706,16 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
3672
3706
  useEffect(() => {
3673
3707
  const wallet = managers.permissionsManager
3674
3708
  if (!walletBuilt || !wallet || !storage) return
3709
+ // Watching an address means asking WhatsOnChain about it; a network with
3710
+ // no WhatsOnChain has no address rail to sweep.
3711
+ const woc = wocConfigFor(selectedNetwork)
3712
+ if (!woc) return
3675
3713
 
3676
3714
  let cancelled = false
3677
3715
  // Assume online until NetInfo says otherwise: a first pass that fails on a
3678
3716
  // dead network is harmless (every address stays watched), while waiting for
3679
3717
  // the first NetInfo event would delay the common case.
3680
3718
  let online = true
3681
- const woc = wocConfigFor(selectedNetwork)
3682
3719
  // Ticks still to sit out after a WhatsOnChain 429. Every tick spends one,
3683
3720
  // including the app-active and back-online ones, so none of them can reach
3684
3721
  // WhatsOnChain while the backoff is pending.
@@ -4140,11 +4177,12 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
4140
4177
  async (txid: string, opts?: { neverFail?: boolean }): Promise<'confirmed' | 'pending' | 'failed'> => {
4141
4178
  if (!storage) throw new Error('Storage not available')
4142
4179
 
4143
- const wocBase =
4144
- selectedNetwork === 'teratest' ? 'https://api.woc-ttn.bsvblockchain.tech' : 'https://api.whatsonchain.com'
4145
- const chain = selectedNetwork === 'main' ? 'main' : 'test'
4180
+ // With no WhatsOnChain there is no second opinion to ask: leave the
4181
+ // transaction to the monitor's own (Arcade) proof checks.
4182
+ const woc = NETWORKS[selectedNetwork].woc
4183
+ if (!woc) return 'pending'
4146
4184
 
4147
- const res = await fetch(`${wocBase}/v1/bsv/${chain}/tx/${txid}/proof/bump`)
4185
+ const res = await fetch(`${woc.apiBase}/v1/bsv/${woc.segment}/tx/${txid}/proof/bump`)
4148
4186
 
4149
4187
  if (res.ok) {
4150
4188
  // XR-059 remainder: a compromised/misbehaving configured indexer must
@@ -4184,7 +4222,7 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
4184
4222
  txid,
4185
4223
  proof,
4186
4224
  fetchRawTx: async () => {
4187
- const r = await fetch(`${wocBase}/v1/bsv/${chain}/tx/${txid}/hex`)
4225
+ const r = await fetch(`${woc.apiBase}/v1/bsv/${woc.segment}/tx/${txid}/hex`)
4188
4226
  if (!r.ok) throw new Error(`raw tx fetch failed: ${r.status}`)
4189
4227
  // XR-059 remainder: same unbounded-hex-decode gap as the BUMP
4190
4228
  // fetch above, on the raw-tx body this time. Throwing here (like
@@ -4204,7 +4242,7 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
4204
4242
  // unconfirmed but perfectly healthy tx also has no proof.
4205
4243
  let onChain = false
4206
4244
  try {
4207
- const head = await fetch(`${wocBase}/v1/bsv/${chain}/tx/hash/${txid}`)
4245
+ const head = await fetch(`${woc.apiBase}/v1/bsv/${woc.segment}/tx/hash/${txid}`)
4208
4246
  onChain = head.ok
4209
4247
  // XR-030: any other non-OK (429/500/401/403/...) is a service
4210
4248
  // problem, not proof of absence — only a 404 is authoritative.
@@ -4340,12 +4378,9 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
4340
4378
  const releaseResult = await releaseStuckReservations()
4341
4379
  const releasedNote = releaseResult === 'No stuck reservations found.' ? '' : releaseResult + '\n\n'
4342
4380
 
4343
- const wocBase =
4344
- selectedNetwork === 'main'
4345
- ? 'https://api.whatsonchain.com/v1/bsv/main'
4346
- : selectedNetwork === 'test'
4347
- ? 'https://api.whatsonchain.com/v1/bsv/test'
4348
- : 'https://api.woc-ttn.bsvblockchain.tech/v1/bsv/test'
4381
+ const woc = NETWORKS[selectedNetwork].woc
4382
+ if (!woc) return releasedNote + 'Spendability check needs WhatsOnChain, which this network does not have.'
4383
+ const wocBase = `${woc.apiBase}/v1/bsv/${woc.segment}`
4349
4384
 
4350
4385
  // Rate limit: max 3 requests/sec (WoC limit ~1 per 0.34s)
4351
4386
  const WOC_INTERVAL = 340
@@ -7,8 +7,10 @@ import { DEFAULT_SETTINGS as LIB_DEFAULT_SETTINGS, WalletSettings } from '@bsv/w
7
7
  // their certificates threw in the dApp. Same wording as ts-stack#665, which
8
8
  // fixes the library; drop this once @bsv/wallet-toolbox-mobile ships it.
9
9
  const LIB_CERTIFIER_DESCRIPTIONS: Record<string, string> = {
10
- '03daf815fe38f83da0ad83b5bedc520aa488aef5cbc93a93c67a7fe60406cbffe8': 'Registry of protocols, baskets, certificate types',
11
- '02cf6cdf466951d8dfc9e7c9367511d0007ed6fba35ed42d425cc412fd6cfd4a17': 'Certifies social media handles, phones and emails'
10
+ '03daf815fe38f83da0ad83b5bedc520aa488aef5cbc93a93c67a7fe60406cbffe8':
11
+ 'Registry of protocols, baskets, certificate types',
12
+ '02cf6cdf466951d8dfc9e7c9367511d0007ed6fba35ed42d425cc412fd6cfd4a17':
13
+ 'Certifies social media handles, phones and emails'
12
14
  }
13
15
 
14
16
  export const DEFAULT_SETTINGS: WalletSettings = {
@@ -194,11 +194,7 @@ export function demoReceiveBsv(satoshis: number, description: string): DemoActio
194
194
  }
195
195
 
196
196
  /** Spend a token. Returns the new row, or null when the balance cannot cover it. */
197
- export function demoSendToken(
198
- assetId: string,
199
- baseUnits: number,
200
- counterpartyKey?: string
201
- ): TokenActivityRow | null {
197
+ export function demoSendToken(assetId: string, baseUnits: number, counterpartyKey?: string): TokenActivityRow | null {
202
198
  if (!demoAssetById(assetId)) return null
203
199
  if (!Number.isFinite(baseUnits) || baseUnits <= 0) return null
204
200
  const held = demoTokenBaseUnits(assetId)