@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.
- package/CHANGELOG.md +71 -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 +841 -236
- 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/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/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
|
@@ -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
|
|
@@ -81,12 +81,11 @@ export async function printRecoveryShares(sources: PrintSharesSources): Promise<
|
|
|
81
81
|
return { ok: false, reason: 'no-material' }
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
//
|
|
85
|
-
//
|
|
86
|
-
//
|
|
87
|
-
//
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
84
|
+
// All shares go in one print job as a multi-page document, so the user gets
|
|
85
|
+
// one dialog (and one PDF, if they save rather than print) with every page.
|
|
86
|
+
// XR-110 split this into one job per share so no single spooled job held the
|
|
87
|
+
// 2-of-3 threshold; the owner reverted that (2026-10-01) as accepted risk —
|
|
88
|
+
// the follow-on dialogs were invisible, and users kept only the first share.
|
|
89
|
+
await Print.printAsync({ html: await generatePrintHTML(shares, identityKey, format, sources.appName) })
|
|
91
90
|
return { ok: true, format }
|
|
92
91
|
}
|
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
AUTO_APPROVE_DAILY_CAP_SATS
|
|
27
27
|
} from '@bsv/expo-wallet-toolbox'
|
|
28
28
|
import { computeConnectionAuthorityTag } from '../../core/services/connectionAuthority'
|
|
29
|
+
import { profileScopedKey } from '../../core/profiles/profileStore'
|
|
29
30
|
|
|
30
31
|
/**
|
|
31
32
|
* expo-router is required lazily rather than imported at module scope: this
|
|
@@ -78,7 +79,7 @@ export function PairScreen() {
|
|
|
78
79
|
// reads for spendingAuthorizationCallback — 0/unset means auto-approve is off.
|
|
79
80
|
const [autoApproveThreshold, setAutoApproveThreshold] = useState(DEFAULT_AUTO_APPROVE_THRESHOLD)
|
|
80
81
|
useEffect(() => {
|
|
81
|
-
AsyncStorage.getItem(AUTO_APPROVE_STORAGE_KEY)
|
|
82
|
+
AsyncStorage.getItem(profileScopedKey(AUTO_APPROVE_STORAGE_KEY))
|
|
82
83
|
.then(v => { if (v !== null) setAutoApproveThreshold(Number(v) || 0) })
|
|
83
84
|
.catch(() => {})
|
|
84
85
|
}, [])
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Profile — your display name (pencil →
|
|
3
|
-
* state, or the claim flow), and your
|
|
4
|
-
* QR (its own screen) or copy it.
|
|
2
|
+
* Profile — this profile's private name and your display name (pencil →
|
|
3
|
+
* confirm), your handle (registered state, or the claim flow), and your
|
|
4
|
+
* Identifier with a way to show it as a QR (its own screen) or copy it.
|
|
5
|
+
*
|
|
6
|
+
* The profile name is a label for the switcher, kept on this device only (the
|
|
7
|
+
* profile store, not the wallet database): unlike the display name it is never
|
|
8
|
+
* published. A recovered-key wallet has no profiles, so no such field.
|
|
5
9
|
*
|
|
6
10
|
* The registry, not this device, is the source of truth for which handle this
|
|
7
11
|
* key holds: `profile_registered_handle` is only an offline cache, shown at
|
|
@@ -10,6 +14,11 @@
|
|
|
10
14
|
* anything. A build with no registry configured for the selected chain says so
|
|
11
15
|
* (`profile_handle_unavailable`) rather than pretending a check can succeed.
|
|
12
16
|
*
|
|
17
|
+
* A profile other than the first can be removed from here ("Remove profile"):
|
|
18
|
+
* the check runs first and explains a refusal, the confirm says what happens
|
|
19
|
+
* (and, with a handle, the cooldown it starts), and only then does it go. See
|
|
20
|
+
* core/profiles/removeProfile for what removal does and in what order.
|
|
21
|
+
*
|
|
13
22
|
* The hero disc wears whatever icon the user picked ("Edit picture" →
|
|
14
23
|
* "Pick icon"), and the same choice is what every other "you" in the app
|
|
15
24
|
* draws — see `core/userAvatar.ts`. Photo sources are not offered yet: they
|
|
@@ -25,6 +34,7 @@ import PressableScale from '../components/ui/PressableScale'
|
|
|
25
34
|
import { GroupedSection } from '../components/ui/GroupedList'
|
|
26
35
|
import { ListRow } from '../components/ui/ListRow'
|
|
27
36
|
import { PencilEditField } from '../components/ui/PencilEditField'
|
|
37
|
+
import { showAlert } from '../components/ui/AlertCard'
|
|
28
38
|
import { showToast } from '../components/ui/Toast'
|
|
29
39
|
import IdentifierRow from '../components/wallet/IdentifierRow'
|
|
30
40
|
import { AvatarGlyph } from '../components/wallet/UserAvatar'
|
|
@@ -33,6 +43,14 @@ import IconPickerSheet from '../components/wallet/IconPickerSheet'
|
|
|
33
43
|
import { makeIdentityClient, resolveIdentity } from '../resolveIdentity'
|
|
34
44
|
import { getHandleRegistryConfig } from '../../core/toolboxConfig'
|
|
35
45
|
import { bindOriginator } from '../../core/mandala/createRuntime'
|
|
46
|
+
import { profileLabel } from '../../core/profiles/profileLabel'
|
|
47
|
+
import type { RemovalBlocker } from '../../core/profiles/assertProfileEmpty'
|
|
48
|
+
import type { ProfileRemovalCheck, RemoveProfileResult } from '../../core/profiles/removeProfile'
|
|
49
|
+
import {
|
|
50
|
+
MAX_PROFILE_NAME_LENGTH,
|
|
51
|
+
updateProfile as updateProfileRecord,
|
|
52
|
+
useProfiles
|
|
53
|
+
} from '../../core/profiles/profileStore'
|
|
36
54
|
import { isValidHandleFormat, parsePaymail } from '../../core/identity/handleRegistry/rules'
|
|
37
55
|
import type { ProfileSigner } from '../../core/identity/handleRegistry/profileCert'
|
|
38
56
|
import { createHandleRegistryClient, type AvailabilityReason } from '../../core/identity/handleRegistry/client'
|
|
@@ -79,14 +97,60 @@ const HANDLE_KV_KEY = 'profile_registered_handle'
|
|
|
79
97
|
const DISPLAY_NAME_KV_KEY = 'profile_display_name'
|
|
80
98
|
const HANDLE_CHECK_DEBOUNCE_MS = 400
|
|
81
99
|
|
|
100
|
+
/** What can stand in the way of removing a profile, grouped the way the user is told about it. */
|
|
101
|
+
const FUNDS_BLOCKERS: RemovalBlocker[] = ['spendable-outputs', 'token-balance']
|
|
102
|
+
const PENDING_BLOCKERS: RemovalBlocker[] = [
|
|
103
|
+
'pending-transactions',
|
|
104
|
+
'offline-queue',
|
|
105
|
+
'token-settlements',
|
|
106
|
+
'localpay-pending',
|
|
107
|
+
'peerpay-outbox',
|
|
108
|
+
'inbox-pending'
|
|
109
|
+
]
|
|
110
|
+
|
|
111
|
+
type RemovalProblem = Exclude<ProfileRemovalCheck, { kind: 'ok' }> | Exclude<RemoveProfileResult, { kind: 'removed' }>
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* How long the switch cover takes to leave. A removal runs under it (a Modal on
|
|
115
|
+
* the Home screen underneath this one), and it is dismissed in the same tick the
|
|
116
|
+
* removal's answer arrives. iOS will not present a second Modal while the first
|
|
117
|
+
* is still dismissing, and an alert that is dropped never settles, so an
|
|
118
|
+
* explanation of a failure that followed the cover waits this long: the fade and
|
|
119
|
+
* a margin.
|
|
120
|
+
*/
|
|
121
|
+
export const PROFILE_COVER_FADE_MS = 500
|
|
122
|
+
const untilCoverGone = () => new Promise<void>(resolve => setTimeout(resolve, PROFILE_COVER_FADE_MS))
|
|
123
|
+
|
|
124
|
+
/** The i18n keys that explain a refusal or failure, one paragraph per kind of reason. */
|
|
125
|
+
function removalProblemKeys(problem: RemovalProblem): string[] {
|
|
126
|
+
if (problem.kind === 'refused')
|
|
127
|
+
return [problem.reason === 'offline' ? 'profile_remove_offline' : 'profile_remove_failed']
|
|
128
|
+
if (problem.kind === 'handle-failed') return ['profile_remove_failed_handle']
|
|
129
|
+
if (problem.kind === 'blocked') {
|
|
130
|
+
const keys: string[] = []
|
|
131
|
+
const has = (group: RemovalBlocker[]) => problem.reasons.some(r => group.includes(r))
|
|
132
|
+
if (has(FUNDS_BLOCKERS)) keys.push('profile_remove_blocked_funds')
|
|
133
|
+
if (has(PENDING_BLOCKERS)) keys.push('profile_remove_blocked_pending')
|
|
134
|
+
// Funds or pending activity in the databases of its other networks, which the open one never shows.
|
|
135
|
+
if (problem.reasons.includes('other-network')) keys.push('profile_remove_blocked_network')
|
|
136
|
+
// An unfinished handle write is the same thing to the user as a handle that would not release.
|
|
137
|
+
if (problem.reasons.includes('handle-journal')) keys.push('profile_remove_failed_handle')
|
|
138
|
+
if (problem.reasons.includes('check-failed')) keys.push('profile_remove_blocked_check')
|
|
139
|
+
if (keys.length > 0) return keys
|
|
140
|
+
}
|
|
141
|
+
return ['profile_remove_failed']
|
|
142
|
+
}
|
|
143
|
+
|
|
82
144
|
export function ProfileScreen() {
|
|
83
145
|
const { t } = useTranslation()
|
|
84
146
|
const { colors } = useTheme()
|
|
85
147
|
const insets = useSafeAreaInsets()
|
|
86
148
|
const Ionicons = loadIonicons()
|
|
87
149
|
const { router } = loadExpoRouter()
|
|
88
|
-
const { managers, adminOriginator, selectedNetwork, storage } =
|
|
150
|
+
const { managers, adminOriginator, selectedNetwork, storage, profilesSupported, checkProfileRemoval, removeProfile } =
|
|
151
|
+
useWallet()
|
|
89
152
|
const wallet = managers?.permissionsManager || null
|
|
153
|
+
const { active: activeProfile, profiles } = useProfiles()
|
|
90
154
|
|
|
91
155
|
const [identityKey, setIdentityKey] = useState('')
|
|
92
156
|
const avatarIcon = useUserAvatarIcon()
|
|
@@ -101,6 +165,14 @@ export function ProfileScreen() {
|
|
|
101
165
|
const [registering, setRegistering] = useState(false)
|
|
102
166
|
/** A journalled write that has not landed yet. Non-blocking, with a retry. */
|
|
103
167
|
const [finishing, setFinishing] = useState(false)
|
|
168
|
+
/**
|
|
169
|
+
* Remove profile is running. Its own flag rather than a read of the active
|
|
170
|
+
* profile, which flips to 0 partway through — that is the removal working —
|
|
171
|
+
* and the row must not vanish from under its own spinner.
|
|
172
|
+
*/
|
|
173
|
+
const [removing, setRemoving] = useState(false)
|
|
174
|
+
/** The same flag, readable before the next render: two taps in one frame must not start two removals. */
|
|
175
|
+
const removingRef = useRef(false)
|
|
104
176
|
|
|
105
177
|
/**
|
|
106
178
|
* Two strings, not the config object: `getHandleRegistryConfig` builds a
|
|
@@ -211,6 +283,19 @@ export function ProfileScreen() {
|
|
|
211
283
|
} else if (result.kind === 'pending' || result.kind === 'idle') {
|
|
212
284
|
// The callout says the first. The second is the ordinary mount, with
|
|
213
285
|
// nothing journalled and so nothing to report.
|
|
286
|
+
} else if (result.kind === 'released') {
|
|
287
|
+
// Only a resumed journal gets here: this screen never starts a release
|
|
288
|
+
// itself, profile removal does. Finishing one means the handle is gone,
|
|
289
|
+
// and the lookup that follows the resume cannot be left to say so — it
|
|
290
|
+
// may be offline, and then the cache would keep offering a handle the
|
|
291
|
+
// registry no longer holds. Nothing to announce: the user asked for the
|
|
292
|
+
// removal that wrote the journal.
|
|
293
|
+
handleEpoch.current += 1
|
|
294
|
+
setRegisteredPaymail(null)
|
|
295
|
+
void storage?.setKeyValue(HANDLE_KV_KEY, '')
|
|
296
|
+
setChangingHandle(false)
|
|
297
|
+
setHandleInput('')
|
|
298
|
+
setAvailability('idle')
|
|
214
299
|
} else if (result.kind === 'unavailable') {
|
|
215
300
|
showToast(t('profile_handle_unavailable'), { type: 'error' })
|
|
216
301
|
} else if (result.kind === 'rejected') {
|
|
@@ -402,6 +487,82 @@ export function ProfileScreen() {
|
|
|
402
487
|
[storage, client, signer, registeredPaymail, finishing, applyResult, t]
|
|
403
488
|
)
|
|
404
489
|
|
|
490
|
+
/** Only this device's store: the name is never published, so there is nothing to wait on. */
|
|
491
|
+
const onSaveProfileName = useCallback(
|
|
492
|
+
(next: string) => updateProfileRecord(activeProfile, { name: next }),
|
|
493
|
+
[activeProfile]
|
|
494
|
+
)
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Ask, confirm, remove. The check comes first and changes nothing, so a
|
|
498
|
+
* refusal is explained before anyone is asked to confirm; the removal then
|
|
499
|
+
* checks again for itself, since the dialog may have sat open a while.
|
|
500
|
+
*/
|
|
501
|
+
const onRemoveProfile = useCallback(async () => {
|
|
502
|
+
if (removingRef.current) return
|
|
503
|
+
removingRef.current = true
|
|
504
|
+
setRemoving(true)
|
|
505
|
+
// Named now: by the time anything is shown the active profile may be another one.
|
|
506
|
+
const label = profileLabel(profiles[activeProfile] ?? { index: activeProfile }, t)
|
|
507
|
+
let removed = false
|
|
508
|
+
/** The switch cover has been up since the removal started, so what follows it waits for it to go. */
|
|
509
|
+
let covered = false
|
|
510
|
+
const explain = async (problem: RemovalProblem) => {
|
|
511
|
+
if (covered) await untilCoverGone()
|
|
512
|
+
return showAlert({
|
|
513
|
+
title: t('profile_remove_problem_title', { profile: label }),
|
|
514
|
+
message: removalProblemKeys(problem)
|
|
515
|
+
.map(key => t(key))
|
|
516
|
+
.join('\n\n'),
|
|
517
|
+
buttons: [{ text: t('vault_ok'), key: 'ok' }]
|
|
518
|
+
})
|
|
519
|
+
}
|
|
520
|
+
try {
|
|
521
|
+
const check = await checkProfileRemoval()
|
|
522
|
+
if (check.kind !== 'ok') {
|
|
523
|
+
await explain(check)
|
|
524
|
+
return
|
|
525
|
+
}
|
|
526
|
+
const choice = await showAlert({
|
|
527
|
+
title: t('profile_remove_confirm_title', { profile: label }),
|
|
528
|
+
message: [
|
|
529
|
+
t('profile_remove_confirm_body', { profile: label }),
|
|
530
|
+
check.handle ? t('profile_remove_confirm_handle', { handle: check.handle }) : null
|
|
531
|
+
]
|
|
532
|
+
.filter(Boolean)
|
|
533
|
+
.join('\n\n'),
|
|
534
|
+
buttons: [
|
|
535
|
+
{ text: t('cancel'), style: 'cancel', key: 'cancel' },
|
|
536
|
+
{ text: t('profile_remove_confirm_action'), style: 'destructive', key: 'remove' }
|
|
537
|
+
]
|
|
538
|
+
})
|
|
539
|
+
if (choice !== 'remove') return
|
|
540
|
+
covered = true
|
|
541
|
+
const result = await removeProfile()
|
|
542
|
+
if (result.kind !== 'removed') {
|
|
543
|
+
await explain(result)
|
|
544
|
+
return
|
|
545
|
+
}
|
|
546
|
+
removed = true
|
|
547
|
+
showToast(t('profile_removed', { profile: label }), { type: 'success' })
|
|
548
|
+
// Profile 0 is open now and this screen was about this profile: leave it,
|
|
549
|
+
// the same way Delete Wallet does (dismissAll leaves one screen, so replace it).
|
|
550
|
+
router.dismissAll()
|
|
551
|
+
router.replace('/')
|
|
552
|
+
} catch (err) {
|
|
553
|
+
// The flow answers rather than throws, so this is a fault in the plumbing
|
|
554
|
+
// around it: still tell the user, and leave nothing unhandled in a press.
|
|
555
|
+
console.warn('[ProfileScreen] removing the profile failed', err)
|
|
556
|
+
await explain({ kind: 'failed', message: err instanceof Error ? err.message : String(err) })
|
|
557
|
+
} finally {
|
|
558
|
+
removingRef.current = false
|
|
559
|
+
setRemoving(false)
|
|
560
|
+
// An attempt may have released the handle or finished a journalled write
|
|
561
|
+
// without going through: have the screen ask the registry again.
|
|
562
|
+
if (!removed) setResumeNonce(n => n + 1)
|
|
563
|
+
}
|
|
564
|
+
}, [profiles, activeProfile, t, checkProfileRemoval, removeProfile, router])
|
|
565
|
+
|
|
405
566
|
const handle = handleInput.trim().toLowerCase()
|
|
406
567
|
const paymailPreview = registryDomain ? `${handle}@${registryDomain}` : handle
|
|
407
568
|
const editingHandle = !!registryDomain && (!registeredPaymail || changingHandle)
|
|
@@ -487,6 +648,20 @@ export function ProfileScreen() {
|
|
|
487
648
|
</PressableScale>
|
|
488
649
|
</View>
|
|
489
650
|
|
|
651
|
+
{profilesSupported && (
|
|
652
|
+
<GroupedSection header={t('profile_name')} footer={t('profile_name_hint')}>
|
|
653
|
+
<PencilEditField
|
|
654
|
+
value={profiles[activeProfile]?.name ?? ''}
|
|
655
|
+
placeholder={profileLabel({ index: activeProfile }, t)}
|
|
656
|
+
onSave={onSaveProfileName}
|
|
657
|
+
editAccessibilityLabel={t('profile_name_edit')}
|
|
658
|
+
saveAccessibilityLabel={t('profile_name_save')}
|
|
659
|
+
maxLength={MAX_PROFILE_NAME_LENGTH}
|
|
660
|
+
allowEmpty
|
|
661
|
+
/>
|
|
662
|
+
</GroupedSection>
|
|
663
|
+
)}
|
|
664
|
+
|
|
490
665
|
<GroupedSection header={t('profile_display_name')} footer={t('profile_display_name_hint')}>
|
|
491
666
|
<PencilEditField
|
|
492
667
|
value={displayName}
|
|
@@ -645,6 +820,22 @@ export function ProfileScreen() {
|
|
|
645
820
|
/>
|
|
646
821
|
{!!identityKey && <IdentifierRow identityKey={identityKey} />}
|
|
647
822
|
</GroupedSection>
|
|
823
|
+
|
|
824
|
+
{profilesSupported && (activeProfile !== 0 || removing) && (
|
|
825
|
+
<GroupedSection>
|
|
826
|
+
<ListRow
|
|
827
|
+
label={t('profile_remove')}
|
|
828
|
+
subtitle={t('profile_remove_hint')}
|
|
829
|
+
icon="trash-outline"
|
|
830
|
+
iconColor={colors.error}
|
|
831
|
+
destructive
|
|
832
|
+
showChevron={false}
|
|
833
|
+
onPress={onRemoveProfile}
|
|
834
|
+
trailing={removing ? <ActivityIndicator size="small" color={colors.error} /> : undefined}
|
|
835
|
+
isLast
|
|
836
|
+
/>
|
|
837
|
+
</GroupedSection>
|
|
838
|
+
)}
|
|
648
839
|
</ScrollView>
|
|
649
840
|
|
|
650
841
|
{/* Where a picture comes from. One source today; Take Photo and Photo
|
|
@@ -10,6 +10,7 @@ import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
|
10
10
|
import { pushAdvisory } from '../../core/push/pushAdvisory'
|
|
11
11
|
import type { PushPermission } from '../../core/push/types'
|
|
12
12
|
import { getPushAdapter } from '../../core/toolboxConfig'
|
|
13
|
+
import { profileScopedKey, useActiveProfileIndex } from '../../core/profiles/profileStore'
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* expo-router is required lazily rather than imported at module scope: this
|
|
@@ -38,18 +39,21 @@ export function SettingsScreen() {
|
|
|
38
39
|
// equivalent to a direct import (same as WalletHomeScreen/PayScreen).
|
|
39
40
|
const { router, useFocusEffect } = loadExpoRouter()
|
|
40
41
|
const { managers, adminOriginator, selectedNetwork, txStatusVersion } = useWallet()
|
|
42
|
+
const activeProfile = useActiveProfileIndex()
|
|
41
43
|
|
|
42
44
|
// Read during render, from the reactive network, so the row disappears on a
|
|
43
45
|
// switch to testnet without a remount.
|
|
44
|
-
const vaultAvailable = isVaultAvailable(selectedNetwork)
|
|
46
|
+
const vaultAvailable = isVaultAvailable(selectedNetwork, activeProfile)
|
|
45
47
|
// F-07: an existing, already-funded vault stays reachable even when the
|
|
46
48
|
// flag is off or the network switched — see showVaultRow below. VaultScreen
|
|
47
49
|
// itself is never gated on that flag for withdraw.
|
|
48
50
|
const { hasVaultMeta } = useVault()
|
|
49
|
-
|
|
51
|
+
// Only the default profile has a vault — on any other an empty vault would
|
|
52
|
+
// read as the user's vault being gone.
|
|
53
|
+
const showVaultRow = activeProfile === 0 && (vaultAvailable || hasVaultMeta)
|
|
50
54
|
|
|
51
|
-
const balanceCacheKey = `cached_wallet_balance_${selectedNetwork}
|
|
52
|
-
const balanceCacheTimestampKey = `cached_wallet_balance_ts_${selectedNetwork}
|
|
55
|
+
const balanceCacheKey = profileScopedKey(`cached_wallet_balance_${selectedNetwork}`, activeProfile)
|
|
56
|
+
const balanceCacheTimestampKey = profileScopedKey(`cached_wallet_balance_ts_${selectedNetwork}`, activeProfile)
|
|
53
57
|
const [accountBalance, setAccountBalance] = useState<number | null>(null)
|
|
54
58
|
const [balanceLoading, setBalanceLoading] = useState(false)
|
|
55
59
|
|