@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
@@ -0,0 +1,373 @@
1
+ /**
2
+ * Contacts — your saved counterparties in a grouped card, a second "Other
3
+ * people" card of network search hits once you type, a scanner for someone's
4
+ * profile code (header, top right) and a New Contact button at the bottom.
5
+ * Reached from the bottom of Pay step "who" (never from Home); back returns
6
+ * there.
7
+ */
8
+ import React, { useCallback, useEffect, useRef, useState } from 'react'
9
+ import {
10
+ ActivityIndicator,
11
+ I18nManager,
12
+ Modal,
13
+ ScrollView,
14
+ StyleSheet,
15
+ Text,
16
+ TextInput,
17
+ TouchableOpacity,
18
+ View
19
+ } from 'react-native'
20
+ import { useSafeAreaInsets } from 'react-native-safe-area-context'
21
+ import { useTranslation } from 'react-i18next'
22
+ import type { DisplayableIdentity } from '@bsv/sdk'
23
+ import { useTheme, spacing, radii, typography, useWallet } from '@bsv/expo-wallet-toolbox'
24
+ import QRScanner from '../components/QRScanner'
25
+ import PressableScale from '../components/ui/PressableScale'
26
+ import { GroupedSection } from '../components/ui/GroupedList'
27
+ import ContactSigil from '../components/wallet/ContactSigil'
28
+ import { useContactsStore } from '../hooks/useContactsStore'
29
+ import { makeIdentityClient, searchIdentities } from '../resolveIdentity'
30
+ import { parseIdentityKeyFromScan } from '../../core/identity/contactLink'
31
+ import { abbreviateKey } from '../../core/pay/counterparty'
32
+ import type { ContactRow } from '../../core/contacts/contactsStore'
33
+
34
+ type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
35
+ let ioniconsComponent: IoniconsComponent | undefined
36
+ function loadIonicons(): IoniconsComponent {
37
+ if (!ioniconsComponent) {
38
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
39
+ ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
40
+ }
41
+ return ioniconsComponent
42
+ }
43
+
44
+ type ExpoRouterModule = typeof import('expo-router')
45
+ let expoRouterMod: ExpoRouterModule | undefined
46
+ function loadExpoRouter(): ExpoRouterModule {
47
+ if (!expoRouterMod) {
48
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
49
+ expoRouterMod = require('expo-router') as ExpoRouterModule
50
+ }
51
+ return expoRouterMod
52
+ }
53
+
54
+ /** Same debounce as Pay's recipient search; the overlay is not free. */
55
+ const SEARCH_DEBOUNCE_MS = 400
56
+ const SEARCH_MIN_CHARS = 2
57
+
58
+ export function ContactsScreen() {
59
+ const { t } = useTranslation()
60
+ const { colors } = useTheme()
61
+ const insets = useSafeAreaInsets()
62
+ const Ionicons = loadIonicons()
63
+ const { router } = loadExpoRouter()
64
+ const { walletUserId, managers, adminOriginator } = useWallet()
65
+ const store = useContactsStore()
66
+
67
+ const [query, setQuery] = useState('')
68
+ const [rows, setRows] = useState<ContactRow[]>([])
69
+ const [scannerVisible, setScannerVisible] = useState(false)
70
+ const [networkHits, setNetworkHits] = useState<DisplayableIdentity[]>([])
71
+ const [searching, setSearching] = useState(false)
72
+
73
+ const reload = useCallback(async () => {
74
+ if (!store || walletUserId === null) return
75
+ setRows(await store.searchContacts(walletUserId, query))
76
+ }, [store, walletUserId, query])
77
+
78
+ useEffect(() => {
79
+ void reload()
80
+ }, [reload])
81
+
82
+ // The network tier: people you have not saved, found by name on the
83
+ // identity overlay. Decorative relative to the local list — a client that
84
+ // will not build, or a lookup that throws, simply leaves the card out.
85
+ const searchTimer = useRef<ReturnType<typeof setTimeout> | null>(null)
86
+ useEffect(() => {
87
+ if (searchTimer.current) clearTimeout(searchTimer.current)
88
+ const text = query.trim()
89
+ if (text.length < SEARCH_MIN_CHARS) {
90
+ setNetworkHits([])
91
+ setSearching(false)
92
+ return
93
+ }
94
+ const idClient = makeIdentityClient(managers?.permissionsManager as never, adminOriginator)
95
+ if (!idClient) return
96
+ let cancelled = false
97
+ setSearching(true)
98
+ searchTimer.current = setTimeout(async () => {
99
+ try {
100
+ const hits = await searchIdentities(idClient, text)
101
+ if (!cancelled) setNetworkHits(hits)
102
+ } catch {
103
+ if (!cancelled) setNetworkHits([])
104
+ } finally {
105
+ if (!cancelled) setSearching(false)
106
+ }
107
+ }, SEARCH_DEBOUNCE_MS)
108
+ return () => {
109
+ cancelled = true
110
+ }
111
+ }, [query, managers, adminOriginator])
112
+
113
+ const savedKeys = new Set(rows.map(r => r.identityKey))
114
+ const otherPeople = networkHits.filter(h => !savedKeys.has(h.identityKey))
115
+
116
+ const onScan = useCallback(
117
+ (data: string) => {
118
+ const identityKey = parseIdentityKeyFromScan(data)
119
+ if (!identityKey) return
120
+ setScannerVisible(false)
121
+ router.push({ pathname: '/contact/add', params: { identityKey } } as never)
122
+ },
123
+ [router]
124
+ )
125
+
126
+ const openNew = useCallback(
127
+ (identity: DisplayableIdentity) => {
128
+ router.push({
129
+ pathname: '/contact/add',
130
+ params: { identityKey: identity.identityKey, name: identity.name ?? '', source: 'search' }
131
+ } as never)
132
+ },
133
+ [router]
134
+ )
135
+
136
+ const showEmpty = rows.length === 0 && otherPeople.length === 0 && !searching
137
+
138
+ return (
139
+ <View style={[styles.container, { backgroundColor: colors.background, paddingTop: insets.top }]}>
140
+ <View style={[styles.header, { borderBottomColor: colors.separator }]}>
141
+ <PressableScale
142
+ onPress={() => router.back()}
143
+ haptic="tap"
144
+ style={styles.headerBtn}
145
+ accessibilityRole="button"
146
+ accessibilityLabel={t('go_back')}
147
+ >
148
+ <Ionicons
149
+ name={I18nManager.isRTL ? 'chevron-forward' : 'chevron-back'}
150
+ size={24}
151
+ color={colors.textSecondary}
152
+ />
153
+ </PressableScale>
154
+ <Text style={[styles.headerTitle, { color: colors.textPrimary }]} numberOfLines={1}>
155
+ {t('contacts')}
156
+ </Text>
157
+ <PressableScale
158
+ onPress={() => setScannerVisible(true)}
159
+ haptic="tap"
160
+ style={styles.headerBtn}
161
+ accessibilityRole="button"
162
+ accessibilityLabel={t('contact_scan_hint')}
163
+ >
164
+ <Ionicons name="qr-code-outline" size={22} color={colors.textPrimary} />
165
+ </PressableScale>
166
+ </View>
167
+
168
+ <View style={styles.searchWrap}>
169
+ <View style={[styles.searchRow, { backgroundColor: colors.fillTertiary }]}>
170
+ <Ionicons name="search" size={16} color={colors.textSecondary} />
171
+ <TextInput
172
+ value={query}
173
+ onChangeText={setQuery}
174
+ placeholder={t('contacts_search_placeholder')}
175
+ placeholderTextColor={colors.textTertiary}
176
+ autoCapitalize="none"
177
+ autoCorrect={false}
178
+ returnKeyType="search"
179
+ style={[styles.searchInput, { color: colors.textPrimary }]}
180
+ />
181
+ {query.length > 0 && (
182
+ <TouchableOpacity
183
+ onPress={() => setQuery('')}
184
+ style={styles.clearBtn}
185
+ hitSlop={8}
186
+ accessibilityRole="button"
187
+ accessibilityLabel={t('cancel')}
188
+ >
189
+ <Ionicons name="close-circle" size={18} color={colors.textTertiary} />
190
+ </TouchableOpacity>
191
+ )}
192
+ </View>
193
+ </View>
194
+
195
+ {showEmpty ? (
196
+ <View style={styles.empty}>
197
+ <Ionicons name="people-outline" size={40} color={colors.textTertiary} />
198
+ <Text style={[styles.emptyTitle, { color: colors.textPrimary }]}>{t('contacts_empty_title')}</Text>
199
+ <Text style={[styles.emptyBody, { color: colors.textSecondary }]}>{t('contacts_empty_body')}</Text>
200
+ </View>
201
+ ) : (
202
+ <ScrollView style={styles.list} contentContainerStyle={styles.listContent} keyboardShouldPersistTaps="handled">
203
+ {rows.length > 0 && (
204
+ <GroupedSection header={t('contacts_your_contacts')}>
205
+ {rows.map((row, idx) => (
206
+ <PressableScale
207
+ key={row.identityKey}
208
+ onPress={() =>
209
+ router.push({ pathname: '/contact', params: { identityKey: row.identityKey } } as never)
210
+ }
211
+ scaleTo={0.98}
212
+ haptic="tap"
213
+ accessibilityRole="button"
214
+ >
215
+ <View
216
+ style={[
217
+ styles.row,
218
+ idx < rows.length - 1 && {
219
+ borderBottomWidth: StyleSheet.hairlineWidth,
220
+ borderBottomColor: colors.separator
221
+ }
222
+ ]}
223
+ >
224
+ <ContactSigil identityKey={row.identityKey} avatarUrl={row.cachedAvatarUrl} />
225
+ <View style={styles.rowText}>
226
+ <Text style={[styles.rowName, { color: colors.textPrimary }]} numberOfLines={1}>
227
+ {row.name}
228
+ </Text>
229
+ <Text style={[styles.rowSub, { color: colors.textSecondary }]} numberOfLines={1}>
230
+ {row.cachedHandle ? row.cachedHandle : t('contact_no_handle')}
231
+ </Text>
232
+ </View>
233
+ <Ionicons name="chevron-forward" size={18} color={colors.textQuaternary} />
234
+ </View>
235
+ </PressableScale>
236
+ ))}
237
+ </GroupedSection>
238
+ )}
239
+
240
+ {(otherPeople.length > 0 || searching) && (
241
+ <GroupedSection
242
+ header={t('contacts_other_people')}
243
+ footer={otherPeople.length > 0 ? t('contacts_network_footer') : undefined}
244
+ >
245
+ {otherPeople.map((hit, idx) => (
246
+ <PressableScale
247
+ key={hit.identityKey}
248
+ onPress={() => openNew(hit)}
249
+ scaleTo={0.98}
250
+ haptic="tap"
251
+ accessibilityRole="button"
252
+ >
253
+ <View
254
+ style={[
255
+ styles.row,
256
+ (idx < otherPeople.length - 1 || searching) && {
257
+ borderBottomWidth: StyleSheet.hairlineWidth,
258
+ borderBottomColor: colors.separator
259
+ }
260
+ ]}
261
+ >
262
+ <ContactSigil identityKey={hit.identityKey} avatarUrl={hit.avatarURL || undefined} />
263
+ <View style={styles.rowText}>
264
+ <Text style={[styles.rowName, { color: colors.textPrimary }]} numberOfLines={1}>
265
+ {hit.name || t('unknown')}
266
+ </Text>
267
+ <Text style={[styles.rowSub, styles.mono, { color: colors.textSecondary }]} numberOfLines={1}>
268
+ {hit.abbreviatedKey || abbreviateKey(hit.identityKey)}
269
+ </Text>
270
+ </View>
271
+ <View style={[styles.badge, { backgroundColor: colors.fill }]}>
272
+ <Text style={[styles.badgeText, { color: colors.textPrimary }]}>{t('contacts_not_saved')}</Text>
273
+ </View>
274
+ <Ionicons name="chevron-forward" size={18} color={colors.textQuaternary} />
275
+ </View>
276
+ </PressableScale>
277
+ ))}
278
+ {searching && (
279
+ <View style={styles.searchingRow}>
280
+ <ActivityIndicator size="small" color={colors.textSecondary} />
281
+ <Text style={[styles.searchingText, { color: colors.textSecondary }]}>{t('searching')}</Text>
282
+ </View>
283
+ )}
284
+ </GroupedSection>
285
+ )}
286
+ </ScrollView>
287
+ )}
288
+
289
+ {/* The one manual-entry door into Contacts (2026-09-18) — every other
290
+ path (scan, deep link, search, a payment's success screen) already
291
+ knows the identity key. */}
292
+ <View style={[styles.footer, { paddingBottom: Math.max(insets.bottom, spacing.lg) }]}>
293
+ <PressableScale
294
+ onPress={() => router.push('/contact/add' as never)}
295
+ haptic="tap"
296
+ style={[styles.newContactBtn, { backgroundColor: colors.accent }]}
297
+ accessibilityRole="button"
298
+ >
299
+ <Ionicons name="person-add-outline" size={18} color={colors.textOnAccent} />
300
+ <Text style={[styles.newContactText, { color: colors.textOnAccent }]}>{t('contact_new_title')}</Text>
301
+ </PressableScale>
302
+ </View>
303
+
304
+ <Modal visible={scannerVisible} animationType="slide" onRequestClose={() => setScannerVisible(false)}>
305
+ <QRScanner onScan={onScan} onClose={() => setScannerVisible(false)} hintText={t('contact_scan_hint')} />
306
+ </Modal>
307
+ </View>
308
+ )
309
+ }
310
+
311
+ export default ContactsScreen
312
+
313
+ const styles = StyleSheet.create({
314
+ container: { flex: 1 },
315
+ header: {
316
+ flexDirection: 'row',
317
+ alignItems: 'center',
318
+ justifyContent: 'space-between',
319
+ paddingHorizontal: spacing.sm,
320
+ paddingVertical: spacing.md,
321
+ borderBottomWidth: StyleSheet.hairlineWidth
322
+ },
323
+ headerBtn: { width: 44, height: 44, alignItems: 'center', justifyContent: 'center' },
324
+ headerTitle: { ...typography.headline, fontWeight: '600', flex: 1, textAlign: 'center' },
325
+ searchWrap: { paddingHorizontal: spacing.lg, paddingTop: spacing.md, paddingBottom: spacing.lg },
326
+ searchRow: {
327
+ flexDirection: 'row',
328
+ alignItems: 'center',
329
+ gap: spacing.sm,
330
+ borderRadius: radii.md,
331
+ paddingHorizontal: spacing.md,
332
+ minHeight: 40
333
+ },
334
+ searchInput: { ...typography.body, flex: 1, paddingVertical: spacing.sm, paddingHorizontal: 0 },
335
+ clearBtn: { width: 28, height: 28, alignItems: 'center', justifyContent: 'center' },
336
+ list: { flex: 1 },
337
+ listContent: { paddingBottom: spacing.lg },
338
+ row: {
339
+ flexDirection: 'row',
340
+ alignItems: 'center',
341
+ gap: spacing.md,
342
+ minHeight: 58,
343
+ paddingVertical: spacing.sm + 2,
344
+ paddingHorizontal: spacing.lg
345
+ },
346
+ rowText: { flex: 1, minWidth: 0, gap: 2 },
347
+ rowName: { ...typography.body },
348
+ rowSub: { ...typography.footnote },
349
+ mono: { fontFamily: 'monospace', fontSize: 12 },
350
+ badge: { paddingHorizontal: 7, paddingVertical: 3, borderRadius: 6 },
351
+ badgeText: { ...typography.caption2, fontWeight: '600' },
352
+ searchingRow: {
353
+ flexDirection: 'row',
354
+ alignItems: 'center',
355
+ justifyContent: 'center',
356
+ gap: spacing.sm,
357
+ paddingVertical: spacing.md
358
+ },
359
+ searchingText: { ...typography.subhead },
360
+ empty: { flex: 1, alignItems: 'center', justifyContent: 'center', gap: spacing.sm, paddingHorizontal: spacing.xxl },
361
+ emptyTitle: { ...typography.headline, fontWeight: '600', marginTop: spacing.sm },
362
+ emptyBody: { ...typography.footnote, textAlign: 'center' },
363
+ footer: { paddingHorizontal: spacing.lg, paddingTop: spacing.sm },
364
+ newContactBtn: {
365
+ flexDirection: 'row',
366
+ alignItems: 'center',
367
+ justifyContent: 'center',
368
+ gap: spacing.sm,
369
+ paddingVertical: spacing.md + 2,
370
+ borderRadius: radii.md
371
+ },
372
+ newContactText: { ...typography.subhead, fontWeight: '600' }
373
+ })
@@ -0,0 +1,234 @@
1
+ /**
2
+ * Your Identifier as a QR: a deep link straight to another wallet's
3
+ * add-contact screen (`bsv-wallet://contact/add?identityKey=…`, 2026-09-18
4
+ * ruling), never the bare key and never a payment request. Copy and Share
5
+ * carry the same link; the callout says what scanning it does and does not do.
6
+ */
7
+ import React, { useCallback, useEffect, useState } from 'react'
8
+ import { I18nManager, Share, StyleSheet, Text, View } from 'react-native'
9
+ import { useSafeAreaInsets } from 'react-native-safe-area-context'
10
+ import { useTranslation } from 'react-i18next'
11
+ import { useTheme, spacing, radii, typography, useWallet } from '@bsv/expo-wallet-toolbox'
12
+ import PressableScale from '../components/ui/PressableScale'
13
+ import { showToast } from '../components/ui/Toast'
14
+ import { contactAddLinkFor } from '../../core/identity/contactLink'
15
+ import { abbreviateKey } from '../../core/pay/counterparty'
16
+
17
+ type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
18
+ let ioniconsComponent: IoniconsComponent | undefined
19
+ function loadIonicons(): IoniconsComponent {
20
+ if (!ioniconsComponent) {
21
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
22
+ ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
23
+ }
24
+ return ioniconsComponent
25
+ }
26
+
27
+ type QRCodeComponent = typeof import('react-native-qrcode-svg').default
28
+ let qrCodeComponent: QRCodeComponent | undefined
29
+ function loadQRCode(): QRCodeComponent {
30
+ if (!qrCodeComponent) {
31
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
32
+ const mod = require('react-native-qrcode-svg')
33
+ qrCodeComponent = (mod?.default ?? mod) as QRCodeComponent
34
+ }
35
+ return qrCodeComponent
36
+ }
37
+
38
+ type ExpoRouterModule = typeof import('expo-router')
39
+ let expoRouterMod: ExpoRouterModule | undefined
40
+ function loadExpoRouter(): ExpoRouterModule {
41
+ if (!expoRouterMod) {
42
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
43
+ expoRouterMod = require('expo-router') as ExpoRouterModule
44
+ }
45
+ return expoRouterMod
46
+ }
47
+
48
+ type ClipboardModule = typeof import('@react-native-clipboard/clipboard').default
49
+ let clipboardModule: ClipboardModule | undefined
50
+ function loadClipboard(): ClipboardModule {
51
+ if (!clipboardModule) {
52
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
53
+ clipboardModule = require('@react-native-clipboard/clipboard').default as ClipboardModule
54
+ }
55
+ return clipboardModule
56
+ }
57
+
58
+ function firstParam(v: string | string[] | undefined): string | undefined {
59
+ return Array.isArray(v) ? v[0] : v
60
+ }
61
+
62
+ const QR_SIZE = 240
63
+
64
+ export function IdentifierScreen() {
65
+ const { t } = useTranslation()
66
+ const { colors } = useTheme()
67
+ const insets = useSafeAreaInsets()
68
+ const Ionicons = loadIonicons()
69
+ const QRCode = loadQRCode()
70
+ const { router, useLocalSearchParams } = loadExpoRouter()
71
+ const { managers, adminOriginator } = useWallet()
72
+ const params = useLocalSearchParams<{
73
+ identityKey?: string | string[]
74
+ name?: string | string[]
75
+ handle?: string | string[]
76
+ }>()
77
+ const [identityKey, setIdentityKey] = useState(firstParam(params.identityKey) ?? '')
78
+ const name = firstParam(params.name) ?? ''
79
+ const handle = firstParam(params.handle) ?? ''
80
+
81
+ // Profile passes the key along; a cold deep link into this screen fetches it.
82
+ useEffect(() => {
83
+ if (identityKey) return
84
+ const wallet = managers?.permissionsManager
85
+ if (!wallet) return
86
+ void wallet.getPublicKey({ identityKey: true }, adminOriginator).then(r => {
87
+ if (r?.publicKey) setIdentityKey(r.publicKey)
88
+ })
89
+ }, [identityKey, managers, adminOriginator])
90
+
91
+ const link = identityKey ? contactAddLinkFor(identityKey) : ''
92
+
93
+ const onCopy = useCallback(() => {
94
+ if (!link) return
95
+ loadClipboard().setString(link)
96
+ showToast(t('copied'), { type: 'success' })
97
+ }, [link, t])
98
+
99
+ const onShare = useCallback(async () => {
100
+ if (!link) return
101
+ try {
102
+ await Share.share({ message: link })
103
+ } catch {
104
+ // The sheet was dismissed; nothing to report.
105
+ }
106
+ }, [link])
107
+
108
+ return (
109
+ <View style={[styles.container, { backgroundColor: colors.background, paddingTop: insets.top }]}>
110
+ <View style={[styles.header, { borderBottomColor: colors.separator }]}>
111
+ <PressableScale
112
+ onPress={() => router.back()}
113
+ haptic="tap"
114
+ style={styles.headerBtn}
115
+ accessibilityRole="button"
116
+ accessibilityLabel={t('go_back')}
117
+ >
118
+ <Ionicons
119
+ name={I18nManager.isRTL ? 'chevron-forward' : 'chevron-back'}
120
+ size={24}
121
+ color={colors.textSecondary}
122
+ />
123
+ </PressableScale>
124
+ <Text style={[styles.headerTitle, { color: colors.textPrimary }]} numberOfLines={1}>
125
+ {t('profile_identifier_section')}
126
+ </Text>
127
+ <View style={styles.headerBtn} />
128
+ </View>
129
+
130
+ <View style={styles.body}>
131
+ <View style={styles.who}>
132
+ <View style={[styles.whoDisc, { backgroundColor: colors.accent }]}>
133
+ <Ionicons name="person" size={20} color={colors.textOnAccent} />
134
+ </View>
135
+ <View>
136
+ <Text style={[styles.whoName, { color: colors.textPrimary }]} numberOfLines={1}>
137
+ {name || abbreviateKey(identityKey)}
138
+ </Text>
139
+ {!!handle && <Text style={[styles.whoHandle, { color: colors.textSecondary }]}>{handle}</Text>}
140
+ </View>
141
+ </View>
142
+
143
+ <View style={[styles.plate, { borderColor: colors.separator }]}>
144
+ {!!link && <QRCode value={link} size={QR_SIZE} color="#000" backgroundColor="#fff" />}
145
+ </View>
146
+
147
+ <Text style={[styles.link, { color: colors.textSecondary }]} numberOfLines={1} ellipsizeMode="middle">
148
+ {link}
149
+ </Text>
150
+
151
+ <View style={styles.actions}>
152
+ <PressableScale
153
+ onPress={onCopy}
154
+ haptic="tap"
155
+ style={[styles.actionBtn, { backgroundColor: colors.fillTertiary }]}
156
+ accessibilityRole="button"
157
+ >
158
+ <Ionicons name="copy-outline" size={18} color={colors.textPrimary} />
159
+ <Text style={[styles.actionLabel, { color: colors.textPrimary }]}>{t('copy')}</Text>
160
+ </PressableScale>
161
+ <PressableScale
162
+ onPress={onShare}
163
+ haptic="tap"
164
+ style={[styles.actionBtn, { backgroundColor: colors.fillTertiary }]}
165
+ accessibilityRole="button"
166
+ >
167
+ <Ionicons name="share-outline" size={18} color={colors.textPrimary} />
168
+ <Text style={[styles.actionLabel, { color: colors.textPrimary }]}>{t('share')}</Text>
169
+ </PressableScale>
170
+ </View>
171
+
172
+ <View style={[styles.callout, { backgroundColor: colors.fillTertiary, borderColor: colors.separator }]}>
173
+ <Ionicons name="information-circle-outline" size={16} color={colors.textSecondary} />
174
+ <Text style={[styles.calloutText, { color: colors.textSecondary }]}>{t('profile_qr_callout')}</Text>
175
+ </View>
176
+ </View>
177
+ </View>
178
+ )
179
+ }
180
+
181
+ export default IdentifierScreen
182
+
183
+ const styles = StyleSheet.create({
184
+ container: { flex: 1 },
185
+ header: {
186
+ flexDirection: 'row',
187
+ alignItems: 'center',
188
+ justifyContent: 'space-between',
189
+ paddingHorizontal: spacing.sm,
190
+ paddingVertical: spacing.md,
191
+ borderBottomWidth: StyleSheet.hairlineWidth
192
+ },
193
+ headerBtn: { width: 44, height: 44, alignItems: 'center', justifyContent: 'center' },
194
+ headerTitle: { ...typography.headline, fontWeight: '600', flex: 1, textAlign: 'center' },
195
+ body: { alignItems: 'center', gap: spacing.lg, paddingHorizontal: spacing.xl, paddingTop: spacing.xl },
196
+ who: { flexDirection: 'row', alignItems: 'center', gap: spacing.sm + 2 },
197
+ whoDisc: { width: 40, height: 40, borderRadius: 20, alignItems: 'center', justifyContent: 'center' },
198
+ whoName: { ...typography.headline, fontWeight: '600' },
199
+ whoHandle: { ...typography.footnote },
200
+ // The plate stays white in both themes: a QR is read by a camera, not by a person.
201
+ plate: {
202
+ padding: spacing.lg,
203
+ borderRadius: radii.xl,
204
+ backgroundColor: '#fff',
205
+ borderWidth: StyleSheet.hairlineWidth,
206
+ width: QR_SIZE + spacing.lg * 2,
207
+ height: QR_SIZE + spacing.lg * 2,
208
+ alignItems: 'center',
209
+ justifyContent: 'center'
210
+ },
211
+ link: { ...typography.caption1, fontFamily: 'monospace', textAlign: 'center', maxWidth: '100%' },
212
+ actions: { flexDirection: 'row', gap: spacing.sm, alignSelf: 'stretch' },
213
+ actionBtn: {
214
+ flex: 1,
215
+ flexDirection: 'row',
216
+ alignItems: 'center',
217
+ justifyContent: 'center',
218
+ gap: spacing.xs,
219
+ minHeight: 44,
220
+ borderRadius: radii.md
221
+ },
222
+ actionLabel: { ...typography.subhead, fontWeight: '500' },
223
+ callout: {
224
+ flexDirection: 'row',
225
+ alignItems: 'center',
226
+ gap: spacing.sm,
227
+ alignSelf: 'stretch',
228
+ borderWidth: StyleSheet.hairlineWidth,
229
+ borderRadius: radii.md,
230
+ paddingVertical: spacing.sm + 2,
231
+ paddingHorizontal: spacing.md
232
+ },
233
+ calloutText: { ...typography.footnote, flex: 1 }
234
+ })