@bsv/expo-wallet-toolbox 0.1.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/LICENSE.txt +28 -0
- package/README.md +512 -0
- package/assets/sounds/payment-receive.wav +0 -0
- package/assets/sounds/payment-send.wav +0 -0
- package/assets/sounds/vault-close.wav +0 -0
- package/assets/sounds/vault-open.wav +0 -0
- package/core/amountFormatHelpers.ts +330 -0
- package/core/backup/RemoteSyncReader.ts +94 -0
- package/core/backup/client.ts +111 -0
- package/core/backup/codec.ts +218 -0
- package/core/backup/constants.ts +88 -0
- package/core/backup/cursor.ts +138 -0
- package/core/backup/derive.ts +46 -0
- package/core/backup/deviceId.ts +33 -0
- package/core/backup/erase.ts +67 -0
- package/core/backup/preference.ts +33 -0
- package/core/backup/push.ts +295 -0
- package/core/backup/restore.ts +152 -0
- package/core/backup/restoreOnImport.ts +119 -0
- package/core/backup/status.ts +46 -0
- package/core/config.tsx +47 -0
- package/core/constants.ts +35 -0
- package/core/context/ExchangeRateContext.tsx +69 -0
- package/core/context/LocalStorageProvider.tsx +225 -0
- package/core/context/UserContext.tsx +129 -0
- package/core/context/VaultContext.tsx +79 -0
- package/core/context/WalletConnectionContext.tsx +454 -0
- package/core/context/WalletContext.tsx +2938 -0
- package/core/context/buildGeneration.ts +37 -0
- package/core/deviceTier.ts +89 -0
- package/core/diskSpace.ts +62 -0
- package/core/displayCurrencies.ts +56 -0
- package/core/headers/OfflineFirstChaintracks.ts +176 -0
- package/core/headers/checkpoints.ts +39 -0
- package/core/headers/fs.ts +119 -0
- package/core/headers/headerStore.ts +333 -0
- package/core/headers/prewarm.ts +36 -0
- package/core/headers/syncHeaders.ts +73 -0
- package/core/hooks/useConfirmationSound.ts +135 -0
- package/core/hooks/useHaptics.ts +51 -0
- package/core/hooks/usePermissionQueue.ts +69 -0
- package/core/i18n/translations.tsx +6692 -0
- package/core/index.ts +295 -0
- package/core/localpay/blePermissions.ts +32 -0
- package/core/localpay/build.ts +392 -0
- package/core/localpay/codec.ts +338 -0
- package/core/localpay/deviceCaps.ts +175 -0
- package/core/localpay/nearbyAdvisory.ts +32 -0
- package/core/localpay/nearbyPermissions.ts +34 -0
- package/core/localpay/pending.ts +385 -0
- package/core/localpay/pendingAborts.ts +67 -0
- package/core/localpay/qr.ts +16 -0
- package/core/localpay/session.ts +277 -0
- package/core/localpay/sessionPolicy.ts +5 -0
- package/core/localpay/transport/awdl.ts +11 -0
- package/core/localpay/transport/ble.ts +159 -0
- package/core/localpay/transport/nearby.ts +12 -0
- package/core/localpay/transport/race.ts +110 -0
- package/core/localpay/transport/select.ts +128 -0
- package/core/localpay/transport/socket.ts +244 -0
- package/core/localpay/types.ts +82 -0
- package/core/localpay/verify.ts +204 -0
- package/core/logging.config.ts +10 -0
- package/core/logging.ts +77 -0
- package/core/mnemonicWallet.ts +180 -0
- package/core/monitor/TaskBackupPush.ts +168 -0
- package/core/monitor/TaskCreditInbox.ts +116 -0
- package/core/monitor/TaskDrainOutbox.ts +122 -0
- package/core/monitor/TaskSendOffline.ts +123 -0
- package/core/monitor/unfailRetry.ts +116 -0
- package/core/net/chainMatch.ts +34 -0
- package/core/net/online.ts +34 -0
- package/core/offline/cancelParked.ts +56 -0
- package/core/offline/hold.ts +127 -0
- package/core/offline/order.ts +109 -0
- package/core/offline/payerHold.ts +144 -0
- package/core/offline/plan.ts +264 -0
- package/core/offline/queueGrace.ts +52 -0
- package/core/parsePeerPayURI.ts +119 -0
- package/core/pay/beefRepair.ts +106 -0
- package/core/pay/creditErrors.ts +46 -0
- package/core/pay/creditInbox.ts +202 -0
- package/core/pay/damagedInbox.ts +64 -0
- package/core/pay/proofNudge.ts +23 -0
- package/core/pay/provenTxFromBump.ts +31 -0
- package/core/pay/rails/address.ts +329 -0
- package/core/pay/rails/handle.ts +617 -0
- package/core/pay/rails/index.ts +197 -0
- package/core/pay/rails/nearby.ts +79 -0
- package/core/pay/receiveFocus.ts +13 -0
- package/core/pay/recordProof.ts +91 -0
- package/core/pay/refreshProofGuard.ts +34 -0
- package/core/pay/sweeper.ts +75 -0
- package/core/pay/tokenAmount.ts +18 -0
- package/core/pay/userError.ts +18 -0
- package/core/pay/watchlist.ts +126 -0
- package/core/peerpay/control.ts +122 -0
- package/core/peerpay/handleResendRequests.ts +475 -0
- package/core/peerpay/inboxAttempts.ts +33 -0
- package/core/peerpay/metadataDecryptor.ts +42 -0
- package/core/peerpay/offlineNacks.ts +96 -0
- package/core/peerpay/outbox.ts +209 -0
- package/core/peerpay/rebuildToken.ts +76 -0
- package/core/peerpay/resendBeef.ts +115 -0
- package/core/services/arcadeBroadcastProvider.ts +214 -0
- package/core/services/capWalletArgs.ts +99 -0
- package/core/services/exchangeRate.ts +63 -0
- package/core/services/secrets/envelope.ts +102 -0
- package/core/services/secrets/hkdf.ts +37 -0
- package/core/services/secrets/index.ts +63 -0
- package/core/services/secrets/kek.ts +274 -0
- package/core/services/secrets/migration.ts +188 -0
- package/core/services/secrets/policy.ts +120 -0
- package/core/services/secrets/storage.ts +54 -0
- package/core/services/secrets/store.ts +125 -0
- package/core/services/secrets/types.ts +85 -0
- package/core/services/usdFxRates.ts +101 -0
- package/core/services/vault/VaultKeyService.ts +312 -0
- package/core/services/vault/backupAttestation.ts +136 -0
- package/core/services/vault/ceremony.ts +972 -0
- package/core/services/vault/ceremonyHost.ts +46 -0
- package/core/services/vault/devMock.ts +22 -0
- package/core/services/vault/driver.ts +197 -0
- package/core/services/vault/guard.ts +90 -0
- package/core/services/vault/k1.ts +75 -0
- package/core/services/vault/mockYubiKey.ts +217 -0
- package/core/services/vault/random.ts +20 -0
- package/core/services/vault/sealing.ts +84 -0
- package/core/services/vault/session.ts +59 -0
- package/core/services/vault/transfers.ts +1151 -0
- package/core/services/vault/types.ts +109 -0
- package/core/services/vault/vaultDerivation.ts +152 -0
- package/core/services/vault/vaultPassphrase.ts +287 -0
- package/core/services/vault/vaultStore.ts +104 -0
- package/core/services/walletArgLimits.ts +234 -0
- package/core/services/walletServiceConfig.ts +170 -0
- package/core/storage/LocalStorageAdapter.ts +58 -0
- package/core/storage/README.md +391 -0
- package/core/storage/StorageExpoSQLite.ts +2008 -0
- package/core/storage/errors.ts +73 -0
- package/core/storage/index.ts +3 -0
- package/core/storage/methods/findSql.ts +286 -0
- package/core/storage/methods/historyNotes.ts +61 -0
- package/core/storage/methods/listActionsSql.ts +212 -0
- package/core/storage/methods/listOutputsSql.ts +211 -0
- package/core/storage/methods/offlineActions.ts +156 -0
- package/core/storage/methods/processOfflineActions.ts +503 -0
- package/core/storage/methods/reclaim.ts +135 -0
- package/core/storage/methods/reviewStatusSql.ts +167 -0
- package/core/storage/methods/unprovenWithoutReqSql.ts +26 -0
- package/core/storage/methods/walletBalanceSql.ts +55 -0
- package/core/storage/schema/createTables.ts +385 -0
- package/core/storage/skipQueuedAncestors.ts +29 -0
- package/core/storage/sqlUpdateValue.ts +12 -0
- package/core/stores/ConnectionStore.ts +71 -0
- package/core/theme/ThemeContext.tsx +182 -0
- package/core/theme/assertThemeContrast.ts +109 -0
- package/core/theme/motion.ts +50 -0
- package/core/theme/tokens.ts +232 -0
- package/core/theme/useThemeStyles.tsx +156 -0
- package/core/walletDbRegistry.ts +110 -0
- package/core/walletMonitor.ts +149 -0
- package/core/walletRepair/runWalletCheck.ts +195 -0
- package/core/walletRepair/shouldReleaseUtxo.ts +18 -0
- package/package.json +86 -0
- package/ui/backupShares.ts +367 -0
- package/ui/components/QRScanner.tsx +353 -0
- package/ui/components/pay/AddressReceive.tsx +507 -0
- package/ui/components/pay/AvailableBalance.tsx +61 -0
- package/ui/components/pay/HandleReceive.tsx +896 -0
- package/ui/components/pay/MessageBoxConfig.tsx +256 -0
- package/ui/components/pay/NearbyAdvisoryModal.tsx +111 -0
- package/ui/components/pay/NearbyFlow.tsx +2542 -0
- package/ui/components/pay/OfflineNotice.tsx +337 -0
- package/ui/components/pay/PayCellRow.tsx +101 -0
- package/ui/components/pay/PayForm.tsx +223 -0
- package/ui/components/pay/PaymentQrDisplay.tsx +105 -0
- package/ui/components/pay/PaymentSuccessOverlay.tsx +266 -0
- package/ui/components/pay/RecipientField.tsx +308 -0
- package/ui/components/pay/RequestHub.tsx +75 -0
- package/ui/components/pay/ResultBanner.tsx +69 -0
- package/ui/components/pay/UniversalSend.tsx +687 -0
- package/ui/components/pay/useRecipientInput.ts +270 -0
- package/ui/components/security/WalletLockNotice.tsx +138 -0
- package/ui/components/ui/AlertCard.tsx +223 -0
- package/ui/components/ui/AppLogo.tsx +166 -0
- package/ui/components/ui/BlurChrome.tsx +72 -0
- package/ui/components/ui/Celebration.tsx +84 -0
- package/ui/components/ui/ChoiceSheet.ts +69 -0
- package/ui/components/ui/CustomSafeArea.tsx +74 -0
- package/ui/components/ui/ErrorBoundary.tsx +154 -0
- package/ui/components/ui/GroupedList.tsx +125 -0
- package/ui/components/ui/IconButton.tsx +105 -0
- package/ui/components/ui/ListRow.tsx +197 -0
- package/ui/components/ui/PermissionSheet.tsx +920 -0
- package/ui/components/ui/PresenceRow.tsx +215 -0
- package/ui/components/ui/PressableScale.tsx +105 -0
- package/ui/components/ui/ScreenGradient.tsx +47 -0
- package/ui/components/ui/ScrollFade.tsx +76 -0
- package/ui/components/ui/Sheet.tsx +342 -0
- package/ui/components/ui/Toast.tsx +142 -0
- package/ui/components/ui/index.ts +8 -0
- package/ui/components/vault/EnrollWizard.tsx +627 -0
- package/ui/components/vault/PassphraseField.tsx +306 -0
- package/ui/components/vault/PhraseBackupSheet.tsx +227 -0
- package/ui/components/vault/VaultBackdrop.tsx +354 -0
- package/ui/components/vault/VaultCeremonySheet.tsx +327 -0
- package/ui/components/wallet/ActivityRow.tsx +408 -0
- package/ui/components/wallet/AmountDisplay.tsx +48 -0
- package/ui/components/wallet/AmountInput.tsx +256 -0
- package/ui/components/wallet/BackupReminderSheet.tsx +168 -0
- package/ui/components/wallet/Balance.tsx +144 -0
- package/ui/components/wallet/BiometricAdvisoryModal.tsx +133 -0
- package/ui/components/wallet/ImportFromBackupPrompt.tsx +93 -0
- package/ui/exportDatabases.ts +122 -0
- package/ui/exportTransactions.ts +129 -0
- package/ui/hooks/useOfflineNoticeActions.ts +136 -0
- package/ui/hooks/useOnline.ts +70 -0
- package/ui/hooks/useSpendableBalance.ts +58 -0
- package/ui/hooks/useVaultBalance.ts +50 -0
- package/ui/importDatabases.ts +170 -0
- package/ui/index.ts +136 -0
- package/ui/isImageUrl.ts +10 -0
- package/ui/printRecoveryShares.ts +93 -0
- package/ui/resolveIdentity.ts +125 -0
- package/ui/screens/ConnectionsScreen.tsx +438 -0
- package/ui/screens/LogsScreen.tsx +432 -0
- package/ui/screens/PairScreen.tsx +288 -0
- package/ui/screens/PayScreen.tsx +479 -0
- package/ui/screens/SettingsScreen.tsx +180 -0
- package/ui/screens/TrustScreen.tsx +831 -0
- package/ui/screens/VaultRecoverScreen.tsx +226 -0
- package/ui/screens/VaultScreen.tsx +423 -0
- package/ui/screens/VaultTransferScreen.tsx +293 -0
- package/ui/screens/WalletCheckScreen.tsx +539 -0
- package/ui/screens/WalletConfigScreen.tsx +1095 -0
- package/ui/screens/WalletHomeScreen.tsx +1597 -0
- package/ui/screens/homeBadges.ts +18 -0
- package/ui/txStatus.ts +79 -0
- package/ui/validateTrust.ts +44 -0
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vault deposit / withdraw — full screen, not a drawer.
|
|
3
|
+
*
|
|
4
|
+
* Direction comes from the `direction` search param ('deposit' | 'withdraw').
|
|
5
|
+
*
|
|
6
|
+
* Both directions run the ceremony sheet. A deposit address is a BIP32 child
|
|
7
|
+
* of the vault's PRIVATE HD node — there is no stored xpub to derive one
|
|
8
|
+
* from without it — so even a deposit needs one YubiKey tap to unwrap that
|
|
9
|
+
* node. Withdraw derives every input's key (and any re-vaulted remainder)
|
|
10
|
+
* from the same unwrapped node and signs in software. Either way the ceremony
|
|
11
|
+
* sheet takes over for insert/PIN/touch — that one stays a sheet
|
|
12
|
+
* deliberately, because it fires from any screen as a system prompt.
|
|
13
|
+
*/
|
|
14
|
+
import React, { useState, useCallback } from 'react'
|
|
15
|
+
import {
|
|
16
|
+
View,
|
|
17
|
+
Text,
|
|
18
|
+
StyleSheet,
|
|
19
|
+
ActivityIndicator,
|
|
20
|
+
ScrollView,
|
|
21
|
+
TouchableOpacity
|
|
22
|
+
} from 'react-native'
|
|
23
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
24
|
+
import { AmountInput, SEND_MAX_VALUE } from '../components/wallet/AmountInput'
|
|
25
|
+
import PressableScale from '../components/ui/PressableScale'
|
|
26
|
+
import AmountDisplay from '../components/wallet/AmountDisplay'
|
|
27
|
+
import { showToast } from '../components/ui/Toast'
|
|
28
|
+
import { showAlert } from '../components/ui/AlertCard'
|
|
29
|
+
import {
|
|
30
|
+
useTheme,
|
|
31
|
+
spacing,
|
|
32
|
+
radii,
|
|
33
|
+
typography,
|
|
34
|
+
useWallet,
|
|
35
|
+
depositToVault,
|
|
36
|
+
withdrawFromVault,
|
|
37
|
+
type VaultWallet,
|
|
38
|
+
getOnline,
|
|
39
|
+
VaultError,
|
|
40
|
+
haptics,
|
|
41
|
+
i18n
|
|
42
|
+
} from '@bsv/expo-wallet-toolbox'
|
|
43
|
+
import { useVaultBalance } from '../hooks/useVaultBalance'
|
|
44
|
+
|
|
45
|
+
const t = (k: string, o?: Record<string, unknown>) => i18n.t(k, o) as string
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @expo/vector-icons' index barrel re-exports every icon set (AntDesign,
|
|
49
|
+
* etc.), one of which reaches expo-font -> expo-asset -- untransformed ESM
|
|
50
|
+
* that Jest cannot parse when eagerly pulled in via the `ui` package barrel.
|
|
51
|
+
* Ionicons is loaded lazily, only when actually rendering, same pattern as
|
|
52
|
+
* this package's other native-module-boundary fixes (expo-router, expo-blur).
|
|
53
|
+
*/
|
|
54
|
+
type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
|
|
55
|
+
let ioniconsComponent: IoniconsComponent | undefined
|
|
56
|
+
function loadIonicons(): IoniconsComponent {
|
|
57
|
+
if (!ioniconsComponent) {
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
59
|
+
ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
|
|
60
|
+
}
|
|
61
|
+
return ioniconsComponent
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* expo-router is required lazily rather than imported at module scope: this
|
|
66
|
+
* file is barrel-exported from the package's `ui` entry point, and a static
|
|
67
|
+
* top-level `import` of expo-router pulls in its own untransformed JSX
|
|
68
|
+
* source (Navigator.js etc.), which Jest cannot parse for any consumer of the
|
|
69
|
+
* barrel, even one that never navigates. Same pattern as
|
|
70
|
+
* core/context/WalletContext.tsx's and WalletHomeScreen.tsx's lazy
|
|
71
|
+
* expo-router load. `useLocalSearchParams` is a hook, but calling it via
|
|
72
|
+
* `loadExpoRouter().useLocalSearchParams()` is equivalent to calling it
|
|
73
|
+
* directly — the module is cached after the first call, so it is the exact
|
|
74
|
+
* same function reference on every render, which is what the rules of hooks
|
|
75
|
+
* actually require (a stable, unconditional call per render).
|
|
76
|
+
*/
|
|
77
|
+
type ExpoRouterModule = typeof import('expo-router')
|
|
78
|
+
let expoRouterMod: ExpoRouterModule | undefined
|
|
79
|
+
function loadExpoRouter(): ExpoRouterModule {
|
|
80
|
+
if (!expoRouterMod) {
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
82
|
+
expoRouterMod = require('expo-router') as ExpoRouterModule
|
|
83
|
+
}
|
|
84
|
+
return expoRouterMod
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* i18next returns the KEY itself when a string is missing, and a key is
|
|
89
|
+
* truthy — so the old `t(...) || t('vault_err_generic')` fallback never fired
|
|
90
|
+
* and shipped raw keys like `vault_err_backup_required` to the screen.
|
|
91
|
+
*/
|
|
92
|
+
function translateVaultError(code: string | undefined): string {
|
|
93
|
+
if (!code) return t('vault_err_generic')
|
|
94
|
+
const key = `vault_err_${code.replace(/-/g, '_')}`
|
|
95
|
+
const translated = t(key)
|
|
96
|
+
return translated === key ? t('vault_err_generic') : translated
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function VaultTransferScreen() {
|
|
100
|
+
const { colors } = useTheme()
|
|
101
|
+
const insets = useSafeAreaInsets()
|
|
102
|
+
const { router, useLocalSearchParams } = loadExpoRouter()
|
|
103
|
+
const Ionicons = loadIonicons()
|
|
104
|
+
const { direction } = useLocalSearchParams<{ direction?: string }>()
|
|
105
|
+
const { managers, adminOriginator, storage } = useWallet()
|
|
106
|
+
const { balance, refresh } = useVaultBalance()
|
|
107
|
+
const [amount, setAmount] = useState('')
|
|
108
|
+
const [busy, setBusy] = useState(false)
|
|
109
|
+
const [error, setError] = useState<string | null>(null)
|
|
110
|
+
|
|
111
|
+
const isDeposit = direction !== 'withdraw'
|
|
112
|
+
|
|
113
|
+
// Send max is a sentinel value, not a number: the withdraw path takes 'all'
|
|
114
|
+
// and lets the toolbox work out the fee, which is the only way to empty the
|
|
115
|
+
// vault exactly. Pre-computing "balance minus fee" here cannot work — a K1
|
|
116
|
+
// withdrawal's fee depends on how many vault inputs it takes to cover the
|
|
117
|
+
// amount (each input is an ordinary ~107-byte unlock), not on any one
|
|
118
|
+
// script's size, and that count is not known until the outputs are selected.
|
|
119
|
+
const isMax = amount === SEND_MAX_VALUE
|
|
120
|
+
|
|
121
|
+
const run = useCallback(async () => {
|
|
122
|
+
const pm = managers?.permissionsManager
|
|
123
|
+
const sats = parseInt(amount, 10)
|
|
124
|
+
if (!pm) return
|
|
125
|
+
if (!isMax && (!Number.isFinite(sats) || sats <= 0)) return
|
|
126
|
+
setBusy(true)
|
|
127
|
+
setError(null)
|
|
128
|
+
try {
|
|
129
|
+
const w = pm as unknown as VaultWallet
|
|
130
|
+
if (isDeposit) {
|
|
131
|
+
await depositToVault(w, adminOriginator, sats, t('vault_deposit_reason', { amount: sats }), {
|
|
132
|
+
isOnline: getOnline
|
|
133
|
+
})
|
|
134
|
+
// vaultOpen/haptic already fired by the ceremony's onArmed
|
|
135
|
+
showToast(t('vault_deposit_done'), { type: 'success' })
|
|
136
|
+
} else {
|
|
137
|
+
const result = await withdrawFromVault(
|
|
138
|
+
w,
|
|
139
|
+
adminOriginator,
|
|
140
|
+
isMax ? 'all' : sats,
|
|
141
|
+
t('vault_withdraw_reason', { amount: isMax ? (balance ?? 0) : sats }),
|
|
142
|
+
{
|
|
143
|
+
// Lets the reservation heal find the reserving transaction with one
|
|
144
|
+
// indexed query instead of paging every action in the wallet.
|
|
145
|
+
findSpendingReferences: storage ? outpoints => storage.findSpendingReferences(outpoints) : undefined,
|
|
146
|
+
isOnline: getOnline
|
|
147
|
+
}
|
|
148
|
+
)
|
|
149
|
+
// vaultOpen/haptic already fired by the ceremony's onArmed
|
|
150
|
+
//
|
|
151
|
+
// A capped withdrawal is partial by design (see VAULT_MAX_INPUTS), so
|
|
152
|
+
// say so rather than letting the balance look wrong: the vault still
|
|
153
|
+
// holds the untouched outputs, and repeating the withdrawal moves them.
|
|
154
|
+
showToast(
|
|
155
|
+
result.remainingInputs > 0
|
|
156
|
+
? t('vault_withdraw_partial', { count: result.remainingInputs })
|
|
157
|
+
: t('vault_withdraw_done'),
|
|
158
|
+
{ type: 'success' }
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
setAmount('')
|
|
162
|
+
refresh()
|
|
163
|
+
router.back()
|
|
164
|
+
} catch (e) {
|
|
165
|
+
console.error('[vault] transfer failed:', e instanceof Error ? e.message : e, e)
|
|
166
|
+
const code = e instanceof VaultError ? e.code : undefined
|
|
167
|
+
|
|
168
|
+
if (code === 'backup-required') {
|
|
169
|
+
// A blocked deposit needs a route out, not a red footnote. Matches the
|
|
170
|
+
// disable-while-funded pattern on the vault screen.
|
|
171
|
+
//
|
|
172
|
+
// The CTA goes to Settings > Wallet, not back to /vault: this refusal
|
|
173
|
+
// only fires once a vault already exists (deposit is only offered
|
|
174
|
+
// from the enrolled vault screen), and the enrolled vault screen has
|
|
175
|
+
// no backup affordance of its own — EnrollWizard, the only other
|
|
176
|
+
// place that records an attestation, isn't reachable from there.
|
|
177
|
+
// Printing recovery shares from wallet-config is a real backup and
|
|
178
|
+
// now records the same attestation (see handlePrintRecoveryShares),
|
|
179
|
+
// so it satisfies the gate. push (not replace) keeps this screen on
|
|
180
|
+
// the stack so the user can come back and retry the deposit.
|
|
181
|
+
haptics.error()
|
|
182
|
+
const choice = await showAlert({
|
|
183
|
+
title: t('vault_deposit_blocked_title'),
|
|
184
|
+
message: t('vault_deposit_blocked_message'),
|
|
185
|
+
buttons: [
|
|
186
|
+
{ text: t('vault_deposit_blocked_dismiss'), style: 'cancel', key: 'cancel' },
|
|
187
|
+
{ text: t('vault_deposit_blocked_cta'), key: 'backup' }
|
|
188
|
+
]
|
|
189
|
+
})
|
|
190
|
+
if (choice === 'backup') router.push('/wallet-config')
|
|
191
|
+
return
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
setError(translateVaultError(code))
|
|
195
|
+
haptics.error()
|
|
196
|
+
} finally {
|
|
197
|
+
setBusy(false)
|
|
198
|
+
}
|
|
199
|
+
}, [amount, isMax, balance, isDeposit, managers?.permissionsManager, adminOriginator, refresh, storage])
|
|
200
|
+
|
|
201
|
+
const sats = parseInt(amount, 10)
|
|
202
|
+
const valid = isMax || (Number.isFinite(sats) && sats > 0)
|
|
203
|
+
|
|
204
|
+
return (
|
|
205
|
+
<View
|
|
206
|
+
style={[
|
|
207
|
+
styles.container,
|
|
208
|
+
{ backgroundColor: colors.backgroundSecondary, paddingTop: insets.top }
|
|
209
|
+
]}
|
|
210
|
+
>
|
|
211
|
+
<View style={[styles.header, { borderBottomColor: colors.separator }]}>
|
|
212
|
+
<TouchableOpacity onPress={() => router.back()} style={styles.iconBtn}>
|
|
213
|
+
<Ionicons name="chevron-back" size={24} color={colors.textSecondary} />
|
|
214
|
+
</TouchableOpacity>
|
|
215
|
+
<Text style={[styles.headerTitle, { color: colors.textPrimary }]}>
|
|
216
|
+
{isDeposit ? t('vault_deposit_title') : t('vault_withdraw_title')}
|
|
217
|
+
</Text>
|
|
218
|
+
<View style={styles.iconBtn} />
|
|
219
|
+
</View>
|
|
220
|
+
|
|
221
|
+
<ScrollView contentContainerStyle={styles.body} keyboardShouldPersistTaps="handled">
|
|
222
|
+
<View style={styles.balanceBlock}>
|
|
223
|
+
<Text style={[styles.balanceLabel, { color: colors.textSecondary }]}>
|
|
224
|
+
{t('vault_balance_label')}
|
|
225
|
+
</Text>
|
|
226
|
+
<Text style={[styles.balance, { color: colors.textPrimary }]}>
|
|
227
|
+
<AmountDisplay>{balance ?? 0}</AmountDisplay>
|
|
228
|
+
</Text>
|
|
229
|
+
</View>
|
|
230
|
+
|
|
231
|
+
<Text style={[styles.sub, { color: colors.textSecondary }]}>
|
|
232
|
+
{isDeposit ? t('vault_deposit_sub') : t('vault_withdraw_sub')}
|
|
233
|
+
</Text>
|
|
234
|
+
|
|
235
|
+
<AmountInput
|
|
236
|
+
value={amount}
|
|
237
|
+
onChangeText={setAmount}
|
|
238
|
+
showMax={!isDeposit}
|
|
239
|
+
maxLabelKey="entire_vault_balance"
|
|
240
|
+
/>
|
|
241
|
+
|
|
242
|
+
{error && <Text style={[styles.err, { color: colors.error }]}>{error}</Text>}
|
|
243
|
+
|
|
244
|
+
<PressableScale
|
|
245
|
+
haptic="confirm"
|
|
246
|
+
onPress={valid && !busy ? run : undefined}
|
|
247
|
+
style={[
|
|
248
|
+
styles.primary,
|
|
249
|
+
{
|
|
250
|
+
backgroundColor: valid ? colors.accent : colors.backgroundElevated,
|
|
251
|
+
opacity: busy ? 0.6 : 1
|
|
252
|
+
}
|
|
253
|
+
]}
|
|
254
|
+
>
|
|
255
|
+
{busy ? (
|
|
256
|
+
<ActivityIndicator color={colors.textOnAccent} />
|
|
257
|
+
) : (
|
|
258
|
+
<Text
|
|
259
|
+
style={[
|
|
260
|
+
styles.primaryLabel,
|
|
261
|
+
{ color: valid ? colors.textOnAccent : colors.textTertiary }
|
|
262
|
+
]}
|
|
263
|
+
>
|
|
264
|
+
{isDeposit ? t('vault_deposit_cta') : t('vault_withdraw_cta')}
|
|
265
|
+
</Text>
|
|
266
|
+
)}
|
|
267
|
+
</PressableScale>
|
|
268
|
+
</ScrollView>
|
|
269
|
+
</View>
|
|
270
|
+
)
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const styles = StyleSheet.create({
|
|
274
|
+
container: { flex: 1 },
|
|
275
|
+
header: {
|
|
276
|
+
flexDirection: 'row',
|
|
277
|
+
alignItems: 'center',
|
|
278
|
+
justifyContent: 'space-between',
|
|
279
|
+
paddingHorizontal: spacing.sm,
|
|
280
|
+
paddingVertical: spacing.md,
|
|
281
|
+
borderBottomWidth: StyleSheet.hairlineWidth
|
|
282
|
+
},
|
|
283
|
+
iconBtn: { width: 44, height: 44, alignItems: 'center', justifyContent: 'center' },
|
|
284
|
+
headerTitle: { ...typography.headline },
|
|
285
|
+
body: { padding: spacing.xl, gap: spacing.lg },
|
|
286
|
+
balanceBlock: { alignItems: 'center', gap: spacing.xs, paddingBottom: spacing.md },
|
|
287
|
+
balanceLabel: { ...typography.footnote, textTransform: 'uppercase' },
|
|
288
|
+
balance: { ...typography.title1, fontVariant: ['tabular-nums'] },
|
|
289
|
+
sub: { ...typography.subhead, textAlign: 'center' },
|
|
290
|
+
err: { ...typography.footnote, textAlign: 'center' },
|
|
291
|
+
primary: { borderRadius: radii.md, paddingVertical: spacing.lg, alignItems: 'center' },
|
|
292
|
+
primaryLabel: { ...typography.headline }
|
|
293
|
+
})
|