@bsv/expo-wallet-toolbox 0.3.0 → 0.4.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.
@@ -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 { setMnemonic: storeMnemonic, hasStoredIdentity } = useLocalStorage()
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 (setMnemonic below), so building one eagerly on first mount —
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 storeMnemonic(wallet.mnemonic)
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, storeMnemonic, buildWalletFromMnemonic, router])
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
- * Once a wallet exists, ask whether this identity has ever attested a
308
- * backup. Re-checked on every focus of this screen (not just mount) so
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 attested = await backupAttestation.get(publicKey)
324
- if (!cancelled) setShowBackupReminder(attested === null)
342
+ const needsReminder = await backupAttestation.needsReminder(publicKey)
343
+ if (!cancelled) setShowBackupReminder(needsReminder)
325
344
  } catch {
326
- // Advisory only — if the check fails, err toward reminding rather
327
- // than silently skipping it.
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
- * (no biometric, no wallet build) so it settles well before the wallet
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>