@bsv/expo-wallet-toolbox 0.2.1 → 0.3.1
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 +232 -0
- package/README.md +34 -9
- package/core/amountFormatHelpers.ts +16 -30
- package/core/context/LocalStorageProvider.tsx +29 -4
- package/core/context/WalletContext.tsx +15 -3
- package/core/i18n/translations.tsx +12 -0
- package/core/index.ts +16 -5
- package/core/localpay/build.ts +4 -1
- package/core/localpay/pending.ts +5 -2
- package/core/pay/counterparty.ts +159 -0
- package/core/pay/creditInbox.ts +0 -3
- package/core/pay/patp.ts +181 -0
- package/core/pay/rails/address.ts +47 -7
- package/core/pay/rails/handle.ts +24 -14
- package/core/peerpay/handleResendRequests.ts +1 -2
- package/core/services/secrets/migration.ts +3 -2
- package/core/services/secrets/store.ts +6 -4
- package/core/services/vault/backupAttestation.ts +17 -2
- package/core/storage/StorageExpoSQLite.ts +37 -0
- package/core/storage/methods/listActionsSql.ts +9 -0
- package/core/theme/sigilPalette.ts +83 -0
- package/package.json +5 -2
- package/ui/components/pay/HandleReceive.tsx +4 -4
- package/ui/components/ui/AppLogo.tsx +9 -1
- package/ui/components/ui/Sigil.tsx +62 -0
- package/ui/components/wallet/ActivityRow.tsx +87 -24
- package/ui/isImageUrl.ts +16 -3
- package/ui/screens/ConnectionsScreen.tsx +12 -2
- package/ui/screens/TrustScreen.tsx +105 -23
- package/ui/screens/WalletCheckScreen.tsx +3 -3
- package/ui/screens/WalletConfigScreen.tsx +23 -104
- package/ui/screens/WalletHomeScreen.tsx +38 -19
|
@@ -6,12 +6,16 @@ import {
|
|
|
6
6
|
ScrollView,
|
|
7
7
|
TextInput,
|
|
8
8
|
TouchableOpacity,
|
|
9
|
-
Image,
|
|
10
9
|
Modal,
|
|
11
10
|
ActivityIndicator
|
|
12
11
|
} from 'react-native'
|
|
12
|
+
import type { StyleProp, ViewStyle } from 'react-native'
|
|
13
|
+
import { SvgUri } from 'react-native-svg'
|
|
13
14
|
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
14
15
|
import { useTranslation } from 'react-i18next'
|
|
16
|
+
// Same deep path WalletContext uses: the package root does not re-export the
|
|
17
|
+
// settings types.
|
|
18
|
+
import type { Certifier as WalletCertifier } from '@bsv/wallet-toolbox-mobile/out/src/WalletSettingsManager'
|
|
15
19
|
import validateTrust from '../validateTrust'
|
|
16
20
|
import { GroupedSection } from '../components/ui/GroupedList'
|
|
17
21
|
import { showAlert } from '../components/ui/AlertCard'
|
|
@@ -34,6 +38,22 @@ function loadIonicons(): IoniconsComponent {
|
|
|
34
38
|
return ioniconsComponent
|
|
35
39
|
}
|
|
36
40
|
|
|
41
|
+
/**
|
|
42
|
+
* expo-image's package entry is raw TypeScript (`main: src/index.ts`), which
|
|
43
|
+
* Jest does not transform under this package's documented config. Requiring
|
|
44
|
+
* it at render time keeps the `ui` barrel importable in consumers' test
|
|
45
|
+
* suites, the same boundary treatment @expo/vector-icons gets above.
|
|
46
|
+
*/
|
|
47
|
+
type ExpoImageComponent = typeof import('expo-image').Image
|
|
48
|
+
let expoImageComponent: ExpoImageComponent | undefined
|
|
49
|
+
function loadExpoImage(): ExpoImageComponent {
|
|
50
|
+
if (!expoImageComponent) {
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
52
|
+
expoImageComponent = require('expo-image').Image as ExpoImageComponent
|
|
53
|
+
}
|
|
54
|
+
return expoImageComponent
|
|
55
|
+
}
|
|
56
|
+
|
|
37
57
|
/**
|
|
38
58
|
* expo-router is required lazily rather than imported at module scope: this
|
|
39
59
|
* file is barrel-exported from the package's `ui` entry point, and a static
|
|
@@ -53,12 +73,71 @@ function loadExpoRouter(): ExpoRouterModule {
|
|
|
53
73
|
}
|
|
54
74
|
|
|
55
75
|
// -------------------- Types --------------------
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
76
|
+
/**
|
|
77
|
+
* The wallet's own settings type, not a local copy: a local copy is how this
|
|
78
|
+
* screen came to read `icon` while every shipped default (and the library's
|
|
79
|
+
* WalletSettingsManager) stores the URL as `iconUrl`, so the built-in
|
|
80
|
+
* certifiers never showed their icons.
|
|
81
|
+
*/
|
|
82
|
+
export type Certifier = WalletCertifier
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Builds before 0.3.0 saved a user-added provider's icon under `icon`. A
|
|
86
|
+
* wallet upgraded in place holds those entries next to `iconUrl` ones, so the
|
|
87
|
+
* screen accepts both on load and writes only the canonical field back.
|
|
88
|
+
* `iconUrl` wins if an entry somehow carries both.
|
|
89
|
+
*/
|
|
90
|
+
export function normaliseCertifier(c: Certifier & { icon?: string }): Certifier {
|
|
91
|
+
const { icon, ...rest } = c
|
|
92
|
+
if (rest.iconUrl || !icon) return rest
|
|
93
|
+
return { ...rest, iconUrl: icon }
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* An icon URL is a promise the certifier's manifest made, not a guarantee: two
|
|
98
|
+
* of the shipped defaults point at .ico favicons the iOS decoder rejects, and
|
|
99
|
+
* any provider can move its file. The initial-letter tile is therefore the
|
|
100
|
+
* fallback for a failed load as well as for a missing URL, so a broken icon
|
|
101
|
+
* never leaves an empty square where the letter used to be.
|
|
102
|
+
*/
|
|
103
|
+
function CertifierIcon({
|
|
104
|
+
url,
|
|
105
|
+
name,
|
|
106
|
+
style,
|
|
107
|
+
placeholderStyle,
|
|
108
|
+
colors
|
|
109
|
+
}: {
|
|
110
|
+
url?: string
|
|
111
|
+
name?: string
|
|
112
|
+
style: React.ComponentProps<ExpoImageComponent>['style']
|
|
113
|
+
placeholderStyle: StyleProp<ViewStyle>
|
|
114
|
+
colors: { accent: string; background: string }
|
|
115
|
+
}) {
|
|
116
|
+
const Image = loadExpoImage()
|
|
117
|
+
// Remembers which URL failed rather than a bare flag, so a corrected URL on
|
|
118
|
+
// the same row gets a fresh attempt.
|
|
119
|
+
const [failedUrl, setFailedUrl] = useState<string | null>(null)
|
|
120
|
+
if (!url || failedUrl === url) {
|
|
121
|
+
return (
|
|
122
|
+
<View style={[placeholderStyle, { backgroundColor: colors.accent }]}>
|
|
123
|
+
<Text style={{ color: colors.background, fontWeight: '700' }}>{name?.[0] || '?'}</Text>
|
|
124
|
+
</View>
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
// expo-image hands an SVG to the platform decoder, which on iOS drops
|
|
128
|
+
// percentage-positioned <text> and similar authoring shortcuts, so a vector
|
|
129
|
+
// mark can come out blank or with its glyph in a corner. react-native-svg's
|
|
130
|
+
// own parser is already in the bundle for the activity sigils and handles
|
|
131
|
+
// those, and its fetch or parse failures surface through onError like a
|
|
132
|
+
// raster load would. The wrapper carries the tile's size and radius.
|
|
133
|
+
if (/\.svg(?:[?#]|$)/i.test(url)) {
|
|
134
|
+
return (
|
|
135
|
+
<View style={[style as StyleProp<ViewStyle>, { overflow: 'hidden' }]}>
|
|
136
|
+
<SvgUri uri={url} width="100%" height="100%" onError={() => setFailedUrl(url)} />
|
|
137
|
+
</View>
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
return <Image source={{ uri: url }} style={style} onError={() => setFailedUrl(url)} />
|
|
62
141
|
}
|
|
63
142
|
|
|
64
143
|
// -------------------- Helpers --------------------
|
|
@@ -98,7 +177,10 @@ export function TrustScreen() {
|
|
|
98
177
|
|
|
99
178
|
// Source of truth from Settings — sort by trust descending so position matches priority
|
|
100
179
|
const initialTrusted: Certifier[] = useMemo(
|
|
101
|
-
() =>
|
|
180
|
+
() =>
|
|
181
|
+
(settings?.trustSettings?.trustedCertifiers || [])
|
|
182
|
+
.map(normaliseCertifier)
|
|
183
|
+
.sort((a, b) => b.trust - a.trust),
|
|
102
184
|
[settings?.trustSettings?.trustedCertifiers]
|
|
103
185
|
)
|
|
104
186
|
|
|
@@ -240,13 +322,13 @@ export function TrustScreen() {
|
|
|
240
322
|
]}
|
|
241
323
|
>
|
|
242
324
|
<View style={styles.certifierHeader}>
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
325
|
+
<CertifierIcon
|
|
326
|
+
url={item.iconUrl}
|
|
327
|
+
name={item.name}
|
|
328
|
+
style={styles.certifierIcon}
|
|
329
|
+
placeholderStyle={styles.certifierIconPlaceholder}
|
|
330
|
+
colors={colors}
|
|
331
|
+
/>
|
|
250
332
|
<View style={{ flex: 1 }}>
|
|
251
333
|
<Text style={[styles.certifierName, { color: colors.textPrimary }]} numberOfLines={1}>
|
|
252
334
|
{item.name}
|
|
@@ -554,13 +636,13 @@ function AddProviderModal({
|
|
|
554
636
|
{fieldsValid && (
|
|
555
637
|
<View style={[styles.previewBox, { borderColor: colors.separator, backgroundColor: colors.fillTertiary }]}>
|
|
556
638
|
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
639
|
+
<CertifierIcon
|
|
640
|
+
url={icon}
|
|
641
|
+
name={name}
|
|
642
|
+
style={styles.previewIcon}
|
|
643
|
+
placeholderStyle={[styles.previewIcon, { justifyContent: 'center', alignItems: 'center' }]}
|
|
644
|
+
colors={colors}
|
|
645
|
+
/>
|
|
564
646
|
<View style={{ marginLeft: spacing.md, flex: 1 }}>
|
|
565
647
|
<Text style={{ fontWeight: '700', color: colors.textPrimary }}>{name}</Text>
|
|
566
648
|
<Text style={[styles.previewKey, { color: colors.textSecondary }]}>{maskKey(identityKey)}</Text>
|
|
@@ -590,7 +672,7 @@ function AddProviderModal({
|
|
|
590
672
|
</TouchableOpacity>
|
|
591
673
|
<TouchableOpacity
|
|
592
674
|
disabled={!ready}
|
|
593
|
-
onPress={() => onAdd({ name, description, icon, identityKey })}
|
|
675
|
+
onPress={() => onAdd({ name, description, iconUrl: icon, identityKey })}
|
|
594
676
|
style={[styles.saveBtn, { backgroundColor: colors.accent, opacity: ready ? 1 : 0.5, flex: 0 }]}
|
|
595
677
|
>
|
|
596
678
|
<Ionicons name="shield-checkmark-outline" size={16} color={colors.background} />
|
|
@@ -17,7 +17,7 @@ import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
|
17
17
|
import { PeerPayClient } from '@bsv/message-box-client'
|
|
18
18
|
import { showAlert } from '../components/ui/AlertCard'
|
|
19
19
|
import { makeCreditClassifier } from '../../core/pay/creditErrors'
|
|
20
|
-
import { creditInboxOnce
|
|
20
|
+
import { creditInboxOnce } from '../../core/pay/creditInbox'
|
|
21
21
|
import { makeBeefRepair } from '../../core/pay/beefRepair'
|
|
22
22
|
import {
|
|
23
23
|
acceptWithRetry,
|
|
@@ -192,8 +192,8 @@ function useWalletCheckPorts(): WalletCheckPorts {
|
|
|
192
192
|
storage: storage ?? undefined,
|
|
193
193
|
classify,
|
|
194
194
|
accept: payment =>
|
|
195
|
-
acceptWithRetry(client, messageBoxUrl, payment,
|
|
196
|
-
internalizeIncoming(wallet as never, client, adminOriginator, p,
|
|
195
|
+
acceptWithRetry(client, messageBoxUrl, payment, p =>
|
|
196
|
+
internalizeIncoming(wallet as never, client, adminOriginator, p, repairBeef)
|
|
197
197
|
)
|
|
198
198
|
})
|
|
199
199
|
return { accepted: outcome.accepted }
|
|
@@ -24,7 +24,6 @@ import {
|
|
|
24
24
|
satoshisPerFiatUnit,
|
|
25
25
|
ExchangeRateContext,
|
|
26
26
|
DISPLAY_CURRENCY_OPTIONS,
|
|
27
|
-
recordBackupAttestation,
|
|
28
27
|
isBackupPushEnabled,
|
|
29
28
|
setBackupPushEnabled,
|
|
30
29
|
BACKUP_CHAINS,
|
|
@@ -33,7 +32,6 @@ import {
|
|
|
33
32
|
TaskBackupPush,
|
|
34
33
|
DEFAULT_BACKUP_URL,
|
|
35
34
|
setMockDriverEnabled,
|
|
36
|
-
UserContext,
|
|
37
35
|
NO_MESSAGE_BOX
|
|
38
36
|
} from '@bsv/expo-wallet-toolbox'
|
|
39
37
|
|
|
@@ -68,7 +66,6 @@ import { showToast } from '../components/ui/Toast'
|
|
|
68
66
|
import { PrivateKey } from '@bsv/sdk'
|
|
69
67
|
import { exportAllWalletDatabases } from '../exportDatabases'
|
|
70
68
|
import { importWalletDatabase } from '../importDatabases'
|
|
71
|
-
import { printRecoveryShares } from '../printRecoveryShares'
|
|
72
69
|
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
73
70
|
|
|
74
71
|
/**
|
|
@@ -108,29 +105,13 @@ function loadExpoRouter(): ExpoRouterModule {
|
|
|
108
105
|
return expoRouterMod
|
|
109
106
|
}
|
|
110
107
|
|
|
111
|
-
/**
|
|
112
|
-
* @react-native-clipboard/clipboard reaches for its native TurboModule at
|
|
113
|
-
* import time (`TurboModuleRegistry.getEnforcing`), which throws under Jest
|
|
114
|
-
* (no native binary registered there) even though the module itself
|
|
115
|
-
* transforms fine. Required lazily, only when a handler actually copies
|
|
116
|
-
* something, so importing the `ui` barrel never touches the native module.
|
|
117
|
-
* Same pattern as WalletHomeScreen.tsx's lazy clipboard load.
|
|
118
|
-
*/
|
|
119
|
-
type ClipboardModule = typeof import('@react-native-clipboard/clipboard').default
|
|
120
|
-
let clipboardModule: ClipboardModule | undefined
|
|
121
|
-
function loadClipboard(): ClipboardModule {
|
|
122
|
-
if (!clipboardModule) {
|
|
123
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
124
|
-
clipboardModule = require('@react-native-clipboard/clipboard').default as ClipboardModule
|
|
125
|
-
}
|
|
126
|
-
return clipboardModule
|
|
127
|
-
}
|
|
128
|
-
|
|
129
108
|
export function WalletConfigScreen() {
|
|
130
109
|
const versionLabel = useMemo(() => appVersionLabel(), [])
|
|
131
110
|
const { t } = useTranslation()
|
|
132
111
|
const { colors } = useTheme()
|
|
133
|
-
const { router } = loadExpoRouter()
|
|
112
|
+
const { router, useLocalSearchParams } = loadExpoRouter()
|
|
113
|
+
const { section } = useLocalSearchParams<{ section?: string }>()
|
|
114
|
+
const openBackup = section === 'backup'
|
|
134
115
|
const Ionicons = loadIonicons()
|
|
135
116
|
const {
|
|
136
117
|
managers,
|
|
@@ -146,8 +127,6 @@ export function WalletConfigScreen() {
|
|
|
146
127
|
const { getMnemonic, getRecoveredKey } = useLocalStorage()
|
|
147
128
|
const insets = useSafeAreaInsets()
|
|
148
129
|
|
|
149
|
-
const [isPrinting, setIsPrinting] = useState(false)
|
|
150
|
-
const [copiedMnemonic, setCopiedMnemonic] = useState(false)
|
|
151
130
|
const [switchingNetwork, setSwitchingNetwork] = useState(false)
|
|
152
131
|
const [networkExpanded, setNetworkExpanded] = useState(false)
|
|
153
132
|
const [isExporting, setIsExporting] = useState(false)
|
|
@@ -158,7 +137,10 @@ export function WalletConfigScreen() {
|
|
|
158
137
|
const [loggingOut, setLoggingOut] = useState(false)
|
|
159
138
|
const [storageBusy, setStorageBusy] = useState(false)
|
|
160
139
|
const [currencyExpanded, setCurrencyExpanded] = useState(false)
|
|
161
|
-
const [advancedExpanded, setAdvancedExpanded] = useState(
|
|
140
|
+
const [advancedExpanded, setAdvancedExpanded] = useState(openBackup)
|
|
141
|
+
const scrollRef = useRef<ScrollView>(null)
|
|
142
|
+
const [backupSectionY, setBackupSectionY] = useState<number | null>(null)
|
|
143
|
+
const scrolledToBackup = useRef(false)
|
|
162
144
|
const [thresholdExpanded, setThresholdExpanded] = useState(false)
|
|
163
145
|
const [thresholdSats, setThresholdSats] = useState(DEFAULT_AUTO_APPROVE_THRESHOLD)
|
|
164
146
|
const [thresholdInput, setThresholdInput] = useState('')
|
|
@@ -167,11 +149,21 @@ export function WalletConfigScreen() {
|
|
|
167
149
|
const [arcTokenInput, setArcTokenInput] = useState('')
|
|
168
150
|
const [arcSaving, setArcSaving] = useState(false)
|
|
169
151
|
const { satoshisPerUSD, usdToFiat = {} } = useContext(ExchangeRateContext)
|
|
170
|
-
const { appName } = useContext(UserContext)
|
|
171
152
|
|
|
172
153
|
const currentCurrency = settings?.currency || 'BSV'
|
|
173
154
|
const messageBox = useMessageBoxConfig(t)
|
|
174
155
|
|
|
156
|
+
useEffect(() => {
|
|
157
|
+
if (openBackup) setAdvancedExpanded(true)
|
|
158
|
+
else scrolledToBackup.current = false
|
|
159
|
+
}, [openBackup])
|
|
160
|
+
|
|
161
|
+
useEffect(() => {
|
|
162
|
+
if (!openBackup || backupSectionY === null || scrolledToBackup.current) return
|
|
163
|
+
scrollRef.current?.scrollTo({ y: backupSectionY, animated: false })
|
|
164
|
+
scrolledToBackup.current = true
|
|
165
|
+
}, [openBackup, backupSectionY])
|
|
166
|
+
|
|
175
167
|
// Load persisted auto-approve threshold
|
|
176
168
|
useEffect(() => {
|
|
177
169
|
AsyncStorage.getItem(AUTO_APPROVE_STORAGE_KEY).then(v => {
|
|
@@ -378,61 +370,6 @@ export function WalletConfigScreen() {
|
|
|
378
370
|
})
|
|
379
371
|
}, [])
|
|
380
372
|
|
|
381
|
-
const handleCopyMnemonic = async () => {
|
|
382
|
-
try {
|
|
383
|
-
// Copy mnemonic if available, otherwise fall back to primary key hex
|
|
384
|
-
const mnemonic = await getMnemonic()
|
|
385
|
-
if (mnemonic) {
|
|
386
|
-
loadClipboard().setString(mnemonic)
|
|
387
|
-
} else {
|
|
388
|
-
const wif = await getRecoveredKey()
|
|
389
|
-
if (!wif) return
|
|
390
|
-
loadClipboard().setString(PrivateKey.fromWif(wif).toHex())
|
|
391
|
-
}
|
|
392
|
-
setCopiedMnemonic(true)
|
|
393
|
-
setTimeout(() => setCopiedMnemonic(false), 2000)
|
|
394
|
-
} catch (error) {
|
|
395
|
-
console.error('Error retrieving recovery key:', error)
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
const handlePrintRecoveryShares = async () => {
|
|
400
|
-
if (isPrinting) return
|
|
401
|
-
setIsPrinting(true)
|
|
402
|
-
try {
|
|
403
|
-
const result = await printRecoveryShares({
|
|
404
|
-
mnemonic: await getMnemonic(),
|
|
405
|
-
recoveredKeyWif: await getRecoveredKey(),
|
|
406
|
-
appName
|
|
407
|
-
})
|
|
408
|
-
if (result.ok) {
|
|
409
|
-
// A resolved print sheet from Settings is the same genuine backup
|
|
410
|
-
// EnrollWizard records — the other route to satisfying the vault's
|
|
411
|
-
// backup prerequisite — so it records the same attestation, through
|
|
412
|
-
// the same writer.
|
|
413
|
-
//
|
|
414
|
-
// A failure here must be visible. The paper is real and correct; only
|
|
415
|
-
// the record is missing. Staying silent would send the user away
|
|
416
|
-
// believing they are covered, and the vault would refuse every deposit
|
|
417
|
-
// later with nothing on screen connecting the two.
|
|
418
|
-
if (!(await recordBackupAttestation(managers?.permissionsManager, adminOriginator, 'shares'))) {
|
|
419
|
-
showToast(t('vault_backup_attest_failed_printed'), { type: 'error' })
|
|
420
|
-
}
|
|
421
|
-
} else {
|
|
422
|
-
showToast(
|
|
423
|
-
result.reason === 'unsupported-word-count'
|
|
424
|
-
? t('vault_shares_word_count')
|
|
425
|
-
: 'Unable to access wallet key. Please authenticate and try again.',
|
|
426
|
-
{ type: 'error' }
|
|
427
|
-
)
|
|
428
|
-
}
|
|
429
|
-
} catch (error: any) {
|
|
430
|
-
console.info('[WalletConfig] Print recovery shares did not complete:', error?.message)
|
|
431
|
-
} finally {
|
|
432
|
-
setIsPrinting(false)
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
|
|
436
373
|
const handleExportData = async () => {
|
|
437
374
|
if (isExporting) return
|
|
438
375
|
setIsExporting(true)
|
|
@@ -545,7 +482,7 @@ export function WalletConfigScreen() {
|
|
|
545
482
|
<Text style={[localStyles.headerTitle, { color: colors.textPrimary }]}>{t('settings')}</Text>
|
|
546
483
|
<View style={localStyles.headerBack} />
|
|
547
484
|
</View>
|
|
548
|
-
<ScrollView style={{ flex: 1 }} contentContainerStyle={{ paddingTop: spacing.lg, paddingBottom: spacing.xxxl }}>
|
|
485
|
+
<ScrollView ref={scrollRef} style={{ flex: 1 }} contentContainerStyle={{ paddingTop: spacing.lg, paddingBottom: spacing.xxxl }}>
|
|
549
486
|
{/* ── Essentials ──
|
|
550
487
|
The rows a holder reaches for without being told to: what their money
|
|
551
488
|
is denominated in, how to hand an app access, and the two ways out of
|
|
@@ -845,6 +782,7 @@ export function WalletConfigScreen() {
|
|
|
845
782
|
</GroupedSection>
|
|
846
783
|
|
|
847
784
|
{/* ── Data & Security ── */}
|
|
785
|
+
<View onLayout={event => setBackupSectionY(event.nativeEvent.layout.y)}>
|
|
848
786
|
<GroupedSection header={t('data_and_security')}>
|
|
849
787
|
{/* Vault's primary entry lives on the wallet menu (below Payments).
|
|
850
788
|
The DEV mock toggle stays here. */}
|
|
@@ -862,31 +800,11 @@ export function WalletConfigScreen() {
|
|
|
862
800
|
}}
|
|
863
801
|
/>
|
|
864
802
|
)}
|
|
865
|
-
{/* Both are recovery material rather than everyday controls, so
|
|
866
|
-
they sit with the rest of the data-and-security rows. */}
|
|
867
803
|
<ListRow
|
|
868
|
-
label={t('
|
|
804
|
+
label={t('backup_wallet_keys', { defaultValue: 'Backup Wallet Keys' })}
|
|
869
805
|
icon="key-outline"
|
|
870
806
|
iconColor="#CC8400"
|
|
871
|
-
onPress={
|
|
872
|
-
showChevron={false}
|
|
873
|
-
trailing={
|
|
874
|
-
<TouchableOpacity onPress={handleCopyMnemonic} style={{ padding: spacing.xs }}>
|
|
875
|
-
<Ionicons
|
|
876
|
-
name={copiedMnemonic ? 'checkmark' : 'copy-outline'}
|
|
877
|
-
size={18}
|
|
878
|
-
color={copiedMnemonic ? colors.success : colors.textSecondary}
|
|
879
|
-
/>
|
|
880
|
-
</TouchableOpacity>
|
|
881
|
-
}
|
|
882
|
-
/>
|
|
883
|
-
<ListRow
|
|
884
|
-
label={t('print_recovery_keys')}
|
|
885
|
-
icon="print-outline"
|
|
886
|
-
iconColor="#5856D6"
|
|
887
|
-
onPress={handlePrintRecoveryShares}
|
|
888
|
-
showChevron={false}
|
|
889
|
-
trailing={isPrinting ? <ActivityIndicator size="small" /> : undefined}
|
|
807
|
+
onPress={() => router.push('/auth/mnemonic?flow=backup')}
|
|
890
808
|
/>
|
|
891
809
|
<ListRow
|
|
892
810
|
label={t('storage_row')}
|
|
@@ -920,6 +838,7 @@ export function WalletConfigScreen() {
|
|
|
920
838
|
isLast
|
|
921
839
|
/>
|
|
922
840
|
</GroupedSection>
|
|
841
|
+
</View>
|
|
923
842
|
|
|
924
843
|
{/* ── Private backup ──
|
|
925
844
|
Its own section purely so the footer can carry the disclosure: the app sends an
|
|
@@ -239,9 +239,10 @@ export function WalletHomeScreen({ topLeft }: WalletHomeScreenProps = {}) {
|
|
|
239
239
|
refreshProof,
|
|
240
240
|
settings,
|
|
241
241
|
walletBuilt,
|
|
242
|
+
walletBuilding,
|
|
242
243
|
buildWalletFromMnemonic
|
|
243
244
|
} = useWallet()
|
|
244
|
-
const {
|
|
245
|
+
const { createMnemonic, hasStoredIdentity, secretsReady } = useLocalStorage()
|
|
245
246
|
const { satoshisPerUSD, usdToFiat = {} } = useContext(ExchangeRateContext)
|
|
246
247
|
const currency = settings?.currency || 'BSV'
|
|
247
248
|
const online = useOnline()
|
|
@@ -250,7 +251,7 @@ export function WalletHomeScreen({ topLeft }: WalletHomeScreenProps = {}) {
|
|
|
250
251
|
/**
|
|
251
252
|
* Apple HIG: never ask for Face ID/Touch ID before the user has done
|
|
252
253
|
* something that explains why. Creating a wallet needs biometric-gated
|
|
253
|
-
* storage (
|
|
254
|
+
* storage (createMnemonic below), so building one eagerly on first mount —
|
|
254
255
|
* as this screen used to — put a biometric prompt in front of a user who
|
|
255
256
|
* had not yet tapped anything. Instead, wallet creation is deferred until
|
|
256
257
|
* the first Pay or Get Paid tap (see destinationPress below), behind a
|
|
@@ -267,45 +268,62 @@ export function WalletHomeScreen({ topLeft }: WalletHomeScreenProps = {}) {
|
|
|
267
268
|
const creatingWalletRef = useRef(false)
|
|
268
269
|
const ensureWalletExists = useCallback(async (): Promise<boolean> => {
|
|
269
270
|
if (managers.permissionsManager) return true
|
|
270
|
-
if (creatingWalletRef.current) return false
|
|
271
|
+
if (!secretsReady || walletBuilding || creatingWalletRef.current) return false
|
|
271
272
|
creatingWalletRef.current = true
|
|
272
273
|
try {
|
|
274
|
+
// A missing manager during migration, unlock, or a failed build does
|
|
275
|
+
// not mean the device has no wallet. Never replace that stored identity.
|
|
276
|
+
if (await hasStoredIdentity()) return false
|
|
273
277
|
const wallet = generateMnemonicWallet()
|
|
274
|
-
const stored = await
|
|
278
|
+
const stored = await createMnemonic(wallet.mnemonic)
|
|
275
279
|
if (!stored) {
|
|
276
280
|
// Biometric access was needed and unavailable/declined — same dead
|
|
277
281
|
// end onboarding's own generate flow hits. Send the user there to
|
|
278
282
|
// retry explicitly rather than silently failing the tap.
|
|
279
|
-
router.replace('/auth/mnemonic')
|
|
283
|
+
if (!(await hasStoredIdentity())) router.replace('/auth/mnemonic')
|
|
280
284
|
return false
|
|
281
285
|
}
|
|
286
|
+
try {
|
|
287
|
+
await backupAttestation.markPending(wallet.identityKey)
|
|
288
|
+
} catch (error) {
|
|
289
|
+
console.warn('[WalletHome] Could not record pending backup reminder:', error)
|
|
290
|
+
}
|
|
282
291
|
await buildWalletFromMnemonic(wallet.mnemonic)
|
|
283
292
|
return true
|
|
293
|
+
} catch (error) {
|
|
294
|
+
console.warn('[WalletHome] Wallet creation did not complete:', error)
|
|
295
|
+
return false
|
|
284
296
|
} finally {
|
|
285
297
|
creatingWalletRef.current = false
|
|
286
298
|
}
|
|
287
|
-
}, [managers.permissionsManager,
|
|
299
|
+
}, [managers.permissionsManager, secretsReady, walletBuilding, hasStoredIdentity, createMnemonic, buildWalletFromMnemonic, router])
|
|
288
300
|
|
|
289
301
|
const [pendingDestination, setPendingDestination] = useState<string | null>(null)
|
|
290
302
|
const [showBiometricAdvisory, setShowBiometricAdvisory] = useState(false)
|
|
291
303
|
const [creatingWalletFromAdvisory, setCreatingWalletFromAdvisory] = useState(false)
|
|
292
304
|
|
|
293
305
|
const destinationPress = useCallback(
|
|
294
|
-
(destination: string) => {
|
|
306
|
+
async (destination: string) => {
|
|
295
307
|
if (managers.permissionsManager) {
|
|
296
308
|
router.push(destination as Parameters<typeof router.push>[0])
|
|
297
309
|
return
|
|
298
310
|
}
|
|
311
|
+
if (!secretsReady || walletBuilding) return
|
|
312
|
+
try {
|
|
313
|
+
if (await hasStoredIdentity()) return
|
|
314
|
+
} catch {
|
|
315
|
+
return
|
|
316
|
+
}
|
|
299
317
|
setPendingDestination(destination)
|
|
300
318
|
setShowBiometricAdvisory(true)
|
|
301
319
|
},
|
|
302
|
-
[managers.permissionsManager, router]
|
|
320
|
+
[managers.permissionsManager, secretsReady, walletBuilding, hasStoredIdentity, router]
|
|
303
321
|
)
|
|
304
322
|
|
|
305
323
|
// ── backup reminder ─────────────────────────────────────────────────
|
|
306
324
|
/**
|
|
307
|
-
*
|
|
308
|
-
*
|
|
325
|
+
* Remind only identities created with an explicit pending-backup record.
|
|
326
|
+
* Older wallets without tracking have unknown status. Re-check on focus so
|
|
309
327
|
* dismissing the card never sticks for the session — it reappears the
|
|
310
328
|
* moment the user lands back on the main page, until they actually back
|
|
311
329
|
* up or import. Same advisory attestation the vault gate reads.
|
|
@@ -313,6 +331,7 @@ export function WalletHomeScreen({ topLeft }: WalletHomeScreenProps = {}) {
|
|
|
313
331
|
const [showBackupReminder, setShowBackupReminder] = useState(false)
|
|
314
332
|
useFocusEffect(
|
|
315
333
|
useCallback(() => {
|
|
334
|
+
setShowBackupReminder(false)
|
|
316
335
|
if (!walletBuilt) return
|
|
317
336
|
const wallet = managers.permissionsManager
|
|
318
337
|
if (!wallet) return
|
|
@@ -320,12 +339,11 @@ export function WalletHomeScreen({ topLeft }: WalletHomeScreenProps = {}) {
|
|
|
320
339
|
;(async () => {
|
|
321
340
|
try {
|
|
322
341
|
const { publicKey } = await wallet.getPublicKey({ identityKey: true }, adminOriginator)
|
|
323
|
-
const
|
|
324
|
-
if (!cancelled) setShowBackupReminder(
|
|
342
|
+
const needsReminder = await backupAttestation.needsReminder(publicKey)
|
|
343
|
+
if (!cancelled) setShowBackupReminder(needsReminder)
|
|
325
344
|
} catch {
|
|
326
|
-
//
|
|
327
|
-
|
|
328
|
-
if (!cancelled) setShowBackupReminder(true)
|
|
345
|
+
// An unavailable status is not proof that the wallet is unbacked.
|
|
346
|
+
if (!cancelled) setShowBackupReminder(false)
|
|
329
347
|
}
|
|
330
348
|
})()
|
|
331
349
|
return () => {
|
|
@@ -381,8 +399,7 @@ export function WalletHomeScreen({ topLeft }: WalletHomeScreenProps = {}) {
|
|
|
381
399
|
|
|
382
400
|
/**
|
|
383
401
|
* Whether a wallet is already stored on this device, checked prompt-free
|
|
384
|
-
*
|
|
385
|
-
* itself finishes building. That build gap is briefly indistinguishable
|
|
402
|
+
* after migration and the initial build settle. That build gap is briefly indistinguishable
|
|
386
403
|
* from "no wallet at all" — both show no permissions manager — and two
|
|
387
404
|
* things key off telling them apart: ImportFromBackupPrompt below (must
|
|
388
405
|
* not flash "import" over an existing user's already-populated screen)
|
|
@@ -393,6 +410,8 @@ export function WalletHomeScreen({ topLeft }: WalletHomeScreenProps = {}) {
|
|
|
393
410
|
*/
|
|
394
411
|
const [knownNoStoredIdentity, setKnownNoStoredIdentity] = useState(false)
|
|
395
412
|
useEffect(() => {
|
|
413
|
+
setKnownNoStoredIdentity(false)
|
|
414
|
+
if (!secretsReady || walletBuilding) return
|
|
396
415
|
let cancelled = false
|
|
397
416
|
;(async () => {
|
|
398
417
|
try {
|
|
@@ -405,7 +424,7 @@ export function WalletHomeScreen({ topLeft }: WalletHomeScreenProps = {}) {
|
|
|
405
424
|
return () => {
|
|
406
425
|
cancelled = true
|
|
407
426
|
}
|
|
408
|
-
}, [hasStoredIdentity])
|
|
427
|
+
}, [hasStoredIdentity, secretsReady, walletBuilding])
|
|
409
428
|
|
|
410
429
|
// ── balance ─────────────────────────────────────────────────────────
|
|
411
430
|
/**
|
|
@@ -1462,7 +1481,7 @@ export function WalletHomeScreen({ topLeft }: WalletHomeScreenProps = {}) {
|
|
|
1462
1481
|
/>
|
|
1463
1482
|
|
|
1464
1483
|
<ImportFromBackupPrompt
|
|
1465
|
-
visible={!hasWallet && knownNoStoredIdentity}
|
|
1484
|
+
visible={!hasWallet && secretsReady && !walletBuilding && knownNoStoredIdentity}
|
|
1466
1485
|
onImport={() => router.push('/auth/mnemonic?flow=import')}
|
|
1467
1486
|
/>
|
|
1468
1487
|
</View>
|