@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.
Files changed (90) hide show
  1. package/CHANGELOG.md +255 -0
  2. package/README.md +19 -0
  3. package/core/amountFormatHelpers.ts +238 -34
  4. package/core/backup/RemoteSyncReader.ts +2 -5
  5. package/core/backup/codec.ts +2 -2
  6. package/core/backup/push.ts +1 -1
  7. package/core/config.tsx +12 -5
  8. package/core/contacts/contactActivity.ts +153 -0
  9. package/core/contacts/contactCache.ts +41 -0
  10. package/core/contacts/contactsStore.ts +183 -0
  11. package/core/context/WalletContext.tsx +55 -10
  12. package/core/demo/demoAssets.ts +60 -0
  13. package/core/demo/demoLedger.ts +240 -0
  14. package/core/demo/demoMandalaRuntime.ts +96 -0
  15. package/core/demo/demoMode.ts +38 -0
  16. package/core/demo/demoWallet.ts +25 -0
  17. package/core/demo/index.ts +26 -0
  18. package/core/demo/useDemo.ts +59 -0
  19. package/core/headers/OfflineFirstChaintracks.ts +52 -14
  20. package/core/headers/headerStore.ts +7 -10
  21. package/core/i18n/translations.tsx +1234 -74
  22. package/core/identity/contactLink.ts +36 -0
  23. package/core/identity/handleRegistry/client.ts +285 -0
  24. package/core/identity/handleRegistry/profileCert.ts +254 -0
  25. package/core/identity/handleRegistry/registration.ts +559 -0
  26. package/core/identity/handleRegistry/resolver.ts +247 -0
  27. package/core/identity/handleRegistry/rules.ts +104 -0
  28. package/core/index.ts +20 -2
  29. package/core/localpay/pendingAborts.ts +5 -1
  30. package/core/monitor/MonitorSupervisor.ts +121 -0
  31. package/core/monitor/TaskBackupPush.ts +1 -1
  32. package/core/monitor/TaskCreditInbox.ts +1 -1
  33. package/core/monitor/TaskDrainOutbox.ts +1 -1
  34. package/core/monitor/TaskSendOffline.ts +1 -1
  35. package/core/net/online.ts +49 -0
  36. package/core/numberFormat.ts +19 -0
  37. package/core/offline/plan.ts +1 -1
  38. package/core/pay/recordProof.ts +2 -6
  39. package/core/services/arcadeBroadcastProvider.ts +1 -4
  40. package/core/services/exchangeRate.ts +1 -1
  41. package/core/services/externalOrigin.ts +5 -2
  42. package/core/services/vault/transfers.ts +2 -2
  43. package/core/services/walletServiceConfig.ts +31 -20
  44. package/core/storage/StorageExpoSQLite.ts +41 -34
  45. package/core/storage/methods/findSql.ts +3 -0
  46. package/core/storage/methods/listActionsSql.ts +8 -5
  47. package/core/storage/methods/listOutputsSql.ts +2 -2
  48. package/core/storage/methods/processOfflineActions.ts +2 -3
  49. package/core/storage/methods/reviewStatusSql.ts +7 -2
  50. package/core/storage/schema/createTables.ts +29 -0
  51. package/core/toolboxConfig.ts +70 -0
  52. package/core/toolboxTypes.ts +40 -0
  53. package/core/userAvatar.ts +79 -0
  54. package/core/walletMonitor.ts +8 -3
  55. package/package.json +7 -7
  56. package/ui/activityFilter.ts +115 -0
  57. package/ui/components/pay/PaymentSuccessOverlay.tsx +46 -6
  58. package/ui/components/pay/RecipientField.tsx +84 -70
  59. package/ui/components/pay/StepBar.tsx +32 -0
  60. package/ui/components/pay/UniversalSend.tsx +677 -149
  61. package/ui/components/ui/PencilEditField.tsx +109 -0
  62. package/ui/components/ui/SlideOverFromRight.tsx +86 -0
  63. package/ui/components/wallet/ActivityRow.tsx +222 -120
  64. package/ui/components/wallet/AmountInput.tsx +18 -6
  65. package/ui/components/wallet/ContactActivityList.tsx +149 -0
  66. package/ui/components/wallet/ContactSigil.tsx +49 -0
  67. package/ui/components/wallet/EditPictureSheet.tsx +99 -0
  68. package/ui/components/wallet/FitAmount.tsx +148 -0
  69. package/ui/components/wallet/IconPickerSheet.tsx +168 -0
  70. package/ui/components/wallet/IdentifierRow.tsx +69 -0
  71. package/ui/components/wallet/ImportFromBackupPrompt.tsx +35 -13
  72. package/ui/components/wallet/ProfileButton.tsx +62 -0
  73. package/ui/components/wallet/UserAvatar.tsx +85 -0
  74. package/ui/components/wallet/avatarIcons.ts +122 -0
  75. package/ui/hooks/useContactsStore.ts +10 -0
  76. package/ui/hooks/useMandala.ts +18 -1
  77. package/ui/hooks/useOnline.ts +65 -20
  78. package/ui/index.ts +26 -1
  79. package/ui/screens/ContactScreen.tsx +289 -0
  80. package/ui/screens/ContactsScreen.tsx +373 -0
  81. package/ui/screens/IdentifierScreen.tsx +234 -0
  82. package/ui/screens/NewContactScreen.tsx +362 -0
  83. package/ui/screens/PayScreen.tsx +20 -7
  84. package/ui/screens/ProfileScreen.tsx +783 -0
  85. package/ui/screens/TransactionDetailScreen.tsx +419 -0
  86. package/ui/screens/TrustScreen.tsx +1 -1
  87. package/ui/screens/WalletConfigScreen.tsx +42 -0
  88. package/ui/screens/WalletHomeScreen.tsx +528 -83
  89. package/ui/tokenStatus.ts +21 -0
  90. package/ui/txStatus.ts +43 -5
@@ -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
+ })
@@ -0,0 +1,362 @@
1
+ /**
2
+ * New Contact — four ways in: a scanned or deep-linked identity key (QR scan
3
+ * on the Contacts header, or `bsv-wallet://contact/add?identityKey=`), a
4
+ * network search hit on Contacts (`?source=search`), the "Save as a contact"
5
+ * offer on a payment's success screen (`?identityKey=` and `?name=` both
6
+ * prefilled, `?source=pay`), or the plain "New Contact" button at the bottom
7
+ * of the Contacts list (2026-09-18) — the only path with no identity key
8
+ * yet, where the Identifier row itself becomes an editable paste field.
9
+ *
10
+ * Any past activity with the key is shown below the form, so you can see who
11
+ * you are about to save.
12
+ */
13
+ import React, { useCallback, useEffect, useMemo, useState } from 'react'
14
+ import { I18nManager, ScrollView, StyleSheet, Text, TextInput, View } from 'react-native'
15
+ import { useSafeAreaInsets } from 'react-native-safe-area-context'
16
+ import { useTranslation } from 'react-i18next'
17
+ import { useTheme, spacing, radii, typography, useWallet } from '@bsv/expo-wallet-toolbox'
18
+ import { GroupedSection } from '../components/ui/GroupedList'
19
+ import PressableScale from '../components/ui/PressableScale'
20
+ import { showToast } from '../components/ui/Toast'
21
+ import ContactSigil from '../components/wallet/ContactSigil'
22
+ import ContactActivityList from '../components/wallet/ContactActivityList'
23
+ import IdentifierRow from '../components/wallet/IdentifierRow'
24
+ import { useContactsStore } from '../hooks/useContactsStore'
25
+ import { abbreviateKey } from '../../core/pay/counterparty'
26
+ import { isCompressedIdentityKey } from '../../core/identity/contactLink'
27
+ import { getHandleRegistryConfig } from '../../core/toolboxConfig'
28
+ import { parsePaymail } from '../../core/identity/handleRegistry/rules'
29
+ import { createHandleRegistryClient } from '../../core/identity/handleRegistry/client'
30
+ import { getContactActivity, type ContactActivityItem } from '../../core/contacts/contactActivity'
31
+ import type { ContactSource } from '../../core/contacts/contactsStore'
32
+
33
+ type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
34
+ let ioniconsComponent: IoniconsComponent | undefined
35
+ function loadIonicons(): IoniconsComponent {
36
+ if (!ioniconsComponent) {
37
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
38
+ ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
39
+ }
40
+ return ioniconsComponent
41
+ }
42
+
43
+ type ExpoRouterModule = typeof import('expo-router')
44
+ let expoRouterMod: ExpoRouterModule | undefined
45
+ function loadExpoRouter(): ExpoRouterModule {
46
+ if (!expoRouterMod) {
47
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
48
+ expoRouterMod = require('expo-router') as ExpoRouterModule
49
+ }
50
+ return expoRouterMod
51
+ }
52
+
53
+ function firstParam(v: string | string[] | undefined): string | undefined {
54
+ return Array.isArray(v) ? v[0] : v
55
+ }
56
+
57
+ const SOURCES: ReadonlySet<string> = new Set<ContactSource>(['manual', 'qr', 'pay', 'search'])
58
+
59
+ export function NewContactScreen() {
60
+ const { t } = useTranslation()
61
+ const { colors } = useTheme()
62
+ const insets = useSafeAreaInsets()
63
+ const Ionicons = loadIonicons()
64
+ const { router, useLocalSearchParams } = loadExpoRouter()
65
+ const { walletUserId, managers, adminOriginator, storage, selectedNetwork } = useWallet()
66
+ const store = useContactsStore()
67
+ const params = useLocalSearchParams<{
68
+ identityKey?: string | string[]
69
+ name?: string | string[]
70
+ handle?: string | string[]
71
+ source?: string | string[]
72
+ }>()
73
+ const prefilledIdentityKey = (firstParam(params.identityKey) ?? '').toLowerCase()
74
+ /**
75
+ * The registry's `handle@domain`, when the caller had one: Pay's "Save as a
76
+ * contact" is the only route that knows it today — the Contacts search tier
77
+ * is an overlay result, which carries no paymail — and it is the only way
78
+ * this column is ever populated.
79
+ *
80
+ * Validated, not trusted. `/contact/add` is a deep-linkable expo-router
81
+ * route, so this param is a string from outside the app — and what it becomes
82
+ * is rendered on ContactScreen under a shield and the words "only they can
83
+ * change it". Anything that is not a paymail is not a handle.
84
+ *
85
+ * Passing `parsePaymail` is only the SHAPE, though, and shape says nothing
86
+ * about whose handle it is: a phishing link can assert any well-formed
87
+ * paymail for any identity key. The registry decides that, below.
88
+ */
89
+ const parsedHandle = parsePaymail(firstParam(params.handle) ?? '')
90
+ const prefilledHandle = parsedHandle ? `${parsedHandle.handle}@${parsedHandle.domain}` : ''
91
+ const handleDomain = parsedHandle?.domain
92
+ const sourceParam = firstParam(params.source)
93
+ const source: ContactSource = sourceParam && SOURCES.has(sourceParam) ? (sourceParam as ContactSource) : 'qr'
94
+ // The only path with no identity key yet: the plain "New Contact" button on
95
+ // the Contacts list. Everywhere else (scan, deep link, search, the payment
96
+ // success screen) arrives with one already known, and the row stays read-only.
97
+ const manualEntry = prefilledIdentityKey === ''
98
+
99
+ const [name, setName] = useState(firstParam(params.name) ?? '')
100
+ const [identifierInput, setIdentifierInput] = useState('')
101
+ const [saving, setSaving] = useState(false)
102
+ const [activity, setActivity] = useState<ContactActivityItem[]>([])
103
+
104
+ const identityKey = manualEntry ? identifierInput.trim().toLowerCase() : prefilledIdentityKey
105
+ const identityKeyValid = isCompressedIdentityKey(identityKey)
106
+ const nameValid = name.trim().length > 0
107
+
108
+ /** Two strings rather than the config object, which is rebuilt every call. */
109
+ const registry = getHandleRegistryConfig(selectedNetwork)
110
+ const registryDomain = registry?.domain
111
+ const registryUrl = registry?.url
112
+ const registryClient = useMemo(
113
+ () =>
114
+ registryDomain && registryUrl
115
+ ? createHandleRegistryClient({ pinned: { domain: registryDomain, url: registryUrl } })
116
+ : null,
117
+ [registryDomain, registryUrl]
118
+ )
119
+
120
+ /**
121
+ * The handle this key actually holds, as the registry answers for it — the
122
+ * only version of the param worth storing.
123
+ *
124
+ * `cachedHandle` is drawn on ContactScreen under a shield reading "only they
125
+ * can change it", and it is the line Pay's contacts tier offers this person
126
+ * by. An asserted string is neither of those things, so it is checked against
127
+ * the key it claims before it is written, on the domain it names (the same
128
+ * domain ContactScreen's own refresh asks). An unproven one is simply not a
129
+ * handle here: that refresh fills the column in later if it is real, and no
130
+ * screen has to un-say a shield in the meantime.
131
+ */
132
+ const [provenFor, setProvenFor] = useState<{ identityKey: string; handle: string } | null>(null)
133
+ // Held against the pair it was proven for, rather than reset when either
134
+ // changes: the manual-entry field rewrites `identityKey` on every keystroke,
135
+ // and a proof carried over to the next key would be exactly the claim this
136
+ // is here to refuse.
137
+ const verifiedHandle =
138
+ provenFor?.identityKey === identityKey && provenFor?.handle === prefilledHandle ? prefilledHandle : ''
139
+ useEffect(() => {
140
+ if (!registryClient || !prefilledHandle || !identityKeyValid) return
141
+ let cancelled = false
142
+ void registryClient.lookupProfile(identityKey, handleDomain).then(seen => {
143
+ if (cancelled || seen.kind !== 'found' || seen.profile.paymail !== prefilledHandle) return
144
+ setProvenFor({ identityKey, handle: prefilledHandle })
145
+ })
146
+ return () => {
147
+ cancelled = true
148
+ }
149
+ }, [registryClient, prefilledHandle, handleDomain, identityKey, identityKeyValid])
150
+
151
+ useEffect(() => {
152
+ if (!identityKeyValid) {
153
+ setActivity([])
154
+ return
155
+ }
156
+ let cancelled = false
157
+ void getContactActivity({
158
+ wallet: managers?.permissionsManager as never,
159
+ adminOriginator,
160
+ settlementsDb: storage?.sqliteDb as never,
161
+ identityKey
162
+ }).then(items => {
163
+ if (!cancelled) setActivity(items)
164
+ })
165
+ return () => {
166
+ cancelled = true
167
+ }
168
+ }, [identityKey, identityKeyValid, managers, adminOriginator, storage])
169
+
170
+ const onSave = useCallback(async () => {
171
+ if (!store || walletUserId === null || !identityKeyValid || !nameValid) return
172
+ setSaving(true)
173
+ try {
174
+ await store.createContact({
175
+ userId: walletUserId,
176
+ identityKey,
177
+ name: name.trim(),
178
+ ...(verifiedHandle ? { cachedHandle: verifiedHandle } : {}),
179
+ source: manualEntry ? 'manual' : source
180
+ })
181
+ showToast(t('contact_saved'), { type: 'success' })
182
+ router.replace({ pathname: '/contact', params: { identityKey } } as never)
183
+ } finally {
184
+ setSaving(false)
185
+ }
186
+ }, [
187
+ store,
188
+ walletUserId,
189
+ identityKey,
190
+ identityKeyValid,
191
+ name,
192
+ nameValid,
193
+ verifiedHandle,
194
+ manualEntry,
195
+ source,
196
+ router,
197
+ t
198
+ ])
199
+
200
+ const canSave = nameValid && identityKeyValid && !saving
201
+ const showIdentifierError = manualEntry && identifierInput.trim().length > 0 && !identityKeyValid
202
+
203
+ return (
204
+ <View style={[styles.container, { backgroundColor: colors.background, paddingTop: insets.top }]}>
205
+ <View style={[styles.header, { borderBottomColor: colors.separator }]}>
206
+ <PressableScale
207
+ onPress={() => router.back()}
208
+ haptic="tap"
209
+ style={styles.headerBtn}
210
+ accessibilityRole="button"
211
+ accessibilityLabel={t('go_back')}
212
+ >
213
+ <Ionicons
214
+ name={I18nManager.isRTL ? 'chevron-forward' : 'chevron-back'}
215
+ size={24}
216
+ color={colors.textSecondary}
217
+ />
218
+ </PressableScale>
219
+ <Text style={[styles.headerTitle, { color: colors.textPrimary }]} numberOfLines={1}>
220
+ {t('contact_new_title')}
221
+ </Text>
222
+ <View style={styles.headerBtn} />
223
+ </View>
224
+
225
+ <ScrollView contentContainerStyle={styles.content} keyboardShouldPersistTaps="handled">
226
+ <View style={styles.hero}>
227
+ <ContactSigil identityKey={identityKeyValid ? identityKey : '0'.repeat(66)} size={72} radius={24} />
228
+ <Text style={[styles.heroKey, { color: identityKeyValid ? colors.textPrimary : colors.textTertiary }]}>
229
+ {identityKeyValid ? abbreviateKey(identityKey) : t('contact_identifier')}
230
+ </Text>
231
+ {/* Only once the registry has confirmed it belongs to this key: a
232
+ handle shown here is the same claim the shield makes on the
233
+ screen this route replaces itself with. */}
234
+ <Text style={[styles.heroCaption, { color: colors.textTertiary }]}>
235
+ {verifiedHandle || t('contact_no_handle_registered')}
236
+ </Text>
237
+ </View>
238
+
239
+ <GroupedSection header={t('contact_name_section')} footer={t('contact_new_name_hint')}>
240
+ <View style={styles.nameRow}>
241
+ <View style={styles.nameLeading}>
242
+ <Ionicons name="pencil-outline" size={17} color={colors.textSecondary} />
243
+ </View>
244
+ <TextInput
245
+ value={name}
246
+ onChangeText={setName}
247
+ placeholder={t('contact_new_title')}
248
+ placeholderTextColor={colors.textTertiary}
249
+ autoFocus={!manualEntry}
250
+ returnKeyType="done"
251
+ style={[styles.nameInput, { color: colors.textPrimary }]}
252
+ />
253
+ </View>
254
+ </GroupedSection>
255
+
256
+ <GroupedSection
257
+ header={t('contact_identifier')}
258
+ footer={showIdentifierError ? t('contact_identifier_invalid') : undefined}
259
+ >
260
+ {manualEntry ? (
261
+ <TextInput
262
+ value={identifierInput}
263
+ onChangeText={setIdentifierInput}
264
+ placeholder={t('contact_identifier_placeholder')}
265
+ placeholderTextColor={colors.textTertiary}
266
+ autoCapitalize="none"
267
+ autoCorrect={false}
268
+ autoFocus
269
+ style={[styles.identifierInput, { color: showIdentifierError ? colors.error : colors.textPrimary }]}
270
+ />
271
+ ) : (
272
+ <IdentifierRow identityKey={identityKey} />
273
+ )}
274
+ </GroupedSection>
275
+
276
+ {activity.length > 0 && (
277
+ <>
278
+ <Text style={[styles.sectionTitle, { color: colors.textTertiary }]}>
279
+ {t('contact_activity').toUpperCase()}
280
+ </Text>
281
+ <ContactActivityList items={activity} identityKey={identityKey} />
282
+ </>
283
+ )}
284
+ </ScrollView>
285
+
286
+ <View style={[styles.footer, { paddingBottom: Math.max(insets.bottom, spacing.lg) }]}>
287
+ <PressableScale
288
+ onPress={onSave}
289
+ disabled={!canSave}
290
+ haptic="confirm"
291
+ style={[styles.cta, { backgroundColor: canSave ? colors.accent : colors.fill }]}
292
+ accessibilityRole="button"
293
+ accessibilityState={{ disabled: !canSave }}
294
+ >
295
+ <Ionicons name="person-add-outline" size={18} color={canSave ? colors.textOnAccent : colors.textTertiary} />
296
+ <Text style={[styles.ctaText, { color: canSave ? colors.textOnAccent : colors.textTertiary }]}>
297
+ {t('contact_save')}
298
+ </Text>
299
+ </PressableScale>
300
+ </View>
301
+ </View>
302
+ )
303
+ }
304
+
305
+ export default NewContactScreen
306
+
307
+ const styles = StyleSheet.create({
308
+ container: { flex: 1 },
309
+ header: {
310
+ flexDirection: 'row',
311
+ alignItems: 'center',
312
+ justifyContent: 'space-between',
313
+ paddingHorizontal: spacing.sm,
314
+ paddingVertical: spacing.md,
315
+ borderBottomWidth: StyleSheet.hairlineWidth
316
+ },
317
+ headerBtn: { width: 44, height: 44, alignItems: 'center', justifyContent: 'center' },
318
+ headerTitle: { ...typography.headline, fontWeight: '600', flex: 1, textAlign: 'center' },
319
+ content: { paddingTop: spacing.lg, paddingBottom: spacing.lg },
320
+ hero: {
321
+ alignItems: 'center',
322
+ gap: spacing.sm,
323
+ paddingHorizontal: spacing.xl,
324
+ paddingTop: spacing.sm,
325
+ paddingBottom: spacing.xl
326
+ },
327
+ heroKey: { fontSize: 18, lineHeight: 24, fontWeight: '700', fontFamily: 'monospace', marginTop: spacing.xs },
328
+ heroCaption: { ...typography.footnote },
329
+ nameRow: {
330
+ flexDirection: 'row',
331
+ alignItems: 'center',
332
+ minHeight: 52,
333
+ paddingLeft: spacing.xs,
334
+ paddingRight: spacing.lg
335
+ },
336
+ nameLeading: { width: 44, height: 44, alignItems: 'center', justifyContent: 'center' },
337
+ nameInput: { ...typography.body, flex: 1, minWidth: 0, paddingVertical: spacing.md, paddingHorizontal: 0 },
338
+ identifierInput: {
339
+ ...typography.subhead,
340
+ fontFamily: 'monospace',
341
+ minHeight: 48,
342
+ paddingHorizontal: spacing.lg,
343
+ paddingVertical: spacing.md
344
+ },
345
+ sectionTitle: {
346
+ fontSize: 10.5,
347
+ fontWeight: '700',
348
+ letterSpacing: 1.3,
349
+ paddingHorizontal: spacing.xl,
350
+ paddingBottom: spacing.sm
351
+ },
352
+ footer: { paddingHorizontal: spacing.lg, paddingTop: spacing.sm },
353
+ cta: {
354
+ flexDirection: 'row',
355
+ alignItems: 'center',
356
+ justifyContent: 'center',
357
+ gap: spacing.sm,
358
+ paddingVertical: spacing.md + 2,
359
+ borderRadius: radii.md
360
+ },
361
+ ctaText: { ...typography.subhead, fontWeight: '600' }
362
+ })
@@ -11,7 +11,7 @@
11
11
  * `?cell=` values survive as deep-link aliases: any `pay-*` opens the send form
12
12
  * (`pay-nearby` with the scanner up), any `get-*` opens that method directly.
13
13
  */
14
- import React, { useCallback, useEffect, useMemo, useState } from 'react'
14
+ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
15
15
  import { I18nManager, InteractionManager, Modal, StyleSheet, Text, TouchableOpacity, View } from 'react-native'
16
16
  import { useSafeAreaInsets } from 'react-native-safe-area-context'
17
17
  import { useTranslation } from 'react-i18next'
@@ -19,7 +19,8 @@ import { useTranslation } from 'react-i18next'
19
19
  import PressableScale from '../components/ui/PressableScale'
20
20
  import { partitionQueueByGrace } from '../../core/offline/queueGrace'
21
21
  import PaymentQrDisplay from '../components/pay/PaymentQrDisplay'
22
- import UniversalSend from '../components/pay/UniversalSend'
22
+ import UniversalSend, { type UniversalSendHandle } from '../components/pay/UniversalSend'
23
+ import type { PayStep } from '../components/pay/StepBar'
23
24
  import RequestHub, { requestSatsFrom, type RequestMethod } from '../components/pay/RequestHub'
24
25
  import NearbyFlow from '../components/pay/NearbyFlow'
25
26
  import HandleReceive from '../components/pay/HandleReceive'
@@ -423,7 +424,13 @@ export function PayScreen({ dismissTo = '/' }: PayScreenProps = {}) {
423
424
  * trying to leave behind, which puts them one edge-swipe away instead of
424
425
  * discarding them.
425
426
  */
427
+ // The three-step send form owns its own step; the header's one back
428
+ // chevron walks it back a step before it leaves the screen (no second back
429
+ // control inside the form — 2026-09-18 design).
430
+ const sendRef = useRef<UniversalSendHandle>(null)
431
+ const [payStep, setPayStep] = useState<PayStep>('who')
426
432
  const goBack = useCallback(() => {
433
+ if (sendRef.current?.back()) return
427
434
  router.dismissTo(dismissTo)
428
435
  }, [dismissTo])
429
436
 
@@ -466,6 +473,8 @@ export function PayScreen({ dismissTo = '/' }: PayScreenProps = {}) {
466
473
  <>
467
474
  {offlineNotice}
468
475
  <UniversalSend
476
+ ref={sendRef}
477
+ onStepChange={setPayStep}
469
478
  initialTarget={initialTarget}
470
479
  initialSats={initialSats}
471
480
  initialTokenAmount={initialTokenAmount}
@@ -545,11 +554,15 @@ export function PayScreen({ dismissTo = '/' }: PayScreenProps = {}) {
545
554
  {direction === 'pay'
546
555
  ? nearbySession
547
556
  ? t('pay_cell_nearby_pay')
548
- : asset
549
- ? // The coin was chosen on Home; this is the one place the
550
- // Pay screen says which one it is armed with.
551
- t('pay_direction_pay_asset', { ticker: asset.ticker })
552
- : t('pay_direction_pay')
557
+ : payStep === 'review'
558
+ ? // The last step is named for what it is: a review, before the
559
+ // button that names the exact figure and asset being sent.
560
+ t('pay_review_title')
561
+ : asset
562
+ ? // The coin was chosen on Home; this is the one place the
563
+ // Pay screen says which one it is armed with.
564
+ t('pay_direction_pay_asset', { ticker: asset.ticker })
565
+ : t('pay_direction_pay')
553
566
  : t(method ? METHOD_TITLE_KEYS[method] : 'local_pay_request')}
554
567
  </Text>
555
568
  <View style={styles.headerBtn} />