@bsv/expo-wallet-toolbox 0.5.0 → 0.9.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 +2000 -0
- package/README.md +66 -1
- package/core/amountFormatHelpers.ts +258 -36
- package/core/backup/RemoteSyncReader.ts +133 -24
- package/core/backup/appData.ts +157 -0
- package/core/backup/client.ts +15 -1
- package/core/backup/codec.ts +149 -11
- package/core/backup/constants.ts +30 -1
- package/core/backup/cursor.ts +31 -2
- package/core/backup/push.ts +71 -5
- package/core/backup/restore.ts +104 -16
- package/core/backup/restoreOnImport.ts +94 -30
- package/core/backup/status.ts +13 -8
- package/core/config.tsx +12 -5
- package/core/constants.ts +14 -1
- package/core/contacts/contactActivity.ts +153 -0
- package/core/contacts/contactCache.ts +41 -0
- package/core/contacts/contactsStore.ts +183 -0
- package/core/context/ExchangeRateContext.tsx +34 -27
- package/core/context/LocalStorageProvider.tsx +43 -40
- package/core/context/UserContext.tsx +18 -7
- package/core/context/VaultContext.tsx +49 -2
- package/core/context/WalletConnectionContext.tsx +203 -11
- package/core/context/WalletContext.tsx +685 -171
- package/core/demo/demoAssets.ts +60 -0
- package/core/demo/demoLedger.ts +240 -0
- package/core/demo/demoMandalaRuntime.ts +96 -0
- package/core/demo/demoMode.ts +38 -0
- package/core/demo/demoWallet.ts +25 -0
- package/core/demo/index.ts +26 -0
- package/core/demo/useDemo.ts +59 -0
- package/core/headers/OfflineFirstChaintracks.ts +99 -17
- package/core/headers/headerStore.ts +33 -14
- package/core/headers/syncHeaders.ts +12 -1
- package/core/i18n/translations.tsx +2186 -98
- package/core/identity/contactLink.ts +36 -0
- package/core/identity/handleRegistry/client.ts +314 -0
- package/core/identity/handleRegistry/keyPinStore.ts +70 -0
- package/core/identity/handleRegistry/profileCert.ts +254 -0
- package/core/identity/handleRegistry/registration.ts +559 -0
- package/core/identity/handleRegistry/resolver.ts +315 -0
- package/core/identity/handleRegistry/rules.ts +104 -0
- package/core/index.ts +53 -5
- package/core/localpay/build.ts +225 -24
- package/core/localpay/pending.ts +110 -7
- package/core/localpay/pendingAbortAuthority.ts +95 -0
- package/core/localpay/pendingAborts.ts +266 -26
- package/core/localpay/session.ts +42 -17
- package/core/localpay/settlementAck.ts +10 -1
- package/core/localpay/transport/socket.ts +52 -3
- package/core/localpay/verify.ts +100 -10
- package/core/mandala/abortGuard.ts +96 -20
- package/core/mandala/createRuntime.ts +206 -33
- package/core/mandala/drain.ts +89 -11
- package/core/mandala/inboxPrehold.ts +186 -0
- package/core/mandala/permissionModule.ts +202 -20
- package/core/mandala/settlementStore.ts +24 -2
- package/core/mandala/types.ts +40 -5
- package/core/monitor/MonitorSupervisor.ts +121 -0
- package/core/monitor/TaskBackupPush.ts +15 -1
- package/core/monitor/TaskCreditInbox.ts +1 -1
- package/core/monitor/TaskDrainOutbox.ts +15 -1
- package/core/monitor/TaskSendOffline.ts +15 -1
- package/core/net/online.ts +49 -0
- package/core/net/publicDestination.ts +91 -0
- package/core/net/validateArcUrl.ts +22 -0
- package/core/numberFormat.ts +19 -0
- package/core/offline/cancelParked.ts +134 -13
- package/core/offline/payerHold.ts +100 -24
- package/core/offline/plan.ts +37 -8
- package/core/pay/beefRepair.ts +6 -2
- package/core/pay/damagedInbox.ts +24 -0
- package/core/pay/rails/address.ts +107 -12
- package/core/pay/rails/handle.ts +117 -22
- package/core/pay/rails/index.ts +45 -7
- package/core/pay/rails/nativeIntent.ts +61 -0
- package/core/pay/receiveHistory.ts +93 -0
- package/core/pay/recordProof.ts +21 -7
- package/core/pay/refreshProofGuard.ts +42 -1
- package/core/pay/watchlist.ts +5 -2
- package/core/peerpay/control.ts +17 -18
- package/core/peerpay/handleResendRequests.ts +58 -4
- package/core/peerpay/outbox.ts +3 -1
- package/core/recovery/backupMaterial.ts +61 -0
- package/core/recovery/createWallet.ts +95 -0
- package/core/recovery/recoverWallet.ts +120 -0
- package/core/recovery/restoreWallet.ts +170 -0
- package/core/recovery/secret.ts +92 -0
- package/core/recovery/shareCollector.ts +71 -0
- package/core/recovery/shareParsing.ts +87 -0
- package/core/recovery/shares.ts +116 -0
- package/core/recovery/useRecoveryDeps.ts +70 -0
- package/core/services/arcTokenStorage.ts +52 -0
- package/core/services/arcadeBroadcastProvider.ts +233 -52
- package/core/services/autoApprovePolicy.ts +105 -0
- package/core/services/callbackToken.ts +19 -0
- package/core/services/capWalletArgs.ts +14 -2
- package/core/services/connectionAuthority.ts +98 -0
- package/core/services/exchangeRate.ts +36 -13
- package/core/services/externalOrigin.ts +16 -2
- package/core/services/secrets/kek.ts +126 -29
- package/core/services/secrets/migration.ts +16 -4
- package/core/services/secrets/store.ts +42 -14
- package/core/services/vault/VaultKeyService.ts +228 -45
- package/core/services/vault/chainRecovery.ts +483 -0
- package/core/services/vault/driver.ts +9 -1
- package/core/services/vault/enrolledSerialRegistry.ts +150 -0
- package/core/services/vault/guard.ts +218 -32
- package/core/services/vault/hardwareLease.ts +19 -0
- package/core/services/vault/metaAuthority.ts +210 -0
- package/core/services/vault/pivReset.ts +64 -23
- package/core/services/vault/r1comb.ts +139 -3
- package/core/services/vault/session.ts +25 -4
- package/core/services/vault/transfers.ts +868 -172
- package/core/services/vault/types.ts +19 -4
- package/core/services/vault/vaultStore.ts +256 -29
- package/core/services/walletArgLimits.ts +45 -2
- package/core/services/walletConnectionValidation.ts +76 -6
- package/core/services/walletServiceConfig.ts +40 -27
- package/core/storage/StorageExpoSQLite.ts +88 -47
- package/core/storage/methods/findSql.ts +24 -2
- package/core/storage/methods/listActionsSql.ts +8 -5
- package/core/storage/methods/listOutputsSql.ts +2 -2
- package/core/storage/methods/offlineActions.ts +10 -1
- package/core/storage/methods/processOfflineActions.ts +117 -25
- package/core/storage/methods/reviewStatusSql.ts +7 -2
- package/core/storage/schema/createTables.ts +155 -2
- package/core/stores/ConnectionStore.ts +34 -0
- package/core/toolboxConfig.ts +104 -0
- package/core/toolboxTypes.ts +40 -0
- package/core/userAvatar.ts +79 -0
- package/core/walletDbRegistry.ts +63 -0
- package/core/walletMonitor.ts +25 -4
- package/core/walletRepair/releaseStuckReservations.ts +72 -0
- package/core/walletRepair/shouldMarkUnspendable.ts +20 -0
- package/core/walletRepair/spenderConsumesOutpoint.ts +29 -0
- package/package.json +7 -7
- package/ui/activityFilter.ts +115 -0
- package/ui/backupShares.ts +26 -169
- package/ui/components/pay/AddressReceive.tsx +13 -6
- package/ui/components/pay/AssetPicker.tsx +30 -9
- package/ui/components/pay/MessageBoxConfig.tsx +16 -0
- package/ui/components/pay/NearbyFlow.tsx +480 -243
- package/ui/components/pay/PaymentSuccessOverlay.tsx +85 -10
- package/ui/components/pay/RecipientField.tsx +84 -70
- package/ui/components/pay/StepBar.tsx +32 -0
- package/ui/components/pay/UniversalSend.tsx +827 -205
- package/ui/components/ui/AlertCard.tsx +38 -5
- package/ui/components/ui/PencilEditField.tsx +109 -0
- package/ui/components/ui/PermissionSheet.tsx +197 -66
- package/ui/components/ui/SlideOverFromRight.tsx +86 -0
- package/ui/components/vault/EnrollWizard.tsx +61 -13
- package/ui/components/vault/vaultErrorCopy.ts +3 -1
- package/ui/components/wallet/ActivityRow.tsx +227 -123
- package/ui/components/wallet/AmountInput.tsx +26 -8
- package/ui/components/wallet/AssetSwitcherDropdown.tsx +22 -2
- package/ui/components/wallet/Balance.tsx +42 -23
- package/ui/components/wallet/BiometricAdvisoryModal.tsx +16 -3
- package/ui/components/wallet/ContactActivityList.tsx +149 -0
- package/ui/components/wallet/ContactSigil.tsx +49 -0
- package/ui/components/wallet/EditPictureSheet.tsx +99 -0
- package/ui/components/wallet/FitAmount.tsx +148 -0
- package/ui/components/wallet/IconPickerSheet.tsx +168 -0
- package/ui/components/wallet/IdentifierRow.tsx +69 -0
- package/ui/components/wallet/ImportFromBackupPrompt.tsx +35 -13
- package/ui/components/wallet/ProfileButton.tsx +62 -0
- package/ui/components/wallet/UserAvatar.tsx +85 -0
- package/ui/components/wallet/avatarIcons.ts +122 -0
- package/ui/exportTransactions.ts +36 -4
- package/ui/hooks/useContactsStore.ts +10 -0
- package/ui/hooks/useExportWalletData.ts +25 -2
- package/ui/hooks/useMandala.ts +18 -1
- package/ui/hooks/useOnline.ts +65 -20
- package/ui/importDatabases.ts +339 -24
- package/ui/index.ts +33 -2
- package/ui/isImageUrl.ts +6 -0
- package/ui/printRecoveryShares.ts +9 -10
- package/ui/recoveryPrompts.ts +91 -0
- package/ui/resolveIdentity.ts +31 -9
- package/ui/screens/ConnectionsScreen.tsx +86 -19
- package/ui/screens/ContactScreen.tsx +289 -0
- package/ui/screens/ContactsScreen.tsx +373 -0
- package/ui/screens/IdentifierScreen.tsx +256 -0
- package/ui/screens/NewContactScreen.tsx +362 -0
- package/ui/screens/PairScreen.tsx +74 -2
- package/ui/screens/PayScreen.tsx +20 -7
- package/ui/screens/ProfileScreen.tsx +783 -0
- package/ui/screens/SettingsScreen.tsx +10 -4
- package/ui/screens/TransactionDetailScreen.tsx +419 -0
- package/ui/screens/TrustScreen.tsx +100 -5
- package/ui/screens/VaultScreen.tsx +410 -61
- package/ui/screens/VaultTransferScreen.tsx +59 -7
- package/ui/screens/WalletCheckScreen.tsx +17 -6
- package/ui/screens/WalletConfigScreen.tsx +124 -28
- package/ui/screens/WalletHomeScreen.tsx +640 -104
- package/ui/screens/detailActionKeys.ts +55 -0
- package/ui/tokenFormat.ts +44 -4
- package/ui/tokenStatus.ts +21 -0
- package/ui/txStatus.ts +48 -5
- package/core/storage/LocalStorageAdapter.ts +0 -58
|
@@ -57,6 +57,10 @@ export function showAlert(options: AlertOptions): Promise<string> {
|
|
|
57
57
|
|
|
58
58
|
const DEFAULT_BUTTONS: AlertButton[] = [{ text: 'OK', key: 'ok' }]
|
|
59
59
|
|
|
60
|
+
/** Upper bound on waiting for the native modal's dismissal (iOS `onDismiss`),
|
|
61
|
+
* so an alert whose modal never presented cannot hold the queue forever. */
|
|
62
|
+
const DISMISS_FALLBACK_MS = 1_000
|
|
63
|
+
|
|
60
64
|
export function AlertHost() {
|
|
61
65
|
const { colors } = useTheme()
|
|
62
66
|
const reducedMotion = useReducedMotion()
|
|
@@ -66,6 +70,13 @@ export function AlertHost() {
|
|
|
66
70
|
const progress = useSharedValue(0)
|
|
67
71
|
const exiting = useRef(false)
|
|
68
72
|
const lastHapticAlert = useRef<ActiveAlert | null>(null)
|
|
73
|
+
// The pressed key, held until the modal is gone. The caller's promise must
|
|
74
|
+
// not settle while the alert's native modal is still presented: a caller
|
|
75
|
+
// that presents native UI next (the export's share sheet) would present it
|
|
76
|
+
// ON this modal, and dismissing the modal takes it down before it can
|
|
77
|
+
// report back.
|
|
78
|
+
const pending = useRef<{ alert: ActiveAlert; key: string; fallback: ReturnType<typeof setTimeout> } | null>(null)
|
|
79
|
+
const [hiding, setHiding] = useState(false)
|
|
69
80
|
|
|
70
81
|
useEffect(() => {
|
|
71
82
|
enqueue = (a: ActiveAlert) => setQueue(q => [...q, a])
|
|
@@ -97,14 +108,35 @@ export function AlertHost() {
|
|
|
97
108
|
}
|
|
98
109
|
}, [current, progress, reducedMotion])
|
|
99
110
|
|
|
111
|
+
/** Resolve the dismissed alert and show the next one. Runs once per alert. */
|
|
112
|
+
const finish = useCallback(() => {
|
|
113
|
+
const done = pending.current
|
|
114
|
+
if (!done) return
|
|
115
|
+
pending.current = null
|
|
116
|
+
clearTimeout(done.fallback)
|
|
117
|
+
exiting.current = false
|
|
118
|
+
setHiding(false)
|
|
119
|
+
setQueue(q => (q[0] === done.alert ? q.slice(1) : q))
|
|
120
|
+
done.alert.resolve(done.key)
|
|
121
|
+
}, [])
|
|
122
|
+
|
|
100
123
|
const dismiss = useCallback((key: string) => {
|
|
101
124
|
if (!current || exiting.current) return
|
|
102
125
|
exiting.current = true
|
|
103
|
-
current.
|
|
126
|
+
pending.current = { alert: current, key, fallback: setTimeout(finish, durations.instant + DISMISS_FALLBACK_MS) }
|
|
104
127
|
progress.value = withTiming(0, { duration: durations.instant })
|
|
105
|
-
//
|
|
106
|
-
|
|
107
|
-
|
|
128
|
+
// After the exit fade, hide the modal. iOS reports the native dismissal
|
|
129
|
+
// through onDismiss; Android has no such event and nothing presented over
|
|
130
|
+
// it to protect, so it finishes here.
|
|
131
|
+
setTimeout(() => {
|
|
132
|
+
if (Platform.OS === 'ios') setHiding(true)
|
|
133
|
+
else finish()
|
|
134
|
+
}, durations.instant)
|
|
135
|
+
}, [current, progress, finish])
|
|
136
|
+
|
|
137
|
+
useEffect(() => () => {
|
|
138
|
+
if (pending.current) clearTimeout(pending.current.fallback)
|
|
139
|
+
}, [])
|
|
108
140
|
|
|
109
141
|
const backdropStyle = useAnimatedStyle(() => ({ opacity: progress.value }))
|
|
110
142
|
const cardStyle = useAnimatedStyle(() => ({
|
|
@@ -124,8 +156,9 @@ export function AlertHost() {
|
|
|
124
156
|
return (
|
|
125
157
|
<Modal
|
|
126
158
|
transparent
|
|
127
|
-
visible
|
|
159
|
+
visible={!hiding}
|
|
128
160
|
animationType="none"
|
|
161
|
+
onDismiss={finish}
|
|
129
162
|
onRequestClose={() => dismiss('cancel')}
|
|
130
163
|
statusBarTranslucent={Platform.OS === 'android'}
|
|
131
164
|
navigationBarTranslucent={Platform.OS === 'android'}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An editable label row for a grouped card (contact name, profile display
|
|
3
|
+
* name): the field is always a live text input, a pencil sits at rest in the
|
|
4
|
+
* leading slot, and once the text has actually changed that slot becomes a
|
|
5
|
+
* filled confirm button (2026-09-17 design ruling). Tapping the pencil only
|
|
6
|
+
* focuses the field; nothing is saved until the check is tapped or the
|
|
7
|
+
* keyboard's return key is pressed with a real change.
|
|
8
|
+
*/
|
|
9
|
+
import React, { useEffect, useRef, useState } from 'react'
|
|
10
|
+
import { StyleSheet, TextInput, View, type StyleProp, type TextStyle } from 'react-native'
|
|
11
|
+
import { useTheme, spacing, typography } from '@bsv/expo-wallet-toolbox'
|
|
12
|
+
import PressableScale from './PressableScale'
|
|
13
|
+
|
|
14
|
+
type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
|
|
15
|
+
let ioniconsComponent: IoniconsComponent | undefined
|
|
16
|
+
function loadIonicons(): IoniconsComponent {
|
|
17
|
+
if (!ioniconsComponent) {
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
19
|
+
ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
|
|
20
|
+
}
|
|
21
|
+
return ioniconsComponent
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface PencilEditFieldProps {
|
|
25
|
+
value: string
|
|
26
|
+
onSave: (next: string) => void | Promise<void>
|
|
27
|
+
placeholder?: string
|
|
28
|
+
textStyle?: StyleProp<TextStyle>
|
|
29
|
+
editAccessibilityLabel: string
|
|
30
|
+
saveAccessibilityLabel: string
|
|
31
|
+
autoCapitalize?: 'none' | 'sentences' | 'words' | 'characters'
|
|
32
|
+
maxLength?: number
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function PencilEditField({
|
|
36
|
+
value,
|
|
37
|
+
onSave,
|
|
38
|
+
placeholder,
|
|
39
|
+
textStyle,
|
|
40
|
+
editAccessibilityLabel,
|
|
41
|
+
saveAccessibilityLabel,
|
|
42
|
+
autoCapitalize = 'words',
|
|
43
|
+
maxLength
|
|
44
|
+
}: PencilEditFieldProps) {
|
|
45
|
+
const { colors } = useTheme()
|
|
46
|
+
const Ionicons = loadIonicons()
|
|
47
|
+
const inputRef = useRef<TextInput>(null)
|
|
48
|
+
const [text, setText] = useState(value)
|
|
49
|
+
// A save that lands from outside (a cache refresh, the parent reloading)
|
|
50
|
+
// re-seeds the field; an in-progress edit is never clobbered, because the
|
|
51
|
+
// parent's value only changes once our own save has gone through.
|
|
52
|
+
useEffect(() => setText(value), [value])
|
|
53
|
+
const changed = text.trim() !== '' && text.trim() !== value.trim()
|
|
54
|
+
|
|
55
|
+
const save = async () => {
|
|
56
|
+
if (!changed) return
|
|
57
|
+
await onSave(text.trim())
|
|
58
|
+
inputRef.current?.blur()
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<View style={styles.row}>
|
|
63
|
+
{changed ? (
|
|
64
|
+
<PressableScale
|
|
65
|
+
onPress={save}
|
|
66
|
+
haptic="confirm"
|
|
67
|
+
style={styles.leading}
|
|
68
|
+
accessibilityRole="button"
|
|
69
|
+
accessibilityLabel={saveAccessibilityLabel}
|
|
70
|
+
>
|
|
71
|
+
<View style={[styles.confirmDisc, { backgroundColor: colors.accent }]}>
|
|
72
|
+
<Ionicons name="checkmark" size={16} color={colors.textOnAccent} />
|
|
73
|
+
</View>
|
|
74
|
+
</PressableScale>
|
|
75
|
+
) : (
|
|
76
|
+
<PressableScale
|
|
77
|
+
onPress={() => inputRef.current?.focus()}
|
|
78
|
+
style={styles.leading}
|
|
79
|
+
accessibilityRole="button"
|
|
80
|
+
accessibilityLabel={editAccessibilityLabel}
|
|
81
|
+
>
|
|
82
|
+
<Ionicons name="pencil-outline" size={17} color={colors.textSecondary} />
|
|
83
|
+
</PressableScale>
|
|
84
|
+
)}
|
|
85
|
+
<TextInput
|
|
86
|
+
ref={inputRef}
|
|
87
|
+
value={text}
|
|
88
|
+
onChangeText={setText}
|
|
89
|
+
placeholder={placeholder}
|
|
90
|
+
placeholderTextColor={colors.textTertiary}
|
|
91
|
+
autoCapitalize={autoCapitalize}
|
|
92
|
+
autoCorrect={false}
|
|
93
|
+
maxLength={maxLength}
|
|
94
|
+
returnKeyType="done"
|
|
95
|
+
onSubmitEditing={save}
|
|
96
|
+
style={[styles.input, { color: colors.textPrimary }, textStyle]}
|
|
97
|
+
/>
|
|
98
|
+
</View>
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const styles = StyleSheet.create({
|
|
103
|
+
row: { flexDirection: 'row', alignItems: 'center', minHeight: 52, paddingLeft: spacing.xs, paddingRight: spacing.lg },
|
|
104
|
+
// A 44pt target around a 17pt glyph / 28pt disc, flush with the card's
|
|
105
|
+
// left padding once the disc's own inset is counted.
|
|
106
|
+
leading: { width: 44, height: 44, alignItems: 'center', justifyContent: 'center' },
|
|
107
|
+
confirmDisc: { width: 28, height: 28, borderRadius: 14, alignItems: 'center', justifyContent: 'center' },
|
|
108
|
+
input: { ...typography.body, flex: 1, minWidth: 0, paddingVertical: spacing.md, paddingHorizontal: 0 }
|
|
109
|
+
})
|
|
@@ -71,7 +71,7 @@ interface GroupPermissions {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
/** Common shape derived from the four existing modals. */
|
|
74
|
-
interface ActivePermission {
|
|
74
|
+
export interface ActivePermission {
|
|
75
75
|
kind: PermissionKind
|
|
76
76
|
requestID: string
|
|
77
77
|
originator: string
|
|
@@ -88,6 +88,52 @@ interface ActivePermission {
|
|
|
88
88
|
renewal?: boolean
|
|
89
89
|
/** Group-specific sub-permissions. */
|
|
90
90
|
groupPermissions?: GroupPermissions
|
|
91
|
+
/**
|
|
92
|
+
* XR-040: set when a `mandala_spend`/`mandala_credit` prompt's per-asset
|
|
93
|
+
* `lines` could not be trusted to be the WHOLE request (absent, malformed,
|
|
94
|
+
* empty, or past `MANDALA_MAX_PROMPT_LINES`) — every asset a single
|
|
95
|
+
* approval would release has to be shown, and a request this sheet cannot
|
|
96
|
+
* fully enumerate must never be approvable. `handleDeny` is unaffected;
|
|
97
|
+
* only the Allow control reads this.
|
|
98
|
+
*/
|
|
99
|
+
approvalBlocked?: boolean
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** One line of a `mandala_spend`/`mandala_credit` prompt's `lines[]` array,
|
|
103
|
+
* as loosely as a JSON.parse of counterparty-adjacent data should be trusted. */
|
|
104
|
+
interface MandalaPromptLine {
|
|
105
|
+
assetId?: unknown
|
|
106
|
+
sendAmount?: unknown
|
|
107
|
+
changeAmount?: unknown
|
|
108
|
+
creditAmount?: unknown
|
|
109
|
+
tokenName?: unknown
|
|
110
|
+
/** Pre-formatted, e.g. "25.00 USDX" — see `MandalaSpendLine`/`MandalaCreditLine`. */
|
|
111
|
+
display?: unknown
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* A sane display ceiling for a multi-asset Mandala prompt. Every real prompt
|
|
116
|
+
* this app's own `MandalaTokenModule` builds groups by assetId — a handful at
|
|
117
|
+
* most — so a `lines` array past this is either a bug or a bad-faith caller,
|
|
118
|
+
* either way not something to enumerate as if it were the whole request.
|
|
119
|
+
*/
|
|
120
|
+
const MANDALA_MAX_PROMPT_LINES = 25
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* `promptData.lines`, validated into a bounded array of loosely-typed line
|
|
124
|
+
* objects — or `null` for anything this sheet cannot enumerate in full
|
|
125
|
+
* (absent, not an array, empty, oversized, or containing a non-object entry).
|
|
126
|
+
* `null` is the caller's signal to block approval rather than silently fall
|
|
127
|
+
* back to the primary-only view (XR-040).
|
|
128
|
+
*/
|
|
129
|
+
function sanitizedMandalaLines(raw: unknown): MandalaPromptLine[] | null {
|
|
130
|
+
if (!Array.isArray(raw) || raw.length === 0 || raw.length > MANDALA_MAX_PROMPT_LINES) return null
|
|
131
|
+
const lines: MandalaPromptLine[] = []
|
|
132
|
+
for (const entry of raw) {
|
|
133
|
+
if (!entry || typeof entry !== 'object') return null
|
|
134
|
+
lines.push(entry as MandalaPromptLine)
|
|
135
|
+
}
|
|
136
|
+
return lines
|
|
91
137
|
}
|
|
92
138
|
|
|
93
139
|
// ---------------------------------------------------------------------------
|
|
@@ -98,7 +144,9 @@ interface ActivePermission {
|
|
|
98
144
|
* Derive the human-friendly "what is being asked" description for each
|
|
99
145
|
* permission type. Technical specifics go into the expandable Details section.
|
|
100
146
|
*/
|
|
101
|
-
|
|
147
|
+
// Exported so the mandala prompt's own display-building logic (XR-040) is
|
|
148
|
+
// unit-testable without rendering the whole sheet's component tree.
|
|
149
|
+
export function deriveActive(
|
|
102
150
|
ctx: {
|
|
103
151
|
protocolRequests: any[]
|
|
104
152
|
basketRequests: any[]
|
|
@@ -270,6 +318,11 @@ function deriveActive(
|
|
|
270
318
|
sendAmount?: number
|
|
271
319
|
changeAmount?: number
|
|
272
320
|
creditAmount?: number
|
|
321
|
+
lines?: unknown
|
|
322
|
+
// XR-041: relinquishOutput's own resolved-target fields.
|
|
323
|
+
amount?: number
|
|
324
|
+
display?: string
|
|
325
|
+
outpoint?: string
|
|
273
326
|
} = {}
|
|
274
327
|
try {
|
|
275
328
|
promptData = JSON.parse(r.message)
|
|
@@ -277,12 +330,27 @@ function deriveActive(
|
|
|
277
330
|
// message not valid JSON — ignore, use defaults
|
|
278
331
|
}
|
|
279
332
|
|
|
333
|
+
const isRelinquish = promptData.type === 'mandala_access' && promptData.action === 'relinquishOutput'
|
|
334
|
+
// XR-041: `display` is pre-formatted ("25.00 USDX"); fall back to the raw
|
|
335
|
+
// base-unit amount + token name when it is not a string, same convention
|
|
336
|
+
// as the spend/credit lines below.
|
|
337
|
+
const relinquishAmount =
|
|
338
|
+
typeof promptData.display === 'string'
|
|
339
|
+
? promptData.display
|
|
340
|
+
: promptData.amount != null
|
|
341
|
+
? `${promptData.amount} ${promptData.tokenName || 'Mandala tokens'}`
|
|
342
|
+
: undefined
|
|
343
|
+
|
|
280
344
|
let description: string
|
|
281
345
|
if (promptData.type === 'mandala_spend' && promptData.sendAmount != null) {
|
|
282
346
|
description = `wants to spend ${promptData.sendAmount} ${promptData.tokenName || 'Mandala tokens'}`
|
|
283
347
|
} else if (promptData.type === 'mandala_credit' && promptData.creditAmount != null) {
|
|
284
348
|
description = `wants to credit ${promptData.creditAmount} ${promptData.tokenName || 'Mandala tokens'} to your wallet`
|
|
285
|
-
} else if (
|
|
349
|
+
} else if (isRelinquish && relinquishAmount) {
|
|
350
|
+
// Named, not generic (XR-041): which holding, not just that "a" holding
|
|
351
|
+
// is being removed.
|
|
352
|
+
description = `wants to remove ${relinquishAmount} from your wallet`
|
|
353
|
+
} else if (isRelinquish) {
|
|
286
354
|
description = 'wants to remove a Mandala token holding from your wallet'
|
|
287
355
|
} else if (promptData.type === 'mandala_access') {
|
|
288
356
|
description = 'wants to see your Mandala token balance'
|
|
@@ -291,11 +359,66 @@ function deriveActive(
|
|
|
291
359
|
}
|
|
292
360
|
|
|
293
361
|
const details: { label: string; value: string }[] = []
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
if (promptData.
|
|
297
|
-
|
|
298
|
-
|
|
362
|
+
let approvalBlocked = false
|
|
363
|
+
|
|
364
|
+
if (promptData.type === 'mandala_spend' || promptData.type === 'mandala_credit') {
|
|
365
|
+
// XR-040: `lines` carries EVERY asset this request touches — rendering
|
|
366
|
+
// only the primary (back-compat) fields below is how a single approval
|
|
367
|
+
// silently released a second, unshown asset. Every sanitized line is
|
|
368
|
+
// rendered; an unsanitizable `lines` blocks approval instead of falling
|
|
369
|
+
// back to a primary-only view that looks complete but is not.
|
|
370
|
+
const lines = sanitizedMandalaLines(promptData.lines)
|
|
371
|
+
if (lines === null) {
|
|
372
|
+
approvalBlocked = true
|
|
373
|
+
details.push({
|
|
374
|
+
label: 'Warning',
|
|
375
|
+
value: 'Could not verify this is the full request — deny and try again.'
|
|
376
|
+
})
|
|
377
|
+
} else {
|
|
378
|
+
const numbered = lines.length > 1
|
|
379
|
+
lines.forEach((line, i) => {
|
|
380
|
+
const suffix = numbered ? ` ${i + 1}` : ''
|
|
381
|
+
if (typeof line.tokenName === 'string' && line.tokenName) {
|
|
382
|
+
details.push({ label: `Token${suffix}`, value: line.tokenName })
|
|
383
|
+
}
|
|
384
|
+
if (typeof line.sendAmount === 'number') {
|
|
385
|
+
details.push({
|
|
386
|
+
label: `Send amount${suffix}`,
|
|
387
|
+
value: typeof line.display === 'string' ? line.display : String(line.sendAmount)
|
|
388
|
+
})
|
|
389
|
+
}
|
|
390
|
+
if (typeof line.changeAmount === 'number' && line.changeAmount !== 0) {
|
|
391
|
+
details.push({ label: `Change${suffix}`, value: String(line.changeAmount) })
|
|
392
|
+
}
|
|
393
|
+
if (typeof line.creditAmount === 'number') {
|
|
394
|
+
details.push({
|
|
395
|
+
label: `Credit amount${suffix}`,
|
|
396
|
+
value: typeof line.display === 'string' ? line.display : String(line.creditAmount)
|
|
397
|
+
})
|
|
398
|
+
}
|
|
399
|
+
if (typeof line.assetId === 'string' && line.assetId) {
|
|
400
|
+
details.push({ label: `Asset ID${suffix}`, value: truncate(line.assetId, 28) })
|
|
401
|
+
}
|
|
402
|
+
})
|
|
403
|
+
}
|
|
404
|
+
} else if (isRelinquish) {
|
|
405
|
+
// XR-041: identify the target the same way mandala_spend/mandala_credit
|
|
406
|
+
// already identify theirs — token, amount, and the exact outpoint.
|
|
407
|
+
if (promptData.tokenName) details.push({ label: 'Token', value: promptData.tokenName })
|
|
408
|
+
if (relinquishAmount) details.push({ label: 'Amount', value: relinquishAmount })
|
|
409
|
+
if (promptData.assetId) details.push({ label: 'Asset ID', value: truncate(promptData.assetId, 28) })
|
|
410
|
+
if (promptData.outpoint) details.push({ label: 'Outpoint', value: truncate(promptData.outpoint, 28) })
|
|
411
|
+
} else {
|
|
412
|
+
if (promptData.assetId) details.push({ label: 'Asset ID', value: truncate(promptData.assetId, 28) })
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// Said in the ALWAYS-VISIBLE description, not only the collapsed Details
|
|
416
|
+
// section — the whole point is that this cannot be missed on the way to
|
|
417
|
+
// an (already-disabled) Allow button.
|
|
418
|
+
if (approvalBlocked) {
|
|
419
|
+
description =
|
|
420
|
+
'wants to spend or credit Mandala tokens, but the full request could not be verified — deny and try again.'
|
|
421
|
+
}
|
|
299
422
|
|
|
300
423
|
return {
|
|
301
424
|
kind: 'mandala',
|
|
@@ -304,7 +427,8 @@ function deriveActive(
|
|
|
304
427
|
originator: r.originator || 'Unknown app',
|
|
305
428
|
title: 'Token Spend Request',
|
|
306
429
|
description,
|
|
307
|
-
details
|
|
430
|
+
details,
|
|
431
|
+
approvalBlocked
|
|
308
432
|
}
|
|
309
433
|
}
|
|
310
434
|
|
|
@@ -503,61 +627,67 @@ const PermissionSheet: React.FC = () => {
|
|
|
503
627
|
// the UI can show the checkmark morph for 400 ms before dismissal.
|
|
504
628
|
// Takes an explicit snapshot of the request to act on so it is safe to call
|
|
505
629
|
// from the flush-on-preempt path where `active` may have already changed.
|
|
506
|
-
const executeGrant = useCallback(
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
630
|
+
const executeGrant = useCallback(
|
|
631
|
+
(request: ActivePermission) => {
|
|
632
|
+
// Clear the pending ref so flush-on-preempt guards don't double-fire.
|
|
633
|
+
pendingGrantRef.current = null
|
|
634
|
+
|
|
635
|
+
if (request.kind === 'btms') {
|
|
636
|
+
advanceBtmsQueue(true)
|
|
637
|
+
} else if (request.kind === 'mandala') {
|
|
638
|
+
advanceMandalaQueue(true)
|
|
639
|
+
} else if (request.kind === 'spending') {
|
|
640
|
+
managers.permissionsManager?.grantPermission({
|
|
641
|
+
requestID: request.requestID,
|
|
642
|
+
ephemeral: true,
|
|
643
|
+
amount: request.amount
|
|
644
|
+
})
|
|
645
|
+
advanceSpendingQueue()
|
|
646
|
+
setSpendingAuthorizationModalOpen(false)
|
|
647
|
+
} else {
|
|
648
|
+
managers.permissionsManager?.grantPermission({
|
|
649
|
+
requestID: request.requestID
|
|
650
|
+
})
|
|
651
|
+
switch (request.kind) {
|
|
652
|
+
case 'protocol':
|
|
653
|
+
advanceProtocolQueue()
|
|
654
|
+
setProtocolAccessModalOpen(false)
|
|
655
|
+
break
|
|
656
|
+
case 'basket':
|
|
657
|
+
advanceBasketQueue()
|
|
658
|
+
setBasketAccessModalOpen(false)
|
|
659
|
+
break
|
|
660
|
+
case 'certificate':
|
|
661
|
+
advanceCertificateQueue()
|
|
662
|
+
setCertificateAccessModalOpen(false)
|
|
663
|
+
break
|
|
664
|
+
}
|
|
539
665
|
}
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
666
|
+
setDetailsExpanded(false)
|
|
667
|
+
// Reset granted so that consecutive BTMS/Mandala requests (sharing sentinel requestID '')
|
|
668
|
+
// don't leave the sheet permanently in granted state / deadlocked.
|
|
669
|
+
setGranted(false)
|
|
670
|
+
},
|
|
671
|
+
[
|
|
672
|
+
managers.permissionsManager,
|
|
673
|
+
advanceProtocolQueue,
|
|
674
|
+
advanceBasketQueue,
|
|
675
|
+
advanceCertificateQueue,
|
|
676
|
+
advanceSpendingQueue,
|
|
677
|
+
advanceBtmsQueue,
|
|
678
|
+
advanceMandalaQueue,
|
|
679
|
+
setProtocolAccessModalOpen,
|
|
680
|
+
setBasketAccessModalOpen,
|
|
681
|
+
setCertificateAccessModalOpen,
|
|
682
|
+
setSpendingAuthorizationModalOpen
|
|
683
|
+
]
|
|
684
|
+
)
|
|
558
685
|
|
|
559
686
|
const handleGrant = useCallback(() => {
|
|
560
|
-
|
|
687
|
+
// XR-040: belt-and-braces alongside the Allow button's own `disabled` —
|
|
688
|
+
// a mandala_spend/mandala_credit prompt whose `lines` this sheet could
|
|
689
|
+
// not fully enumerate must never be approvable, from any call path.
|
|
690
|
+
if (!active || granted || active.approvalBlocked) return
|
|
561
691
|
haptics.success()
|
|
562
692
|
setGranted(true)
|
|
563
693
|
if (grantTimerRef.current !== null) {
|
|
@@ -766,12 +896,13 @@ const PermissionSheet: React.FC = () => {
|
|
|
766
896
|
<PressableScale
|
|
767
897
|
style={[styles.buttonAllow, { backgroundColor: colors.accent }]}
|
|
768
898
|
onPress={handleGrant}
|
|
769
|
-
disabled={granted}
|
|
899
|
+
disabled={granted || active.approvalBlocked}
|
|
770
900
|
>
|
|
771
|
-
{granted
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
901
|
+
{granted ? (
|
|
902
|
+
<Ionicons name="checkmark" size={22} color={colors.textOnAccent} />
|
|
903
|
+
) : (
|
|
904
|
+
<Text style={[styles.buttonAllowText, { color: colors.textOnAccent }]}>{t('authorize')}</Text>
|
|
905
|
+
)}
|
|
775
906
|
</PressableScale>
|
|
776
907
|
</View>
|
|
777
908
|
</View>
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A full-screen surface that arrives from the right and leaves to the right —
|
|
3
|
+
* the push/pop a native stack gives you, for a view presented inside a screen
|
|
4
|
+
* rather than routed to.
|
|
5
|
+
*
|
|
6
|
+
* React Native's `Modal` animates only vertically (`animationType="slide"`
|
|
7
|
+
* comes up from the bottom), which reads as a sheet, not a push. So the
|
|
8
|
+
* transform is ours, and per the motion rules it runs on the UI thread via
|
|
9
|
+
* Reanimated and decelerates on `easings.out` — never a JS timer.
|
|
10
|
+
*
|
|
11
|
+
* Reduced motion collapses the translation to a crossfade rather than removing
|
|
12
|
+
* the transition: the surface still needs to read as arriving.
|
|
13
|
+
*/
|
|
14
|
+
import React, { useEffect, useState } from 'react'
|
|
15
|
+
import { StyleSheet, useWindowDimensions, View } from 'react-native'
|
|
16
|
+
import Animated, {
|
|
17
|
+
runOnJS,
|
|
18
|
+
useAnimatedStyle,
|
|
19
|
+
useReducedMotion,
|
|
20
|
+
useSharedValue,
|
|
21
|
+
withTiming
|
|
22
|
+
} from 'react-native-reanimated'
|
|
23
|
+
import { durations, easings } from '@bsv/expo-wallet-toolbox'
|
|
24
|
+
|
|
25
|
+
export default function SlideOverFromRight({
|
|
26
|
+
visible,
|
|
27
|
+
onClosed,
|
|
28
|
+
children
|
|
29
|
+
}: {
|
|
30
|
+
visible: boolean
|
|
31
|
+
/** Fired once the surface has finished leaving, so the caller can drop its content. */
|
|
32
|
+
onClosed?: () => void
|
|
33
|
+
children: React.ReactNode
|
|
34
|
+
}) {
|
|
35
|
+
const { width } = useWindowDimensions()
|
|
36
|
+
const reduced = useReducedMotion()
|
|
37
|
+
// Mounted for as long as anything is on screen — through the close animation,
|
|
38
|
+
// not just while `visible` is true.
|
|
39
|
+
const [mounted, setMounted] = useState(visible)
|
|
40
|
+
const progress = useSharedValue(visible ? 1 : 0)
|
|
41
|
+
|
|
42
|
+
// Adjusting own state during render, which React sanctions for "derive from
|
|
43
|
+
// a prop that just changed" — an effect would mount one frame late and the
|
|
44
|
+
// surface would jump in already half-arrived.
|
|
45
|
+
if (visible && !mounted) setMounted(true)
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
const done = (finished?: boolean) => {
|
|
49
|
+
'worklet'
|
|
50
|
+
if (finished && !visible) {
|
|
51
|
+
runOnJS(setMounted)(false)
|
|
52
|
+
if (onClosed) runOnJS(onClosed)()
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
progress.value = withTiming(
|
|
56
|
+
visible ? 1 : 0,
|
|
57
|
+
{ duration: visible ? durations.moderate : durations.quick, easing: easings.out },
|
|
58
|
+
done
|
|
59
|
+
)
|
|
60
|
+
// `onClosed` is deliberately absent: an inline callback from the caller
|
|
61
|
+
// would re-run this effect on every render and restart the animation.
|
|
62
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
63
|
+
}, [visible, progress])
|
|
64
|
+
|
|
65
|
+
const style = useAnimatedStyle(() =>
|
|
66
|
+
reduced
|
|
67
|
+
? { opacity: progress.value, transform: [{ translateX: 0 }] }
|
|
68
|
+
: { opacity: 1, transform: [{ translateX: (1 - progress.value) * width }] }
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
if (!mounted) return null
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<View style={[StyleSheet.absoluteFill, styles.above]} pointerEvents="box-none">
|
|
75
|
+
<Animated.View style={[StyleSheet.absoluteFill, style]}>{children}</Animated.View>
|
|
76
|
+
</View>
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const styles = StyleSheet.create({
|
|
81
|
+
// A full-screen surface has to cover the screen it arrives over, including
|
|
82
|
+
// that screen's own lifted chrome. The list's top ScrollFade carries
|
|
83
|
+
// zIndex 1, and being a later sibling is not enough to beat it — without
|
|
84
|
+
// this the fade's 24pt band paints straight across the arriving surface.
|
|
85
|
+
above: { zIndex: 10 }
|
|
86
|
+
})
|