@bsv/expo-wallet-toolbox 0.4.0 → 0.7.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 (182) hide show
  1. package/CHANGELOG.md +547 -0
  2. package/README.md +19 -1
  3. package/assets/sounds/vault-deposit.wav +0 -0
  4. package/assets/sounds/vault-withdraw.wav +0 -0
  5. package/core/amountFormatHelpers.ts +238 -34
  6. package/core/backup/RemoteSyncReader.ts +2 -5
  7. package/core/backup/codec.ts +2 -2
  8. package/core/backup/push.ts +1 -1
  9. package/core/config.tsx +16 -1
  10. package/core/contacts/contactActivity.ts +153 -0
  11. package/core/contacts/contactCache.ts +41 -0
  12. package/core/contacts/contactsStore.ts +183 -0
  13. package/core/context/VaultContext.tsx +8 -11
  14. package/core/context/WalletConnectionContext.tsx +137 -52
  15. package/core/context/WalletContext.tsx +464 -30
  16. package/core/demo/demoAssets.ts +60 -0
  17. package/core/demo/demoLedger.ts +240 -0
  18. package/core/demo/demoMandalaRuntime.ts +96 -0
  19. package/core/demo/demoMode.ts +38 -0
  20. package/core/demo/demoWallet.ts +25 -0
  21. package/core/demo/index.ts +26 -0
  22. package/core/demo/useDemo.ts +59 -0
  23. package/core/headers/OfflineFirstChaintracks.ts +52 -14
  24. package/core/headers/headerStore.ts +7 -10
  25. package/core/hooks/useConfirmationSound.ts +14 -8
  26. package/core/i18n/translations.tsx +4562 -986
  27. package/core/identity/contactLink.ts +36 -0
  28. package/core/identity/handleRegistry/client.ts +285 -0
  29. package/core/identity/handleRegistry/profileCert.ts +254 -0
  30. package/core/identity/handleRegistry/registration.ts +559 -0
  31. package/core/identity/handleRegistry/resolver.ts +247 -0
  32. package/core/identity/handleRegistry/rules.ts +104 -0
  33. package/core/index.ts +116 -15
  34. package/core/localpay/build.ts +674 -37
  35. package/core/localpay/codec.ts +68 -5
  36. package/core/localpay/pending.ts +240 -22
  37. package/core/localpay/pendingAborts.ts +5 -1
  38. package/core/localpay/settlementAck.ts +149 -0
  39. package/core/localpay/types.ts +14 -1
  40. package/core/localpay/verify.ts +118 -69
  41. package/core/mandala/abortGuard.ts +134 -0
  42. package/core/mandala/basketMigration.ts +166 -0
  43. package/core/mandala/bundle.ts +244 -0
  44. package/core/mandala/createRuntime.ts +2437 -0
  45. package/core/mandala/drain.ts +670 -0
  46. package/core/mandala/permissionModule.ts +642 -0
  47. package/core/mandala/resendTransfer.ts +175 -0
  48. package/core/mandala/runtime.ts +357 -0
  49. package/core/mandala/settlementStore.ts +412 -0
  50. package/core/mandala/types.ts +290 -0
  51. package/core/monitor/MonitorSupervisor.ts +121 -0
  52. package/core/monitor/TaskBackupPush.ts +1 -1
  53. package/core/monitor/TaskCreditInbox.ts +1 -1
  54. package/core/monitor/TaskDrainOutbox.ts +1 -1
  55. package/core/monitor/TaskSendOffline.ts +1 -1
  56. package/core/net/online.ts +49 -0
  57. package/core/numberFormat.ts +19 -0
  58. package/core/offline/cancelParked.ts +94 -1
  59. package/core/offline/payerHold.ts +152 -12
  60. package/core/offline/plan.ts +1 -1
  61. package/core/offline/tokenFrames.ts +197 -0
  62. package/core/parsePeerPayURI.ts +70 -17
  63. package/core/pay/rails/address.ts +51 -3
  64. package/core/pay/rails/handle.ts +88 -9
  65. package/core/pay/rails/index.ts +16 -6
  66. package/core/pay/rails/nearby.ts +114 -4
  67. package/core/pay/recordProof.ts +2 -6
  68. package/core/services/arcadeBroadcastProvider.ts +1 -4
  69. package/core/services/capWalletArgs.ts +8 -9
  70. package/core/services/exchangeRate.ts +1 -1
  71. package/core/services/externalOrigin.ts +42 -0
  72. package/core/services/vault/VaultKeyService.ts +912 -251
  73. package/core/services/vault/ceremony.ts +435 -367
  74. package/core/services/vault/ceremonyHost.ts +27 -21
  75. package/core/services/vault/devMock.ts +30 -7
  76. package/core/services/vault/driver.ts +95 -41
  77. package/core/services/vault/guard.ts +514 -56
  78. package/core/services/vault/hardwareLease.ts +22 -0
  79. package/core/services/vault/mockYubiKey.ts +258 -90
  80. package/core/services/vault/pivReset.ts +145 -0
  81. package/core/services/vault/r1comb.ts +976 -0
  82. package/core/services/vault/session.ts +93 -26
  83. package/core/services/vault/transfers.ts +2617 -747
  84. package/core/services/vault/types.ts +100 -43
  85. package/core/services/vault/vaultStore.ts +991 -74
  86. package/core/services/walletConnectionValidation.ts +293 -0
  87. package/core/services/walletServiceConfig.ts +31 -20
  88. package/core/storage/StorageExpoSQLite.ts +420 -87
  89. package/core/storage/dbImage.ts +48 -0
  90. package/core/storage/methods/findSql.ts +3 -54
  91. package/core/storage/methods/listActionsSql.ts +8 -5
  92. package/core/storage/methods/listOutputsSql.ts +9 -5
  93. package/core/storage/methods/offlineActions.ts +15 -0
  94. package/core/storage/methods/processOfflineActions.ts +265 -9
  95. package/core/storage/methods/reviewStatusSql.ts +7 -2
  96. package/core/storage/methods/walletBalanceSql.ts +16 -4
  97. package/core/storage/schema/createTables.ts +152 -0
  98. package/core/storage/sqlUpdateValue.ts +24 -0
  99. package/core/toolboxConfig.ts +182 -1
  100. package/core/toolboxTypes.ts +40 -0
  101. package/core/userAvatar.ts +79 -0
  102. package/core/walletMonitor.ts +8 -3
  103. package/core/walletRepair/runWalletCheck.ts +19 -2
  104. package/package.json +31 -30
  105. package/ui/activityFilter.ts +115 -0
  106. package/ui/components/QRScanner.tsx +1 -1
  107. package/ui/components/pay/AdmissionNotice.tsx +99 -0
  108. package/ui/components/pay/AssetPicker.tsx +184 -0
  109. package/ui/components/pay/AvailableBalance.tsx +33 -2
  110. package/ui/components/pay/HandleReceive.tsx +213 -50
  111. package/ui/components/pay/NearbyFlow.tsx +616 -69
  112. package/ui/components/pay/PayForm.tsx +73 -8
  113. package/ui/components/pay/PaymentSuccessOverlay.tsx +89 -8
  114. package/ui/components/pay/RecipientField.tsx +132 -73
  115. package/ui/components/pay/RequestHub.tsx +68 -8
  116. package/ui/components/pay/ResultBanner.tsx +41 -4
  117. package/ui/components/pay/StepBar.tsx +32 -0
  118. package/ui/components/pay/UniversalSend.tsx +1118 -86
  119. package/ui/components/pay/tokenSendCopy.ts +116 -0
  120. package/ui/components/pay/useRecipientInput.ts +36 -7
  121. package/ui/components/ui/PencilEditField.tsx +109 -0
  122. package/ui/components/ui/PermissionSheet.tsx +65 -4
  123. package/ui/components/ui/Sheet.tsx +9 -2
  124. package/ui/components/ui/SlideOverFromRight.tsx +86 -0
  125. package/ui/components/vault/EnrollWizard.tsx +1432 -488
  126. package/ui/components/vault/KeyChooser.tsx +96 -0
  127. package/ui/components/vault/VaultCeremonySheet.tsx +107 -43
  128. package/ui/components/vault/vaultErrorCopy.ts +145 -0
  129. package/ui/components/wallet/ActivityRow.tsx +283 -97
  130. package/ui/components/wallet/AmountInput.tsx +92 -28
  131. package/ui/components/wallet/AssetAmount.tsx +95 -0
  132. package/ui/components/wallet/AssetSwitcherDropdown.tsx +261 -0
  133. package/ui/components/wallet/ContactActivityList.tsx +149 -0
  134. package/ui/components/wallet/ContactSigil.tsx +49 -0
  135. package/ui/components/wallet/EditPictureSheet.tsx +99 -0
  136. package/ui/components/wallet/FitAmount.tsx +148 -0
  137. package/ui/components/wallet/IconPickerSheet.tsx +168 -0
  138. package/ui/components/wallet/IdentifierRow.tsx +69 -0
  139. package/ui/components/wallet/ImportFromBackupPrompt.tsx +35 -13
  140. package/ui/components/wallet/ProfileButton.tsx +62 -0
  141. package/ui/components/wallet/UserAvatar.tsx +85 -0
  142. package/ui/components/wallet/avatarIcons.ts +122 -0
  143. package/ui/components/wallet/tokenEviction.ts +65 -0
  144. package/ui/hooks/useContactsStore.ts +10 -0
  145. package/ui/hooks/useExportWalletData.ts +39 -0
  146. package/ui/hooks/useMandala.ts +320 -0
  147. package/ui/hooks/useOnline.ts +65 -20
  148. package/ui/hooks/useVaultBalance.ts +105 -7
  149. package/ui/hooks/useVaultCoverage.ts +52 -0
  150. package/ui/importDatabases.ts +7 -3
  151. package/ui/index.ts +75 -7
  152. package/ui/screens/ConnectionsScreen.tsx +46 -29
  153. package/ui/screens/ContactScreen.tsx +289 -0
  154. package/ui/screens/ContactsScreen.tsx +373 -0
  155. package/ui/screens/IdentifierScreen.tsx +234 -0
  156. package/ui/screens/NewContactScreen.tsx +362 -0
  157. package/ui/screens/PairScreen.tsx +12 -12
  158. package/ui/screens/PayScreen.tsx +145 -12
  159. package/ui/screens/ProfileScreen.tsx +783 -0
  160. package/ui/screens/SettingsScreen.tsx +18 -9
  161. package/ui/screens/TransactionDetailScreen.tsx +419 -0
  162. package/ui/screens/TrustScreen.tsx +1 -1
  163. package/ui/screens/VaultScreen.tsx +925 -171
  164. package/ui/screens/VaultTransferScreen.tsx +376 -123
  165. package/ui/screens/WalletCheckScreen.tsx +10 -1
  166. package/ui/screens/WalletConfigScreen.tsx +80 -16
  167. package/ui/screens/WalletHomeScreen.tsx +915 -139
  168. package/ui/screens/homeBadges.ts +9 -1
  169. package/ui/screens/tokenRowTitle.ts +68 -0
  170. package/ui/tokenFormat.ts +108 -0
  171. package/ui/tokenSeen.ts +75 -0
  172. package/ui/tokenStatus.ts +100 -0
  173. package/ui/txStatus.ts +43 -5
  174. package/assets/sounds/vault-close.wav +0 -0
  175. package/assets/sounds/vault-open.wav +0 -0
  176. package/core/services/vault/k1.ts +0 -75
  177. package/core/services/vault/sealing.ts +0 -84
  178. package/core/services/vault/vaultDerivation.ts +0 -152
  179. package/core/services/vault/vaultPassphrase.ts +0 -287
  180. package/ui/components/vault/PassphraseField.tsx +0 -306
  181. package/ui/components/vault/PhraseBackupSheet.tsx +0 -227
  182. package/ui/screens/VaultRecoverScreen.tsx +0 -226
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.7.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",
@@ -29,53 +29,54 @@
29
29
  "CHANGELOG.md"
30
30
  ],
31
31
  "peerDependencies": {
32
- "@bsv/air-gap": "^0.1.1",
32
+ "@bsv/air-gap": "^0.1.3",
33
33
  "@bsv/backup-cache-client": "^0.1.0",
34
- "@bsv/btms-permission-module": "^1.1.0",
35
- "@bsv/message-box-client": "^2.2.1",
34
+ "@bsv/btms-permission-module": "^1.2.1",
35
+ "@bsv/mandala": "^0.2.0",
36
+ "@bsv/message-box-client": "^2.5.3",
36
37
  "@bsv/react-native-localpay-transport": "*",
37
- "@bsv/sdk": "^2.4.1",
38
- "@bsv/templates": "^1.10.0",
39
- "@bsv/wallet-toolbox-mobile": "^2.4.3",
38
+ "@bsv/sdk": "^2.8.2",
39
+ "@bsv/templates": "^1.10.3",
40
+ "@bsv/wallet-toolbox-mobile": "^2.14.0",
40
41
  "@expo/vector-icons": "^15.0.3",
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",
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Narrowing the activity list: by the word a row says (Sent, Received, Spent,
3
+ * Transferred) and by a search over what the row shows plus who it was with.
4
+ *
5
+ * The search only ever reads what this device already holds: the row's own
6
+ * title (the sender's note, or the name recorded when the payment was made)
7
+ * and, when the counterparty is a saved contact, that contact's name and
8
+ * handle. It never asks the network who a key belongs to.
9
+ *
10
+ * Every typed word has to appear somewhere, in any order, ignoring case and
11
+ * accents. That is "fuzzy" in the forgiving sense, not a ranked or
12
+ * typo-tolerant one: a row either says what was typed or it does not.
13
+ */
14
+ import { counterpartyOf } from '../core/pay/counterparty'
15
+ import type { ContactRow } from '../core/contacts/contactsStore'
16
+ import type { ActivityAction } from './components/wallet/ActivityRow'
17
+ import { activityKind, type ActivityKind } from './txStatus'
18
+
19
+ export type ActivityKindFilter = 'all' | ActivityKind
20
+
21
+ /** The chips, in the order they are drawn. */
22
+ export const ACTIVITY_KIND_FILTERS: readonly ActivityKindFilter[] = ['all', 'sent', 'received', 'spent', 'transferred']
23
+
24
+ /** A chip names its kind with the row's own status key, so the two always read the same word. */
25
+ export function kindFilterLabelKey(kind: ActivityKindFilter): string {
26
+ return kind === 'all' ? 'activity_filter_all' : `tx_status_${kind}`
27
+ }
28
+
29
+ export interface ActivityFilter {
30
+ kind: ActivityKindFilter
31
+ /** Already normalised by `searchTerms`. */
32
+ terms: readonly string[]
33
+ }
34
+
35
+ export function isActivityFilterActive(filter: ActivityFilter): boolean {
36
+ return filter.kind !== 'all' || filter.terms.length > 0
37
+ }
38
+
39
+ /** Only the Latin combining marks: Indic vowel signs are letters, not accents. */
40
+ const COMBINING_DIACRITICS = /[̀-ͯ]/g
41
+
42
+ function normalise(text: string): string {
43
+ let folded = text
44
+ try {
45
+ folded = text.normalize('NFKD').replace(COMBINING_DIACRITICS, '')
46
+ } catch {
47
+ // An engine without normalisation still gets a case-insensitive search.
48
+ }
49
+ return folded.toLowerCase()
50
+ }
51
+
52
+ /**
53
+ * The words to look for. A leading `@` is dropped because handles are stored
54
+ * without one; an `@` further in (a paymail) is part of what was typed.
55
+ */
56
+ export function searchTerms(query: string): string[] {
57
+ return normalise(query)
58
+ .split(/\s+/)
59
+ .map(word => word.replace(/^@+/, ''))
60
+ .filter(word => word.length > 0)
61
+ }
62
+
63
+ export interface ContactNames {
64
+ name: string
65
+ cachedHandle?: string
66
+ }
67
+
68
+ /** Contacts keyed by lower-cased identity key: the wallet lower-cases every label it stores. */
69
+ export function contactNamesByKey(
70
+ contacts: readonly Pick<ContactRow, 'identityKey' | 'name' | 'cachedHandle'>[]
71
+ ): Map<string, ContactNames> {
72
+ return new Map(contacts.map(c => [c.identityKey.toLowerCase(), { name: c.name, cachedHandle: c.cachedHandle }]))
73
+ }
74
+
75
+ /** The part of a token row this cares about: see `ActivityRow`'s `token` prop. */
76
+ export interface ActivityRowToken {
77
+ title: string
78
+ incoming: boolean
79
+ counterpartyKey?: string
80
+ }
81
+
82
+ /**
83
+ * Whether a row survives the filter.
84
+ *
85
+ * `token` is the row's token half when it has one, exactly as the list draws
86
+ * it: a token row is read by its own title and direction, never by the wallet
87
+ * action underneath (whose description is a library string carrying a raw
88
+ * token id, and whose satoshis are the BSV the transfer cost).
89
+ */
90
+ export function matchesActivity(
91
+ action: ActivityAction,
92
+ token: ActivityRowToken | undefined,
93
+ filter: ActivityFilter,
94
+ contacts: ReadonlyMap<string, ContactNames>
95
+ ): boolean {
96
+ if (filter.kind !== 'all') {
97
+ // Same direction rule the row itself uses to pick its word.
98
+ const incoming = token ? token.incoming : action.satoshis >= 0
99
+ if (activityKind(incoming, action.labels) !== filter.kind) return false
100
+ }
101
+ if (filter.terms.length === 0) return true
102
+
103
+ const counterpartyKey = token
104
+ ? token.counterpartyKey
105
+ : (() => {
106
+ const cp = counterpartyOf(action)
107
+ return cp?.kind === 'identityKey' ? cp.value : undefined
108
+ })()
109
+ const contact = counterpartyKey ? contacts.get(counterpartyKey.toLowerCase()) : undefined
110
+ // One field per line, so no word can match across the seam of two fields.
111
+ const haystack = normalise(
112
+ [token ? token.title : action.description, contact?.name, contact?.cachedHandle].filter(Boolean).join('\n')
113
+ )
114
+ return filter.terms.every(term => haystack.includes(term))
115
+ }
@@ -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
  })