@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,256 @@
|
|
|
1
|
+
import React, { useContext, useState, useEffect, useRef } from 'react'
|
|
2
|
+
import { View, TextInput, TouchableOpacity, Text, StyleSheet } from 'react-native'
|
|
3
|
+
import Animated, { FadeInUp, FadeOutDown, useReducedMotion } from 'react-native-reanimated'
|
|
4
|
+
import { useTranslation } from 'react-i18next'
|
|
5
|
+
import {
|
|
6
|
+
useTheme,
|
|
7
|
+
spacing,
|
|
8
|
+
typography,
|
|
9
|
+
radii,
|
|
10
|
+
durations,
|
|
11
|
+
useWallet,
|
|
12
|
+
ExchangeRateContext,
|
|
13
|
+
parseDisplayToSatoshis,
|
|
14
|
+
formatAmount,
|
|
15
|
+
isFiatCurrency,
|
|
16
|
+
fiatFractionDigits,
|
|
17
|
+
satoshisPerFiatUnit
|
|
18
|
+
} from '@bsv/expo-wallet-toolbox'
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @expo/vector-icons' index barrel re-exports every icon set (AntDesign,
|
|
22
|
+
* etc.), one of which reaches expo-font -> expo-asset -- untransformed ESM
|
|
23
|
+
* that Jest cannot parse when eagerly pulled in via the `ui` package barrel.
|
|
24
|
+
* Ionicons is loaded lazily, only when actually rendering, same pattern as
|
|
25
|
+
* this package's other native-module-boundary fixes (expo-router, expo-blur).
|
|
26
|
+
*/
|
|
27
|
+
type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
|
|
28
|
+
let ioniconsComponent: IoniconsComponent | undefined
|
|
29
|
+
function loadIonicons(): IoniconsComponent {
|
|
30
|
+
if (!ioniconsComponent) {
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
32
|
+
ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
|
|
33
|
+
}
|
|
34
|
+
return ioniconsComponent
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const SEND_MAX_VALUE = '2099999999999999'
|
|
38
|
+
|
|
39
|
+
interface AmountInputProps {
|
|
40
|
+
/**
|
|
41
|
+
* Show the "Send Max" shortcut. Defaults to true for send flows.
|
|
42
|
+
* Pass false when asking someone ELSE to pay: the max there would be the
|
|
43
|
+
* requester's own balance, which is meaningless to the payer.
|
|
44
|
+
*/
|
|
45
|
+
showMax?: boolean
|
|
46
|
+
/**
|
|
47
|
+
* i18n key for the label shown once max is chosen. Defaults to the wallet
|
|
48
|
+
* wording; the vault passes its own, since "entire wallet balance" would be
|
|
49
|
+
* plainly wrong on a screen moving only the vault basket.
|
|
50
|
+
*/
|
|
51
|
+
maxLabelKey?: string
|
|
52
|
+
value: string
|
|
53
|
+
onChangeText: (text: string) => void
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Unit-aware amount input component.
|
|
58
|
+
*
|
|
59
|
+
* In BSV mode (default): accepts integer satoshis via number-pad.
|
|
60
|
+
* In fiat mode: accepts a decimal amount in the selected currency (0 decimals
|
|
61
|
+
* for JPY, 2 for EUR, etc.) via decimal-pad, converts to satoshis internally.
|
|
62
|
+
*
|
|
63
|
+
* The `onChangeText` callback always emits satoshi integer strings.
|
|
64
|
+
* The `value` prop is always satoshi integer strings.
|
|
65
|
+
*/
|
|
66
|
+
export const AmountInput: React.FC<AmountInputProps> = ({
|
|
67
|
+
value,
|
|
68
|
+
onChangeText,
|
|
69
|
+
showMax = true,
|
|
70
|
+
maxLabelKey = 'entire_wallet_balance'
|
|
71
|
+
}) => {
|
|
72
|
+
const { t } = useTranslation()
|
|
73
|
+
const { colors } = useTheme()
|
|
74
|
+
const { settings } = useWallet()
|
|
75
|
+
const { satoshisPerUSD, usdToFiat = {} } = useContext(ExchangeRateContext)
|
|
76
|
+
const reducedMotion = useReducedMotion()
|
|
77
|
+
const Ionicons = loadIonicons()
|
|
78
|
+
|
|
79
|
+
const currency = settings?.currency || 'BSV'
|
|
80
|
+
const isFiat = isFiatCurrency(currency)
|
|
81
|
+
const fractionDigits = isFiat ? fiatFractionDigits(currency) : 0
|
|
82
|
+
const isSendMax = value === SEND_MAX_VALUE
|
|
83
|
+
|
|
84
|
+
// In fiat mode, we maintain a separate display value from the satoshi value
|
|
85
|
+
const [fiatDisplayValue, setFiatDisplayValue] = useState('')
|
|
86
|
+
const lastEmittedSats = useRef('')
|
|
87
|
+
|
|
88
|
+
// Sync fiat display value when the satoshi value changes externally (e.g., cleared by parent)
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
if (!isFiat) return
|
|
91
|
+
// Avoid re-syncing when we caused the change ourselves
|
|
92
|
+
if (value === lastEmittedSats.current) return
|
|
93
|
+
|
|
94
|
+
if (!value || value === '0') {
|
|
95
|
+
setFiatDisplayValue('')
|
|
96
|
+
} else if (value === SEND_MAX_VALUE) {
|
|
97
|
+
// Don't try to convert SEND_MAX_VALUE to fiat
|
|
98
|
+
} else {
|
|
99
|
+
const sats = parseInt(value, 10)
|
|
100
|
+
const per = satoshisPerFiatUnit(currency, satoshisPerUSD, usdToFiat)
|
|
101
|
+
if (!isNaN(sats) && per > 0) {
|
|
102
|
+
const amount = sats / per
|
|
103
|
+
if (fractionDigits === 0) {
|
|
104
|
+
setFiatDisplayValue(String(Math.round(amount)))
|
|
105
|
+
} else {
|
|
106
|
+
setFiatDisplayValue(
|
|
107
|
+
amount % 1 === 0
|
|
108
|
+
? amount.toFixed(0)
|
|
109
|
+
: amount.toFixed(fractionDigits).replace(/0+$/, '').replace(/\.$/, '')
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
lastEmittedSats.current = value
|
|
115
|
+
}, [value, isFiat, currency, satoshisPerUSD, usdToFiat, fractionDigits])
|
|
116
|
+
|
|
117
|
+
const handleChangeText = (text: string) => {
|
|
118
|
+
if (isFiat) {
|
|
119
|
+
const allowed = fractionDigits === 0 ? /^\d*$/ : new RegExp(`^\\d*\\.?\\d{0,${fractionDigits}}$`)
|
|
120
|
+
if (text && !allowed.test(text)) return
|
|
121
|
+
setFiatDisplayValue(text)
|
|
122
|
+
const sats = parseDisplayToSatoshis(text, currency, satoshisPerUSD, usdToFiat)
|
|
123
|
+
const satsStr = text ? String(sats) : ''
|
|
124
|
+
lastEmittedSats.current = satsStr
|
|
125
|
+
onChangeText(satsStr)
|
|
126
|
+
} else {
|
|
127
|
+
onChangeText(text)
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (isSendMax) {
|
|
132
|
+
return (
|
|
133
|
+
<View style={[styles.row, { backgroundColor: colors.backgroundSecondary, borderColor: colors.accent }]}>
|
|
134
|
+
<View style={styles.sendMaxDisplay}>
|
|
135
|
+
<Ionicons name="wallet-outline" size={18} color={colors.accent} />
|
|
136
|
+
<Text style={[styles.sendMaxLabel, { color: colors.accent }]}>{t(maxLabelKey)}</Text>
|
|
137
|
+
</View>
|
|
138
|
+
<TouchableOpacity
|
|
139
|
+
onPress={() => {
|
|
140
|
+
if (isFiat) setFiatDisplayValue('')
|
|
141
|
+
onChangeText('')
|
|
142
|
+
}}
|
|
143
|
+
style={[styles.clearButton, { backgroundColor: colors.fill }]}
|
|
144
|
+
>
|
|
145
|
+
<Ionicons name="close" size={16} color={colors.accent} />
|
|
146
|
+
</TouchableOpacity>
|
|
147
|
+
</View>
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const displayValue = isFiat ? fiatDisplayValue : value
|
|
152
|
+
const placeholder = isFiat ? (fractionDigits === 0 ? '0' : '0.00') : '0'
|
|
153
|
+
const keyboardType = isFiat && fractionDigits > 0 ? ('decimal-pad' as const) : ('number-pad' as const)
|
|
154
|
+
const unitLabel = isFiat ? currency : 'satoshis'
|
|
155
|
+
|
|
156
|
+
// Secondary converted-currency line: BSV when showing fiat, USD when showing BSV
|
|
157
|
+
const satsForConversion = value ? parseInt(value, 10) : 0
|
|
158
|
+
const secondaryText = isFiat
|
|
159
|
+
? (satsForConversion > 0 ? formatAmount(satsForConversion, 'BSV', satoshisPerUSD) : null)
|
|
160
|
+
: (satsForConversion > 0 && satoshisPerUSD > 0 ? formatAmount(satsForConversion, 'USD', satoshisPerUSD) : null)
|
|
161
|
+
|
|
162
|
+
const entering = reducedMotion ? undefined : FadeInUp.duration(durations.instant)
|
|
163
|
+
const exiting = reducedMotion ? undefined : FadeOutDown.duration(durations.instant)
|
|
164
|
+
|
|
165
|
+
return (
|
|
166
|
+
<View>
|
|
167
|
+
<View style={[styles.row, { backgroundColor: colors.backgroundSecondary, borderColor: colors.separator }]}>
|
|
168
|
+
<TextInput
|
|
169
|
+
value={displayValue}
|
|
170
|
+
onChangeText={handleChangeText}
|
|
171
|
+
placeholder={placeholder}
|
|
172
|
+
placeholderTextColor={colors.textTertiary}
|
|
173
|
+
keyboardType={keyboardType}
|
|
174
|
+
returnKeyType="done"
|
|
175
|
+
style={[styles.input, { color: colors.textPrimary }]}
|
|
176
|
+
/>
|
|
177
|
+
<View style={styles.unitLabelPressable}>
|
|
178
|
+
<Animated.View key={unitLabel} entering={entering} exiting={exiting}>
|
|
179
|
+
<Text style={[styles.unitLabel, { color: colors.textSecondary }]}>{unitLabel}</Text>
|
|
180
|
+
</Animated.View>
|
|
181
|
+
</View>
|
|
182
|
+
{showMax && (
|
|
183
|
+
<TouchableOpacity
|
|
184
|
+
onPress={() => onChangeText(SEND_MAX_VALUE)}
|
|
185
|
+
style={[styles.maxButton, { backgroundColor: colors.fill }]}
|
|
186
|
+
>
|
|
187
|
+
<Text style={[styles.maxText, { color: colors.accent }]}>{t('send_max')}</Text>
|
|
188
|
+
</TouchableOpacity>
|
|
189
|
+
)}
|
|
190
|
+
</View>
|
|
191
|
+
{secondaryText != null && (
|
|
192
|
+
<Text style={[styles.secondaryAmount, { color: colors.textSecondary }]}>{secondaryText}</Text>
|
|
193
|
+
)}
|
|
194
|
+
</View>
|
|
195
|
+
)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Keep legacy export name for backward compatibility during migration
|
|
199
|
+
export const SatsAmountInput = AmountInput
|
|
200
|
+
|
|
201
|
+
const styles = StyleSheet.create({
|
|
202
|
+
row: {
|
|
203
|
+
flexDirection: 'row',
|
|
204
|
+
alignItems: 'center',
|
|
205
|
+
borderRadius: radii.md,
|
|
206
|
+
borderWidth: StyleSheet.hairlineWidth
|
|
207
|
+
},
|
|
208
|
+
input: {
|
|
209
|
+
...typography.largeTitle,
|
|
210
|
+
fontVariant: ['tabular-nums'],
|
|
211
|
+
flex: 1,
|
|
212
|
+
paddingHorizontal: spacing.md,
|
|
213
|
+
paddingVertical: spacing.md
|
|
214
|
+
},
|
|
215
|
+
unitLabelPressable: {
|
|
216
|
+
paddingRight: spacing.sm
|
|
217
|
+
},
|
|
218
|
+
unitLabel: {
|
|
219
|
+
...typography.footnote
|
|
220
|
+
},
|
|
221
|
+
secondaryAmount: {
|
|
222
|
+
...typography.title3,
|
|
223
|
+
marginTop: spacing.xs,
|
|
224
|
+
paddingHorizontal: spacing.xs
|
|
225
|
+
},
|
|
226
|
+
maxButton: {
|
|
227
|
+
paddingHorizontal: spacing.md,
|
|
228
|
+
paddingVertical: spacing.sm,
|
|
229
|
+
borderRadius: radii.sm,
|
|
230
|
+
marginRight: spacing.sm
|
|
231
|
+
},
|
|
232
|
+
maxText: {
|
|
233
|
+
...typography.footnote,
|
|
234
|
+
fontWeight: '600'
|
|
235
|
+
},
|
|
236
|
+
sendMaxDisplay: {
|
|
237
|
+
flex: 1,
|
|
238
|
+
flexDirection: 'row',
|
|
239
|
+
alignItems: 'center',
|
|
240
|
+
gap: spacing.sm,
|
|
241
|
+
paddingHorizontal: spacing.md,
|
|
242
|
+
paddingVertical: spacing.md
|
|
243
|
+
},
|
|
244
|
+
sendMaxLabel: {
|
|
245
|
+
...typography.body,
|
|
246
|
+
fontWeight: '600'
|
|
247
|
+
},
|
|
248
|
+
clearButton: {
|
|
249
|
+
width: 28,
|
|
250
|
+
height: 28,
|
|
251
|
+
borderRadius: 14,
|
|
252
|
+
alignItems: 'center',
|
|
253
|
+
justifyContent: 'center',
|
|
254
|
+
marginRight: spacing.sm
|
|
255
|
+
}
|
|
256
|
+
})
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A non-blocking card anchored to the bottom of the screen on a freshly
|
|
3
|
+
* auto-created wallet (balance zero, empty activity), prompting the user to
|
|
4
|
+
* secure their keys before the screen fills up with real money and history.
|
|
5
|
+
* Deliberately "attention" styled (warning-tinted border/icon) — this is the
|
|
6
|
+
* one prompt in the app that guards against irreversible key loss — but it
|
|
7
|
+
* must never trap the user: no backdrop, no Modal, rest of the screen stays
|
|
8
|
+
* fully interactive underneath it (pointerEvents="box-none" on the wrapper).
|
|
9
|
+
*
|
|
10
|
+
* Advisory only, same as the rest of the backup-attestation system — closing
|
|
11
|
+
* this card without acting reopens it next launch until the user backs up or
|
|
12
|
+
* imports (see `useWallet`/`backupAttestation`).
|
|
13
|
+
*/
|
|
14
|
+
import React, { useEffect, useState } from 'react'
|
|
15
|
+
import { StyleSheet, Text, View } from 'react-native'
|
|
16
|
+
import Animated, {
|
|
17
|
+
useSharedValue,
|
|
18
|
+
useAnimatedStyle,
|
|
19
|
+
withSpring,
|
|
20
|
+
withTiming,
|
|
21
|
+
useReducedMotion,
|
|
22
|
+
runOnJS
|
|
23
|
+
} from 'react-native-reanimated'
|
|
24
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
25
|
+
import { useTheme, spacing, radii, typography, springs, durations, i18n } from '@bsv/expo-wallet-toolbox'
|
|
26
|
+
import PressableScale from '../ui/PressableScale'
|
|
27
|
+
|
|
28
|
+
const t = (k: string, o?: Record<string, unknown>) => i18n.t(k, o) as string
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @expo/vector-icons' index barrel re-exports every icon set, one of which
|
|
32
|
+
* reaches expo-font -> expo-asset -- untransformed ESM Jest cannot parse
|
|
33
|
+
* when eagerly pulled in via the `ui` package barrel. Loaded lazily, same
|
|
34
|
+
* pattern as this package's other native-module-boundary fixes.
|
|
35
|
+
*/
|
|
36
|
+
type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
|
|
37
|
+
let ioniconsComponent: IoniconsComponent | undefined
|
|
38
|
+
function loadIonicons(): IoniconsComponent {
|
|
39
|
+
if (!ioniconsComponent) {
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
41
|
+
ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
|
|
42
|
+
}
|
|
43
|
+
return ioniconsComponent
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const BackupReminderSheet: React.FC<{
|
|
47
|
+
visible: boolean
|
|
48
|
+
onClose: () => void
|
|
49
|
+
onBackupNow: () => void
|
|
50
|
+
}> = ({ visible, onClose, onBackupNow }) => {
|
|
51
|
+
const { colors } = useTheme()
|
|
52
|
+
const Ionicons = loadIonicons()
|
|
53
|
+
const reducedMotion = useReducedMotion()
|
|
54
|
+
const insets = useSafeAreaInsets()
|
|
55
|
+
|
|
56
|
+
// Rendered independently of `visible` so the exit slide-down can finish
|
|
57
|
+
// before the card unmounts (mirrors Sheet's rendered/wasVisible pattern).
|
|
58
|
+
const [rendered, setRendered] = useState(visible)
|
|
59
|
+
const progress = useSharedValue(visible ? 1 : 0)
|
|
60
|
+
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (visible) {
|
|
63
|
+
setRendered(true)
|
|
64
|
+
progress.value = reducedMotion ? withTiming(1, { duration: durations.instant }) : withSpring(1, springs.snappy)
|
|
65
|
+
} else if (rendered) {
|
|
66
|
+
progress.value = withTiming(0, { duration: durations.instant }, finished => {
|
|
67
|
+
if (finished) runOnJS(setRendered)(false)
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
}, [visible, progress, reducedMotion]) // eslint-disable-line react-hooks/exhaustive-deps
|
|
71
|
+
|
|
72
|
+
const cardStyle = useAnimatedStyle(() => ({
|
|
73
|
+
opacity: progress.value,
|
|
74
|
+
transform: [{ translateY: (1 - progress.value) * 40 }, { scale: 0.96 + 0.04 * progress.value }]
|
|
75
|
+
}))
|
|
76
|
+
|
|
77
|
+
if (!rendered) return null
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
// box-none: this wrapper (and the empty space around the card) never
|
|
81
|
+
// intercepts touches, so the screen behind stays fully interactive.
|
|
82
|
+
<View style={[styles.wrapper, { paddingBottom: insets.bottom + spacing.md }]} pointerEvents="box-none">
|
|
83
|
+
<Animated.View
|
|
84
|
+
style={[
|
|
85
|
+
styles.card,
|
|
86
|
+
{ backgroundColor: colors.sheetBackground, borderColor: colors.warning },
|
|
87
|
+
cardStyle
|
|
88
|
+
]}
|
|
89
|
+
>
|
|
90
|
+
<PressableScale haptic="tap" onPress={onClose} style={styles.closeButton}>
|
|
91
|
+
<Ionicons name="close" size={20} color={colors.textSecondary} />
|
|
92
|
+
</PressableScale>
|
|
93
|
+
|
|
94
|
+
<View style={styles.body}>
|
|
95
|
+
<View style={[styles.heroIcon, { backgroundColor: colors.warning + '22' }]}>
|
|
96
|
+
<Ionicons name="warning-outline" size={28} color={colors.warning} />
|
|
97
|
+
</View>
|
|
98
|
+
<Text style={[styles.h1, { color: colors.textPrimary }]}>{t('backup_reminder_title')}</Text>
|
|
99
|
+
<Text style={[styles.p, { color: colors.textSecondary }]}>{t('backup_reminder_body')}</Text>
|
|
100
|
+
|
|
101
|
+
<PressableScale
|
|
102
|
+
haptic="confirm"
|
|
103
|
+
onPress={onBackupNow}
|
|
104
|
+
style={[styles.primary, { backgroundColor: colors.warning }]}
|
|
105
|
+
>
|
|
106
|
+
<Ionicons name="key-outline" size={20} color={colors.textOnAccent} style={styles.btnIcon} />
|
|
107
|
+
<Text style={[styles.primaryLabel, { color: colors.textOnAccent }]}>{t('backup_reminder_now')}</Text>
|
|
108
|
+
</PressableScale>
|
|
109
|
+
</View>
|
|
110
|
+
</Animated.View>
|
|
111
|
+
</View>
|
|
112
|
+
)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const styles = StyleSheet.create({
|
|
116
|
+
wrapper: {
|
|
117
|
+
position: 'absolute',
|
|
118
|
+
left: 0,
|
|
119
|
+
right: 0,
|
|
120
|
+
bottom: 0,
|
|
121
|
+
zIndex: 40,
|
|
122
|
+
alignItems: 'center',
|
|
123
|
+
paddingHorizontal: spacing.lg
|
|
124
|
+
},
|
|
125
|
+
card: {
|
|
126
|
+
width: '100%',
|
|
127
|
+
maxWidth: 380,
|
|
128
|
+
borderRadius: radii.xl,
|
|
129
|
+
borderWidth: 2,
|
|
130
|
+
overflow: 'hidden',
|
|
131
|
+
shadowColor: '#000',
|
|
132
|
+
shadowOffset: { width: 0, height: 8 },
|
|
133
|
+
shadowOpacity: 0.3,
|
|
134
|
+
shadowRadius: 24,
|
|
135
|
+
elevation: 12
|
|
136
|
+
},
|
|
137
|
+
closeButton: {
|
|
138
|
+
position: 'absolute',
|
|
139
|
+
top: spacing.sm,
|
|
140
|
+
right: spacing.sm,
|
|
141
|
+
zIndex: 1,
|
|
142
|
+
width: 32,
|
|
143
|
+
height: 32,
|
|
144
|
+
alignItems: 'center',
|
|
145
|
+
justifyContent: 'center'
|
|
146
|
+
},
|
|
147
|
+
body: { padding: spacing.lg, paddingTop: spacing.lg, gap: spacing.sm, alignItems: 'center' },
|
|
148
|
+
heroIcon: {
|
|
149
|
+
width: 44,
|
|
150
|
+
height: 44,
|
|
151
|
+
borderRadius: 22,
|
|
152
|
+
alignItems: 'center',
|
|
153
|
+
justifyContent: 'center',
|
|
154
|
+
marginBottom: spacing.xs
|
|
155
|
+
},
|
|
156
|
+
h1: { ...typography.headline, textAlign: 'center' },
|
|
157
|
+
p: { ...typography.footnote, textAlign: 'center', marginBottom: spacing.xs },
|
|
158
|
+
primary: {
|
|
159
|
+
width: '100%',
|
|
160
|
+
flexDirection: 'row',
|
|
161
|
+
alignItems: 'center',
|
|
162
|
+
justifyContent: 'center',
|
|
163
|
+
borderRadius: radii.md,
|
|
164
|
+
paddingVertical: spacing.md
|
|
165
|
+
},
|
|
166
|
+
primaryLabel: { ...typography.subhead, fontWeight: '600' },
|
|
167
|
+
btnIcon: { marginRight: spacing.sm }
|
|
168
|
+
})
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import React, { useCallback, useEffect } from 'react'
|
|
2
|
+
import { View, Text, StyleSheet } from 'react-native'
|
|
3
|
+
import { useTheme, useWallet } from '@bsv/expo-wallet-toolbox'
|
|
4
|
+
import AmountDisplay from './AmountDisplay'
|
|
5
|
+
import AppLogo from '../ui/AppLogo'
|
|
6
|
+
import { sdk } from '@bsv/wallet-toolbox-mobile'
|
|
7
|
+
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
8
|
+
|
|
9
|
+
const BALANCE_CACHE_KEY = 'cached_wallet_balance'
|
|
10
|
+
const BALANCE_CACHE_TIMESTAMP_KEY = 'cached_wallet_balance_timestamp'
|
|
11
|
+
const CACHE_DURATION = 30000 // 30 seconds
|
|
12
|
+
|
|
13
|
+
export default function Balance() {
|
|
14
|
+
const { colors } = useTheme()
|
|
15
|
+
const { managers, adminOriginator, txStatusVersion } = useWallet()
|
|
16
|
+
const [accountBalance, setAccountBalance] = React.useState<number | null>(null)
|
|
17
|
+
const [balanceLoading, setBalanceLoading] = React.useState(false)
|
|
18
|
+
// Read through a ref, not the state value: `accountBalance` in this callback's
|
|
19
|
+
// deps would give it a new identity on every fetch, re-running both effects
|
|
20
|
+
// below and firing a second, pointless fetch each time the figure changes.
|
|
21
|
+
const accountBalanceRef = React.useRef<number | null>(null)
|
|
22
|
+
accountBalanceRef.current = accountBalance
|
|
23
|
+
|
|
24
|
+
const refreshBalance = useCallback(async () => {
|
|
25
|
+
try {
|
|
26
|
+
|
|
27
|
+
if (!managers.permissionsManager) {
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Only show loading if we don't have cached data
|
|
32
|
+
if (accountBalanceRef.current === null) {
|
|
33
|
+
setBalanceLoading(true)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Fetch the first page
|
|
37
|
+
const { totalOutputs } = await managers.permissionsManager.listOutputs(
|
|
38
|
+
{ basket: sdk.specOpWalletBalance },
|
|
39
|
+
adminOriginator
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
const total = totalOutputs ?? 0
|
|
43
|
+
setAccountBalance(total)
|
|
44
|
+
|
|
45
|
+
// Cache the new balance
|
|
46
|
+
await Promise.all([
|
|
47
|
+
AsyncStorage.setItem(BALANCE_CACHE_KEY, String(total)),
|
|
48
|
+
AsyncStorage.setItem(BALANCE_CACHE_TIMESTAMP_KEY, String(Date.now()))
|
|
49
|
+
])
|
|
50
|
+
|
|
51
|
+
setBalanceLoading(false)
|
|
52
|
+
} catch (e) {
|
|
53
|
+
console.error('Error refreshing balance:', e)
|
|
54
|
+
setBalanceLoading(false)
|
|
55
|
+
}
|
|
56
|
+
}, [managers, adminOriginator])
|
|
57
|
+
|
|
58
|
+
// Load cached balance immediately on mount
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
let mounted = true
|
|
61
|
+
|
|
62
|
+
const loadCachedBalance = async () => {
|
|
63
|
+
try {
|
|
64
|
+
const [cachedBalance, cachedTimestamp] = await Promise.all([
|
|
65
|
+
AsyncStorage.getItem(BALANCE_CACHE_KEY),
|
|
66
|
+
AsyncStorage.getItem(BALANCE_CACHE_TIMESTAMP_KEY)
|
|
67
|
+
])
|
|
68
|
+
|
|
69
|
+
if (mounted && cachedBalance !== null) {
|
|
70
|
+
const balance = Number(cachedBalance)
|
|
71
|
+
const timestamp = Number(cachedTimestamp)
|
|
72
|
+
const isRecent = timestamp && Date.now() - timestamp < CACHE_DURATION
|
|
73
|
+
|
|
74
|
+
setAccountBalance(balance)
|
|
75
|
+
|
|
76
|
+
// If cache is old, fetch fresh data
|
|
77
|
+
if (!isRecent) {
|
|
78
|
+
refreshBalance()
|
|
79
|
+
}
|
|
80
|
+
} else if (mounted) {
|
|
81
|
+
// No cache, fetch fresh data
|
|
82
|
+
refreshBalance()
|
|
83
|
+
}
|
|
84
|
+
} catch (error) {
|
|
85
|
+
console.error('Error loading cached balance:', error)
|
|
86
|
+
if (mounted) refreshBalance()
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
loadCachedBalance()
|
|
91
|
+
return () => {
|
|
92
|
+
mounted = false
|
|
93
|
+
}
|
|
94
|
+
}, [refreshBalance])
|
|
95
|
+
|
|
96
|
+
// Refresh balance when SSE reports a transaction status change
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
if (txStatusVersion > 0) {
|
|
99
|
+
refreshBalance()
|
|
100
|
+
}
|
|
101
|
+
}, [txStatusVersion, refreshBalance])
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<View style={[componentStyles.container, { backgroundColor: colors.paperBackground }]}>
|
|
105
|
+
<Text style={[componentStyles.sectionTitle, { color: colors.textPrimary }]}>you have</Text>
|
|
106
|
+
{accountBalance === null && balanceLoading ? (
|
|
107
|
+
<View style={componentStyles.loadingContainer}>
|
|
108
|
+
<AppLogo size={50} rotate />
|
|
109
|
+
</View>
|
|
110
|
+
) : (
|
|
111
|
+
<Text onPress={refreshBalance} style={[componentStyles.balance, { color: colors.textPrimary }]}>
|
|
112
|
+
<AmountDisplay abbreviate>{accountBalance ?? 0}</AmountDisplay>
|
|
113
|
+
<Text style={[componentStyles.cacheIndicator, { color: colors.textSecondary }]}></Text>
|
|
114
|
+
</Text>
|
|
115
|
+
)}
|
|
116
|
+
</View>
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const componentStyles = StyleSheet.create({
|
|
121
|
+
container: {
|
|
122
|
+
padding: 16,
|
|
123
|
+
borderRadius: 12
|
|
124
|
+
},
|
|
125
|
+
loadingContainer: {
|
|
126
|
+
alignItems: 'center',
|
|
127
|
+
justifyContent: 'center'
|
|
128
|
+
},
|
|
129
|
+
sectionTitle: {
|
|
130
|
+
fontSize: 18,
|
|
131
|
+
fontWeight: '600',
|
|
132
|
+
marginBottom: 16,
|
|
133
|
+
textAlign: 'center'
|
|
134
|
+
},
|
|
135
|
+
balance: {
|
|
136
|
+
fontSize: 30,
|
|
137
|
+
fontWeight: 'bold',
|
|
138
|
+
textAlign: 'center'
|
|
139
|
+
},
|
|
140
|
+
cacheIndicator: {
|
|
141
|
+
fontSize: 16,
|
|
142
|
+
fontWeight: 'normal'
|
|
143
|
+
}
|
|
144
|
+
})
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One-time consent gate shown the first time the user taps Pay or Get Paid
|
|
3
|
+
* with no wallet yet created. Apple HIG: never surface a Face ID/Touch ID
|
|
4
|
+
* prompt before the user has done something that explains why it's
|
|
5
|
+
* happening. Wallet creation needs biometric-gated storage, so instead of
|
|
6
|
+
* building the wallet eagerly on first launch (which put a biometric prompt
|
|
7
|
+
* in front of a user who hadn't tapped anything), creation is deferred to
|
|
8
|
+
* this moment and this modal explains the prompt before it fires.
|
|
9
|
+
*
|
|
10
|
+
* Blocking by design (unlike the non-blocking BackupReminderSheet): this is
|
|
11
|
+
* a single explicit decision point, not a recurring nag, and the user is
|
|
12
|
+
* already mid-action (about to pay or receive) so a brief pause here reads
|
|
13
|
+
* as consent, not interruption.
|
|
14
|
+
*/
|
|
15
|
+
import React from 'react'
|
|
16
|
+
import { ActivityIndicator, Modal, Platform, Pressable, StyleSheet, Text, View } from 'react-native'
|
|
17
|
+
import { useTheme, spacing, radii, typography, i18n } from '@bsv/expo-wallet-toolbox'
|
|
18
|
+
import PressableScale from '../ui/PressableScale'
|
|
19
|
+
|
|
20
|
+
const t = (k: string, o?: Record<string, unknown>) => i18n.t(k, o) as string
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @expo/vector-icons' index barrel re-exports every icon set, one of which
|
|
24
|
+
* reaches expo-font -> expo-asset -- untransformed ESM Jest cannot parse
|
|
25
|
+
* when eagerly pulled in via the `ui` package barrel. Loaded lazily, same
|
|
26
|
+
* pattern as this package's other native-module-boundary fixes.
|
|
27
|
+
*/
|
|
28
|
+
type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
|
|
29
|
+
let ioniconsComponent: IoniconsComponent | undefined
|
|
30
|
+
function loadIonicons(): IoniconsComponent {
|
|
31
|
+
if (!ioniconsComponent) {
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
33
|
+
ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
|
|
34
|
+
}
|
|
35
|
+
return ioniconsComponent
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const BiometricAdvisoryModal: React.FC<{
|
|
39
|
+
visible: boolean
|
|
40
|
+
/** Wallet creation (mnemonic generation + biometric-gated storage write) is
|
|
41
|
+
* running. The PBKDF2/BIP32 math alone is real, blocking JS-thread work —
|
|
42
|
+
* dismissing the modal the instant Continue is tapped left the screen
|
|
43
|
+
* looking frozen for that whole stretch, with nothing on screen explaining
|
|
44
|
+
* why. Keeping the modal up with a spinner in place of the label instead. */
|
|
45
|
+
loading?: boolean
|
|
46
|
+
onCancel: () => void
|
|
47
|
+
onContinue: () => void
|
|
48
|
+
}> = ({ visible, loading = false, onCancel, onContinue }) => {
|
|
49
|
+
const { colors } = useTheme()
|
|
50
|
+
const Ionicons = loadIonicons()
|
|
51
|
+
|
|
52
|
+
if (!visible) return null
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<Modal
|
|
56
|
+
transparent
|
|
57
|
+
visible
|
|
58
|
+
animationType="fade"
|
|
59
|
+
onRequestClose={loading ? undefined : onCancel}
|
|
60
|
+
statusBarTranslucent={Platform.OS === 'android'}
|
|
61
|
+
navigationBarTranslucent={Platform.OS === 'android'}
|
|
62
|
+
>
|
|
63
|
+
<View style={[styles.backdrop, { backgroundColor: colors.scrim }]}>
|
|
64
|
+
<Pressable
|
|
65
|
+
style={StyleSheet.absoluteFill}
|
|
66
|
+
onPress={loading ? undefined : onCancel}
|
|
67
|
+
accessible={true}
|
|
68
|
+
accessibilityRole="button"
|
|
69
|
+
accessibilityLabel="Close"
|
|
70
|
+
accessibilityHint="Dismisses this advisory"
|
|
71
|
+
/>
|
|
72
|
+
<View style={[styles.card, { backgroundColor: colors.sheetBackground, borderColor: colors.separator }]}>
|
|
73
|
+
<View style={[styles.heroIcon, { backgroundColor: colors.fillTertiary }]}>
|
|
74
|
+
<Ionicons name="finger-print" size={28} color={colors.accent} />
|
|
75
|
+
</View>
|
|
76
|
+
<Text style={[styles.title, { color: colors.textPrimary }]}>{t('biometric_advisory_title')}</Text>
|
|
77
|
+
<Text style={[styles.body, { color: colors.textSecondary }]}>{t('biometric_advisory_body')}</Text>
|
|
78
|
+
|
|
79
|
+
<PressableScale
|
|
80
|
+
haptic="confirm"
|
|
81
|
+
onPress={loading ? undefined : onContinue}
|
|
82
|
+
disabled={loading}
|
|
83
|
+
style={[styles.primary, { backgroundColor: colors.accent, opacity: loading ? 0.7 : 1 }]}
|
|
84
|
+
>
|
|
85
|
+
{loading ? (
|
|
86
|
+
<ActivityIndicator color={colors.textOnAccent} />
|
|
87
|
+
) : (
|
|
88
|
+
<Text style={[styles.primaryLabel, { color: colors.textOnAccent }]}>{t('continue')}</Text>
|
|
89
|
+
)}
|
|
90
|
+
</PressableScale>
|
|
91
|
+
|
|
92
|
+
<PressableScale haptic="tap" onPress={loading ? undefined : onCancel} disabled={loading} style={styles.secondary}>
|
|
93
|
+
<Text style={[styles.secondaryLabel, { color: loading ? colors.textTertiary : colors.textSecondary }]}>
|
|
94
|
+
{t('cancel')}
|
|
95
|
+
</Text>
|
|
96
|
+
</PressableScale>
|
|
97
|
+
</View>
|
|
98
|
+
</View>
|
|
99
|
+
</Modal>
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const styles = StyleSheet.create({
|
|
104
|
+
backdrop: { flex: 1, alignItems: 'center', justifyContent: 'center', paddingHorizontal: spacing.xl },
|
|
105
|
+
card: {
|
|
106
|
+
width: '100%',
|
|
107
|
+
maxWidth: 360,
|
|
108
|
+
borderRadius: radii.xl,
|
|
109
|
+
borderWidth: StyleSheet.hairlineWidth,
|
|
110
|
+
padding: spacing.xl,
|
|
111
|
+
alignItems: 'center',
|
|
112
|
+
gap: spacing.md
|
|
113
|
+
},
|
|
114
|
+
heroIcon: {
|
|
115
|
+
width: 56,
|
|
116
|
+
height: 56,
|
|
117
|
+
borderRadius: 28,
|
|
118
|
+
alignItems: 'center',
|
|
119
|
+
justifyContent: 'center',
|
|
120
|
+
marginBottom: spacing.xs
|
|
121
|
+
},
|
|
122
|
+
title: { ...typography.title2, textAlign: 'center' },
|
|
123
|
+
body: { ...typography.subhead, textAlign: 'center', marginBottom: spacing.sm },
|
|
124
|
+
primary: {
|
|
125
|
+
width: '100%',
|
|
126
|
+
borderRadius: radii.md,
|
|
127
|
+
paddingVertical: spacing.lg,
|
|
128
|
+
alignItems: 'center'
|
|
129
|
+
},
|
|
130
|
+
primaryLabel: { ...typography.headline },
|
|
131
|
+
secondary: { paddingVertical: spacing.sm, alignItems: 'center' },
|
|
132
|
+
secondaryLabel: { ...typography.body }
|
|
133
|
+
})
|