@bsv/expo-wallet-toolbox 0.12.0 → 0.13.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 (53) hide show
  1. package/CHANGELOG.md +71 -0
  2. package/core/backup/erase.ts +7 -1
  3. package/core/backup/preference.ts +12 -4
  4. package/core/backup/push.ts +8 -1
  5. package/core/backup/status.ts +6 -2
  6. package/core/context/WalletContext.tsx +841 -236
  7. package/core/i18n/translations.tsx +376 -0
  8. package/core/identity/handleRegistry/registration.ts +57 -3
  9. package/core/index.ts +24 -1
  10. package/core/mandala/createRuntime.ts +3 -3
  11. package/core/mandala/runtime.ts +7 -2
  12. package/core/mnemonicWallet.ts +46 -40
  13. package/core/monitor/MonitorSupervisor.ts +35 -1
  14. package/core/monitor/TaskCreditInbox.ts +24 -0
  15. package/core/pay/rails/handle.ts +4 -2
  16. package/core/peerpay/outbox.ts +11 -1
  17. package/core/profiles/assertProfileEmpty.ts +287 -0
  18. package/core/profiles/discovery.ts +84 -0
  19. package/core/profiles/profileLabel.ts +13 -0
  20. package/core/profiles/profileStore.ts +265 -0
  21. package/core/profiles/purgeProfile.ts +76 -0
  22. package/core/profiles/removeProfile.ts +257 -0
  23. package/core/push/events.ts +52 -5
  24. package/core/push/identities.ts +55 -0
  25. package/core/push/profilePush.ts +143 -0
  26. package/core/push/registration.ts +362 -24
  27. package/core/push/types.ts +5 -1
  28. package/core/services/arcTokenStorage.ts +17 -2
  29. package/core/services/vault/transfers.ts +6 -1
  30. package/core/services/vault/vaultStore.ts +16 -3
  31. package/core/stores/ConnectionStore.ts +11 -7
  32. package/core/toolboxConfig.ts +7 -3
  33. package/core/userAvatar.ts +12 -5
  34. package/core/walletDbRegistry.ts +73 -0
  35. package/package.json +1 -1
  36. package/ui/backupShares.ts +2 -3
  37. package/ui/components/pay/MessageBoxConfig.tsx +6 -5
  38. package/ui/components/ui/PencilEditField.tsx +5 -2
  39. package/ui/components/wallet/Balance.tsx +3 -1
  40. package/ui/components/wallet/ProfileButton.tsx +92 -18
  41. package/ui/components/wallet/ProfileSwitcherPopover.tsx +247 -0
  42. package/ui/hooks/useOfflineNoticeActions.ts +2 -1
  43. package/ui/hooks/useSpendableBalance.ts +3 -1
  44. package/ui/printRecoveryShares.ts +6 -7
  45. package/ui/screens/PairScreen.tsx +2 -1
  46. package/ui/screens/ProfileScreen.tsx +195 -4
  47. package/ui/screens/SettingsScreen.tsx +8 -4
  48. package/ui/screens/VaultScreen.tsx +31 -2
  49. package/ui/screens/VaultTransferScreen.tsx +25 -2
  50. package/ui/screens/WalletCheckScreen.tsx +2 -1
  51. package/ui/screens/WalletConfigScreen.tsx +51 -21
  52. package/ui/screens/WalletHomeScreen.tsx +6 -3
  53. package/ui/tokenSeen.ts +13 -9
@@ -34,6 +34,7 @@ import { EnrollWizard } from '../components/vault/EnrollWizard'
34
34
  import { KeyChooser, vaultKeyLabel, formatVaultSerial } from '../components/vault/KeyChooser'
35
35
  import { VaultBackdrop } from '../components/vault/VaultBackdrop'
36
36
  import { vaultErrorCopy } from '../components/vault/vaultErrorCopy'
37
+ import { profileLabel } from '../../core/profiles/profileLabel'
37
38
  import { useVaultBalance } from '../hooks/useVaultBalance'
38
39
  import { useVaultCoverage } from '../hooks/useVaultCoverage'
39
40
  import { useExportWalletData } from '../hooks/useExportWalletData'
@@ -150,7 +151,16 @@ export function VaultScreen() {
150
151
  const { balance, loading, refresh } = useVaultBalance()
151
152
  const { coverage, refresh: refreshCoverage } = useVaultCoverage()
152
153
  const { exportData, exporting } = useExportWalletData()
153
- const { managers, adminOriginator, selectedNetwork, storage, walletBuilding, buildWalletFromMnemonic } = useWallet()
154
+ const {
155
+ managers,
156
+ adminOriginator,
157
+ selectedNetwork,
158
+ storage,
159
+ walletBuilding,
160
+ buildWalletFromMnemonic,
161
+ activeProfile,
162
+ profiles
163
+ } = useWallet()
154
164
  const { createMnemonic, hasStoredIdentity, secretsReady } = useLocalStorage()
155
165
 
156
166
  /** undefined = loading; null = not enrolled. */
@@ -193,7 +203,7 @@ export function VaultScreen() {
193
203
  // so everything this gates collapses on a network switch without a remount —
194
204
  // in particular the two doors into EnrollWizard, whose factory-reset offer is
195
205
  // the fund-loss path a testnet vault reopens.
196
- const enabled = isVaultAvailable(selectedNetwork)
206
+ const enabled = isVaultAvailable(selectedNetwork, activeProfile)
197
207
  // Which refusal to print when it is off. A build with the flag off says so
198
208
  // first (spec §5.5); a released build that is simply on the wrong network owes
199
209
  // the user that reason instead — "not available yet" would describe an
@@ -1079,6 +1089,25 @@ export function VaultScreen() {
1079
1089
  </View>
1080
1090
  )
1081
1091
 
1092
+ // Only the default profile has a vault. Reachable here only through a deep
1093
+ // link or a back stack that outlived a profile switch: no door, not even
1094
+ // withdraw or chain restore, opens on another profile's identity.
1095
+ if (activeProfile !== 0) {
1096
+ return (
1097
+ <View style={[styles.container, { backgroundColor: colors.backgroundSecondary, paddingTop: insets.top }]}>
1098
+ {Header}
1099
+ <View style={styles.centered}>
1100
+ <Ionicons name="lock-closed-outline" size={44} color={colors.textSecondary} />
1101
+ <Text style={[styles.p, { color: colors.textPrimary }]}>
1102
+ {t('vault_profile_only_default', {
1103
+ profile: profileLabel(profiles.find(p => p.index === 0) ?? { index: 0 }, t)
1104
+ })}
1105
+ </Text>
1106
+ </View>
1107
+ </View>
1108
+ )
1109
+ }
1110
+
1082
1111
  if (recoveryError) {
1083
1112
  return (
1084
1113
  <View style={[styles.container, { backgroundColor: colors.backgroundSecondary, paddingTop: insets.top }]}>
@@ -33,6 +33,7 @@ import { showAlert } from '../components/ui/AlertCard'
33
33
  import { KeyChooser, vaultKeyLabel } from '../components/vault/KeyChooser'
34
34
  import { vaultErrorCopy, type VaultErrorParams } from '../components/vault/vaultErrorCopy'
35
35
  import { expectVaultBalance, useVaultBalance } from '../hooks/useVaultBalance'
36
+ import { profileLabel } from '../../core/profiles/profileLabel'
36
37
  import {
37
38
  useTheme,
38
39
  spacing,
@@ -129,7 +130,7 @@ export function VaultTransferScreen() {
129
130
  const { router, useLocalSearchParams } = loadExpoRouter()
130
131
  const Ionicons = loadIonicons()
131
132
  const { direction } = useLocalSearchParams<{ direction?: string }>()
132
- const { managers, adminOriginator, selectedNetwork, storage, settings } = useWallet()
133
+ const { managers, adminOriginator, selectedNetwork, storage, settings, activeProfile, profiles } = useWallet()
133
134
  const { satoshisPerUSD, usdToFiat = {} } = useContext(ExchangeRateContext)
134
135
  const { balance, refresh } = useVaultBalance()
135
136
  const [meta, setMeta] = useState<VaultMeta | null>(null)
@@ -147,7 +148,7 @@ export function VaultTransferScreen() {
147
148
  // Release flag AND mainnet (task 11): deposits create a vault output, and one
148
149
  // must never land off mainnet. Withdrawal of pre-existing outputs is never
149
150
  // gated — that is how a testnet tester gets their coins back out.
150
- const released = isVaultAvailable(selectedNetwork)
151
+ const released = isVaultAvailable(selectedNetwork, activeProfile)
151
152
  // See VaultScreen: "not available yet" describes an unreleased build, not a
152
153
  // released build on the wrong network.
153
154
  const unavailableCopy = isVaultEnabled() ? 'vault_not_on_mainnet_body' : 'vault_not_released_body'
@@ -474,6 +475,28 @@ export function VaultTransferScreen() {
474
475
  router
475
476
  ])
476
477
 
478
+ // Only the default profile has a vault — see VaultScreen.
479
+ if (activeProfile !== 0) {
480
+ return (
481
+ <View style={[styles.container, { backgroundColor: colors.backgroundSecondary, paddingTop: insets.top }]}>
482
+ <View style={[styles.header, { borderBottomColor: colors.separator }]}>
483
+ <TouchableOpacity onPress={() => router.back()} style={styles.iconBtn}>
484
+ <Ionicons name="chevron-back" size={24} color={colors.textSecondary} />
485
+ </TouchableOpacity>
486
+ <Text style={[styles.headerTitle, { color: colors.textPrimary }]}>{t('vault_title')}</Text>
487
+ <View style={styles.iconBtn} />
488
+ </View>
489
+ <View style={styles.body}>
490
+ <Text style={{ ...typography.body, color: colors.textSecondary, textAlign: 'center' }}>
491
+ {t('vault_profile_only_default', {
492
+ profile: profileLabel(profiles.find(p => p.index === 0) ?? { index: 0 }, t)
493
+ })}
494
+ </Text>
495
+ </View>
496
+ </View>
497
+ )
498
+ }
499
+
477
500
  return (
478
501
  <View style={[styles.container, { backgroundColor: colors.backgroundSecondary, paddingTop: insets.top }]}>
479
502
  <View style={[styles.header, { borderBottomColor: colors.separator }]}>
@@ -46,6 +46,7 @@ import { userFacingPayError } from '../../core/pay/userError'
46
46
  import { backupAttestation } from '../../core/services/vault/backupAttestation'
47
47
  import { getBackupUploadState } from '../../core/backup/status'
48
48
  import { getOnline, haptics, spacing, typography, useTheme, useWallet } from '@bsv/expo-wallet-toolbox'
49
+ import { profileScopedKey } from '../../core/profiles/profileStore'
49
50
 
50
51
  /**
51
52
  * @expo/vector-icons' index barrel re-exports every icon set (AntDesign,
@@ -188,7 +189,7 @@ function useWalletCheckPorts(): WalletCheckPorts {
188
189
  },
189
190
  creditInbox: async () => {
190
191
  if (!wallet) return { accepted: 0 }
191
- const saved = await AsyncStorage.getItem(MESSAGE_BOX_URL_KEY)
192
+ const saved = await AsyncStorage.getItem(profileScopedKey(MESSAGE_BOX_URL_KEY))
192
193
  const messageBoxUrl = !saved || saved === LEGACY_MESSAGE_BOX_URL ? DEFAULT_MESSAGE_BOX_URL : saved
193
194
  if (!messageBoxUrl || messageBoxUrl === NO_MESSAGE_BOX) return { accepted: 0 }
194
195
  const client = new PeerPayClient({
@@ -71,6 +71,8 @@ import { PrivateKey } from '@bsv/sdk'
71
71
  import { useExportWalletData } from '../hooks/useExportWalletData'
72
72
  import { importWalletDatabase } from '../importDatabases'
73
73
  import { useSafeAreaInsets } from 'react-native-safe-area-context'
74
+ import { profileScopedKey } from '../../core/profiles/profileStore'
75
+ import { profileLabel } from '../../core/profiles/profileLabel'
74
76
 
75
77
  /**
76
78
  * @expo/vector-icons' index barrel re-exports every icon set (AntDesign,
@@ -148,7 +150,10 @@ export function WalletConfigScreen() {
148
150
  rebuildWallet,
149
151
  storage,
150
152
  settings,
151
- updateSettings
153
+ updateSettings,
154
+ activeProfile,
155
+ profiles,
156
+ profilesSupported
152
157
  } = useWallet()
153
158
  const { getMnemonic, getRecoveredKey } = useLocalStorage()
154
159
  const insets = useSafeAreaInsets()
@@ -197,7 +202,7 @@ export function WalletConfigScreen() {
197
202
 
198
203
  // Load persisted auto-approve threshold
199
204
  useEffect(() => {
200
- AsyncStorage.getItem(AUTO_APPROVE_STORAGE_KEY).then(v => {
205
+ AsyncStorage.getItem(profileScopedKey(AUTO_APPROVE_STORAGE_KEY)).then(v => {
201
206
  if (v !== null) setThresholdSats(Number(v) || 0)
202
207
  })
203
208
  }, [])
@@ -211,11 +216,23 @@ export function WalletConfigScreen() {
211
216
  })
212
217
  }, [])
213
218
 
214
- // Load the backup-push opt-out. Defaults to on, so a slow read shows the true default
215
- // rather than flashing "Off".
219
+ // The profile the screen is showing right now, for handlers that await something (a
220
+ // confirm, a server delete) before they touch `backupPushOn`.
221
+ const activeProfileRef = useRef(activeProfile)
222
+ activeProfileRef.current = activeProfile
223
+
224
+ // Load the backup-push opt-out of the profile on screen. Defaults to on, so a slow read
225
+ // shows the true default rather than flashing "Off". Re-read when the profile changes:
226
+ // the opt-out is per profile and this screen can outlive a switch.
216
227
  useEffect(() => {
217
- isBackupPushEnabled().then(setBackupPushOn)
218
- }, [])
228
+ let current = true
229
+ isBackupPushEnabled(activeProfile).then(on => {
230
+ if (current) setBackupPushOn(on)
231
+ })
232
+ return () => {
233
+ current = false
234
+ }
235
+ }, [activeProfile])
219
236
 
220
237
  /**
221
238
  * Toggle pushing to the backup server.
@@ -227,6 +244,8 @@ export function WalletConfigScreen() {
227
244
  */
228
245
  const handleToggleBackupPush = useCallback(async () => {
229
246
  const next = !backupPushOn
247
+ // Pinned before the confirm: the write belongs to the profile whose toggle was pressed.
248
+ const profile = activeProfile
230
249
  if (!next) {
231
250
  const choice = await showAlert({
232
251
  title: t('backup_push_off_title'),
@@ -239,11 +258,11 @@ export function WalletConfigScreen() {
239
258
  if (choice !== 'confirm') return
240
259
  }
241
260
 
242
- await setBackupPushEnabled(next)
243
- setBackupPushOn(next)
261
+ await setBackupPushEnabled(next, profile)
262
+ if (profile === activeProfileRef.current) setBackupPushOn(next)
244
263
  if (next) TaskBackupPush.requestNow()
245
264
  showToast(next ? t('backup_push_on_toast') : t('backup_push_off_toast'), { type: 'info' })
246
- }, [backupPushOn, t])
265
+ }, [backupPushOn, activeProfile, t])
247
266
 
248
267
  /**
249
268
  * Erase the server's copy of this wallet's backup, on request (GDPR Article 17).
@@ -259,6 +278,8 @@ export function WalletConfigScreen() {
259
278
  const handleEraseBackup = useCallback(async () => {
260
279
  if (erasingBackup) return
261
280
 
281
+ // Pinned before the confirm: every step below is for the profile whose erase this is.
282
+ const profile = activeProfile
262
283
  const choice = await showAlert({
263
284
  title: t('backup_erase_title'),
264
285
  message: t('backup_erase_message'),
@@ -274,7 +295,7 @@ export function WalletConfigScreen() {
274
295
  const mnemonic = await getMnemonic()
275
296
  const wif = mnemonic ? null : await getRecoveredKey()
276
297
  const primaryKey = mnemonic
277
- ? recoverMnemonicWallet(mnemonic).primaryKey
298
+ ? recoverMnemonicWallet(mnemonic, '', profile).primaryKey
278
299
  : wif
279
300
  ? PrivateKey.fromWif(wif).toArray()
280
301
  : null
@@ -288,9 +309,9 @@ export function WalletConfigScreen() {
288
309
  // chain propagates — a partial erasure must never be reported as done.
289
310
  let deleted = 0
290
311
  for (const chain of BACKUP_CHAINS) {
291
- deleted += (await eraseRemoteBackup({ primaryKey, chain, baseUrl: getBackupUrl() })).deleted
312
+ deleted += (await eraseRemoteBackup({ primaryKey, chain, baseUrl: getBackupUrl(), profileIndex: profile })).deleted
292
313
  }
293
- setBackupPushOn(false)
314
+ if (profile === activeProfileRef.current) setBackupPushOn(false)
294
315
  showToast(t('backup_erase_done', { count: deleted }), { type: 'success' })
295
316
  } catch (e) {
296
317
  // Never report an erasure that did not happen. The server's copy is still there and
@@ -299,11 +320,11 @@ export function WalletConfigScreen() {
299
320
  showToast(t('backup_erase_failed'), { type: 'error' })
300
321
  // Pushing is off either way — eraseRemoteBackup wrote that before it tried the
301
322
  // delete, and a failed erasure is no reason to start uploading again.
302
- setBackupPushOn(false)
323
+ if (profile === activeProfileRef.current) setBackupPushOn(false)
303
324
  } finally {
304
325
  setErasingBackup(false)
305
326
  }
306
- }, [erasingBackup, t, getMnemonic, getRecoveredKey])
327
+ }, [erasingBackup, t, getMnemonic, getRecoveredKey, activeProfile])
307
328
 
308
329
  /**
309
330
  * Show what the wallet database is using, and offer the one safe reclaim.
@@ -371,7 +392,7 @@ export function WalletConfigScreen() {
371
392
  // Load persisted ARC URL + token for current network. The token is read
372
393
  // via getArcApiToken (XR-106: SecureStore-backed, not plaintext AsyncStorage).
373
394
  useEffect(() => {
374
- Promise.all([AsyncStorage.getItem(arcUrlStorageKey(selectedNetwork)), getArcApiToken(selectedNetwork)]).then(
395
+ Promise.all([AsyncStorage.getItem(profileScopedKey(arcUrlStorageKey(selectedNetwork))), getArcApiToken(selectedNetwork)]).then(
375
396
  ([url, token]) => {
376
397
  setArcUrlInput(url ?? DEFAULT_ARC_URLS[selectedNetwork] ?? '')
377
398
  setArcTokenInput(token ?? '')
@@ -387,7 +408,7 @@ export function WalletConfigScreen() {
387
408
  const sats = parseDisplayToSatoshis(text, currentCurrency, satoshisPerUSD, usdToFiat)
388
409
  const clamped = Math.max(0, Math.round(sats))
389
410
  setThresholdSats(clamped)
390
- AsyncStorage.setItem(AUTO_APPROVE_STORAGE_KEY, String(clamped))
411
+ AsyncStorage.setItem(profileScopedKey(AUTO_APPROVE_STORAGE_KEY), String(clamped))
391
412
  }, 600)
392
413
  }, [currentCurrency, satoshisPerUSD, usdToFiat])
393
414
 
@@ -450,7 +471,7 @@ export function WalletConfigScreen() {
450
471
  setArcSaving(true)
451
472
  try {
452
473
  const token = arcTokenInput.trim()
453
- const previousUrl = (await AsyncStorage.getItem(arcUrlStorageKey(selectedNetwork))) ?? defaultUrl
474
+ const previousUrl = (await AsyncStorage.getItem(profileScopedKey(arcUrlStorageKey(selectedNetwork)))) ?? defaultUrl
454
475
  const previousToken = (await getArcApiToken(selectedNetwork)) ?? ''
455
476
  const nextUrl = url || defaultUrl
456
477
  const originChanged = previousUrl !== nextUrl
@@ -461,9 +482,9 @@ export function WalletConfigScreen() {
461
482
  // stored) is an intentional, explicit entry and is still honored.
462
483
  const stalePriorToken = originChanged && token === previousToken
463
484
  if (url && url !== defaultUrl) {
464
- await AsyncStorage.setItem(arcUrlStorageKey(selectedNetwork), url)
485
+ await AsyncStorage.setItem(profileScopedKey(arcUrlStorageKey(selectedNetwork)), url)
465
486
  } else {
466
- await AsyncStorage.removeItem(arcUrlStorageKey(selectedNetwork))
487
+ await AsyncStorage.removeItem(profileScopedKey(arcUrlStorageKey(selectedNetwork)))
467
488
  }
468
489
  if (token && !stalePriorToken) {
469
490
  await setArcApiToken(selectedNetwork, token)
@@ -482,7 +503,7 @@ export function WalletConfigScreen() {
482
503
 
483
504
  const handleResetArc = async () => {
484
505
  await Promise.all([
485
- AsyncStorage.removeItem(arcUrlStorageKey(selectedNetwork)),
506
+ AsyncStorage.removeItem(profileScopedKey(arcUrlStorageKey(selectedNetwork))),
486
507
  setArcApiToken(selectedNetwork, null)
487
508
  ])
488
509
  setArcUrlInput(DEFAULT_ARC_URLS[selectedNetwork] ?? '')
@@ -599,7 +620,16 @@ export function WalletConfigScreen() {
599
620
  {advancedExpanded && (
600
621
  <>
601
622
  {/* ── Configuration ── */}
602
- <GroupedSection header={t('configuration')}>
623
+ <GroupedSection
624
+ header={t('configuration')}
625
+ footer={
626
+ profilesSupported
627
+ ? t('profile_settings_scope_note', {
628
+ profile: profileLabel(profiles.find(p => p.index === activeProfile) ?? { index: activeProfile }, t)
629
+ })
630
+ : undefined
631
+ }
632
+ >
603
633
  <ListRow
604
634
  label={t('bsv_network')}
605
635
  value={
@@ -101,6 +101,7 @@ import { tokenRowTitle } from './tokenRowTitle'
101
101
  import { useMandala, useMandalaRuntime, useTokenActivity, tokenActivityByTxid } from '../hooks/useMandala'
102
102
  import { announceEviction, evictionsFrom } from '../components/wallet/tokenEviction'
103
103
  import { SEEN_EVICTIONS_KEY, useSeenSet } from '../tokenSeen'
104
+ import { profileScopedKey, useActiveProfileIndex } from '../../core/profiles/profileStore'
104
105
  import { tokenRowStatusView } from '../tokenStatus'
105
106
  import { formatTokenAmount, tokenAmountParts } from '../tokenFormat'
106
107
  import AssetSwitcherDropdown, { BSV_LABEL } from '../components/wallet/AssetSwitcherDropdown'
@@ -128,7 +129,7 @@ import { useOnline } from '../hooks/useOnline'
128
129
  import { useOfflineNoticeActions } from '../hooks/useOfflineNoticeActions'
129
130
 
130
131
  async function readMessageBoxUrl(): Promise<string | undefined> {
131
- const saved = await AsyncStorage.getItem(MESSAGE_BOX_URL_KEY)
132
+ const saved = await AsyncStorage.getItem(profileScopedKey(MESSAGE_BOX_URL_KEY))
132
133
  if (saved === NO_MESSAGE_BOX) return undefined
133
134
  if (!saved || saved === LEGACY_MESSAGE_BOX_URL) return DEFAULT_MESSAGE_BOX_URL
134
135
  return saved
@@ -451,7 +452,8 @@ export function WalletHomeScreen({ topLeft }: WalletHomeScreenProps = {}) {
451
452
  }, [walletBuilt, managers.permissionsManager, adminOriginator])
452
453
  )
453
454
 
454
- const balanceCacheKey = `cached_wallet_balance_${selectedNetwork}`
455
+ const activeProfile = useActiveProfileIndex()
456
+ const balanceCacheKey = profileScopedKey(`cached_wallet_balance_${selectedNetwork}`, activeProfile)
455
457
  /**
456
458
  * Whether what is mounted is this network's wallet.
457
459
  *
@@ -1794,7 +1796,7 @@ export function WalletHomeScreen({ topLeft }: WalletHomeScreenProps = {}) {
1794
1796
  destinationPress — enrolment needs no wallet, and the Vault
1795
1797
  screen's own Deposit button runs the lazy wallet-creation path
1796
1798
  when it comes to that. */}
1797
- {(isVaultAvailable(selectedNetwork) || hasVaultMeta) && (
1799
+ {activeProfile === 0 && (isVaultAvailable(selectedNetwork, activeProfile) || hasVaultMeta) && (
1798
1800
  <PressableScale
1799
1801
  haptic="confirm"
1800
1802
  onPress={() => router.push('/vault')}
@@ -1814,6 +1816,7 @@ export function WalletHomeScreen({ topLeft }: WalletHomeScreenProps = {}) {
1814
1816
  t,
1815
1817
  router,
1816
1818
  selectedNetwork,
1819
+ activeProfile,
1817
1820
  hasVaultMeta,
1818
1821
  hasTokens,
1819
1822
  heldAsset,
package/ui/tokenSeen.ts CHANGED
@@ -16,13 +16,15 @@
16
16
  */
17
17
  import { useCallback, useEffect, useState } from 'react'
18
18
  import AsyncStorage from '@react-native-async-storage/async-storage'
19
+ import { profileScopedKey, useActiveProfileIndex } from '../core/profiles/profileStore'
19
20
 
20
21
  export const SEEN_ASSETS_KEY = 'mandala_seen_assets'
21
22
  export const SEEN_EVICTIONS_KEY = 'mandala_seen_evictions'
22
23
 
23
- export async function readSeen(key: string): Promise<string[]> {
24
+ /** `key` is the base key; what was seen is remembered per wallet profile. */
25
+ export async function readSeen(key: string, profileIndex?: number): Promise<string[]> {
24
26
  try {
25
- const raw = await AsyncStorage.getItem(key)
27
+ const raw = await AsyncStorage.getItem(profileScopedKey(key, profileIndex))
26
28
  if (!raw) return []
27
29
  const parsed: unknown = JSON.parse(raw)
28
30
  return Array.isArray(parsed) ? parsed.filter((v): v is string => typeof v === 'string') : []
@@ -31,11 +33,11 @@ export async function readSeen(key: string): Promise<string[]> {
31
33
  }
32
34
  }
33
35
 
34
- export async function markSeen(key: string, id: string): Promise<void> {
36
+ export async function markSeen(key: string, id: string, profileIndex?: number): Promise<void> {
35
37
  try {
36
- const current = await readSeen(key)
38
+ const current = await readSeen(key, profileIndex)
37
39
  if (current.includes(id)) return
38
- await AsyncStorage.setItem(key, JSON.stringify([...current, id]))
40
+ await AsyncStorage.setItem(profileScopedKey(key, profileIndex), JSON.stringify([...current, id]))
39
41
  } catch {
40
42
  // Cosmetic state. A write failure means one repeated subtitle or one
41
43
  // repeated alert, never a wrong balance.
@@ -50,23 +52,25 @@ export interface SeenSet {
50
52
 
51
53
  export function useSeenSet(key: string): SeenSet {
52
54
  const [seen, setSeen] = useState<string[]>([])
55
+ const profileIndex = useActiveProfileIndex()
53
56
 
54
57
  useEffect(() => {
55
58
  let live = true
56
- void readSeen(key).then(ids => {
59
+ setSeen([])
60
+ void readSeen(key, profileIndex).then(ids => {
57
61
  if (live) setSeen(ids)
58
62
  })
59
63
  return () => {
60
64
  live = false
61
65
  }
62
- }, [key])
66
+ }, [key, profileIndex])
63
67
 
64
68
  const see = useCallback(
65
69
  (id: string) => {
66
70
  setSeen(prev => (prev.includes(id) ? prev : [...prev, id]))
67
- void markSeen(key, id)
71
+ void markSeen(key, id, profileIndex)
68
72
  },
69
- [key]
73
+ [key, profileIndex]
70
74
  )
71
75
 
72
76
  const isSeen = useCallback((id: string) => seen.includes(id), [seen])