@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,354 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { StyleSheet, View } from 'react-native'
|
|
3
|
+
import Svg, { G, Path } from 'react-native-svg'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Isometric blueprint of a security key with a vault wheel on it, sat behind
|
|
7
|
+
* the setup screen's copy.
|
|
8
|
+
*
|
|
9
|
+
* Replaces the 80pt badge that used to sit above the headline: at that size the
|
|
10
|
+
* safe glyph read as a generic settings icon, so the screen's one chance to say
|
|
11
|
+
* what this feature is was spent on something the eye skipped.
|
|
12
|
+
*
|
|
13
|
+
* The subject is both halves of the idea in one object — the key you hold, and
|
|
14
|
+
* the vault it opens. A plain vault door was drawn first and said only half of
|
|
15
|
+
* it: the hardware requirement is the part a user needs to see before tapping
|
|
16
|
+
* "Set up vault".
|
|
17
|
+
*
|
|
18
|
+
* Geometry is real rather than faked. Every point is a 3D coordinate pushed
|
|
19
|
+
* through a true isometric projection, so circles come out as correctly-tilted
|
|
20
|
+
* ellipses, extrusions share one set of axes, and the vertical edges of each
|
|
21
|
+
* solid land on actual silhouette points. An earlier version skewed a flat
|
|
22
|
+
* drawing instead; the ellipses were wrong in a way that read as a smudged logo.
|
|
23
|
+
*
|
|
24
|
+
* The dashed scaffold is what makes it read as a technical drawing rather than
|
|
25
|
+
* an icon, and it deliberately runs off the edges: a drawing that fits entirely
|
|
26
|
+
* inside its box reads as a picture pasted on the background rather than as the
|
|
27
|
+
* background.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/* ---------------------------------------------------------------- projection */
|
|
31
|
+
|
|
32
|
+
const COS30 = Math.sqrt(3) / 2
|
|
33
|
+
const SIN30 = 0.5
|
|
34
|
+
|
|
35
|
+
interface P3 {
|
|
36
|
+
/** Across the key's width. */
|
|
37
|
+
x: number
|
|
38
|
+
/** Up. */
|
|
39
|
+
y: number
|
|
40
|
+
/** Along the key's length — +z runs toward the USB plug, screen lower-left. */
|
|
41
|
+
z: number
|
|
42
|
+
}
|
|
43
|
+
interface P2 {
|
|
44
|
+
x: number
|
|
45
|
+
y: number
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function iso(p: P3): P2 {
|
|
49
|
+
return { x: (p.x - p.z) * COS30, y: (p.x + p.z) * SIN30 - p.y }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const SEGMENTS = 64
|
|
53
|
+
|
|
54
|
+
/** Ring in the horizontal plane — every round feature here lies flat on the key. */
|
|
55
|
+
function ringY(atY: number, r: number, ox = 0, oz = 0): P3[] {
|
|
56
|
+
return Array.from({ length: SEGMENTS }, (_, i) => {
|
|
57
|
+
const a = (i / SEGMENTS) * Math.PI * 2
|
|
58
|
+
return { x: ox + r * Math.cos(a), y: atY, z: oz + r * Math.sin(a) }
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Rounded rectangle lying flat — the key's body, its contact pad, its plug. */
|
|
63
|
+
function roundedRectY(
|
|
64
|
+
atY: number,
|
|
65
|
+
x0: number,
|
|
66
|
+
x1: number,
|
|
67
|
+
z0: number,
|
|
68
|
+
z1: number,
|
|
69
|
+
r: number
|
|
70
|
+
): P3[] {
|
|
71
|
+
const STEP = 8
|
|
72
|
+
const corners: [number, number, number][] = [
|
|
73
|
+
[x1 - r, z1 - r, 0],
|
|
74
|
+
[x0 + r, z1 - r, 90],
|
|
75
|
+
[x0 + r, z0 + r, 180],
|
|
76
|
+
[x1 - r, z0 + r, 270]
|
|
77
|
+
]
|
|
78
|
+
return corners.flatMap(([cx, cz, from]) =>
|
|
79
|
+
Array.from({ length: STEP + 1 }, (_, i) => {
|
|
80
|
+
const a = ((from + (i / STEP) * 90) * Math.PI) / 180
|
|
81
|
+
return { x: cx + r * Math.cos(a), y: atY, z: cz + r * Math.sin(a) }
|
|
82
|
+
})
|
|
83
|
+
)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function path(points: P3[], close = true): string {
|
|
87
|
+
const d = points
|
|
88
|
+
.map((p, i) => {
|
|
89
|
+
const q = iso(p)
|
|
90
|
+
return `${i === 0 ? 'M' : 'L'}${q.x.toFixed(2)} ${q.y.toFixed(2)}`
|
|
91
|
+
})
|
|
92
|
+
.join(' ')
|
|
93
|
+
return close ? `${d} Z` : d
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function seg(a: P3, b: P3): string {
|
|
97
|
+
return path([a, b], false)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The corners a solid actually shows a vertical edge at: its left and right
|
|
102
|
+
* silhouette, plus the corner nearest the viewer. Picked from the projection
|
|
103
|
+
* rather than hard-coded, so they stay right if the shape moves.
|
|
104
|
+
*/
|
|
105
|
+
function verticalEdges(top: P3[]): P3[] {
|
|
106
|
+
let left = 0
|
|
107
|
+
let right = 0
|
|
108
|
+
let near = 0
|
|
109
|
+
top.forEach((p, i) => {
|
|
110
|
+
const q = iso(p)
|
|
111
|
+
if (q.x < iso(top[left]).x) left = i
|
|
112
|
+
if (q.x > iso(top[right]).x) right = i
|
|
113
|
+
if (q.y > iso(top[near]).y) near = i
|
|
114
|
+
})
|
|
115
|
+
return [top[left], top[right], top[near]]
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Top and bottom outlines plus the vertical edges between them. */
|
|
119
|
+
function prism(top: P3[], yBottom: number, edges = 3): string[] {
|
|
120
|
+
const bottom = top.map(p => ({ ...p, y: yBottom }))
|
|
121
|
+
return [
|
|
122
|
+
path(top),
|
|
123
|
+
path(bottom),
|
|
124
|
+
...verticalEdges(top)
|
|
125
|
+
.slice(0, edges)
|
|
126
|
+
.map(p => seg(p, { ...p, y: yBottom }))
|
|
127
|
+
]
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/* ------------------------------------------------------------------ geometry */
|
|
131
|
+
|
|
132
|
+
/** Key body: length along z, width along x, thickness in y. */
|
|
133
|
+
const T = 26
|
|
134
|
+
const BODY_X = 60
|
|
135
|
+
const BODY_Z_FAR = -168
|
|
136
|
+
const BODY_Z_USB = 148
|
|
137
|
+
|
|
138
|
+
/** USB-A plug, projecting past the body's near end. */
|
|
139
|
+
const PLUG_Z = 232
|
|
140
|
+
const PLUG_X = 32
|
|
141
|
+
const PLUG_Y0 = 5
|
|
142
|
+
const PLUG_Y1 = 21
|
|
143
|
+
|
|
144
|
+
/** Keyring hole, near the far end. */
|
|
145
|
+
const HOLE = { z: -118, r: 25, inner: 18 }
|
|
146
|
+
/** The gold touch contact, an inset panel on the top face. */
|
|
147
|
+
const PAD = { z0: 58, z1: 122, x: 38, r: 12 }
|
|
148
|
+
|
|
149
|
+
/** Vault wheel, mounted on the top face. */
|
|
150
|
+
const HUB_Z = -14
|
|
151
|
+
const R_FLANGE = 60
|
|
152
|
+
const R_DRUM = 50
|
|
153
|
+
const DRUM_H = 13
|
|
154
|
+
const R_BEZEL = 42
|
|
155
|
+
const R_TRACK = 33
|
|
156
|
+
const R_BOSS = 10
|
|
157
|
+
const SPOKES = Array.from({ length: 6 }, (_, i) => (i / 6) * Math.PI * 2)
|
|
158
|
+
/** Bolt lugs stand proud of the flange, one between each pair of spokes. */
|
|
159
|
+
const LUGS = Array.from({ length: 8 }, (_, i) => (i / 8) * Math.PI * 2 + Math.PI / 8)
|
|
160
|
+
/** A second, smaller dial offset on the drum face, as on the reference drawing. */
|
|
161
|
+
const DIAL = { x: -19, z: -34, r: 11 }
|
|
162
|
+
|
|
163
|
+
const TOP = T
|
|
164
|
+
const DRUM_TOP = TOP + DRUM_H
|
|
165
|
+
|
|
166
|
+
const bodyTop = roundedRectY(TOP, -BODY_X, BODY_X, BODY_Z_FAR, BODY_Z_USB, 46)
|
|
167
|
+
const plugTop = roundedRectY(PLUG_Y1, -PLUG_X, PLUG_X, BODY_Z_USB - 10, PLUG_Z, 4)
|
|
168
|
+
const padTop = roundedRectY(TOP + 0.5, -PAD.x, PAD.x, PAD.z0, PAD.z1, PAD.r)
|
|
169
|
+
const drumTop = ringY(DRUM_TOP, R_DRUM, 0, HUB_Z)
|
|
170
|
+
const bossTop = ringY(DRUM_TOP + 9, R_BOSS - 3, 0, HUB_Z)
|
|
171
|
+
|
|
172
|
+
function lug(angle: number): P3[] {
|
|
173
|
+
const spread = 0.14
|
|
174
|
+
const [r0, r1] = [R_FLANGE - 8, R_FLANGE + 9]
|
|
175
|
+
const corners: [number, number][] = [
|
|
176
|
+
[r0, angle - spread],
|
|
177
|
+
[r1, angle - spread],
|
|
178
|
+
[r1, angle + spread],
|
|
179
|
+
[r0, angle + spread]
|
|
180
|
+
]
|
|
181
|
+
return corners.map(([r, a]) => ({
|
|
182
|
+
x: r * Math.cos(a),
|
|
183
|
+
y: TOP + 4,
|
|
184
|
+
z: HUB_Z + r * Math.sin(a)
|
|
185
|
+
}))
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/* --------------------------------------------------------------- view bounds */
|
|
189
|
+
|
|
190
|
+
/** Extremes of the dashed scaffold, so the viewBox frames drawing plus rails. */
|
|
191
|
+
const SCAFFOLD: P3[] = [
|
|
192
|
+
{ x: -190, y: 0, z: -290 },
|
|
193
|
+
{ x: 190, y: 0, z: 290 },
|
|
194
|
+
{ x: 0, y: 120, z: HUB_Z },
|
|
195
|
+
{ x: 0, y: -70, z: HUB_Z }
|
|
196
|
+
]
|
|
197
|
+
|
|
198
|
+
const BOUNDS = [...bodyTop, ...plugTop, ...SCAFFOLD].map(iso).reduce(
|
|
199
|
+
(acc, q) => ({
|
|
200
|
+
minX: Math.min(acc.minX, q.x),
|
|
201
|
+
maxX: Math.max(acc.maxX, q.x),
|
|
202
|
+
minY: Math.min(acc.minY, q.y),
|
|
203
|
+
maxY: Math.max(acc.maxY, q.y)
|
|
204
|
+
}),
|
|
205
|
+
{ minX: Infinity, maxX: -Infinity, minY: Infinity, maxY: -Infinity }
|
|
206
|
+
)
|
|
207
|
+
const ZOOM = 0.9
|
|
208
|
+
const MID_X = (BOUNDS.minX + BOUNDS.maxX) / 2
|
|
209
|
+
const MID_Y = (BOUNDS.minY + BOUNDS.maxY) / 2
|
|
210
|
+
const VIEW_W = (BOUNDS.maxX - BOUNDS.minX) * ZOOM
|
|
211
|
+
const VIEW_H = (BOUNDS.maxY - BOUNDS.minY) * ZOOM
|
|
212
|
+
const VIEW_BOX = [MID_X - VIEW_W / 2, MID_Y - VIEW_H / 2, VIEW_W, VIEW_H].map(n => n.toFixed(1)).join(' ')
|
|
213
|
+
|
|
214
|
+
/* --------------------------------------------------------------- components */
|
|
215
|
+
|
|
216
|
+
interface VaultBackdropProps {
|
|
217
|
+
/** Stroke colour — pass the theme's primary text colour so it inverts with the theme. */
|
|
218
|
+
color: string
|
|
219
|
+
/** Hairline wash; the copy below it has to stay the loudest thing on screen. */
|
|
220
|
+
opacity?: number
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export function VaultBackdrop({ color, opacity = 0.3 }: VaultBackdropProps) {
|
|
224
|
+
const solid = {
|
|
225
|
+
stroke: color,
|
|
226
|
+
strokeWidth: 1.1,
|
|
227
|
+
fill: 'none' as const,
|
|
228
|
+
strokeLinecap: 'round' as const,
|
|
229
|
+
strokeLinejoin: 'round' as const
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return (
|
|
233
|
+
<View pointerEvents="none" style={StyleSheet.absoluteFill}>
|
|
234
|
+
<Svg width="100%" height="100%" viewBox={VIEW_BOX} preserveAspectRatio="xMidYMid meet">
|
|
235
|
+
{/* ── Construction scaffold ── */}
|
|
236
|
+
<G {...solid} strokeWidth={0.8} strokeDasharray="7 8" opacity={opacity * 0.5}>
|
|
237
|
+
{/* Centrelines through the wheel: along the key, across it, and up */}
|
|
238
|
+
<Path d={seg({ x: 0, y: TOP, z: -290 }, { x: 0, y: TOP, z: 290 })} />
|
|
239
|
+
<Path d={seg({ x: -190, y: TOP, z: HUB_Z }, { x: 190, y: TOP, z: HUB_Z })} />
|
|
240
|
+
<Path d={seg({ x: 0, y: -70, z: HUB_Z }, { x: 0, y: 120, z: HUB_Z })} />
|
|
241
|
+
{/* and through the keyring hole */}
|
|
242
|
+
<Path d={seg({ x: 0, y: -60, z: HOLE.z }, { x: 0, y: 96, z: HOLE.z })} />
|
|
243
|
+
<Path d={seg({ x: -150, y: TOP, z: HOLE.z }, { x: 150, y: TOP, z: HOLE.z })} />
|
|
244
|
+
{/* Rails offset off each long edge, the way a drawing carries its
|
|
245
|
+
dimensions out past the part */}
|
|
246
|
+
{[-112, 112].map(x => (
|
|
247
|
+
<Path key={`rail${x}`} d={seg({ x, y: 0, z: -270 }, { x, y: 0, z: 270 })} />
|
|
248
|
+
))}
|
|
249
|
+
{/* Cross-rails past each end */}
|
|
250
|
+
{[BODY_Z_FAR - 64, PLUG_Z + 42].map(z => (
|
|
251
|
+
<Path key={`cross${z}`} d={seg({ x: -170, y: 0, z }, { x: 170, y: 0, z })} />
|
|
252
|
+
))}
|
|
253
|
+
</G>
|
|
254
|
+
|
|
255
|
+
{/* ── Key body ── */}
|
|
256
|
+
<G {...solid} opacity={opacity}>
|
|
257
|
+
{prism(bodyTop, 0).map((d, i) => (
|
|
258
|
+
<Path key={`body${i}`} d={d} />
|
|
259
|
+
))}
|
|
260
|
+
|
|
261
|
+
{/* USB-A plug, and the tongue inside its mouth */}
|
|
262
|
+
{prism(plugTop, PLUG_Y0).map((d, i) => (
|
|
263
|
+
<Path key={`plug${i}`} d={d} />
|
|
264
|
+
))}
|
|
265
|
+
<Path
|
|
266
|
+
d={path([
|
|
267
|
+
{ x: -PLUG_X, y: PLUG_Y0, z: PLUG_Z },
|
|
268
|
+
{ x: -PLUG_X, y: PLUG_Y1, z: PLUG_Z },
|
|
269
|
+
{ x: PLUG_X, y: PLUG_Y1, z: PLUG_Z },
|
|
270
|
+
{ x: PLUG_X, y: PLUG_Y0, z: PLUG_Z }
|
|
271
|
+
])}
|
|
272
|
+
/>
|
|
273
|
+
<Path
|
|
274
|
+
d={path([
|
|
275
|
+
{ x: -PLUG_X + 7, y: PLUG_Y0 + 4, z: PLUG_Z - 1 },
|
|
276
|
+
{ x: -PLUG_X + 7, y: PLUG_Y1 - 4, z: PLUG_Z - 1 },
|
|
277
|
+
{ x: PLUG_X - 7, y: PLUG_Y1 - 4, z: PLUG_Z - 1 },
|
|
278
|
+
{ x: PLUG_X - 7, y: PLUG_Y0 + 4, z: PLUG_Z - 1 }
|
|
279
|
+
])}
|
|
280
|
+
/>
|
|
281
|
+
|
|
282
|
+
{/* Touch contact panel */}
|
|
283
|
+
<Path d={path(padTop)} />
|
|
284
|
+
|
|
285
|
+
{/* Keyring hole: rim on the top face, wall down to the underside */}
|
|
286
|
+
<Path d={path(ringY(TOP, HOLE.r, 0, HOLE.z))} />
|
|
287
|
+
<Path d={path(ringY(TOP, HOLE.inner, 0, HOLE.z))} />
|
|
288
|
+
<Path d={path(ringY(2, HOLE.inner, 0, HOLE.z))} />
|
|
289
|
+
</G>
|
|
290
|
+
|
|
291
|
+
{/* ── Vault wheel ── */}
|
|
292
|
+
<G {...solid} opacity={opacity}>
|
|
293
|
+
{/* Flange plate the drum stands on, with its bolt lugs */}
|
|
294
|
+
<Path d={path(ringY(TOP, R_FLANGE, 0, HUB_Z))} />
|
|
295
|
+
{LUGS.map((a, i) => (
|
|
296
|
+
<G key={`lug${i}`}>
|
|
297
|
+
{prism(lug(a), TOP, 2).map((d, j) => (
|
|
298
|
+
<Path key={`l${i}-${j}`} d={d} />
|
|
299
|
+
))}
|
|
300
|
+
</G>
|
|
301
|
+
))}
|
|
302
|
+
|
|
303
|
+
{/* Drum: top and bottom rings joined at their silhouette */}
|
|
304
|
+
<Path d={path(ringY(TOP, R_DRUM, 0, HUB_Z))} />
|
|
305
|
+
<Path d={path(drumTop)} />
|
|
306
|
+
{verticalEdges(drumTop)
|
|
307
|
+
.slice(0, 2)
|
|
308
|
+
.map((p, i) => (
|
|
309
|
+
<Path key={`drum${i}`} d={seg(p, { ...p, y: TOP })} />
|
|
310
|
+
))}
|
|
311
|
+
|
|
312
|
+
{/* Face rings */}
|
|
313
|
+
<Path d={path(ringY(DRUM_TOP, R_BEZEL, 0, HUB_Z))} />
|
|
314
|
+
<Path d={path(ringY(DRUM_TOP, R_TRACK, 0, HUB_Z))} />
|
|
315
|
+
|
|
316
|
+
{/* Handle spokes with their grips */}
|
|
317
|
+
{SPOKES.map((a, i) => {
|
|
318
|
+
const inner: P3 = {
|
|
319
|
+
x: R_BOSS * Math.cos(a),
|
|
320
|
+
y: DRUM_TOP + 4,
|
|
321
|
+
z: HUB_Z + R_BOSS * Math.sin(a)
|
|
322
|
+
}
|
|
323
|
+
const outer: P3 = {
|
|
324
|
+
x: (R_TRACK - 3) * Math.cos(a),
|
|
325
|
+
y: DRUM_TOP + 4,
|
|
326
|
+
z: HUB_Z + (R_TRACK - 3) * Math.sin(a)
|
|
327
|
+
}
|
|
328
|
+
return (
|
|
329
|
+
<G key={`spoke${i}`}>
|
|
330
|
+
<Path d={seg(inner, outer)} />
|
|
331
|
+
<Path d={path(ringY(DRUM_TOP + 4, 4.5, outer.x, outer.z))} />
|
|
332
|
+
</G>
|
|
333
|
+
)
|
|
334
|
+
})}
|
|
335
|
+
|
|
336
|
+
{/* Boss at the centre of the wheel */}
|
|
337
|
+
<Path d={path(ringY(DRUM_TOP + 4, R_BOSS, 0, HUB_Z))} />
|
|
338
|
+
<Path d={path(bossTop)} />
|
|
339
|
+
{verticalEdges(bossTop)
|
|
340
|
+
.slice(0, 2)
|
|
341
|
+
.map((p, i) => (
|
|
342
|
+
<Path key={`boss${i}`} d={seg(p, { ...p, y: DRUM_TOP + 4 })} />
|
|
343
|
+
))}
|
|
344
|
+
|
|
345
|
+
{/* Secondary dial, offset on the drum face */}
|
|
346
|
+
<Path d={path(ringY(DRUM_TOP, DIAL.r, DIAL.x, HUB_Z + DIAL.z))} />
|
|
347
|
+
<Path d={path(ringY(DRUM_TOP + 4, DIAL.r - 4, DIAL.x, HUB_Z + DIAL.z))} />
|
|
348
|
+
</G>
|
|
349
|
+
</Svg>
|
|
350
|
+
</View>
|
|
351
|
+
)
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
export default VaultBackdrop
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The vault ceremony sheet — the one place the user is told what to do with the
|
|
3
|
+
* YubiKey and why. Globally mounted (beside PermissionSheet); driven by
|
|
4
|
+
* VaultContext, which mirrors the ceremony singleton.
|
|
5
|
+
*
|
|
6
|
+
* Every phase says three things: WHY (the reason string / transfer summary),
|
|
7
|
+
* WHAT to do now (the phase copy + illustration), and how long is left
|
|
8
|
+
* (countdown on awaiting-touch and armed). Motion is scale/opacity of the
|
|
9
|
+
* sheet's own subviews only — never a fractional-opacity animation over glass
|
|
10
|
+
* (the UIVisualEffectView freeze guardrail).
|
|
11
|
+
*/
|
|
12
|
+
import React, { useEffect, useRef, useState } from 'react'
|
|
13
|
+
import { View, Text, StyleSheet, TextInput, ActivityIndicator, Platform } from 'react-native'
|
|
14
|
+
import Animated, {
|
|
15
|
+
useSharedValue,
|
|
16
|
+
useAnimatedStyle,
|
|
17
|
+
withRepeat,
|
|
18
|
+
withTiming,
|
|
19
|
+
withSequence,
|
|
20
|
+
cancelAnimation,
|
|
21
|
+
useReducedMotion,
|
|
22
|
+
Easing
|
|
23
|
+
} from 'react-native-reanimated'
|
|
24
|
+
import Sheet from '../ui/Sheet'
|
|
25
|
+
import PressableScale from '../ui/PressableScale'
|
|
26
|
+
import {
|
|
27
|
+
useTheme,
|
|
28
|
+
spacing,
|
|
29
|
+
radii,
|
|
30
|
+
typography,
|
|
31
|
+
useVault,
|
|
32
|
+
haptics,
|
|
33
|
+
i18n,
|
|
34
|
+
type CeremonyPhase,
|
|
35
|
+
type VaultErrorCode
|
|
36
|
+
} from '@bsv/expo-wallet-toolbox'
|
|
37
|
+
|
|
38
|
+
const t = (k: string, opts?: Record<string, unknown>) => i18n.t(k, opts) as string
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @expo/vector-icons' index barrel re-exports every icon set (AntDesign,
|
|
42
|
+
* etc.), one of which reaches expo-font -> expo-asset -- untransformed ESM
|
|
43
|
+
* that Jest cannot parse when eagerly pulled in via the `ui` package barrel.
|
|
44
|
+
* Ionicons is loaded lazily, only when actually rendering, same pattern as
|
|
45
|
+
* this package's other native-module-boundary fixes (expo-router, expo-blur).
|
|
46
|
+
*/
|
|
47
|
+
type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
|
|
48
|
+
let ioniconsComponent: IoniconsComponent | undefined
|
|
49
|
+
function loadIonicons(): IoniconsComponent {
|
|
50
|
+
if (!ioniconsComponent) {
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
52
|
+
ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
|
|
53
|
+
}
|
|
54
|
+
return ioniconsComponent
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const ERROR_COPY: Record<string, string> = {
|
|
58
|
+
'serial-mismatch': 'vault_err_wrong_key',
|
|
59
|
+
'wrong-key': 'vault_err_wrong_key',
|
|
60
|
+
'touch-timeout': 'vault_err_touch_timeout',
|
|
61
|
+
'pin-locked': 'vault_err_pin_locked',
|
|
62
|
+
'pin-invalid': 'vault_err_pin_invalid',
|
|
63
|
+
'key-removed-mid-op': 'vault_err_removed',
|
|
64
|
+
'no-key': 'vault_err_no_key',
|
|
65
|
+
'driver-unavailable': 'vault_err_unavailable',
|
|
66
|
+
'not-enrolled': 'vault_err_unavailable',
|
|
67
|
+
'mgmt-key-custom': 'vault_err_mgmt_key',
|
|
68
|
+
'user-cancelled': 'vault_err_generic',
|
|
69
|
+
'unsupported-platform': 'vault_err_unavailable',
|
|
70
|
+
'slot-occupied': 'vault_err_generic',
|
|
71
|
+
'pin-required': 'vault_enter_pin',
|
|
72
|
+
'nfc-lost': 'vault_err_nfc_lost'
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Errors where the fix is simply "do the tap again" — worth a Retry button
|
|
76
|
+
* instead of only Dismiss. Must stay a SUBSET of `CeremonyController`'s own
|
|
77
|
+
* retryable set (services/vault/ceremony.ts) or the button renders but does
|
|
78
|
+
* nothing — 'key-removed-mid-op' is deliberately excluded even though the
|
|
79
|
+
* ceremony loop can produce it, because it can ALSO arrive from a moment the
|
|
80
|
+
* loop doesn't cover (waiting-for-key), where retry would be a dead button. */
|
|
81
|
+
const RETRYABLE_ERRORS = new Set<string>(['touch-timeout', 'nfc-lost'])
|
|
82
|
+
|
|
83
|
+
/** Swallows the sheet's dismiss while work is in flight — `Sheet` requires an
|
|
84
|
+
* onClose, and cancelling mid-operation is the thing we are preventing. */
|
|
85
|
+
const noop = (): void => {}
|
|
86
|
+
|
|
87
|
+
const PhaseIcon: Record<CeremonyPhase, keyof IoniconsComponent['glyphMap']> = {
|
|
88
|
+
idle: 'lock-closed',
|
|
89
|
+
'waiting-for-key': 'hardware-chip-outline',
|
|
90
|
+
connecting: 'sync-outline',
|
|
91
|
+
'pin-entry': 'keypad-outline',
|
|
92
|
+
'awaiting-touch': 'finger-print-outline',
|
|
93
|
+
preparing: 'lock-open-outline',
|
|
94
|
+
broadcasting: 'paper-plane-outline',
|
|
95
|
+
armed: 'lock-open',
|
|
96
|
+
error: 'alert-circle-outline'
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export const VaultCeremonySheet: React.FC = () => {
|
|
100
|
+
const { colors } = useTheme()
|
|
101
|
+
const { state, submitPin, cancel, retry } = useVault()
|
|
102
|
+
const reducedMotion = useReducedMotion()
|
|
103
|
+
const [pin, setPin] = useState('')
|
|
104
|
+
const Ionicons = loadIonicons()
|
|
105
|
+
|
|
106
|
+
const phase = state.phase
|
|
107
|
+
// 'armed' stays hidden: it persists for the whole retention window, so
|
|
108
|
+
// showing it would leave the sheet up for minutes after a transfer is done
|
|
109
|
+
// — deposit and withdrawal both arm the same way and are treated alike here.
|
|
110
|
+
const visible = phase !== 'idle' && phase !== 'armed'
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Work is under way and there is nothing for the user to do but wait.
|
|
114
|
+
*
|
|
115
|
+
* The sheet is deliberately NOT dismissable here. A backdrop tap runs
|
|
116
|
+
* cancel(), which mid-operation is the abandonment this progress display
|
|
117
|
+
* exists to prevent — and a cancelled withdrawal can leave the vault UTXO
|
|
118
|
+
* reserved. Cancel stays available while we are waiting on the user
|
|
119
|
+
* (waiting-for-key, pin-entry).
|
|
120
|
+
*/
|
|
121
|
+
const busy = phase === 'preparing' || phase === 'broadcasting'
|
|
122
|
+
|
|
123
|
+
// Pulse the icon while waiting for the user to act (insert / touch).
|
|
124
|
+
const pulse = useSharedValue(1)
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
const active =
|
|
127
|
+
phase === 'waiting-for-key' ||
|
|
128
|
+
phase === 'awaiting-touch' ||
|
|
129
|
+
phase === 'preparing' ||
|
|
130
|
+
phase === 'broadcasting'
|
|
131
|
+
if (active && !reducedMotion) {
|
|
132
|
+
pulse.value = withRepeat(
|
|
133
|
+
withSequence(
|
|
134
|
+
withTiming(1.12, { duration: 700, easing: Easing.inOut(Easing.quad) }),
|
|
135
|
+
withTiming(1, { duration: 700, easing: Easing.inOut(Easing.quad) })
|
|
136
|
+
),
|
|
137
|
+
-1,
|
|
138
|
+
false
|
|
139
|
+
)
|
|
140
|
+
} else {
|
|
141
|
+
cancelAnimation(pulse)
|
|
142
|
+
pulse.value = withTiming(1, { duration: 150 })
|
|
143
|
+
}
|
|
144
|
+
return () => cancelAnimation(pulse)
|
|
145
|
+
}, [phase, reducedMotion, pulse])
|
|
146
|
+
const pulseStyle = useAnimatedStyle(() => ({ transform: [{ scale: pulse.value }] }))
|
|
147
|
+
|
|
148
|
+
// Reset the PIN field whenever we (re)enter pin-entry.
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
if (phase === 'pin-entry') setPin('')
|
|
151
|
+
}, [phase])
|
|
152
|
+
|
|
153
|
+
const reason = state.reason
|
|
154
|
+
const errCode = state.error?.code as VaultErrorCode | undefined
|
|
155
|
+
|
|
156
|
+
// iOS talks to the key over NFC (a tap), Android over USB (insert + touch).
|
|
157
|
+
const nfc = Platform.OS === 'ios'
|
|
158
|
+
|
|
159
|
+
const title = (() => {
|
|
160
|
+
switch (phase) {
|
|
161
|
+
case 'waiting-for-key':
|
|
162
|
+
return nfc ? t('vault_hold_key_nfc') : t('vault_insert_key')
|
|
163
|
+
case 'connecting':
|
|
164
|
+
return t('vault_reading_key')
|
|
165
|
+
case 'pin-entry':
|
|
166
|
+
return t('vault_enter_pin')
|
|
167
|
+
case 'awaiting-touch':
|
|
168
|
+
return nfc ? t('vault_keep_holding_nfc') : t('vault_touch_contact')
|
|
169
|
+
case 'preparing':
|
|
170
|
+
return t('vault_unlocking_funds')
|
|
171
|
+
case 'broadcasting':
|
|
172
|
+
return t('vault_sending_to_network')
|
|
173
|
+
case 'error':
|
|
174
|
+
return t((errCode && ERROR_COPY[errCode]) ?? 'vault_err_generic')
|
|
175
|
+
default:
|
|
176
|
+
return ''
|
|
177
|
+
}
|
|
178
|
+
})()
|
|
179
|
+
|
|
180
|
+
const iconColor = phase === 'error' ? colors.error : colors.accent
|
|
181
|
+
|
|
182
|
+
return (
|
|
183
|
+
<Sheet visible={visible} onClose={busy ? noop : cancel} title={t('vault_title')} fitContent>
|
|
184
|
+
<View style={styles.body}>
|
|
185
|
+
{reason ? <Text style={[styles.reason, { color: colors.textSecondary }]}>{reason}</Text> : null}
|
|
186
|
+
|
|
187
|
+
<Animated.View style={[styles.iconWrap, { backgroundColor: colors.backgroundSecondary }, pulseStyle]}>
|
|
188
|
+
{phase === 'connecting' || busy ? (
|
|
189
|
+
<ActivityIndicator color={iconColor} />
|
|
190
|
+
) : (
|
|
191
|
+
<Ionicons name={PhaseIcon[phase]} size={40} color={iconColor} />
|
|
192
|
+
)}
|
|
193
|
+
</Animated.View>
|
|
194
|
+
|
|
195
|
+
<Text style={[styles.title, { color: colors.textPrimary }]}>{title}</Text>
|
|
196
|
+
|
|
197
|
+
{/* The whole point of the busy phases: say the work is real and say
|
|
198
|
+
not to leave, so a wait for tx assembly or the network reads as
|
|
199
|
+
progress rather than a hang. */}
|
|
200
|
+
{busy && (
|
|
201
|
+
<Text style={[styles.subtitle, { color: colors.textSecondary }]}>
|
|
202
|
+
{phase === 'broadcasting' ? t('vault_sending_sub') : t('vault_unlocking_sub')}
|
|
203
|
+
</Text>
|
|
204
|
+
)}
|
|
205
|
+
|
|
206
|
+
{phase === 'awaiting-touch' && <TouchCountdown color={colors.accent} trackColor={colors.backgroundSecondary} />}
|
|
207
|
+
|
|
208
|
+
{phase === 'pin-entry' && (
|
|
209
|
+
<>
|
|
210
|
+
<Text style={[styles.subtitle, { color: colors.textSecondary }]}>
|
|
211
|
+
{nfc ? t('vault_pin_sub_nfc') : t('vault_pin_sub_usb')}
|
|
212
|
+
</Text>
|
|
213
|
+
<TextInput
|
|
214
|
+
style={[styles.pin, { color: colors.textPrimary, backgroundColor: colors.backgroundSecondary }]}
|
|
215
|
+
value={pin}
|
|
216
|
+
onChangeText={setPin}
|
|
217
|
+
placeholder="••••••"
|
|
218
|
+
placeholderTextColor={colors.textTertiary}
|
|
219
|
+
keyboardType="number-pad"
|
|
220
|
+
secureTextEntry
|
|
221
|
+
maxLength={8}
|
|
222
|
+
autoFocus
|
|
223
|
+
/>
|
|
224
|
+
{state.error?.code === 'pin-invalid' && typeof state.error.retriesLeft === 'number' && (
|
|
225
|
+
<Text style={[styles.hint, { color: colors.warning }]}>
|
|
226
|
+
{t('vault_pin_retries', { count: state.error.retriesLeft })}
|
|
227
|
+
</Text>
|
|
228
|
+
)}
|
|
229
|
+
<PressableScale
|
|
230
|
+
haptic="confirm"
|
|
231
|
+
onPress={() => {
|
|
232
|
+
if (pin.length >= 4) submitPin(pin)
|
|
233
|
+
}}
|
|
234
|
+
style={[styles.primaryBtn, { backgroundColor: colors.accent, opacity: pin.length >= 4 ? 1 : 0.4 }]}
|
|
235
|
+
>
|
|
236
|
+
<Text style={[styles.primaryLabel, { color: colors.textOnAccent }]}>{t('vault_unlock_cta')}</Text>
|
|
237
|
+
</PressableScale>
|
|
238
|
+
</>
|
|
239
|
+
)}
|
|
240
|
+
|
|
241
|
+
{phase === 'error' && errCode === 'pin-invalid' && (
|
|
242
|
+
<Text style={[styles.subtitle, { color: colors.textSecondary }]}>
|
|
243
|
+
{typeof state.error?.retriesLeft === 'number'
|
|
244
|
+
? t('vault_pin_invalid_retry', { count: state.error.retriesLeft })
|
|
245
|
+
: t('vault_pin_invalid_retry_generic')}
|
|
246
|
+
</Text>
|
|
247
|
+
)}
|
|
248
|
+
|
|
249
|
+
{phase === 'error' && (
|
|
250
|
+
<View style={styles.errorActions}>
|
|
251
|
+
{errCode && RETRYABLE_ERRORS.has(errCode) && (
|
|
252
|
+
<PressableScale
|
|
253
|
+
haptic="confirm"
|
|
254
|
+
onPress={retry}
|
|
255
|
+
style={[styles.primaryBtn, { backgroundColor: colors.accent }]}
|
|
256
|
+
>
|
|
257
|
+
<Text style={[styles.primaryLabel, { color: colors.textOnAccent }]}>{t('vault_retry')}</Text>
|
|
258
|
+
</PressableScale>
|
|
259
|
+
)}
|
|
260
|
+
<PressableScale onPress={cancel} style={styles.secondaryBtn}>
|
|
261
|
+
<Text style={[styles.secondaryLabel, { color: colors.textSecondary }]}>{t('vault_dismiss')}</Text>
|
|
262
|
+
</PressableScale>
|
|
263
|
+
</View>
|
|
264
|
+
)}
|
|
265
|
+
|
|
266
|
+
{(phase === 'waiting-for-key' || phase === 'awaiting-touch' || phase === 'connecting') && (
|
|
267
|
+
<PressableScale onPress={cancel} style={styles.secondaryBtn}>
|
|
268
|
+
<Text style={[styles.secondaryLabel, { color: colors.textSecondary }]}>{t('vault_cancel')}</Text>
|
|
269
|
+
</PressableScale>
|
|
270
|
+
)}
|
|
271
|
+
</View>
|
|
272
|
+
</Sheet>
|
|
273
|
+
)
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** 15-second ring that empties while the key waits for a touch. Purely a UI
|
|
277
|
+
* countdown — the native touch policy enforces the real timeout. */
|
|
278
|
+
const TouchCountdown: React.FC<{ color: string; trackColor: string }> = ({ color, trackColor }) => {
|
|
279
|
+
const reducedMotion = useReducedMotion()
|
|
280
|
+
const progress = useSharedValue(1)
|
|
281
|
+
const startedRef = useRef(false)
|
|
282
|
+
useEffect(() => {
|
|
283
|
+
if (startedRef.current) return
|
|
284
|
+
startedRef.current = true
|
|
285
|
+
if (reducedMotion) return
|
|
286
|
+
haptics.tap()
|
|
287
|
+
progress.value = withTiming(0, { duration: 15000, easing: Easing.linear })
|
|
288
|
+
return () => cancelAnimation(progress)
|
|
289
|
+
}, [progress, reducedMotion])
|
|
290
|
+
const style = useAnimatedStyle(() => ({ width: `${Math.max(0, progress.value) * 100}%` }))
|
|
291
|
+
return (
|
|
292
|
+
<View style={[styles.countdownTrack, { backgroundColor: trackColor }]}>
|
|
293
|
+
<Animated.View style={[styles.countdownFill, { backgroundColor: color }, style]} />
|
|
294
|
+
</View>
|
|
295
|
+
)
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const styles = StyleSheet.create({
|
|
299
|
+
body: { paddingHorizontal: spacing.xl, paddingBottom: spacing.xxl, alignItems: 'center', gap: spacing.lg },
|
|
300
|
+
reason: { ...typography.subhead, textAlign: 'center' },
|
|
301
|
+
iconWrap: {
|
|
302
|
+
width: 88,
|
|
303
|
+
height: 88,
|
|
304
|
+
borderRadius: 44,
|
|
305
|
+
alignItems: 'center',
|
|
306
|
+
justifyContent: 'center',
|
|
307
|
+
marginTop: spacing.md
|
|
308
|
+
},
|
|
309
|
+
title: { ...typography.title3, textAlign: 'center' },
|
|
310
|
+
subtitle: { ...typography.subhead, textAlign: 'center', marginTop: -spacing.sm },
|
|
311
|
+
pin: {
|
|
312
|
+
width: '70%',
|
|
313
|
+
textAlign: 'center',
|
|
314
|
+
...typography.title2,
|
|
315
|
+
letterSpacing: 8,
|
|
316
|
+
borderRadius: radii.md,
|
|
317
|
+
paddingVertical: spacing.md
|
|
318
|
+
},
|
|
319
|
+
hint: { ...typography.footnote },
|
|
320
|
+
primaryBtn: { width: '100%', borderRadius: radii.md, paddingVertical: spacing.lg, alignItems: 'center' },
|
|
321
|
+
primaryLabel: { ...typography.headline },
|
|
322
|
+
secondaryBtn: { paddingVertical: spacing.md, alignItems: 'center' },
|
|
323
|
+
secondaryLabel: { ...typography.body },
|
|
324
|
+
errorActions: { width: '100%', gap: spacing.sm },
|
|
325
|
+
countdownTrack: { width: '80%', height: 6, borderRadius: 3, overflow: 'hidden' },
|
|
326
|
+
countdownFill: { height: '100%' }
|
|
327
|
+
})
|