@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
@@ -1,306 +0,0 @@
1
- /**
2
- * Vault passphrase entry with a live strength meter.
3
- *
4
- * Two things this component exists to prevent:
5
- *
6
- * 1. A weak passphrase. The vault key comes from the wallet mnemonic plus this
7
- * passphrase via BIP39 PBKDF2 at 2048 rounds, so anyone holding the
8
- * mnemonic can grind a typeable password in hours. The meter shows the
9
- * honest crack time rather than a vague "weak/strong" badge.
10
- *
11
- * 2. A typo. BIP39 passphrases carry no checksum, so a mistyped passphrase
12
- * silently opens a different, valid, EMPTY vault. Hence the confirm field.
13
- *
14
- * Colour discipline: chroma here is STATUS (the meter), never an action. The
15
- * primary action keeps the achromatic accent fill, per the app's token pairing.
16
- */
17
- import React, { useMemo, useState } from 'react'
18
- import { View, Text, TextInput, StyleSheet, Pressable } from 'react-native'
19
- import PressableScale from '../ui/PressableScale'
20
- import { showToast } from '../ui/Toast'
21
- import {
22
- useTheme,
23
- spacing,
24
- radii,
25
- typography,
26
- passphraseStrength,
27
- generatePassphrase,
28
- normalizeVaultPassphrase,
29
- MINIMUM_WORD_COUNT,
30
- RECOMMENDED_WORD_COUNT,
31
- type PassphraseTier
32
- } from '@bsv/expo-wallet-toolbox'
33
-
34
- /**
35
- * @expo/vector-icons' index barrel re-exports every icon set (AntDesign,
36
- * etc.), one of which reaches expo-font -> expo-asset -- untransformed ESM
37
- * that Jest cannot parse when eagerly pulled in via the `ui` package barrel.
38
- * Ionicons is loaded lazily, only when actually rendering, same pattern as
39
- * this package's other native-module-boundary fixes (expo-router, expo-blur).
40
- */
41
- type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
42
- let ioniconsComponent: IoniconsComponent | undefined
43
- function loadIonicons(): IoniconsComponent {
44
- if (!ioniconsComponent) {
45
- // eslint-disable-next-line @typescript-eslint/no-require-imports
46
- ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
47
- }
48
- return ioniconsComponent
49
- }
50
-
51
- /**
52
- * expo-clipboard ships an untransformed ESM build (its Clipboard.js imports
53
- * from expo-modules-core with a bare `import` statement) that Jest cannot
54
- * parse when eagerly pulled in via the `ui` package barrel. Required lazily,
55
- * only when a handler actually copies something, same pattern as this
56
- * package's other native-module-boundary fixes (@react-native-clipboard,
57
- * expo-router, expo-blur).
58
- */
59
- type ExpoClipboardModule = typeof import('expo-clipboard')
60
- let expoClipboardModule: ExpoClipboardModule | undefined
61
- function loadExpoClipboard(): ExpoClipboardModule {
62
- if (!expoClipboardModule) {
63
- // eslint-disable-next-line @typescript-eslint/no-require-imports
64
- expoClipboardModule = require('expo-clipboard') as ExpoClipboardModule
65
- }
66
- return expoClipboardModule
67
- }
68
-
69
- export interface PassphraseFieldProps {
70
- value: string
71
- onChangeText: (v: string) => void
72
- confirm: string
73
- onChangeConfirm: (v: string) => void
74
- /** Called with the normalised passphrase whenever validity changes. */
75
- onValidityChange?: (ok: boolean) => void
76
- }
77
-
78
- /** Meter colour by tier. Status chroma only — never used for actions. */
79
- function tierColor(tier: PassphraseTier, colors: Record<string, string>): string {
80
- switch (tier) {
81
- case 'empty':
82
- return colors.separator
83
- case 'weak':
84
- return colors.error
85
- case 'fair':
86
- return colors.warning
87
- default:
88
- return colors.success
89
- }
90
- }
91
-
92
- const TIER_LABEL: Record<PassphraseTier, string> = {
93
- empty: '',
94
- weak: 'Too weak',
95
- fair: 'Still too weak',
96
- strong: 'Strong',
97
- excellent: 'Excellent'
98
- }
99
-
100
- export function PassphraseField({
101
- value,
102
- onChangeText,
103
- confirm,
104
- onChangeConfirm,
105
- onValidityChange
106
- }: PassphraseFieldProps) {
107
- const { colors } = useTheme()
108
- const [reveal, setReveal] = useState(false)
109
- const Ionicons = loadIonicons()
110
-
111
- const strength = useMemo(() => passphraseStrength(value), [value])
112
- // Compare normalised, so a stray trailing space is not reported as a
113
- // mismatch when BIP39 would treat both the same after our normalisation.
114
- const confirmed =
115
- confirm.length > 0 && normalizeVaultPassphrase(confirm) === normalizeVaultPassphrase(value)
116
- const mismatch = confirm.length > 0 && !confirmed
117
- const ok = strength.ok && confirmed
118
-
119
- React.useEffect(() => {
120
- onValidityChange?.(ok)
121
- }, [ok, onValidityChange])
122
-
123
- const onGenerate = () => {
124
- const generated = generatePassphrase()
125
- onChangeText(generated)
126
- onChangeConfirm(generated)
127
- setReveal(true) // they must be able to read what they now have to keep
128
- }
129
-
130
- const onCopy = async () => {
131
- await loadExpoClipboard().setStringAsync(value)
132
- showToast('Passphrase copied', { type: 'info' })
133
- }
134
-
135
- const meterColor = tierColor(strength.tier, colors as unknown as Record<string, string>)
136
-
137
- return (
138
- <View style={styles.wrap}>
139
- {/* ── passphrase ─────────────────────────────────────────────── */}
140
- <View
141
- style={[
142
- styles.field,
143
- { backgroundColor: colors.backgroundElevated, borderColor: colors.separator }
144
- ]}
145
- >
146
- <TextInput
147
- value={value}
148
- onChangeText={onChangeText}
149
- secureTextEntry={!reveal}
150
- autoCapitalize="none"
151
- autoCorrect={false}
152
- spellCheck={false}
153
- // A password manager offering to save this is fine, but iOS strong-
154
- // password suggestions would propose a short random string, which is
155
- // exactly the wrong shape for a 2048-round KDF.
156
- textContentType="none"
157
- style={[styles.input, { color: colors.textPrimary }]}
158
- accessibilityLabel="Vault passphrase"
159
- />
160
- {value.length === 0 && (
161
- <Text
162
- pointerEvents="none"
163
- style={[styles.placeholder, { color: colors.textTertiary }]}
164
- >{`${MINIMUM_WORD_COUNT} or more random words`}</Text>
165
- )}
166
- <Pressable
167
- onPress={() => setReveal(r => !r)}
168
- hitSlop={8}
169
- accessibilityRole="button"
170
- accessibilityLabel={reveal ? 'Hide passphrase' : 'Show passphrase'}
171
- >
172
- <Ionicons name={reveal ? 'eye-off' : 'eye'} size={20} color={colors.textSecondary} />
173
- </Pressable>
174
- </View>
175
-
176
- {/* ── strength meter ─────────────────────────────────────────── */}
177
- <View style={styles.meterBlock}>
178
- <View style={[styles.meterTrack, { backgroundColor: colors.separator }]}>
179
- <View
180
- style={[
181
- styles.meterFill,
182
- { width: `${Math.round(strength.fraction * 100)}%`, backgroundColor: meterColor }
183
- ]}
184
- />
185
- </View>
186
- <View style={styles.meterRow}>
187
- <Text style={[styles.tier, { color: meterColor }]}>{TIER_LABEL[strength.tier]}</Text>
188
- {value.length > 0 && (
189
- <Text style={[styles.crack, { color: colors.textSecondary }]} numberOfLines={1}>
190
- Cracked in {strength.crackTime}
191
- </Text>
192
- )}
193
- </View>
194
- {value.length > 0 && !strength.ok && strength.reason && (
195
- <Text style={[styles.hint, { color: colors.textSecondary }]}>{strength.reason}</Text>
196
- )}
197
- </View>
198
-
199
- {/* ── generate ───────────────────────────────────────────────── */}
200
- <View style={styles.genRow}>
201
- <PressableScale
202
- haptic="confirm"
203
- onPress={onGenerate}
204
- style={[styles.ghost, { borderColor: colors.separator }]}
205
- >
206
- <Ionicons name="dice-outline" size={16} color={colors.info} />
207
- <Text style={[styles.ghostLabel, { color: colors.info }]}>
208
- Generate {RECOMMENDED_WORD_COUNT} random words
209
- </Text>
210
- </PressableScale>
211
- {value.length > 0 && (
212
- <PressableScale
213
- onPress={onCopy}
214
- style={[styles.ghost, { borderColor: colors.separator }]}
215
- >
216
- <Ionicons name="copy-outline" size={16} color={colors.info} />
217
- <Text style={[styles.ghostLabel, { color: colors.info }]}>Copy</Text>
218
- </PressableScale>
219
- )}
220
- </View>
221
-
222
- {/* ── confirm ────────────────────────────────────────────────── */}
223
- <View
224
- style={[
225
- styles.field,
226
- {
227
- backgroundColor: colors.backgroundElevated,
228
- borderColor: mismatch ? colors.error : colors.separator
229
- }
230
- ]}
231
- >
232
- <TextInput
233
- value={confirm}
234
- onChangeText={onChangeConfirm}
235
- secureTextEntry={!reveal}
236
- autoCapitalize="none"
237
- autoCorrect={false}
238
- spellCheck={false}
239
- textContentType="none"
240
- style={[styles.input, { color: colors.textPrimary }]}
241
- accessibilityLabel="Confirm vault passphrase"
242
- />
243
- {confirm.length === 0 && (
244
- <Text pointerEvents="none" style={[styles.placeholder, { color: colors.textTertiary }]}>
245
- Type it again
246
- </Text>
247
- )}
248
- {confirm.length > 0 && (
249
- <Ionicons
250
- name={confirmed ? 'checkmark-circle' : 'close-circle'}
251
- size={20}
252
- color={confirmed ? colors.success : colors.error}
253
- />
254
- )}
255
- </View>
256
- {mismatch && (
257
- <Text style={[styles.hint, { color: colors.error }]}>
258
- These do not match. A mistyped passphrase opens a different, empty vault — there is no way
259
- to detect it later.
260
- </Text>
261
- )}
262
- </View>
263
- )
264
- }
265
-
266
- const styles = StyleSheet.create({
267
- wrap: { gap: spacing.md },
268
- field: {
269
- flexDirection: 'row',
270
- alignItems: 'center',
271
- gap: spacing.sm,
272
- borderRadius: radii.md,
273
- borderWidth: StyleSheet.hairlineWidth,
274
- paddingHorizontal: spacing.lg,
275
- paddingVertical: spacing.md
276
- },
277
- input: { flex: 1, ...typography.body },
278
- // Sits exactly where the input's own text starts, so swapping between them
279
- // as the user types does not shift anything.
280
- placeholder: {
281
- ...typography.body,
282
- position: 'absolute',
283
- left: spacing.lg,
284
- right: spacing.lg
285
- },
286
- meterBlock: { gap: spacing.xs },
287
- meterTrack: { height: 4, borderRadius: 2, overflow: 'hidden' },
288
- meterFill: { height: 4, borderRadius: 2 },
289
- meterRow: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center' },
290
- tier: { ...typography.footnote, fontWeight: '600' },
291
- crack: { ...typography.footnote, flexShrink: 1 },
292
- hint: { ...typography.footnote },
293
- genRow: { flexDirection: 'row', gap: spacing.sm },
294
- ghost: {
295
- flexDirection: 'row',
296
- alignItems: 'center',
297
- gap: spacing.xs,
298
- borderRadius: radii.md,
299
- borderWidth: StyleSheet.hairlineWidth,
300
- paddingHorizontal: spacing.md,
301
- paddingVertical: spacing.sm
302
- },
303
- ghostLabel: { ...typography.footnote, fontWeight: '600' }
304
- })
305
-
306
- export default PassphraseField
@@ -1,227 +0,0 @@
1
- /**
2
- * Reveals the recovery phrase and takes the user's word that they wrote it
3
- * down.
4
- *
5
- * No verification quiz by design: the person needs to be held accountable, but
6
- * verification should not be painful. The confirm is an attestation, and the
7
- * caller records it as such.
8
- *
9
- * The caller is responsible for reading the mnemonic out of secure storage —
10
- * getMnemonic() is already behind the biometric latch, so this component never
11
- * touches storage and never holds the phrase beyond its own mount.
12
- */
13
- import React, { useState } from 'react'
14
- import { View, Text, StyleSheet, ScrollView } from 'react-native'
15
- import { useTheme, spacing, radii, typography, i18n } from '@bsv/expo-wallet-toolbox'
16
- import PressableScale from '../ui/PressableScale'
17
- import { showToast } from '../ui/Toast'
18
-
19
- const t = (k: string, o?: Record<string, unknown>) => i18n.t(k, o) as string
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
- /**
39
- * @react-native-clipboard/clipboard reaches for its native TurboModule at
40
- * import time (`TurboModuleRegistry.getEnforcing`), which throws under Jest
41
- * (no native binary registered there) even though the module itself
42
- * transforms fine. Required lazily, only when a handler actually copies
43
- * something, so importing the `ui` barrel never touches the native module.
44
- * Same pattern as WalletHomeScreen.tsx's lazy clipboard load.
45
- */
46
- type ClipboardModule = typeof import('@react-native-clipboard/clipboard').default
47
- let clipboardModule: ClipboardModule | undefined
48
- function loadClipboard(): ClipboardModule {
49
- if (!clipboardModule) {
50
- // eslint-disable-next-line @typescript-eslint/no-require-imports
51
- clipboardModule = require('@react-native-clipboard/clipboard').default as ClipboardModule
52
- }
53
- return clipboardModule
54
- }
55
-
56
- export const PhraseBackupSheet: React.FC<{
57
- mnemonic: string
58
- onAttest: () => void
59
- onCancel: () => void
60
- }> = ({ mnemonic, onAttest, onCancel }) => {
61
- const { colors } = useTheme()
62
- const [acknowledged, setAcknowledged] = useState(false)
63
- const words = mnemonic.trim().split(/\s+/)
64
- const Ionicons = loadIonicons()
65
-
66
- return (
67
- <ScrollView contentContainerStyle={styles.body}>
68
- <Text style={[styles.p, { color: colors.textSecondary }]}>
69
- {t('vault_phrase_intro', { count: words.length })}
70
- </Text>
71
-
72
- {/* Two fixed columns with the index in its own right-aligned gutter, so
73
- every word starts on the same x. The old grid let each cell size to
74
- its own content, which put the words on a ragged left edge and made a
75
- list you have to hunt through rather than one you can read down.
76
- Inverted (warning-tinted fill, high-contrast text) rather than the
77
- page's ordinary card styling — this is the one block of content the
78
- user actually has to act on (copy to paper), so it needs to read as
79
- distinct from the surrounding chrome, not blend into it. */}
80
- <View style={[styles.grid, { backgroundColor: colors.warning, borderColor: colors.warning }]}>
81
- {words.map((word, i) => (
82
- <View key={i} style={styles.wordCell}>
83
- <Text style={[styles.wordIndex, { color: colors.textOnAccent, opacity: 0.6 }]}>{i + 1}</Text>
84
- <Text style={[styles.word, { color: colors.textOnAccent }]}>{word}</Text>
85
- </View>
86
- ))}
87
- </View>
88
-
89
- {/* Copy is deliberately the quietest control on the screen. The screen is
90
- asking for pen and paper; a full-width button offering the clipboard
91
- instead argues against its own instruction. */}
92
- <PressableScale
93
- onPress={() => {
94
- loadClipboard().setString(mnemonic)
95
- showToast(t('vault_phrase_copied'), { type: 'success' })
96
- }}
97
- style={styles.copyRow}
98
- >
99
- <Ionicons name="copy-outline" size={15} color={colors.textSecondary} />
100
- <Text style={[styles.copyLabel, { color: colors.textSecondary }]}>{t('vault_phrase_copy')}</Text>
101
- </PressableScale>
102
-
103
- {/* Tinted rather than outlined: the border box read as an error state on
104
- a screen where nothing has gone wrong. */}
105
- <View style={[styles.warnBox, { backgroundColor: colors.warning + '14' }]}>
106
- <Ionicons name="warning-outline" size={16} color={colors.warning} />
107
- <Text style={[styles.warnText, { color: colors.textSecondary }]}>
108
- {t('vault_phrase_warning')}
109
- </Text>
110
- </View>
111
-
112
- <PressableScale
113
- onPress={() => setAcknowledged(a => !a)}
114
- style={[
115
- styles.checkRow,
116
- {
117
- // colors.fill, not `colors.accent + '14'`: accent is the NAMED colour
118
- // 'white' (dark) / 'black' (light), so appending hex alpha produced
119
- // "white14" and Reanimated threw on the animated style. fill is the
120
- // theme's own translucent overlay and is valid in both themes.
121
- backgroundColor: acknowledged ? colors.fill : colors.backgroundSecondary,
122
- borderColor: acknowledged ? colors.accent : colors.separator
123
- }
124
- ]}
125
- >
126
- <Ionicons
127
- name={acknowledged ? 'checkmark-circle' : 'ellipse-outline'}
128
- size={22}
129
- color={acknowledged ? colors.accent : colors.textTertiary}
130
- />
131
- <Text style={[styles.checkLabel, { color: colors.textPrimary }]}>
132
- {t('vault_phrase_attest')}
133
- </Text>
134
- </PressableScale>
135
-
136
- <PressableScale
137
- haptic="confirm"
138
- onPress={acknowledged ? onAttest : undefined}
139
- style={[
140
- styles.primary,
141
- // Outlined until the box is ticked, matching the enrolment gate: a
142
- // disabled fill in the secondary background is invisible in dark mode.
143
- {
144
- backgroundColor: acknowledged ? colors.accent : 'transparent',
145
- borderWidth: acknowledged ? 0 : StyleSheet.hairlineWidth,
146
- borderColor: colors.separator
147
- }
148
- ]}
149
- >
150
- <Text
151
- style={[
152
- styles.primaryLabel,
153
- { color: acknowledged ? colors.textOnAccent : colors.textTertiary }
154
- ]}
155
- >
156
- {t('vault_phrase_done')}
157
- </Text>
158
- </PressableScale>
159
-
160
- <PressableScale onPress={onCancel} style={styles.secondary}>
161
- <Text style={[styles.secondaryLabel, { color: colors.textSecondary }]}>
162
- {t('vault_back')}
163
- </Text>
164
- </PressableScale>
165
- </ScrollView>
166
- )
167
- }
168
-
169
- const styles = StyleSheet.create({
170
- body: { padding: spacing.xl, gap: spacing.lg },
171
- p: { ...typography.subhead, textAlign: 'center' },
172
- grid: {
173
- flexDirection: 'row',
174
- flexWrap: 'wrap',
175
- rowGap: spacing.md,
176
- borderRadius: radii.md,
177
- borderWidth: StyleSheet.hairlineWidth,
178
- paddingVertical: spacing.lg,
179
- paddingHorizontal: spacing.md
180
- },
181
- wordCell: {
182
- width: '50%',
183
- flexDirection: 'row',
184
- alignItems: 'baseline',
185
- gap: spacing.sm,
186
- paddingHorizontal: spacing.sm
187
- },
188
- // Fixed gutter, right-aligned: 1 and 12 then occupy the same width and the
189
- // words line up in two clean columns.
190
- wordIndex: { ...typography.caption2, width: 20, textAlign: 'right' },
191
- word: { ...typography.body, fontWeight: '600' },
192
- copyRow: {
193
- flexDirection: 'row',
194
- alignItems: 'center',
195
- alignSelf: 'center',
196
- gap: spacing.xs,
197
- paddingVertical: spacing.xs,
198
- paddingHorizontal: spacing.sm
199
- },
200
- copyLabel: { ...typography.footnote },
201
- warnBox: {
202
- flexDirection: 'row',
203
- gap: spacing.sm,
204
- alignItems: 'flex-start',
205
- borderRadius: radii.md,
206
- padding: spacing.md
207
- },
208
- warnText: { ...typography.footnote, flex: 1 },
209
- checkRow: {
210
- flexDirection: 'row',
211
- alignItems: 'center',
212
- gap: spacing.md,
213
- borderRadius: radii.md,
214
- borderWidth: StyleSheet.hairlineWidth,
215
- padding: spacing.lg
216
- },
217
- checkLabel: { ...typography.subhead, flex: 1 },
218
- primary: {
219
- width: '100%',
220
- borderRadius: radii.md,
221
- paddingVertical: spacing.lg,
222
- alignItems: 'center'
223
- },
224
- primaryLabel: { ...typography.headline },
225
- secondary: { paddingVertical: spacing.md, alignItems: 'center' },
226
- secondaryLabel: { ...typography.body }
227
- })