@bsv/expo-wallet-toolbox 0.5.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.
- package/CHANGELOG.md +255 -0
- package/README.md +19 -0
- package/core/amountFormatHelpers.ts +238 -34
- package/core/backup/RemoteSyncReader.ts +2 -5
- package/core/backup/codec.ts +2 -2
- package/core/backup/push.ts +1 -1
- package/core/config.tsx +12 -5
- package/core/contacts/contactActivity.ts +153 -0
- package/core/contacts/contactCache.ts +41 -0
- package/core/contacts/contactsStore.ts +183 -0
- package/core/context/WalletContext.tsx +55 -10
- package/core/demo/demoAssets.ts +60 -0
- package/core/demo/demoLedger.ts +240 -0
- package/core/demo/demoMandalaRuntime.ts +96 -0
- package/core/demo/demoMode.ts +38 -0
- package/core/demo/demoWallet.ts +25 -0
- package/core/demo/index.ts +26 -0
- package/core/demo/useDemo.ts +59 -0
- package/core/headers/OfflineFirstChaintracks.ts +52 -14
- package/core/headers/headerStore.ts +7 -10
- package/core/i18n/translations.tsx +1234 -74
- package/core/identity/contactLink.ts +36 -0
- package/core/identity/handleRegistry/client.ts +285 -0
- package/core/identity/handleRegistry/profileCert.ts +254 -0
- package/core/identity/handleRegistry/registration.ts +559 -0
- package/core/identity/handleRegistry/resolver.ts +247 -0
- package/core/identity/handleRegistry/rules.ts +104 -0
- package/core/index.ts +20 -2
- package/core/localpay/pendingAborts.ts +5 -1
- package/core/monitor/MonitorSupervisor.ts +121 -0
- package/core/monitor/TaskBackupPush.ts +1 -1
- package/core/monitor/TaskCreditInbox.ts +1 -1
- package/core/monitor/TaskDrainOutbox.ts +1 -1
- package/core/monitor/TaskSendOffline.ts +1 -1
- package/core/net/online.ts +49 -0
- package/core/numberFormat.ts +19 -0
- package/core/offline/plan.ts +1 -1
- package/core/pay/recordProof.ts +2 -6
- package/core/services/arcadeBroadcastProvider.ts +1 -4
- package/core/services/exchangeRate.ts +1 -1
- package/core/services/externalOrigin.ts +5 -2
- package/core/services/vault/transfers.ts +2 -2
- package/core/services/walletServiceConfig.ts +31 -20
- package/core/storage/StorageExpoSQLite.ts +41 -34
- package/core/storage/methods/findSql.ts +3 -0
- package/core/storage/methods/listActionsSql.ts +8 -5
- package/core/storage/methods/listOutputsSql.ts +2 -2
- package/core/storage/methods/processOfflineActions.ts +2 -3
- package/core/storage/methods/reviewStatusSql.ts +7 -2
- package/core/storage/schema/createTables.ts +29 -0
- package/core/toolboxConfig.ts +70 -0
- package/core/toolboxTypes.ts +40 -0
- package/core/userAvatar.ts +79 -0
- package/core/walletMonitor.ts +8 -3
- package/package.json +7 -7
- package/ui/activityFilter.ts +115 -0
- package/ui/components/pay/PaymentSuccessOverlay.tsx +46 -6
- package/ui/components/pay/RecipientField.tsx +84 -70
- package/ui/components/pay/StepBar.tsx +32 -0
- package/ui/components/pay/UniversalSend.tsx +677 -149
- package/ui/components/ui/PencilEditField.tsx +109 -0
- package/ui/components/ui/SlideOverFromRight.tsx +86 -0
- package/ui/components/wallet/ActivityRow.tsx +222 -120
- package/ui/components/wallet/AmountInput.tsx +18 -6
- package/ui/components/wallet/ContactActivityList.tsx +149 -0
- package/ui/components/wallet/ContactSigil.tsx +49 -0
- package/ui/components/wallet/EditPictureSheet.tsx +99 -0
- package/ui/components/wallet/FitAmount.tsx +148 -0
- package/ui/components/wallet/IconPickerSheet.tsx +168 -0
- package/ui/components/wallet/IdentifierRow.tsx +69 -0
- package/ui/components/wallet/ImportFromBackupPrompt.tsx +35 -13
- package/ui/components/wallet/ProfileButton.tsx +62 -0
- package/ui/components/wallet/UserAvatar.tsx +85 -0
- package/ui/components/wallet/avatarIcons.ts +122 -0
- package/ui/hooks/useContactsStore.ts +10 -0
- package/ui/hooks/useMandala.ts +18 -1
- package/ui/hooks/useOnline.ts +65 -20
- package/ui/index.ts +26 -1
- package/ui/screens/ContactScreen.tsx +289 -0
- package/ui/screens/ContactsScreen.tsx +373 -0
- package/ui/screens/IdentifierScreen.tsx +234 -0
- package/ui/screens/NewContactScreen.tsx +362 -0
- package/ui/screens/PayScreen.tsx +20 -7
- package/ui/screens/ProfileScreen.tsx +783 -0
- package/ui/screens/TransactionDetailScreen.tsx +419 -0
- package/ui/screens/TrustScreen.tsx +1 -1
- package/ui/screens/WalletConfigScreen.tsx +42 -0
- package/ui/screens/WalletHomeScreen.tsx +528 -83
- package/ui/tokenStatus.ts +21 -0
- package/ui/txStatus.ts +43 -5
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A contact: their face, name and read-only registered handle up top; your
|
|
3
|
+
* own name for them (editable, pencil → confirm); their Identifier with a
|
|
4
|
+
* copy button; delete; and every interaction with them across every asset
|
|
5
|
+
* (2026-09-17 ruling), drawn with the same rows Home uses.
|
|
6
|
+
*/
|
|
7
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react'
|
|
8
|
+
import { I18nManager, ScrollView, 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, typography, useWallet } from '@bsv/expo-wallet-toolbox'
|
|
12
|
+
import { showAlert } from '../components/ui/AlertCard'
|
|
13
|
+
import { GroupedSection } from '../components/ui/GroupedList'
|
|
14
|
+
import { ListRow } from '../components/ui/ListRow'
|
|
15
|
+
import { PencilEditField } from '../components/ui/PencilEditField'
|
|
16
|
+
import PressableScale from '../components/ui/PressableScale'
|
|
17
|
+
import ContactSigil from '../components/wallet/ContactSigil'
|
|
18
|
+
import ContactActivityList from '../components/wallet/ContactActivityList'
|
|
19
|
+
import IdentifierRow from '../components/wallet/IdentifierRow'
|
|
20
|
+
import { useContactsStore } from '../hooks/useContactsStore'
|
|
21
|
+
import { getContactActivity, type ContactActivityItem } from '../../core/contacts/contactActivity'
|
|
22
|
+
import { mergeContactCache } from '../../core/contacts/contactCache'
|
|
23
|
+
import { makeIdentityClient, resolveIdentity } from '../resolveIdentity'
|
|
24
|
+
import { getHandleRegistryConfig } from '../../core/toolboxConfig'
|
|
25
|
+
import { parsePaymail } from '../../core/identity/handleRegistry/rules'
|
|
26
|
+
import { createHandleRegistryClient } from '../../core/identity/handleRegistry/client'
|
|
27
|
+
import type { ContactRow } from '../../core/contacts/contactsStore'
|
|
28
|
+
|
|
29
|
+
type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
|
|
30
|
+
let ioniconsComponent: IoniconsComponent | undefined
|
|
31
|
+
function loadIonicons(): IoniconsComponent {
|
|
32
|
+
if (!ioniconsComponent) {
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
34
|
+
ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
|
|
35
|
+
}
|
|
36
|
+
return ioniconsComponent
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
type ExpoRouterModule = typeof import('expo-router')
|
|
40
|
+
let expoRouterMod: ExpoRouterModule | undefined
|
|
41
|
+
function loadExpoRouter(): ExpoRouterModule {
|
|
42
|
+
if (!expoRouterMod) {
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
44
|
+
expoRouterMod = require('expo-router') as ExpoRouterModule
|
|
45
|
+
}
|
|
46
|
+
return expoRouterMod
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function firstParam(v: string | string[] | undefined): string | undefined {
|
|
50
|
+
return Array.isArray(v) ? v[0] : v
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function ContactScreen() {
|
|
54
|
+
const { t } = useTranslation()
|
|
55
|
+
const { colors } = useTheme()
|
|
56
|
+
const insets = useSafeAreaInsets()
|
|
57
|
+
const Ionicons = loadIonicons()
|
|
58
|
+
const { router, useLocalSearchParams } = loadExpoRouter()
|
|
59
|
+
const { managers, adminOriginator, storage, walletUserId, selectedNetwork } = useWallet()
|
|
60
|
+
const store = useContactsStore()
|
|
61
|
+
const params = useLocalSearchParams<{ identityKey?: string | string[] }>()
|
|
62
|
+
const identityKey = firstParam(params.identityKey) ?? ''
|
|
63
|
+
|
|
64
|
+
const [contact, setContact] = useState<ContactRow | undefined>(undefined)
|
|
65
|
+
const [activity, setActivity] = useState<ContactActivityItem[]>([])
|
|
66
|
+
|
|
67
|
+
const reload = useCallback(async () => {
|
|
68
|
+
if (!store || walletUserId === null || !identityKey) return
|
|
69
|
+
setContact(await store.getContact(walletUserId, identityKey))
|
|
70
|
+
}, [store, walletUserId, identityKey])
|
|
71
|
+
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
void reload()
|
|
74
|
+
}, [reload])
|
|
75
|
+
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
if (!identityKey) return
|
|
78
|
+
const wallet = managers?.permissionsManager
|
|
79
|
+
void getContactActivity({
|
|
80
|
+
wallet: wallet as never,
|
|
81
|
+
adminOriginator,
|
|
82
|
+
settlementsDb: storage?.sqliteDb as never,
|
|
83
|
+
identityKey
|
|
84
|
+
}).then(setActivity)
|
|
85
|
+
}, [identityKey, managers, adminOriginator, storage])
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Best-effort background cache refresh: the overlay's avatar and the
|
|
89
|
+
* registry's handle, in ONE write. `refreshContactCache` replaces all three
|
|
90
|
+
* cache columns, so two separate calls would each blank what the other just
|
|
91
|
+
* stored. Once per visit — the write feeds `reload`, and re-running on the
|
|
92
|
+
* contact it produced would be a loop.
|
|
93
|
+
*
|
|
94
|
+
* One guard per source, though, not one for the pass. The two clients arrive
|
|
95
|
+
* at different moments: a screen drawn before the wallet finished building
|
|
96
|
+
* has no identity client, while a chain WITH a registry configured has its
|
|
97
|
+
* registry client from the first render — so a single guard would be claimed
|
|
98
|
+
* by the pass that could only do the registry half, and the avatar would
|
|
99
|
+
* never be refreshed for the whole visit even though `managers` is a
|
|
100
|
+
* dependency precisely so that it could be.
|
|
101
|
+
*
|
|
102
|
+
* `name` is never touched: it is the user's own label for this person.
|
|
103
|
+
*/
|
|
104
|
+
const refreshedAvatarKeyRef = useRef('')
|
|
105
|
+
const refreshedHandleKeyRef = useRef('')
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
if (!identityKey || !store || walletUserId === null || !contact) return
|
|
108
|
+
const idClient = makeIdentityClient(managers?.permissionsManager as never, adminOriginator)
|
|
109
|
+
const registry = getHandleRegistryConfig(selectedNetwork)
|
|
110
|
+
const client = registry ? createHandleRegistryClient({ pinned: registry }) : null
|
|
111
|
+
const wantAvatar = !!idClient && refreshedAvatarKeyRef.current !== identityKey
|
|
112
|
+
const wantHandle = !!client && refreshedHandleKeyRef.current !== identityKey
|
|
113
|
+
if (!wantAvatar && !wantHandle) return
|
|
114
|
+
if (wantAvatar) refreshedAvatarKeyRef.current = identityKey
|
|
115
|
+
if (wantHandle) refreshedHandleKeyRef.current = identityKey
|
|
116
|
+
let cancelled = false
|
|
117
|
+
// A pass that never reaches its decision hands the guard back, so a
|
|
118
|
+
// `contact` that changes mid-lookup (a rename, whose `reload` is a new
|
|
119
|
+
// row) is re-checked instead of losing this visit's refresh. It cannot
|
|
120
|
+
// reopen the loop the guard is for: that path is exactly the one this is
|
|
121
|
+
// true on. Set BEFORE the write, not after: a cancellation landing while
|
|
122
|
+
// the UPDATE is in flight would otherwise repeat both lookups to send the
|
|
123
|
+
// same three columns again.
|
|
124
|
+
let decided = false
|
|
125
|
+
void (async () => {
|
|
126
|
+
const [identity, lookup] = await Promise.all([
|
|
127
|
+
wantAvatar && idClient ? resolveIdentity(idClient, identityKey).then(([, found]) => found) : null,
|
|
128
|
+
// A contact whose cached handle names another domain is looked up
|
|
129
|
+
// there; everyone else on the registry this build is configured for.
|
|
130
|
+
wantHandle && client
|
|
131
|
+
? client.lookupProfile(identityKey, parsePaymail(contact.cachedHandle ?? '')?.domain)
|
|
132
|
+
: null
|
|
133
|
+
])
|
|
134
|
+
if (cancelled) return
|
|
135
|
+
// `lookupProfile`, not `lookupIdentityKey`: a `failed` lookup is the
|
|
136
|
+
// registry not having answered, and writing `''` for it would blank a
|
|
137
|
+
// contact's handle every time this screen is opened offline. Only an
|
|
138
|
+
// answer — `found` or `none` — may change the column.
|
|
139
|
+
const learnedHandle = lookup?.kind === 'found' ? lookup.profile.paymail : lookup?.kind === 'none' ? '' : undefined
|
|
140
|
+
const next = mergeContactCache(contact, {
|
|
141
|
+
...(identity?.avatarURL ? { cachedAvatarUrl: identity.avatarURL } : {}),
|
|
142
|
+
...(learnedHandle === undefined ? {} : { cachedHandle: learnedHandle })
|
|
143
|
+
})
|
|
144
|
+
decided = true
|
|
145
|
+
if (!next) return
|
|
146
|
+
await store.refreshContactCache(walletUserId, identityKey, next)
|
|
147
|
+
if (!cancelled) void reload().catch(() => {})
|
|
148
|
+
})().catch(() => {})
|
|
149
|
+
return () => {
|
|
150
|
+
cancelled = true
|
|
151
|
+
if (decided) return
|
|
152
|
+
if (wantAvatar) refreshedAvatarKeyRef.current = ''
|
|
153
|
+
if (wantHandle) refreshedHandleKeyRef.current = ''
|
|
154
|
+
}
|
|
155
|
+
}, [identityKey, store, walletUserId, managers, adminOriginator, selectedNetwork, contact, reload])
|
|
156
|
+
|
|
157
|
+
const onDelete = useCallback(async () => {
|
|
158
|
+
if (!store || walletUserId === null || !contact) return
|
|
159
|
+
const choice = await showAlert({
|
|
160
|
+
title: t('contact_delete'),
|
|
161
|
+
message: t('contact_delete_body', { name: contact.name }),
|
|
162
|
+
buttons: [
|
|
163
|
+
{ text: t('cancel'), style: 'cancel', key: 'cancel' },
|
|
164
|
+
{ text: t('contact_delete'), style: 'destructive', key: 'delete' }
|
|
165
|
+
]
|
|
166
|
+
})
|
|
167
|
+
if (choice !== 'delete') return
|
|
168
|
+
await store.deleteContact(walletUserId, identityKey)
|
|
169
|
+
router.back()
|
|
170
|
+
}, [store, walletUserId, contact, identityKey, t, router])
|
|
171
|
+
|
|
172
|
+
if (!contact) return <View style={[styles.container, { backgroundColor: colors.background }]} />
|
|
173
|
+
|
|
174
|
+
return (
|
|
175
|
+
<View style={[styles.container, { backgroundColor: colors.background, paddingTop: insets.top }]}>
|
|
176
|
+
<View style={[styles.header, { borderBottomColor: colors.separator }]}>
|
|
177
|
+
<PressableScale
|
|
178
|
+
onPress={() => router.back()}
|
|
179
|
+
haptic="tap"
|
|
180
|
+
style={styles.headerBtn}
|
|
181
|
+
accessibilityRole="button"
|
|
182
|
+
accessibilityLabel={t('go_back')}
|
|
183
|
+
>
|
|
184
|
+
<Ionicons
|
|
185
|
+
name={I18nManager.isRTL ? 'chevron-forward' : 'chevron-back'}
|
|
186
|
+
size={24}
|
|
187
|
+
color={colors.textSecondary}
|
|
188
|
+
/>
|
|
189
|
+
</PressableScale>
|
|
190
|
+
<Text style={[styles.headerTitle, { color: colors.textPrimary }]} numberOfLines={1}>
|
|
191
|
+
{contact.name}
|
|
192
|
+
</Text>
|
|
193
|
+
<View style={styles.headerBtn} />
|
|
194
|
+
</View>
|
|
195
|
+
|
|
196
|
+
<ScrollView
|
|
197
|
+
contentContainerStyle={[styles.content, { paddingBottom: Math.max(insets.bottom, spacing.lg) }]}
|
|
198
|
+
keyboardShouldPersistTaps="handled"
|
|
199
|
+
>
|
|
200
|
+
<View style={styles.hero}>
|
|
201
|
+
<ContactSigil identityKey={identityKey} avatarUrl={contact.cachedAvatarUrl} size={72} radius={24} />
|
|
202
|
+
<Text style={[styles.heroName, { color: colors.textPrimary }]} numberOfLines={1}>
|
|
203
|
+
{contact.name}
|
|
204
|
+
</Text>
|
|
205
|
+
{!!contact.cachedHandle && (
|
|
206
|
+
<>
|
|
207
|
+
<Text style={[styles.handle, { color: colors.textSecondary }]}>{contact.cachedHandle}</Text>
|
|
208
|
+
<View style={styles.captionRow}>
|
|
209
|
+
<Ionicons name="shield-checkmark-outline" size={12} color={colors.textTertiary} />
|
|
210
|
+
<Text style={[styles.handleCaption, { color: colors.textTertiary }]}>
|
|
211
|
+
{t('contact_handle_caption')}
|
|
212
|
+
</Text>
|
|
213
|
+
</View>
|
|
214
|
+
</>
|
|
215
|
+
)}
|
|
216
|
+
</View>
|
|
217
|
+
|
|
218
|
+
<GroupedSection header={t('contact_name_section')} footer={t('contact_name_hint')}>
|
|
219
|
+
<PencilEditField
|
|
220
|
+
value={contact.name}
|
|
221
|
+
placeholder={t('contact_new_title')}
|
|
222
|
+
onSave={async next => {
|
|
223
|
+
if (walletUserId === null) return
|
|
224
|
+
await store?.renameContact(walletUserId, identityKey, next)
|
|
225
|
+
void reload()
|
|
226
|
+
}}
|
|
227
|
+
editAccessibilityLabel={t('contact_edit_name')}
|
|
228
|
+
saveAccessibilityLabel={t('contact_save_name')}
|
|
229
|
+
/>
|
|
230
|
+
</GroupedSection>
|
|
231
|
+
|
|
232
|
+
<GroupedSection header={t('contact_identifier')}>
|
|
233
|
+
<IdentifierRow identityKey={identityKey} />
|
|
234
|
+
</GroupedSection>
|
|
235
|
+
|
|
236
|
+
<GroupedSection>
|
|
237
|
+
<ListRow
|
|
238
|
+
label={t('contact_delete')}
|
|
239
|
+
icon="trash-outline"
|
|
240
|
+
iconColor={colors.error}
|
|
241
|
+
destructive
|
|
242
|
+
showChevron={false}
|
|
243
|
+
onPress={onDelete}
|
|
244
|
+
isLast
|
|
245
|
+
/>
|
|
246
|
+
</GroupedSection>
|
|
247
|
+
|
|
248
|
+
<Text style={[styles.sectionTitle, { color: colors.textTertiary }]}>{t('contact_activity').toUpperCase()}</Text>
|
|
249
|
+
<ContactActivityList items={activity} identityKey={identityKey} />
|
|
250
|
+
</ScrollView>
|
|
251
|
+
</View>
|
|
252
|
+
)
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export default ContactScreen
|
|
256
|
+
|
|
257
|
+
const styles = StyleSheet.create({
|
|
258
|
+
container: { flex: 1 },
|
|
259
|
+
header: {
|
|
260
|
+
flexDirection: 'row',
|
|
261
|
+
alignItems: 'center',
|
|
262
|
+
justifyContent: 'space-between',
|
|
263
|
+
paddingHorizontal: spacing.sm,
|
|
264
|
+
paddingVertical: spacing.md,
|
|
265
|
+
borderBottomWidth: StyleSheet.hairlineWidth
|
|
266
|
+
},
|
|
267
|
+
headerBtn: { width: 44, height: 44, alignItems: 'center', justifyContent: 'center' },
|
|
268
|
+
headerTitle: { ...typography.headline, fontWeight: '600', flex: 1, textAlign: 'center' },
|
|
269
|
+
content: { paddingTop: spacing.lg },
|
|
270
|
+
hero: {
|
|
271
|
+
alignItems: 'center',
|
|
272
|
+
gap: spacing.sm,
|
|
273
|
+
paddingHorizontal: spacing.xl,
|
|
274
|
+
paddingTop: spacing.sm,
|
|
275
|
+
paddingBottom: spacing.xl
|
|
276
|
+
},
|
|
277
|
+
heroName: { ...typography.title2, fontWeight: '700', marginTop: spacing.xs },
|
|
278
|
+
handle: { ...typography.body, fontWeight: '500' },
|
|
279
|
+
captionRow: { flexDirection: 'row', alignItems: 'center', gap: spacing.xs },
|
|
280
|
+
handleCaption: { ...typography.caption1 },
|
|
281
|
+
// Tracked small caps, matching GroupedSection's own header.
|
|
282
|
+
sectionTitle: {
|
|
283
|
+
fontSize: 10.5,
|
|
284
|
+
fontWeight: '700',
|
|
285
|
+
letterSpacing: 1.3,
|
|
286
|
+
paddingHorizontal: spacing.xl,
|
|
287
|
+
paddingBottom: spacing.sm
|
|
288
|
+
}
|
|
289
|
+
})
|
|
@@ -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
|
+
})
|