@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
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
MESSAGE_BOX_URL_KEY,
|
|
22
22
|
NO_MESSAGE_BOX
|
|
23
23
|
} from '@bsv/expo-wallet-toolbox'
|
|
24
|
+
import { profileScopedKey } from '../../../core/profiles/profileStore'
|
|
24
25
|
|
|
25
26
|
/**
|
|
26
27
|
* @expo/vector-icons' index barrel re-exports every icon set (AntDesign,
|
|
@@ -46,11 +47,11 @@ export function useMessageBoxConfig(t: ReturnType<typeof import('react-i18next')
|
|
|
46
47
|
const [showConfig, setShowConfig] = useState(false)
|
|
47
48
|
|
|
48
49
|
useEffect(() => {
|
|
49
|
-
AsyncStorage.getItem(MESSAGE_BOX_URL_KEY).then(saved => {
|
|
50
|
+
AsyncStorage.getItem(profileScopedKey(MESSAGE_BOX_URL_KEY)).then(saved => {
|
|
50
51
|
// A preference equal to the retired default means "default", not a
|
|
51
52
|
// deliberate choice of that server — follow the new default instead.
|
|
52
53
|
if (saved === LEGACY_MESSAGE_BOX_URL) {
|
|
53
|
-
void AsyncStorage.removeItem(MESSAGE_BOX_URL_KEY)
|
|
54
|
+
void AsyncStorage.removeItem(profileScopedKey(MESSAGE_BOX_URL_KEY))
|
|
54
55
|
return
|
|
55
56
|
}
|
|
56
57
|
if (saved) {
|
|
@@ -85,7 +86,7 @@ export function useMessageBoxConfig(t: ReturnType<typeof import('react-i18next')
|
|
|
85
86
|
}
|
|
86
87
|
setIsSaving(true)
|
|
87
88
|
try {
|
|
88
|
-
await AsyncStorage.setItem(MESSAGE_BOX_URL_KEY, trimmed)
|
|
89
|
+
await AsyncStorage.setItem(profileScopedKey(MESSAGE_BOX_URL_KEY), trimmed)
|
|
89
90
|
setMessageBoxUrl(trimmed)
|
|
90
91
|
setShowConfig(false)
|
|
91
92
|
showToast(t('message_box_saved'), { type: 'success' })
|
|
@@ -99,7 +100,7 @@ export function useMessageBoxConfig(t: ReturnType<typeof import('react-i18next')
|
|
|
99
100
|
)
|
|
100
101
|
|
|
101
102
|
const handleReset = useCallback(async () => {
|
|
102
|
-
await AsyncStorage.removeItem(MESSAGE_BOX_URL_KEY)
|
|
103
|
+
await AsyncStorage.removeItem(profileScopedKey(MESSAGE_BOX_URL_KEY))
|
|
103
104
|
setMessageBoxUrl(DEFAULT_MESSAGE_BOX_URL)
|
|
104
105
|
setUrlInput(DEFAULT_MESSAGE_BOX_URL)
|
|
105
106
|
setShowConfig(false)
|
|
@@ -110,7 +111,7 @@ export function useMessageBoxConfig(t: ReturnType<typeof import('react-i18next')
|
|
|
110
111
|
const noneValue = NO_MESSAGE_BOX
|
|
111
112
|
setIsSaving(true)
|
|
112
113
|
try {
|
|
113
|
-
await AsyncStorage.setItem(MESSAGE_BOX_URL_KEY, noneValue)
|
|
114
|
+
await AsyncStorage.setItem(profileScopedKey(MESSAGE_BOX_URL_KEY), noneValue)
|
|
114
115
|
setMessageBoxUrl(noneValue)
|
|
115
116
|
setUrlInput(noneValue)
|
|
116
117
|
setShowConfig(true)
|
|
@@ -30,6 +30,8 @@ export interface PencilEditFieldProps {
|
|
|
30
30
|
saveAccessibilityLabel: string
|
|
31
31
|
autoCapitalize?: 'none' | 'sentences' | 'words' | 'characters'
|
|
32
32
|
maxLength?: number
|
|
33
|
+
/** Let the text be emptied and saved as '' (a name that can go back to its default). */
|
|
34
|
+
allowEmpty?: boolean
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
export function PencilEditField({
|
|
@@ -40,7 +42,8 @@ export function PencilEditField({
|
|
|
40
42
|
editAccessibilityLabel,
|
|
41
43
|
saveAccessibilityLabel,
|
|
42
44
|
autoCapitalize = 'words',
|
|
43
|
-
maxLength
|
|
45
|
+
maxLength,
|
|
46
|
+
allowEmpty = false
|
|
44
47
|
}: PencilEditFieldProps) {
|
|
45
48
|
const { colors } = useTheme()
|
|
46
49
|
const Ionicons = loadIonicons()
|
|
@@ -50,7 +53,7 @@ export function PencilEditField({
|
|
|
50
53
|
// re-seeds the field; an in-progress edit is never clobbered, because the
|
|
51
54
|
// parent's value only changes once our own save has gone through.
|
|
52
55
|
useEffect(() => setText(value), [value])
|
|
53
|
-
const changed = text.trim() !== '' && text.trim() !== value.trim()
|
|
56
|
+
const changed = (allowEmpty || text.trim() !== '') && text.trim() !== value.trim()
|
|
54
57
|
|
|
55
58
|
const save = async () => {
|
|
56
59
|
if (!changed) return
|
|
@@ -5,6 +5,7 @@ import Sheet from './Sheet'
|
|
|
5
5
|
import PressableScale from './PressableScale'
|
|
6
6
|
import { useTranslation } from 'react-i18next'
|
|
7
7
|
import AmountDisplay from '../wallet/AmountDisplay'
|
|
8
|
+
import { describeProtocolPrompt } from './protocolPrompt'
|
|
8
9
|
import {
|
|
9
10
|
spacing,
|
|
10
11
|
radii,
|
|
@@ -250,17 +251,22 @@ export function deriveActive(
|
|
|
250
251
|
|
|
251
252
|
if (ctx.protocolAccessModalOpen && ctx.protocolRequests.length > 0) {
|
|
252
253
|
const r = ctx.protocolRequests[0]
|
|
254
|
+
const prompt = describeProtocolPrompt(r.protocolID ?? '', r.counterparty, r.keyID)
|
|
255
|
+
const details: { label: string; value: string }[] = [
|
|
256
|
+
{ label: 'Protocol', value: truncate(prompt.protocolLabel, 40) },
|
|
257
|
+
{ label: 'Security level', value: String(r.protocolSecurityLevel) }
|
|
258
|
+
]
|
|
259
|
+
if (prompt.counterpartyLabel) details.push({ label: 'Shared with', value: prompt.counterpartyLabel })
|
|
260
|
+
if (prompt.keyIDLabel) details.push({ label: 'Key ID', value: truncate(prompt.keyIDLabel, 40) })
|
|
261
|
+
if (prompt.askEveryTime) details.push({ label: 'Approval', value: 'This signature only' })
|
|
253
262
|
return {
|
|
254
263
|
kind: 'protocol',
|
|
255
264
|
requestID: r.requestID,
|
|
256
265
|
originator: r.originator || 'Unknown app',
|
|
257
|
-
title: r.renewal ?
|
|
258
|
-
description: r.description || 'wants to use a cryptographic protocol',
|
|
266
|
+
title: r.renewal ? `${prompt.title} Renewal` : prompt.title,
|
|
267
|
+
description: prompt.description ?? (r.description || 'wants to use a cryptographic protocol'),
|
|
259
268
|
renewal: r.renewal,
|
|
260
|
-
details
|
|
261
|
-
{ label: 'Protocol ID', value: truncate(r.protocolID, 28) },
|
|
262
|
-
{ label: 'Security level', value: String(r.protocolSecurityLevel) }
|
|
263
|
-
]
|
|
269
|
+
details
|
|
264
270
|
}
|
|
265
271
|
}
|
|
266
272
|
|
|
@@ -807,7 +813,9 @@ const PermissionSheet: React.FC = () => {
|
|
|
807
813
|
</Text>
|
|
808
814
|
{active.groupPermissions.protocolPermissions.map((p, i) => (
|
|
809
815
|
<View key={i} style={styles.groupRow}>
|
|
810
|
-
<Text style={[styles.groupRowLabel, { color: colors.textPrimary }]}>
|
|
816
|
+
<Text style={[styles.groupRowLabel, { color: colors.textPrimary }]}>
|
|
817
|
+
{describeProtocolPrompt(p.protocolID[1], p.counterparty).protocolLabel}
|
|
818
|
+
</Text>
|
|
811
819
|
{p.description && (
|
|
812
820
|
<Text style={[styles.groupRowDesc, { color: colors.textSecondary }]}>{p.description}</Text>
|
|
813
821
|
)}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { PrivateKey, PublicKey, Utils } from '@bsv/sdk'
|
|
2
|
+
|
|
3
|
+
/** BRC-29's protocol name. Apps sign under it to receive and move payments,
|
|
4
|
+
* and this wallet's own payment keys (BSV address receipts, change) live
|
|
5
|
+
* under it too, so a grant here is a grant over money. */
|
|
6
|
+
const BRC29_PROTOCOL_NAME = '3241645161d8'
|
|
7
|
+
|
|
8
|
+
/** The BRC-42 'anyone' counterparty (1·G), in canonical form. */
|
|
9
|
+
const ANYONE_PUBLIC_KEY = new PrivateKey(1).toPublicKey().toString()
|
|
10
|
+
|
|
11
|
+
type Counterparty = { kind: 'anyone' } | { kind: 'self' } | { kind: 'party'; key: string }
|
|
12
|
+
|
|
13
|
+
/** The protocol grant's counterparty as the permissions manager reports it:
|
|
14
|
+
* 'self' when the app named none, 'anyone' as the literal or as 1·G in any
|
|
15
|
+
* encoding, otherwise another party's key. */
|
|
16
|
+
function classifyCounterparty(counterparty: unknown): Counterparty {
|
|
17
|
+
if (counterparty === undefined || counterparty === null || counterparty === '' || counterparty === 'self') {
|
|
18
|
+
return { kind: 'self' }
|
|
19
|
+
}
|
|
20
|
+
if (counterparty === 'anyone') return { kind: 'anyone' }
|
|
21
|
+
const raw = String(counterparty)
|
|
22
|
+
try {
|
|
23
|
+
const key = PublicKey.fromString(raw).toString()
|
|
24
|
+
return key === ANYONE_PUBLIC_KEY ? { kind: 'anyone' } : { kind: 'party', key }
|
|
25
|
+
} catch {
|
|
26
|
+
return { kind: 'party', key: raw }
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function abbreviate(key: string): string {
|
|
31
|
+
return key.length <= 13 ? key : key.slice(0, 8) + '…' + key.slice(-4)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** One space-separated part of a key ID as text: the decoded value when the
|
|
35
|
+
* part is canonical base64 of printable ASCII (BRC-29 key IDs are usually
|
|
36
|
+
* base64 prefix + ' ' + base64 suffix), otherwise the part as given. */
|
|
37
|
+
function readablePart(part: string): string {
|
|
38
|
+
try {
|
|
39
|
+
const bytes = Utils.toArray(part, 'base64')
|
|
40
|
+
if (bytes.length === 0 || Utils.toBase64(bytes) !== part) return part
|
|
41
|
+
if (!bytes.every(b => b >= 0x20 && b <= 0x7e)) return part
|
|
42
|
+
return Utils.toUTF8(bytes)
|
|
43
|
+
} catch {
|
|
44
|
+
return part
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** A key ID as a person can read it, so an app's fixed key ID ("xana-earnings
|
|
49
|
+
* 1") is visibly not one of the wallet's own. */
|
|
50
|
+
export function readableKeyID(keyID: string): string {
|
|
51
|
+
return keyID.split(' ').map(readablePart).join(' ')
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface ProtocolPrompt {
|
|
55
|
+
/** Sheet title, before any "Renewal" suffix. */
|
|
56
|
+
title: string
|
|
57
|
+
/** What approving lets the app do, completing "<app> …". Undefined means
|
|
58
|
+
* the caller's own text (or its generic fallback) is used. */
|
|
59
|
+
description?: string
|
|
60
|
+
/** Name to show for the protocol in place of its raw ID. */
|
|
61
|
+
protocolLabel: string
|
|
62
|
+
/** Who the keys are shared with, when that is worth naming. */
|
|
63
|
+
counterpartyLabel?: string
|
|
64
|
+
/** The key ID asked for, readable, when the request carries it. */
|
|
65
|
+
keyIDLabel?: string
|
|
66
|
+
/** The approval covers this one call and is never reused
|
|
67
|
+
* (core/services/signingPermissionPolicy.ts's ASK_EVERY_TIME_PROTOCOLS). */
|
|
68
|
+
askEveryTime?: boolean
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Plain-language copy for a protocol permission request. Most protocol names
|
|
73
|
+
* are an app's own words and are shown as they are. BRC-29's is an opaque
|
|
74
|
+
* hex ID, and approving it lets the app sign with a key that can hold money,
|
|
75
|
+
* so it gets its own title and a description that says which money. The
|
|
76
|
+
* address rail's own key IDs never reach a prompt (vault guard's
|
|
77
|
+
* isAddressRailKeyID refuses them), so the copy describes the app's key.
|
|
78
|
+
*/
|
|
79
|
+
export function describeProtocolPrompt(protocolName: string, counterparty?: unknown, keyID?: unknown): ProtocolPrompt {
|
|
80
|
+
if (protocolName.toLowerCase().trim() !== BRC29_PROTOCOL_NAME) {
|
|
81
|
+
return { title: 'Protocol Access', protocolLabel: protocolName }
|
|
82
|
+
}
|
|
83
|
+
const party = classifyCounterparty(counterparty)
|
|
84
|
+
const protocolLabel = 'Payments (BRC-29)'
|
|
85
|
+
const keyIDLabel = typeof keyID === 'string' ? readableKeyID(keyID) : undefined
|
|
86
|
+
switch (party.kind) {
|
|
87
|
+
case 'anyone':
|
|
88
|
+
return {
|
|
89
|
+
title: 'Payment Key Signature',
|
|
90
|
+
description:
|
|
91
|
+
'wants a signature from one of your payment keys. Coins paid to this key could be spent with this signature.',
|
|
92
|
+
protocolLabel,
|
|
93
|
+
askEveryTime: true,
|
|
94
|
+
counterpartyLabel: 'Anyone',
|
|
95
|
+
keyIDLabel
|
|
96
|
+
}
|
|
97
|
+
case 'self':
|
|
98
|
+
return {
|
|
99
|
+
title: 'Payment Key Signature',
|
|
100
|
+
description:
|
|
101
|
+
"wants a signature from one of your wallet's own payment keys. Your change could be spent with this signature.",
|
|
102
|
+
protocolLabel,
|
|
103
|
+
askEveryTime: true,
|
|
104
|
+
counterpartyLabel: 'Only you',
|
|
105
|
+
keyIDLabel
|
|
106
|
+
}
|
|
107
|
+
case 'party':
|
|
108
|
+
return {
|
|
109
|
+
title: 'Payment Key Signature',
|
|
110
|
+
description:
|
|
111
|
+
'wants a signature from a payment key you share with another party. Coins paid to this key could be spent with this signature.',
|
|
112
|
+
protocolLabel,
|
|
113
|
+
askEveryTime: true,
|
|
114
|
+
counterpartyLabel: abbreviate(party.key),
|
|
115
|
+
keyIDLabel
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -5,6 +5,7 @@ import AmountDisplay from './AmountDisplay'
|
|
|
5
5
|
import AppLogo from '../ui/AppLogo'
|
|
6
6
|
import { sdk } from '@bsv/wallet-toolbox-mobile'
|
|
7
7
|
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
8
|
+
import { profileScopedKey, useActiveProfileIndex } from '../../../core/profiles/profileStore'
|
|
8
9
|
|
|
9
10
|
// XR-058: scoped by network (matching useSpendableBalance's pattern) rather
|
|
10
11
|
// than a single global key, so one wallet/network context can never read
|
|
@@ -16,7 +17,8 @@ const CACHE_DURATION = 30000 // 30 seconds
|
|
|
16
17
|
export default function Balance() {
|
|
17
18
|
const { colors } = useTheme()
|
|
18
19
|
const { managers, adminOriginator, txStatusVersion, selectedNetwork } = useWallet()
|
|
19
|
-
const
|
|
20
|
+
const activeProfile = useActiveProfileIndex()
|
|
21
|
+
const cacheKey = profileScopedKey(`${BALANCE_CACHE_PREFIX}${selectedNetwork}`, activeProfile)
|
|
20
22
|
const timestampKey = `${cacheKey}_timestamp`
|
|
21
23
|
// { key, value } rather than a bare number: `key` is compared against the
|
|
22
24
|
// live `cacheKey` everywhere below, so a figure read for a since-departed
|
|
@@ -8,13 +8,18 @@
|
|
|
8
8
|
* host app's `app/index.tsx`, so this needed no package API change. Same disc
|
|
9
9
|
* as the settings button on the right (surfaceRaised + hairline), so the two
|
|
10
10
|
* bookend the header as a matched pair.
|
|
11
|
+
*
|
|
12
|
+
* With wallet profiles (a mnemonic wallet), pressing opens the profile
|
|
13
|
+
* switcher; the active profile's row is the way into Profile. A recovered-key
|
|
14
|
+
* wallet has no profiles, so it keeps going straight to Profile.
|
|
11
15
|
*/
|
|
12
|
-
import React from 'react'
|
|
13
|
-
import { StyleSheet } from 'react-native'
|
|
14
|
-
import { useTheme, useUserAvatarIcon } from '@bsv/expo-wallet-toolbox'
|
|
16
|
+
import React, { useRef, useState } from 'react'
|
|
17
|
+
import { StyleSheet, View } from 'react-native'
|
|
18
|
+
import { useTheme, useUserAvatarIcon, useWallet } from '@bsv/expo-wallet-toolbox'
|
|
15
19
|
import { useTranslation } from 'react-i18next'
|
|
16
20
|
import PressableScale from '../ui/PressableScale'
|
|
17
21
|
import { AvatarGlyph } from './UserAvatar'
|
|
22
|
+
import ProfileSwitcherPopover from './ProfileSwitcherPopover'
|
|
18
23
|
|
|
19
24
|
type ExpoRouterModule = typeof import('expo-router')
|
|
20
25
|
let expoRouterMod: ExpoRouterModule | undefined
|
|
@@ -31,22 +36,91 @@ export default function ProfileButton() {
|
|
|
31
36
|
const { t } = useTranslation()
|
|
32
37
|
const { router } = loadExpoRouter()
|
|
33
38
|
const avatar = useUserAvatarIcon()
|
|
39
|
+
const {
|
|
40
|
+
profilesSupported,
|
|
41
|
+
profiles,
|
|
42
|
+
activeProfile,
|
|
43
|
+
switchProfile,
|
|
44
|
+
addProfile,
|
|
45
|
+
walletBuilding,
|
|
46
|
+
switchingProfile,
|
|
47
|
+
removingProfile
|
|
48
|
+
} = useWallet()
|
|
49
|
+
const discRef = useRef<View>(null)
|
|
50
|
+
const [open, setOpen] = useState(false)
|
|
51
|
+
/** Which profile the running switch is headed to, for the cover's label. */
|
|
52
|
+
const [target, setTarget] = useState<number | null>(null)
|
|
53
|
+
// Until the first layout measure lands: roughly where Home's top bar puts the disc.
|
|
54
|
+
const [anchor, setAnchor] = useState({ x: 16, y: 54, height: 34 })
|
|
55
|
+
|
|
56
|
+
const openProfile = () => router.push('/profile' as never)
|
|
57
|
+
|
|
58
|
+
// Where the card hangs from, kept current from layout so a press opens at once.
|
|
59
|
+
const measure = () => {
|
|
60
|
+
discRef.current?.measureInWindow?.((x, y, _w, height) => {
|
|
61
|
+
if (Number.isFinite(x) && Number.isFinite(y)) setAnchor({ x, y, height: height || 34 })
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const onPress = () => {
|
|
66
|
+
if (!profilesSupported) {
|
|
67
|
+
openProfile()
|
|
68
|
+
return
|
|
69
|
+
}
|
|
70
|
+
measure()
|
|
71
|
+
setOpen(true)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const run = (to: number, action: () => Promise<void>) => {
|
|
75
|
+
setTarget(to)
|
|
76
|
+
setOpen(false)
|
|
77
|
+
action()
|
|
78
|
+
.catch(err => console.warn('[ProfileButton] profile action failed:', err))
|
|
79
|
+
.finally(() => setTarget(null))
|
|
80
|
+
}
|
|
81
|
+
|
|
34
82
|
return (
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
83
|
+
<>
|
|
84
|
+
<View ref={discRef} collapsable={false} onLayout={measure}>
|
|
85
|
+
<PressableScale
|
|
86
|
+
onPress={onPress}
|
|
87
|
+
haptic="tap"
|
|
88
|
+
hitSlop={5}
|
|
89
|
+
style={[styles.disc, { backgroundColor: colors.surfaceRaised, borderColor: colors.surfaceRaisedBorder }]}
|
|
90
|
+
accessibilityRole="button"
|
|
91
|
+
accessibilityLabel={profilesSupported ? t('profile_switcher_a11y') : t('profile')}
|
|
92
|
+
>
|
|
93
|
+
<AvatarGlyph
|
|
94
|
+
family={avatar?.family ?? 'ionicons'}
|
|
95
|
+
name={avatar?.name ?? 'person-outline'}
|
|
96
|
+
size={17}
|
|
97
|
+
color={colors.textSecondary}
|
|
98
|
+
/>
|
|
99
|
+
</PressableScale>
|
|
100
|
+
</View>
|
|
101
|
+
{profilesSupported && (
|
|
102
|
+
<ProfileSwitcherPopover
|
|
103
|
+
visible={open || switchingProfile}
|
|
104
|
+
onClose={() => setOpen(false)}
|
|
105
|
+
anchor={anchor}
|
|
106
|
+
profiles={profiles}
|
|
107
|
+
active={activeProfile}
|
|
108
|
+
avatar={avatar}
|
|
109
|
+
busy={walletBuilding || switchingProfile}
|
|
110
|
+
// A removal is started from the Profile screen, not from here, so `target` is
|
|
111
|
+
// empty for it: the cover names the profile being removed instead.
|
|
112
|
+
switchingTo={switchingProfile ? (target ?? removingProfile ?? activeProfile) : null}
|
|
113
|
+
removing={typeof removingProfile === 'number'}
|
|
114
|
+
onSelect={n => run(n, () => switchProfile(n))}
|
|
115
|
+
onOpenProfile={() => {
|
|
116
|
+
setOpen(false)
|
|
117
|
+
openProfile()
|
|
118
|
+
}}
|
|
119
|
+
// The full list, removed profiles included: that count is the index the new profile gets.
|
|
120
|
+
onAdd={() => run(profiles.length, addProfile)}
|
|
121
|
+
/>
|
|
122
|
+
)}
|
|
123
|
+
</>
|
|
50
124
|
)
|
|
51
125
|
}
|
|
52
126
|
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The profile switcher: what the Home avatar opens.
|
|
3
|
+
*
|
|
4
|
+
* One row per wallet profile (one mnemonic, many wallets — see
|
|
5
|
+
* core/profiles/profileStore), a checkmark on the active one, and "Add profile"
|
|
6
|
+
* underneath. Tapping the active row opens that profile's own screen (name,
|
|
7
|
+
* handle, picture); tapping another switches the whole wallet to it.
|
|
8
|
+
*
|
|
9
|
+
* A small card hanging under the avatar, styled like the coin switcher
|
|
10
|
+
* (AssetSwitcherDropdown). It sits in a transparent Modal rather than in-tree
|
|
11
|
+
* because the avatar lives inside the header slot, whose box would clip it.
|
|
12
|
+
*
|
|
13
|
+
* While a switch runs, the same Modal turns into a full-screen cover: tearing
|
|
14
|
+
* one wallet down and building the next takes a moment, and the old wallet must
|
|
15
|
+
* not sit there looking live meanwhile. One Modal for both, because iOS will
|
|
16
|
+
* not present a second one while the first is still dismissing.
|
|
17
|
+
*/
|
|
18
|
+
import React from 'react'
|
|
19
|
+
import {
|
|
20
|
+
ActivityIndicator,
|
|
21
|
+
Modal,
|
|
22
|
+
Pressable,
|
|
23
|
+
StyleSheet,
|
|
24
|
+
Text,
|
|
25
|
+
TouchableOpacity,
|
|
26
|
+
View,
|
|
27
|
+
useWindowDimensions
|
|
28
|
+
} from 'react-native'
|
|
29
|
+
import { useTranslation } from 'react-i18next'
|
|
30
|
+
import { hitTargets, radii, spacing, typography, useTheme } from '@bsv/expo-wallet-toolbox'
|
|
31
|
+
import type { ProfileRecord } from '../../../core/profiles/profileStore'
|
|
32
|
+
import { profileLabel } from '../../../core/profiles/profileLabel'
|
|
33
|
+
import type { AppChain } from '../../../core/config'
|
|
34
|
+
import type { AvatarIcon } from '../../../core/userAvatar'
|
|
35
|
+
import { AvatarGlyph } from './UserAvatar'
|
|
36
|
+
|
|
37
|
+
/** Same lazy load as AssetSwitcherDropdown — see the note there. */
|
|
38
|
+
type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
|
|
39
|
+
let ioniconsComponent: IoniconsComponent | undefined
|
|
40
|
+
function loadIonicons(): IoniconsComponent {
|
|
41
|
+
if (!ioniconsComponent) {
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
43
|
+
ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
|
|
44
|
+
}
|
|
45
|
+
return ioniconsComponent
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const NETWORK_LABEL_KEY: Record<AppChain, string> = { main: 'mainnet', test: 'testnet', teratest: 'teratest' }
|
|
49
|
+
|
|
50
|
+
export interface ProfileSwitcherPopoverProps {
|
|
51
|
+
visible: boolean
|
|
52
|
+
onClose: () => void
|
|
53
|
+
/** Window coordinates of the avatar the card hangs from. */
|
|
54
|
+
anchor: { x: number; y: number; height: number }
|
|
55
|
+
/** Every record, removed ones included (their indices stay the other profiles' numbers); the card lists the live ones. */
|
|
56
|
+
profiles: ProfileRecord[]
|
|
57
|
+
active: number
|
|
58
|
+
/** The active profile's avatar; other profiles show the default glyph. */
|
|
59
|
+
avatar: AvatarIcon | null
|
|
60
|
+
/** A build or switch is in flight: rows and Add are inert. */
|
|
61
|
+
busy: boolean
|
|
62
|
+
onSelect: (index: number) => void
|
|
63
|
+
onOpenProfile: () => void
|
|
64
|
+
onAdd: () => void
|
|
65
|
+
/** A switch is running: show the full-screen cover instead of the card. */
|
|
66
|
+
switchingTo?: number | null
|
|
67
|
+
/** The running transition is the removal of `switchingTo`, not a switch to it. */
|
|
68
|
+
removing?: boolean
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export default function ProfileSwitcherPopover({
|
|
72
|
+
visible,
|
|
73
|
+
onClose,
|
|
74
|
+
anchor,
|
|
75
|
+
profiles,
|
|
76
|
+
active,
|
|
77
|
+
avatar,
|
|
78
|
+
busy,
|
|
79
|
+
onSelect,
|
|
80
|
+
onOpenProfile,
|
|
81
|
+
onAdd,
|
|
82
|
+
switchingTo = null,
|
|
83
|
+
removing = false
|
|
84
|
+
}: ProfileSwitcherPopoverProps) {
|
|
85
|
+
const { colors } = useTheme()
|
|
86
|
+
const { t } = useTranslation()
|
|
87
|
+
const { width } = useWindowDimensions()
|
|
88
|
+
const Ionicons = loadIonicons()
|
|
89
|
+
const cardWidth = Math.min(280, width - spacing.lg * 2)
|
|
90
|
+
const left = Math.max(spacing.lg, Math.min(anchor.x, width - spacing.lg - cardWidth))
|
|
91
|
+
const live = profiles.filter(p => !p.deleted)
|
|
92
|
+
|
|
93
|
+
if (switchingTo !== null) {
|
|
94
|
+
// Add heads for an index with no record yet, so fall back to the default label.
|
|
95
|
+
const target = profiles.find(p => p.index === switchingTo) ?? { index: switchingTo }
|
|
96
|
+
return (
|
|
97
|
+
<Modal visible transparent animationType="fade" onRequestClose={() => {}} statusBarTranslucent>
|
|
98
|
+
<View
|
|
99
|
+
testID="profile-switch-cover"
|
|
100
|
+
style={[styles.cover, { backgroundColor: colors.background }]}
|
|
101
|
+
accessibilityViewIsModal
|
|
102
|
+
accessibilityLiveRegion="polite"
|
|
103
|
+
>
|
|
104
|
+
<ActivityIndicator size="large" color={colors.textSecondary} />
|
|
105
|
+
<Text style={[styles.coverLabel, { color: colors.textSecondary }]}>
|
|
106
|
+
{t(removing ? 'profile_removing' : 'profile_switching', { profile: profileLabel(target, t) })}
|
|
107
|
+
</Text>
|
|
108
|
+
</View>
|
|
109
|
+
</Modal>
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<Modal visible={visible} transparent animationType="fade" onRequestClose={onClose} statusBarTranslucent>
|
|
115
|
+
<Pressable
|
|
116
|
+
style={StyleSheet.absoluteFill}
|
|
117
|
+
onPress={onClose}
|
|
118
|
+
accessibilityRole="button"
|
|
119
|
+
accessibilityLabel={t('cancel')}
|
|
120
|
+
/>
|
|
121
|
+
<View
|
|
122
|
+
testID="profile-switcher"
|
|
123
|
+
style={[
|
|
124
|
+
styles.card,
|
|
125
|
+
{
|
|
126
|
+
top: anchor.y + anchor.height + spacing.xs,
|
|
127
|
+
left,
|
|
128
|
+
width: cardWidth,
|
|
129
|
+
backgroundColor: colors.surfaceRaised,
|
|
130
|
+
borderColor: colors.surfaceRaisedBorder,
|
|
131
|
+
shadowColor: colors.textPrimary
|
|
132
|
+
}
|
|
133
|
+
]}
|
|
134
|
+
>
|
|
135
|
+
<View style={styles.list}>
|
|
136
|
+
{live.map(p => {
|
|
137
|
+
const selected = p.index === active
|
|
138
|
+
const label = profileLabel(p, t)
|
|
139
|
+
const network = p.network !== 'main' ? t(NETWORK_LABEL_KEY[p.network]) : undefined
|
|
140
|
+
return (
|
|
141
|
+
<TouchableOpacity
|
|
142
|
+
key={p.index}
|
|
143
|
+
testID={`profile-row-${p.index}`}
|
|
144
|
+
style={[styles.row, selected && { backgroundColor: colors.fill }]}
|
|
145
|
+
onPress={() => (selected ? onOpenProfile() : onSelect(p.index))}
|
|
146
|
+
disabled={busy}
|
|
147
|
+
activeOpacity={0.6}
|
|
148
|
+
accessibilityRole="button"
|
|
149
|
+
accessibilityState={{ selected, disabled: busy }}
|
|
150
|
+
accessibilityLabel={[label, network].filter(Boolean).join(', ')}
|
|
151
|
+
>
|
|
152
|
+
<View
|
|
153
|
+
style={[styles.disc, { backgroundColor: colors.background, borderColor: colors.surfaceRaisedBorder }]}
|
|
154
|
+
>
|
|
155
|
+
<AvatarGlyph
|
|
156
|
+
family={selected && avatar ? avatar.family : 'ionicons'}
|
|
157
|
+
name={selected && avatar ? avatar.name : 'person-outline'}
|
|
158
|
+
size={15}
|
|
159
|
+
color={colors.textSecondary}
|
|
160
|
+
/>
|
|
161
|
+
</View>
|
|
162
|
+
<View style={styles.body}>
|
|
163
|
+
<Text style={[styles.name, { color: colors.textPrimary }]} numberOfLines={1}>
|
|
164
|
+
{label}
|
|
165
|
+
</Text>
|
|
166
|
+
{!!network && (
|
|
167
|
+
<Text style={[styles.detail, { color: colors.textSecondary }]} numberOfLines={1}>
|
|
168
|
+
{network}
|
|
169
|
+
</Text>
|
|
170
|
+
)}
|
|
171
|
+
</View>
|
|
172
|
+
<View style={styles.check}>
|
|
173
|
+
{selected && <Ionicons name="checkmark" size={20} color={colors.accent} />}
|
|
174
|
+
</View>
|
|
175
|
+
</TouchableOpacity>
|
|
176
|
+
)
|
|
177
|
+
})}
|
|
178
|
+
</View>
|
|
179
|
+
<View style={[styles.separator, { backgroundColor: colors.separator }]} />
|
|
180
|
+
<TouchableOpacity
|
|
181
|
+
testID="profile-add"
|
|
182
|
+
style={styles.row}
|
|
183
|
+
onPress={onAdd}
|
|
184
|
+
disabled={busy}
|
|
185
|
+
activeOpacity={0.6}
|
|
186
|
+
accessibilityRole="button"
|
|
187
|
+
accessibilityState={{ disabled: busy }}
|
|
188
|
+
accessibilityLabel={t('profile_add')}
|
|
189
|
+
>
|
|
190
|
+
<View style={styles.disc}>
|
|
191
|
+
<Ionicons name="add-circle-outline" size={22} color={colors.accent} />
|
|
192
|
+
</View>
|
|
193
|
+
<Text style={[styles.name, styles.body, { color: colors.accent }]}>{t('profile_add')}</Text>
|
|
194
|
+
</TouchableOpacity>
|
|
195
|
+
</View>
|
|
196
|
+
</Modal>
|
|
197
|
+
)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const styles = StyleSheet.create({
|
|
201
|
+
card: {
|
|
202
|
+
position: 'absolute',
|
|
203
|
+
// Same numbers as the coin switcher card, so the two read as one family.
|
|
204
|
+
borderRadius: 20,
|
|
205
|
+
borderWidth: StyleSheet.hairlineWidth,
|
|
206
|
+
padding: 6,
|
|
207
|
+
elevation: 12,
|
|
208
|
+
shadowOffset: { width: 0, height: 16 },
|
|
209
|
+
shadowOpacity: 0.22,
|
|
210
|
+
shadowRadius: 30
|
|
211
|
+
},
|
|
212
|
+
list: { gap: 2 },
|
|
213
|
+
row: {
|
|
214
|
+
flexDirection: 'row',
|
|
215
|
+
alignItems: 'center',
|
|
216
|
+
gap: spacing.md,
|
|
217
|
+
minHeight: hitTargets.minimum,
|
|
218
|
+
paddingVertical: 9,
|
|
219
|
+
paddingHorizontal: 10,
|
|
220
|
+
borderRadius: radii.lg
|
|
221
|
+
},
|
|
222
|
+
disc: {
|
|
223
|
+
width: 30,
|
|
224
|
+
height: 30,
|
|
225
|
+
borderRadius: 15,
|
|
226
|
+
borderWidth: StyleSheet.hairlineWidth,
|
|
227
|
+
borderColor: 'transparent',
|
|
228
|
+
alignItems: 'center',
|
|
229
|
+
justifyContent: 'center'
|
|
230
|
+
},
|
|
231
|
+
body: { flex: 1, minWidth: 0 },
|
|
232
|
+
name: { ...typography.body, fontWeight: '600' },
|
|
233
|
+
detail: { ...typography.footnote, marginTop: 1 },
|
|
234
|
+
check: { width: 20, alignItems: 'center' },
|
|
235
|
+
separator: { height: StyleSheet.hairlineWidth, marginHorizontal: 10, marginVertical: 4 },
|
|
236
|
+
cover: {
|
|
237
|
+
position: 'absolute',
|
|
238
|
+
top: 0,
|
|
239
|
+
left: 0,
|
|
240
|
+
right: 0,
|
|
241
|
+
bottom: 0,
|
|
242
|
+
alignItems: 'center',
|
|
243
|
+
justifyContent: 'center',
|
|
244
|
+
gap: spacing.lg
|
|
245
|
+
},
|
|
246
|
+
coverLabel: { ...typography.body }
|
|
247
|
+
})
|
|
@@ -12,9 +12,10 @@ import { updateOfflineAction, type OfflineActionRow } from '../../core/storage/m
|
|
|
12
12
|
import type { StorageExpoSQLite } from '../../core/storage/StorageExpoSQLite'
|
|
13
13
|
import { showToast } from '../components/ui/Toast'
|
|
14
14
|
import { offlineActionDetails } from '../components/pay/OfflineNotice'
|
|
15
|
+
import { profileScopedKey } from '../../core/profiles/profileStore'
|
|
15
16
|
|
|
16
17
|
async function readMessageBoxUrl(): Promise<string | undefined> {
|
|
17
|
-
const saved = await AsyncStorage.getItem(MESSAGE_BOX_URL_KEY)
|
|
18
|
+
const saved = await AsyncStorage.getItem(profileScopedKey(MESSAGE_BOX_URL_KEY))
|
|
18
19
|
if (saved === NO_MESSAGE_BOX) return undefined
|
|
19
20
|
if (!saved || saved === LEGACY_MESSAGE_BOX_URL) return DEFAULT_MESSAGE_BOX_URL
|
|
20
21
|
return saved
|
|
@@ -12,10 +12,12 @@ import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
|
12
12
|
import { sdk } from '@bsv/wallet-toolbox-mobile'
|
|
13
13
|
import { useWallet, readWalletBalance } from '@bsv/expo-wallet-toolbox'
|
|
14
14
|
import { storageMatchesNetwork } from '../../core/net/chainMatch'
|
|
15
|
+
import { profileScopedKey, useActiveProfileIndex } from '../../core/profiles/profileStore'
|
|
15
16
|
|
|
16
17
|
export function useSpendableBalance(): number | null {
|
|
17
18
|
const { managers, adminOriginator, selectedNetwork, storage, txStatusVersion, walletUserId } = useWallet()
|
|
18
|
-
const
|
|
19
|
+
const activeProfile = useActiveProfileIndex()
|
|
20
|
+
const cacheKey = profileScopedKey(`cached_wallet_balance_${selectedNetwork}`, activeProfile)
|
|
19
21
|
const [balance, setBalance] = useState<{ key: string; value: number } | null>(null)
|
|
20
22
|
// Serialize reads, retaining the latest invalidation while one is in flight.
|
|
21
23
|
// A plain busy flag loses it: the old effect is cancelled, while the new one
|