@bsv/expo-wallet-toolbox 0.12.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +118 -0
- package/core/backup/erase.ts +7 -1
- package/core/backup/preference.ts +12 -4
- package/core/backup/push.ts +8 -1
- package/core/backup/status.ts +6 -2
- package/core/context/WalletContext.tsx +855 -238
- package/core/i18n/translations.tsx +376 -0
- package/core/identity/handleRegistry/registration.ts +57 -3
- package/core/index.ts +24 -1
- package/core/mandala/createRuntime.ts +3 -3
- package/core/mandala/runtime.ts +7 -2
- package/core/mnemonicWallet.ts +46 -40
- package/core/monitor/MonitorSupervisor.ts +35 -1
- package/core/monitor/TaskCreditInbox.ts +24 -0
- package/core/pay/rails/handle.ts +4 -2
- package/core/peerpay/outbox.ts +11 -1
- package/core/profiles/assertProfileEmpty.ts +287 -0
- package/core/profiles/discovery.ts +84 -0
- package/core/profiles/profileLabel.ts +13 -0
- package/core/profiles/profileStore.ts +265 -0
- package/core/profiles/purgeProfile.ts +76 -0
- package/core/profiles/removeProfile.ts +257 -0
- package/core/push/events.ts +52 -5
- package/core/push/identities.ts +55 -0
- package/core/push/profilePush.ts +143 -0
- package/core/push/registration.ts +362 -24
- package/core/push/types.ts +5 -1
- package/core/services/arcTokenStorage.ts +17 -2
- package/core/services/signingPermissionPolicy.ts +258 -0
- package/core/services/vault/guard.ts +55 -14
- package/core/services/vault/transfers.ts +6 -1
- package/core/services/vault/vaultStore.ts +16 -3
- package/core/stores/ConnectionStore.ts +11 -7
- package/core/toolboxConfig.ts +7 -3
- package/core/userAvatar.ts +12 -5
- package/core/walletDbRegistry.ts +73 -0
- package/package.json +1 -1
- package/ui/backupShares.ts +2 -3
- package/ui/components/pay/MessageBoxConfig.tsx +6 -5
- package/ui/components/ui/PencilEditField.tsx +5 -2
- package/ui/components/ui/PermissionSheet.tsx +15 -7
- package/ui/components/ui/protocolPrompt.ts +118 -0
- package/ui/components/wallet/Balance.tsx +3 -1
- package/ui/components/wallet/ProfileButton.tsx +92 -18
- package/ui/components/wallet/ProfileSwitcherPopover.tsx +247 -0
- package/ui/hooks/useOfflineNoticeActions.ts +2 -1
- package/ui/hooks/useSpendableBalance.ts +3 -1
- package/ui/printRecoveryShares.ts +6 -7
- package/ui/screens/PairScreen.tsx +2 -1
- package/ui/screens/ProfileScreen.tsx +195 -4
- package/ui/screens/SettingsScreen.tsx +8 -4
- package/ui/screens/VaultScreen.tsx +31 -2
- package/ui/screens/VaultTransferScreen.tsx +25 -2
- package/ui/screens/WalletCheckScreen.tsx +2 -1
- package/ui/screens/WalletConfigScreen.tsx +51 -21
- package/ui/screens/WalletHomeScreen.tsx +6 -3
- package/ui/tokenSeen.ts +13 -9
|
@@ -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
|
-
//
|
|
215
|
-
//
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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])
|