@bsv/expo-wallet-toolbox 0.4.0 → 0.5.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 (118) hide show
  1. package/CHANGELOG.md +292 -0
  2. package/README.md +0 -1
  3. package/assets/sounds/vault-deposit.wav +0 -0
  4. package/assets/sounds/vault-withdraw.wav +0 -0
  5. package/core/config.tsx +9 -1
  6. package/core/context/VaultContext.tsx +8 -11
  7. package/core/context/WalletConnectionContext.tsx +137 -52
  8. package/core/context/WalletContext.tsx +409 -20
  9. package/core/hooks/useConfirmationSound.ts +14 -8
  10. package/core/i18n/translations.tsx +3368 -952
  11. package/core/index.ts +97 -14
  12. package/core/localpay/build.ts +674 -37
  13. package/core/localpay/codec.ts +68 -5
  14. package/core/localpay/pending.ts +240 -22
  15. package/core/localpay/settlementAck.ts +149 -0
  16. package/core/localpay/types.ts +14 -1
  17. package/core/localpay/verify.ts +118 -69
  18. package/core/mandala/abortGuard.ts +134 -0
  19. package/core/mandala/basketMigration.ts +166 -0
  20. package/core/mandala/bundle.ts +244 -0
  21. package/core/mandala/createRuntime.ts +2437 -0
  22. package/core/mandala/drain.ts +670 -0
  23. package/core/mandala/permissionModule.ts +642 -0
  24. package/core/mandala/resendTransfer.ts +175 -0
  25. package/core/mandala/runtime.ts +357 -0
  26. package/core/mandala/settlementStore.ts +412 -0
  27. package/core/mandala/types.ts +290 -0
  28. package/core/offline/cancelParked.ts +94 -1
  29. package/core/offline/payerHold.ts +152 -12
  30. package/core/offline/tokenFrames.ts +197 -0
  31. package/core/parsePeerPayURI.ts +70 -17
  32. package/core/pay/rails/address.ts +51 -3
  33. package/core/pay/rails/handle.ts +88 -9
  34. package/core/pay/rails/index.ts +16 -6
  35. package/core/pay/rails/nearby.ts +114 -4
  36. package/core/services/capWalletArgs.ts +8 -9
  37. package/core/services/externalOrigin.ts +39 -0
  38. package/core/services/vault/VaultKeyService.ts +912 -251
  39. package/core/services/vault/ceremony.ts +435 -367
  40. package/core/services/vault/ceremonyHost.ts +27 -21
  41. package/core/services/vault/devMock.ts +30 -7
  42. package/core/services/vault/driver.ts +95 -41
  43. package/core/services/vault/guard.ts +514 -56
  44. package/core/services/vault/hardwareLease.ts +22 -0
  45. package/core/services/vault/mockYubiKey.ts +258 -90
  46. package/core/services/vault/pivReset.ts +145 -0
  47. package/core/services/vault/r1comb.ts +976 -0
  48. package/core/services/vault/session.ts +93 -26
  49. package/core/services/vault/transfers.ts +2617 -747
  50. package/core/services/vault/types.ts +100 -43
  51. package/core/services/vault/vaultStore.ts +991 -74
  52. package/core/services/walletConnectionValidation.ts +293 -0
  53. package/core/storage/StorageExpoSQLite.ts +382 -56
  54. package/core/storage/dbImage.ts +48 -0
  55. package/core/storage/methods/findSql.ts +0 -54
  56. package/core/storage/methods/listOutputsSql.ts +7 -3
  57. package/core/storage/methods/offlineActions.ts +15 -0
  58. package/core/storage/methods/processOfflineActions.ts +263 -6
  59. package/core/storage/methods/walletBalanceSql.ts +16 -4
  60. package/core/storage/schema/createTables.ts +123 -0
  61. package/core/storage/sqlUpdateValue.ts +24 -0
  62. package/core/toolboxConfig.ts +112 -1
  63. package/core/walletRepair/runWalletCheck.ts +19 -2
  64. package/package.json +25 -24
  65. package/ui/components/QRScanner.tsx +1 -1
  66. package/ui/components/pay/AdmissionNotice.tsx +99 -0
  67. package/ui/components/pay/AssetPicker.tsx +184 -0
  68. package/ui/components/pay/AvailableBalance.tsx +33 -2
  69. package/ui/components/pay/HandleReceive.tsx +213 -50
  70. package/ui/components/pay/NearbyFlow.tsx +616 -69
  71. package/ui/components/pay/PayForm.tsx +73 -8
  72. package/ui/components/pay/PaymentSuccessOverlay.tsx +43 -2
  73. package/ui/components/pay/RecipientField.tsx +49 -4
  74. package/ui/components/pay/RequestHub.tsx +68 -8
  75. package/ui/components/pay/ResultBanner.tsx +41 -4
  76. package/ui/components/pay/UniversalSend.tsx +534 -30
  77. package/ui/components/pay/tokenSendCopy.ts +116 -0
  78. package/ui/components/pay/useRecipientInput.ts +36 -7
  79. package/ui/components/ui/PermissionSheet.tsx +65 -4
  80. package/ui/components/ui/Sheet.tsx +9 -2
  81. package/ui/components/vault/EnrollWizard.tsx +1432 -488
  82. package/ui/components/vault/KeyChooser.tsx +96 -0
  83. package/ui/components/vault/VaultCeremonySheet.tsx +107 -43
  84. package/ui/components/vault/vaultErrorCopy.ts +145 -0
  85. package/ui/components/wallet/ActivityRow.tsx +101 -17
  86. package/ui/components/wallet/AmountInput.tsx +77 -25
  87. package/ui/components/wallet/AssetAmount.tsx +95 -0
  88. package/ui/components/wallet/AssetSwitcherDropdown.tsx +261 -0
  89. package/ui/components/wallet/tokenEviction.ts +65 -0
  90. package/ui/hooks/useExportWalletData.ts +39 -0
  91. package/ui/hooks/useMandala.ts +303 -0
  92. package/ui/hooks/useVaultBalance.ts +105 -7
  93. package/ui/hooks/useVaultCoverage.ts +52 -0
  94. package/ui/importDatabases.ts +7 -3
  95. package/ui/index.ts +50 -7
  96. package/ui/screens/ConnectionsScreen.tsx +46 -29
  97. package/ui/screens/PairScreen.tsx +12 -12
  98. package/ui/screens/PayScreen.tsx +130 -10
  99. package/ui/screens/SettingsScreen.tsx +18 -9
  100. package/ui/screens/VaultScreen.tsx +925 -171
  101. package/ui/screens/VaultTransferScreen.tsx +376 -123
  102. package/ui/screens/WalletCheckScreen.tsx +10 -1
  103. package/ui/screens/WalletConfigScreen.tsx +38 -16
  104. package/ui/screens/WalletHomeScreen.tsx +417 -86
  105. package/ui/screens/homeBadges.ts +9 -1
  106. package/ui/screens/tokenRowTitle.ts +68 -0
  107. package/ui/tokenFormat.ts +108 -0
  108. package/ui/tokenSeen.ts +75 -0
  109. package/ui/tokenStatus.ts +79 -0
  110. package/assets/sounds/vault-close.wav +0 -0
  111. package/assets/sounds/vault-open.wav +0 -0
  112. package/core/services/vault/k1.ts +0 -75
  113. package/core/services/vault/sealing.ts +0 -84
  114. package/core/services/vault/vaultDerivation.ts +0 -152
  115. package/core/services/vault/vaultPassphrase.ts +0 -287
  116. package/ui/components/vault/PassphraseField.tsx +0 -306
  117. package/ui/components/vault/PhraseBackupSheet.tsx +0 -227
  118. package/ui/screens/VaultRecoverScreen.tsx +0 -226
@@ -15,6 +15,26 @@ export interface ToolboxServiceConfig {
15
15
  taalApiKey?: string
16
16
  }
17
17
 
18
+ /**
19
+ * The three endpoints a Mandala stablecoin deployment is addressed by, for one
20
+ * chain (offline-settlement spec §12: endpoints live in the host's toolbox
21
+ * config, never in an env read inside this package).
22
+ *
23
+ * All three are required together, and that is the point: `overlayUrl` without
24
+ * `overlayIdentityKey` is an overlay whose σ_I nothing can verify, which is
25
+ * indistinguishable from no overlay at all — so a half-stated chain entry is
26
+ * treated as an unstated one (`getMandalaEndpoints` returns undefined) rather
27
+ * than producing a runtime that can submit but never prove.
28
+ */
29
+ export interface MandalaEndpointConfig {
30
+ /** Origin of the issuer's overlay, no trailing slash — `${overlayUrl}/submit` is posted to. */
31
+ overlayUrl: string
32
+ /** 66-hex compressed key; the ONLY key an admission signature may come from. */
33
+ overlayIdentityKey: string
34
+ /** MessageBox host for the `'mandala-payments'` box (the handle rail). */
35
+ messageBoxUrl: string
36
+ }
37
+
18
38
  /**
19
39
  * Runtime configuration supplied by the host app.
20
40
  *
@@ -51,11 +71,31 @@ export interface ToolboxConfig {
51
71
  backupUrl: string | null
52
72
  /** Per-chain service endpoints and keys. Omitted chains use built-in defaults. */
53
73
  services?: Partial<Record<AppChain, ToolboxServiceConfig>>
74
+ /**
75
+ * Per-chain Mandala stablecoin endpoints. There is deliberately NO default:
76
+ * an issuer's overlay and its identity key are deployment facts this package
77
+ * cannot guess, and guessing one would mean verifying admissions against the
78
+ * wrong key. A chain with no complete entry has no Mandala runtime
79
+ * (`useWallet().mandala` is undefined). Which chains carry an entry is the
80
+ * host's whole policy — e.g. testnet only while the issuer's overlay is a
81
+ * testnet deployment.
82
+ */
83
+ mandala?: Partial<Record<AppChain, MandalaEndpointConfig>>
84
+ /**
85
+ * Release gate for the YubiKey vault (spec §0, D15). Default false: the home
86
+ * button and Settings row are hidden, the vault route shows "Not available
87
+ * yet", and no code path may enrol hardware or create a vault output. Turned
88
+ * on per build profile by the host (EXPO_PUBLIC_VAULT_ENABLED in eas.json),
89
+ * never read from process.env here.
90
+ */
91
+ vaultEnabled?: boolean
54
92
  }
55
93
 
56
94
  interface ResolvedConfig {
57
95
  backupUrl: string
58
96
  services: Partial<Record<AppChain, ToolboxServiceConfig>>
97
+ mandala: Partial<Record<AppChain, MandalaEndpointConfig>>
98
+ vaultEnabled: boolean
59
99
  }
60
100
 
61
101
  let current: ResolvedConfig | null = null
@@ -98,7 +138,9 @@ export function configureToolbox(config: ToolboxConfig): void {
98
138
  }
99
139
  current = {
100
140
  backupUrl: config.backupUrl == null ? '' : normalizeBackupUrl(config.backupUrl),
101
- services: config.services ?? {}
141
+ services: config.services ?? {},
142
+ mandala: config.mandala ?? {},
143
+ vaultEnabled: config.vaultEnabled === true
102
144
  }
103
145
  }
104
146
 
@@ -123,6 +165,75 @@ export function getServiceConfig(chain: AppChain): ToolboxServiceConfig {
123
165
  return current.services[chain] ?? {}
124
166
  }
125
167
 
168
+ const COMPRESSED_KEY = /^0[23][0-9a-fA-F]{64}$/
169
+
170
+ /**
171
+ * The Mandala endpoints for a chain, or undefined when this build has none.
172
+ *
173
+ * Deliberately NOT throwing when the toolbox is unconfigured, for the same
174
+ * reason `isVaultEnabled` does not: this is read while building the wallet and
175
+ * while rendering, and "unconfigured" must look like "Mandala off" rather than
176
+ * crash a wallet that never wanted stablecoins.
177
+ *
178
+ * A partial or malformed entry answers undefined rather than a half-usable
179
+ * object: an overlay URL with no verifiable identity key can submit but can
180
+ * never prove an admission, which is the one shape this feature must not have.
181
+ */
182
+ export function getMandalaEndpoints(chain: AppChain): MandalaEndpointConfig | undefined {
183
+ const entry = current?.mandala[chain]
184
+ if (!entry) return undefined
185
+ const overlayUrl = entry.overlayUrl?.trim().replace(/\/+$/, '') ?? ''
186
+ const overlayIdentityKey = entry.overlayIdentityKey?.trim() ?? ''
187
+ const messageBoxUrl = entry.messageBoxUrl?.trim().replace(/\/+$/, '') ?? ''
188
+ if (overlayUrl === '' || messageBoxUrl === '') return undefined
189
+ if (!COMPRESSED_KEY.test(overlayIdentityKey)) return undefined
190
+ return { overlayUrl, overlayIdentityKey, messageBoxUrl }
191
+ }
192
+
193
+ /**
194
+ * Whether Mandala stablecoins are available on this network.
195
+ *
196
+ * Exactly the chains the host stated complete endpoints for — nothing else
197
+ * gates it. (v1 hardcoded mainnet on top of that, ux §2; since 2026-09-15 the
198
+ * host's `mandala` map is the whole policy, so a testnet-only rollout is a
199
+ * config choice, not a code change.) Chain is a parameter, not a module read,
200
+ * for the same reason `isVaultAvailable`'s is: screens must re-render when the
201
+ * user switches network.
202
+ */
203
+ export function isMandalaAvailable(chain: AppChain): boolean {
204
+ return getMandalaEndpoints(chain) !== undefined
205
+ }
206
+
207
+ /**
208
+ * Whether this build may enrol vault hardware or create vault outputs.
209
+ *
210
+ * Deliberately NOT throwing when unconfigured: this is read while rendering
211
+ * the home screen, and "unconfigured" must look like "vault off", not crash.
212
+ */
213
+ export function isVaultEnabled(): boolean {
214
+ return current?.vaultEnabled ?? false
215
+ }
216
+
217
+ /**
218
+ * Whether the vault may be used on this network.
219
+ *
220
+ * Vault is mainnet-only by product decision (2026-09-12): there is no reason to
221
+ * hold different hardware keys per network, and high-value storage is
222
+ * meaningless on a chain whose coins are worthless. Keeping it off testnet also
223
+ * removes a fund-loss path — the enrollment wizard's reset offer reads enrolled
224
+ * serials from one wallet+chain namespace, but a YubiKey is physical and shared
225
+ * across all of them, so a testnet wizard could offer to factory-reset a live
226
+ * mainnet signer.
227
+ *
228
+ * Chain is a parameter, not a module read: screens must re-render when the user
229
+ * switches network, and `selectedNetwork` from the wallet context is what makes
230
+ * that reactive. Keeping it a parameter also keeps this module a leaf — it must
231
+ * never import `vaultStore`.
232
+ */
233
+ export function isVaultAvailable(chain: AppChain): boolean {
234
+ return isVaultEnabled() && chain === 'main'
235
+ }
236
+
126
237
  /** Test-only: drop the installed configuration. */
127
238
  export function resetToolboxConfig(): void {
128
239
  current = null
@@ -2,7 +2,7 @@
2
2
  * Ordered Check-my-wallet repair steps.
3
3
  *
4
4
  * Records first so phantom spendable outputs do not poison later sends.
5
- * freedCoins = reviewSpendable.released + releaseStuck.released + reviewStatus.restoredInputs
5
+ * freedCoins = reviewSpendable.released + releaseStuck.released + reviewStatus.restoredInputs + reviewTokens.removed
6
6
  *
7
7
  * A port throw marks that step error; later steps still run.
8
8
  */
@@ -10,6 +10,7 @@
10
10
  export type WalletCheckStepId =
11
11
  | 'online'
12
12
  | 'records'
13
+ | 'tokens'
13
14
  | 'coins'
14
15
  | 'proofs'
15
16
  | 'missed_payments'
@@ -48,6 +49,13 @@ export interface WalletCheckPorts {
48
49
  /** Whether the recovery phrase was written down or the shares printed. */
49
50
  checkPhraseBackup: () => Promise<{ backedUp: boolean }>
50
51
  reviewSpendable: () => Promise<{ released: number; recovered: number }>
52
+ /**
53
+ * Token settlement rows and held coins, checked against the issuer's overlay.
54
+ * `removed` = transactions the overlay refused, now failed locally; `unattested`
55
+ * = rows/coins the overlay has no record of, reported and left alone. Throws
56
+ * when the overlay cannot be reached.
57
+ */
58
+ reviewTokens: () => Promise<{ settled: number; removed: number; unattested: number }>
51
59
  checkProofs: () => Promise<{ repaired: number }>
52
60
  reviewStatus: () => Promise<{ failedTxs: number; restoredInputs: number }>
53
61
  releaseStuck: () => Promise<{ released: number }>
@@ -144,6 +152,14 @@ export async function runWalletCheck(
144
152
  })
145
153
  record('records', records, () => ((records as { ok?: boolean }).ok === true ? 'ok' : 'error'))
146
154
 
155
+ onStep('tokens')
156
+ const tokens = await guard(skips, 'tokens', { settled: 0, removed: 0, unattested: 0 }, () =>
157
+ settle(() => ports.reviewTokens(), { settled: 0, removed: 0, unattested: 0 })
158
+ )
159
+ record('tokens', tokens, () =>
160
+ !(tokens as { ok?: boolean }).ok ? 'error' : tokens.value.unattested > 0 ? 'attention' : 'ok'
161
+ )
162
+
147
163
  onStep('proofs')
148
164
  const proofs = await guard(skips, 'proofs', { repaired: 0 }, () =>
149
165
  settle(() => ports.checkProofs(), { repaired: 0 })
@@ -185,7 +201,8 @@ export async function runWalletCheck(
185
201
  record('coins', spendable, () => ((spendable as { ok?: boolean }).ok === true ? 'ok' : 'error'))
186
202
 
187
203
  return {
188
- freedCoins: spendable.value.released + records.value.stuckReleased + records.value.restoredInputs,
204
+ freedCoins:
205
+ spendable.value.released + records.value.stuckReleased + records.value.restoredInputs + tokens.value.removed,
189
206
  recoveredPayments: missed.value.accepted + missed.value.imported,
190
207
  repairedProofs: proofs.value.repaired,
191
208
  steps,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsv/expo-wallet-toolbox",
3
- "version": "0.4.0",
3
+ "version": "0.5.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",
@@ -32,6 +32,7 @@
32
32
  "@bsv/air-gap": "^0.1.1",
33
33
  "@bsv/backup-cache-client": "^0.1.0",
34
34
  "@bsv/btms-permission-module": "^1.1.0",
35
+ "@bsv/mandala": "^0.2.0",
35
36
  "@bsv/message-box-client": "^2.2.1",
36
37
  "@bsv/react-native-localpay-transport": "*",
37
38
  "@bsv/sdk": "^2.4.1",
@@ -41,41 +42,41 @@
41
42
  "@noble/curves": "^2.3.0",
42
43
  "@react-native-async-storage/async-storage": "^2.2.0",
43
44
  "@react-native-clipboard/clipboard": "^1.16.2",
44
- "@react-native-community/netinfo": "^11.5.2",
45
+ "@react-native-community/netinfo": "^12.0.1",
45
46
  "@urbit/sigil-js": "^2.2.0",
46
47
  "date-fns": "^4.1.0",
47
- "expo-audio": "~55.0.16",
48
- "expo-blur": "~55.0.14",
49
- "expo-camera": "~55.0.19",
50
- "expo-clipboard": "~55.0.13",
51
- "expo-crypto": "~55.0.15",
52
- "expo-device": "~55.0.17",
53
- "expo-document-picker": "~55.0.13",
54
- "expo-file-system": "~55.0.20",
55
- "expo-haptics": "~55.0.14",
56
- "expo-image": "~55.0.11",
57
- "expo-local-authentication": "~55.0.14",
58
- "expo-localization": "~55.0.15",
59
- "expo-print": "~55.0.15",
60
- "expo-router": "~55.0.16",
61
- "expo-secure-store": "~55.0.14",
62
- "expo-sharing": "~55.0.19",
63
- "expo-sqlite": "~55.0.16",
64
- "expo-status-bar": "~55.0.6",
48
+ "expo-audio": "~57.0.5",
49
+ "expo-blur": "~57.0.3",
50
+ "expo-camera": "~57.0.5",
51
+ "expo-clipboard": "~57.0.2",
52
+ "expo-crypto": "~57.0.3",
53
+ "expo-device": "~57.0.2",
54
+ "expo-document-picker": "~57.0.2",
55
+ "expo-file-system": "~57.0.7",
56
+ "expo-haptics": "~57.0.3",
57
+ "expo-image": "~57.0.5",
58
+ "expo-local-authentication": "~57.0.3",
59
+ "expo-localization": "~57.0.2",
60
+ "expo-print": "~57.0.2",
61
+ "expo-router": "~57.0.21",
62
+ "expo-secure-store": "~57.0.4",
63
+ "expo-sharing": "~57.0.19",
64
+ "expo-sqlite": "~57.0.3",
65
+ "expo-status-bar": "~57.0.1",
65
66
  "i18next": "^25.2.1",
66
67
  "mobx": "^6.13.7",
67
68
  "mobx-react-lite": "^4.1.0",
68
69
  "qrcode": "^1.5.4",
69
70
  "react": "^19.2.0",
70
- "react-i18next": "^15.5.3",
71
- "react-native": "^0.83.6",
71
+ "react-i18next": "^16.6.6",
72
+ "react-native": "^0.86.3",
72
73
  "react-native-engine-native": "*",
73
- "react-native-gesture-handler": "~2.30.0",
74
+ "react-native-gesture-handler": "~2.32.0",
74
75
  "react-native-localize": "^3.4.1",
75
76
  "react-native-nitro-modules": "^0.35.2",
76
77
  "react-native-qrcode-svg": "^6.3.15",
77
78
  "react-native-reanimated": "^4.2.1",
78
- "react-native-safe-area-context": "~5.6.0",
79
+ "react-native-safe-area-context": "~5.7.0",
79
80
  "react-native-secp-native": "*",
80
81
  "react-native-sse": "^1.2.1",
81
82
  "react-native-svg": "^15.15.3",
@@ -271,7 +271,7 @@ const styles = StyleSheet.create({
271
271
 
272
272
  // ── Scanner overlay ────────────────────────────────────────────────────
273
273
  overlay: {
274
- ...StyleSheet.absoluteFillObject,
274
+ ...StyleSheet.absoluteFill,
275
275
  justifyContent: 'space-between'
276
276
  },
277
277
  overlayTop: {
@@ -0,0 +1,99 @@
1
+ /**
2
+ * "You can't be paid in USDX yet" — the screen that replaces a payment code
3
+ * rather than showing one that cannot work.
4
+ *
5
+ * Showing the QR anyway would manufacture a failure inside someone else's app,
6
+ * attributed to nothing: the payer scans, their wallet refuses, and neither
7
+ * party can see why. Withholding the code and naming the party who decides is
8
+ * the whole of error prevention in one screen.
9
+ *
10
+ * It deliberately offers no "How to get registered" affordance. There is no
11
+ * route inside this wallet to become registered — registration is the issuer's
12
+ * chain, gated by whatever the issuer requires — so a button for it would
13
+ * dead-end. What it offers instead is the rail that works right now.
14
+ */
15
+ import React from 'react'
16
+ import { StyleSheet, Text, View } from 'react-native'
17
+ import { useTranslation } from 'react-i18next'
18
+ import { hitTargets, radii, spacing, typography, useTheme } from '@bsv/expo-wallet-toolbox'
19
+ import PressableScale from '../ui/PressableScale'
20
+
21
+ /**
22
+ * @expo/vector-icons' index barrel re-exports every icon set (AntDesign,
23
+ * etc.), one of which reaches expo-font -> expo-asset -- untransformed ESM
24
+ * that Jest cannot parse when eagerly pulled in via the `ui` package barrel.
25
+ * Ionicons is loaded lazily, only when actually rendering, same pattern as
26
+ * this package's other native-module-boundary fixes (expo-router, expo-blur).
27
+ */
28
+ type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
29
+ let ioniconsComponent: IoniconsComponent | undefined
30
+ function loadIonicons(): IoniconsComponent {
31
+ if (!ioniconsComponent) {
32
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
33
+ ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
34
+ }
35
+ return ioniconsComponent
36
+ }
37
+
38
+ export interface AdmissionNoticeProps {
39
+ ticker: string
40
+ /** Resolved issuer name; falls back to "the issuer" rather than a hex key. */
41
+ issuerName?: string
42
+ /**
43
+ * The runtime's own plain reason, when it has one. It wins over the generic
44
+ * body: a specific true sentence beats a general true sentence.
45
+ */
46
+ reason?: string | null
47
+ onBsvInstead: () => void
48
+ }
49
+
50
+ export default function AdmissionNotice({ ticker, issuerName, reason, onBsvInstead }: AdmissionNoticeProps) {
51
+ const { t } = useTranslation()
52
+ const { colors } = useTheme()
53
+ const Ionicons = loadIonicons()
54
+ const issuer = issuerName || t('token_issuer_fallback')
55
+
56
+ return (
57
+ // One region, so the title and the reason are read together before the
58
+ // route row rather than as three unrelated announcements.
59
+ <View style={styles.wrap} accessibilityRole="summary" accessible>
60
+ <Ionicons name="alert-circle-outline" size={48} color={colors.textTertiary} />
61
+ <Text style={[styles.title, { color: colors.textPrimary }]} textBreakStrategy="balanced">
62
+ {t('token_admit_title', { ticker })}
63
+ </Text>
64
+ <Text style={[styles.body, { color: colors.textSecondary }]} textBreakStrategy="balanced">
65
+ {reason || t('token_admit_body', { issuer, ticker })}
66
+ </Text>
67
+ <PressableScale
68
+ onPress={onBsvInstead}
69
+ haptic="tap"
70
+ style={[styles.route, { backgroundColor: colors.backgroundElevated, borderColor: colors.separator }]}
71
+ accessibilityRole="button"
72
+ accessibilityLabel={t('token_admit_bsv_instead')}
73
+ >
74
+ <Ionicons name="arrow-down" size={18} color={colors.textPrimary} />
75
+ <Text style={[styles.routeLabel, { color: colors.textPrimary }]}>{t('token_admit_bsv_instead')}</Text>
76
+ <Ionicons name="chevron-forward" size={18} color={colors.textQuaternary} />
77
+ </PressableScale>
78
+ </View>
79
+ )
80
+ }
81
+
82
+ const styles = StyleSheet.create({
83
+ wrap: { alignItems: 'center', paddingHorizontal: spacing.xl, paddingVertical: spacing.xxl, gap: spacing.md },
84
+ title: { ...typography.title3, textAlign: 'center' },
85
+ body: { ...typography.subhead, textAlign: 'center', maxWidth: 320 },
86
+ route: {
87
+ flexDirection: 'row',
88
+ alignItems: 'center',
89
+ gap: spacing.md,
90
+ alignSelf: 'stretch',
91
+ minHeight: hitTargets.minimum,
92
+ paddingVertical: spacing.md,
93
+ paddingHorizontal: spacing.lg,
94
+ borderRadius: radii.lg,
95
+ borderWidth: StyleSheet.hairlineWidth,
96
+ marginTop: spacing.md
97
+ },
98
+ routeLabel: { ...typography.headline, fontWeight: '600', flex: 1 }
99
+ })
@@ -0,0 +1,184 @@
1
+ /**
2
+ * "Paying with" / "Getting paid in" — the asset question, asked inside the flow
3
+ * that already asks who and how much.
4
+ *
5
+ * The asset is a property of a payment, not a mode of the wallet: there is no
6
+ * token screen to switch into and no setting to change, because a person who
7
+ * holds two kinds of money does not want a second wallet, they want to choose
8
+ * once, here, at the moment it matters.
9
+ *
10
+ * It sits ABOVE the recipient field on purpose. Choosing an asset changes the
11
+ * unit of the amount, the available figure and which recipient shapes are even
12
+ * legal (a token has no address rail), so asking it second would silently
13
+ * invalidate work the user had already done.
14
+ *
15
+ * The control is the display-currency expander from Settings, verbatim: a row
16
+ * with a down-chevron that opens an inline list with a trailing checkmark. Not
17
+ * a segmented control — that caps out at four options and this list is as long
18
+ * as the user's holdings. It is layout, not animation, so Reduce Motion needs
19
+ * no special case.
20
+ *
21
+ * Renders `null` when the wallet holds no token, which is the whole of "a
22
+ * wallet that has never held one renders today's screen".
23
+ */
24
+ import React, { useState } from 'react'
25
+ import { StyleSheet, Text, TouchableOpacity, View } from 'react-native'
26
+ import { hitTargets, spacing, typography, useTheme } from '@bsv/expo-wallet-toolbox'
27
+ import type { TokenBalance } from '../../../core/mandala/runtime'
28
+ import { ListRow } from '../ui/ListRow'
29
+ import { formatTokenAmountWithUnit } from '../../tokenFormat'
30
+
31
+ /**
32
+ * @expo/vector-icons' index barrel re-exports every icon set (AntDesign,
33
+ * etc.), one of which reaches expo-font -> expo-asset -- untransformed ESM
34
+ * that Jest cannot parse when eagerly pulled in via the `ui` package barrel.
35
+ * Ionicons is loaded lazily, only when actually rendering, same pattern as
36
+ * this package's other native-module-boundary fixes (expo-router, expo-blur).
37
+ */
38
+ type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
39
+ let ioniconsComponent: IoniconsComponent | undefined
40
+ function loadIonicons(): IoniconsComponent {
41
+ if (!ioniconsComponent) {
42
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
43
+ ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
44
+ }
45
+ return ioniconsComponent
46
+ }
47
+
48
+ /**
49
+ * The BSV row's label is the literal string, like `mainnet`/`testnet` elsewhere
50
+ * in this app: a `pay_asset_bsv` key would be byte-identical in all twelve
51
+ * locales and fail translation parity for being untranslated.
52
+ */
53
+ const BSV_LABEL = 'BSV'
54
+
55
+ export interface AssetPickerProps {
56
+ /** Held assets. Empty means no picker at all. */
57
+ balances: TokenBalance[]
58
+ /** `null` selects BSV — the default, and what every existing flow assumes. */
59
+ selected: string | null
60
+ onSelect: (assetId: string | null) => void
61
+ /** Shown beside the BSV row; `null` is UNKNOWN and prints nothing. */
62
+ bsvBalanceText?: string | null
63
+ /** Whether the collapsed row shows each asset's figure (Pay does; Get paid doesn't). */
64
+ showFigures?: boolean
65
+ }
66
+
67
+ export default function AssetPicker({
68
+ balances,
69
+ selected,
70
+ onSelect,
71
+ bsvBalanceText = null,
72
+ showFigures = true
73
+ }: AssetPickerProps) {
74
+ const { colors } = useTheme()
75
+ const [expanded, setExpanded] = useState(false)
76
+
77
+ if (balances.length === 0) return null
78
+
79
+ const current = balances.find(b => b.asset.assetId === selected) ?? null
80
+ const currentLabel = current ? current.asset.label || current.asset.ticker : BSV_LABEL
81
+ const currentFigure = current
82
+ ? formatTokenAmountWithUnit(current.baseUnits, current.asset)
83
+ : bsvBalanceText
84
+
85
+ const choose = (assetId: string | null) => {
86
+ onSelect(assetId)
87
+ setExpanded(false)
88
+ }
89
+
90
+ return (
91
+ <View>
92
+ <View
93
+ accessible
94
+ accessibilityRole="button"
95
+ accessibilityState={{ expanded }}
96
+ accessibilityLabel={[currentLabel, showFigures ? currentFigure : null].filter(Boolean).join(', ')}
97
+ >
98
+ <ListRow
99
+ label={currentLabel}
100
+ value={showFigures && currentFigure ? currentFigure : undefined}
101
+ icon="cash-outline"
102
+ isLast={!expanded}
103
+ onPress={() => setExpanded(e => !e)}
104
+ showChevron
105
+ chevronDown
106
+ />
107
+ </View>
108
+ {expanded && (
109
+ <View style={[styles.options, { backgroundColor: colors.backgroundElevated, borderColor: colors.separator }]}>
110
+ <AssetOption
111
+ label={BSV_LABEL}
112
+ figure={showFigures ? bsvBalanceText : null}
113
+ selected={selected === null}
114
+ onPress={() => choose(null)}
115
+ />
116
+ {balances.map(b => (
117
+ <AssetOption
118
+ key={b.asset.assetId}
119
+ label={b.asset.label || b.asset.ticker}
120
+ figure={showFigures ? formatTokenAmountWithUnit(b.baseUnits, b.asset) : null}
121
+ selected={selected === b.asset.assetId}
122
+ onPress={() => choose(b.asset.assetId)}
123
+ />
124
+ ))}
125
+ </View>
126
+ )}
127
+ </View>
128
+ )
129
+ }
130
+
131
+ function AssetOption({
132
+ label,
133
+ figure,
134
+ selected,
135
+ onPress
136
+ }: {
137
+ label: string
138
+ figure?: string | null
139
+ selected: boolean
140
+ onPress: () => void
141
+ }) {
142
+ const { colors } = useTheme()
143
+ const Ionicons = loadIonicons()
144
+ return (
145
+ <TouchableOpacity
146
+ style={styles.option}
147
+ onPress={onPress}
148
+ activeOpacity={0.6}
149
+ accessibilityRole="button"
150
+ // The checkmark is not the only signal: state travels with the element.
151
+ accessibilityState={{ selected }}
152
+ accessibilityLabel={[label, figure].filter(Boolean).join(', ')}
153
+ >
154
+ <Text style={[styles.optionLabel, { color: colors.textPrimary }]} numberOfLines={1}>
155
+ {label}
156
+ </Text>
157
+ {!!figure && (
158
+ <Text style={[styles.optionFigure, { color: colors.textSecondary }]} numberOfLines={1}>
159
+ {figure}
160
+ </Text>
161
+ )}
162
+ {selected && <Ionicons name="checkmark" size={20} color={colors.accent} style={styles.check} />}
163
+ </TouchableOpacity>
164
+ )
165
+ }
166
+
167
+ const styles = StyleSheet.create({
168
+ options: {
169
+ borderBottomLeftRadius: 12,
170
+ borderBottomRightRadius: 12,
171
+ borderTopWidth: StyleSheet.hairlineWidth
172
+ },
173
+ option: {
174
+ flexDirection: 'row',
175
+ alignItems: 'center',
176
+ gap: spacing.sm,
177
+ minHeight: hitTargets.minimum,
178
+ paddingVertical: spacing.md,
179
+ paddingHorizontal: spacing.lg
180
+ },
181
+ optionLabel: { ...typography.body, flex: 1 },
182
+ optionFigure: { ...typography.footnote, fontVariant: ['tabular-nums'] },
183
+ check: { marginLeft: spacing.xs }
184
+ })
@@ -25,13 +25,43 @@ import {
25
25
  } from '@bsv/expo-wallet-toolbox'
26
26
  import AmountDisplay from '../wallet/AmountDisplay'
27
27
 
28
- export default function AvailableBalance({ withUnit = false }: { withUnit?: boolean }) {
28
+ export default function AvailableBalance({
29
+ withUnit = false,
30
+ text,
31
+ note
32
+ }: {
33
+ withUnit?: boolean
34
+ /**
35
+ * An already-formatted figure to render verbatim. When present the wallet's
36
+ * own spendable balance is not consulted at all — this component sources its
37
+ * BSV figure itself and takes no balance prop, so a token figure can reach
38
+ * this line no other way.
39
+ */
40
+ text?: string
41
+ /** A second line under the figure — today, the frozen subtotal (advisory). */
42
+ note?: string
43
+ }) {
29
44
  const { t } = useTranslation()
30
45
  const { colors } = useTheme()
31
46
  const { settings } = useWallet()
32
47
  const { satoshisPerUSD, usdToFiat = {} } = useContext(ExchangeRateContext)
33
48
  const balance = useSpendableBalance()
34
49
 
50
+ if (text !== undefined) {
51
+ return (
52
+ <>
53
+ <Text style={[styles.text, { color: colors.textSecondary }]} accessibilityRole="text">
54
+ <Text style={[styles.figure, { color: colors.textPrimary }]}>{text}</Text> {t('available')}
55
+ </Text>
56
+ {!!note && (
57
+ <Text style={[styles.note, { color: colors.textSecondary }]} accessibilityRole="text">
58
+ {note}
59
+ </Text>
60
+ )}
61
+ </>
62
+ )
63
+ }
64
+
35
65
  if (balance == null) return null
36
66
 
37
67
  if (withUnit) {
@@ -57,5 +87,6 @@ export default function AvailableBalance({ withUnit = false }: { withUnit?: bool
57
87
 
58
88
  const styles = StyleSheet.create({
59
89
  text: { ...typography.footnote, marginTop: spacing.sm },
60
- figure: { ...typography.footnote, fontWeight: '600', fontVariant: ['tabular-nums'] }
90
+ figure: { ...typography.footnote, fontWeight: '600', fontVariant: ['tabular-nums'] },
91
+ note: { ...typography.footnote, marginTop: spacing.xs }
61
92
  })