@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.
Files changed (240) hide show
  1. package/LICENSE.txt +28 -0
  2. package/README.md +512 -0
  3. package/assets/sounds/payment-receive.wav +0 -0
  4. package/assets/sounds/payment-send.wav +0 -0
  5. package/assets/sounds/vault-close.wav +0 -0
  6. package/assets/sounds/vault-open.wav +0 -0
  7. package/core/amountFormatHelpers.ts +330 -0
  8. package/core/backup/RemoteSyncReader.ts +94 -0
  9. package/core/backup/client.ts +111 -0
  10. package/core/backup/codec.ts +218 -0
  11. package/core/backup/constants.ts +88 -0
  12. package/core/backup/cursor.ts +138 -0
  13. package/core/backup/derive.ts +46 -0
  14. package/core/backup/deviceId.ts +33 -0
  15. package/core/backup/erase.ts +67 -0
  16. package/core/backup/preference.ts +33 -0
  17. package/core/backup/push.ts +295 -0
  18. package/core/backup/restore.ts +152 -0
  19. package/core/backup/restoreOnImport.ts +119 -0
  20. package/core/backup/status.ts +46 -0
  21. package/core/config.tsx +47 -0
  22. package/core/constants.ts +35 -0
  23. package/core/context/ExchangeRateContext.tsx +69 -0
  24. package/core/context/LocalStorageProvider.tsx +225 -0
  25. package/core/context/UserContext.tsx +129 -0
  26. package/core/context/VaultContext.tsx +79 -0
  27. package/core/context/WalletConnectionContext.tsx +454 -0
  28. package/core/context/WalletContext.tsx +2938 -0
  29. package/core/context/buildGeneration.ts +37 -0
  30. package/core/deviceTier.ts +89 -0
  31. package/core/diskSpace.ts +62 -0
  32. package/core/displayCurrencies.ts +56 -0
  33. package/core/headers/OfflineFirstChaintracks.ts +176 -0
  34. package/core/headers/checkpoints.ts +39 -0
  35. package/core/headers/fs.ts +119 -0
  36. package/core/headers/headerStore.ts +333 -0
  37. package/core/headers/prewarm.ts +36 -0
  38. package/core/headers/syncHeaders.ts +73 -0
  39. package/core/hooks/useConfirmationSound.ts +135 -0
  40. package/core/hooks/useHaptics.ts +51 -0
  41. package/core/hooks/usePermissionQueue.ts +69 -0
  42. package/core/i18n/translations.tsx +6692 -0
  43. package/core/index.ts +295 -0
  44. package/core/localpay/blePermissions.ts +32 -0
  45. package/core/localpay/build.ts +392 -0
  46. package/core/localpay/codec.ts +338 -0
  47. package/core/localpay/deviceCaps.ts +175 -0
  48. package/core/localpay/nearbyAdvisory.ts +32 -0
  49. package/core/localpay/nearbyPermissions.ts +34 -0
  50. package/core/localpay/pending.ts +385 -0
  51. package/core/localpay/pendingAborts.ts +67 -0
  52. package/core/localpay/qr.ts +16 -0
  53. package/core/localpay/session.ts +277 -0
  54. package/core/localpay/sessionPolicy.ts +5 -0
  55. package/core/localpay/transport/awdl.ts +11 -0
  56. package/core/localpay/transport/ble.ts +159 -0
  57. package/core/localpay/transport/nearby.ts +12 -0
  58. package/core/localpay/transport/race.ts +110 -0
  59. package/core/localpay/transport/select.ts +128 -0
  60. package/core/localpay/transport/socket.ts +244 -0
  61. package/core/localpay/types.ts +82 -0
  62. package/core/localpay/verify.ts +204 -0
  63. package/core/logging.config.ts +10 -0
  64. package/core/logging.ts +77 -0
  65. package/core/mnemonicWallet.ts +180 -0
  66. package/core/monitor/TaskBackupPush.ts +168 -0
  67. package/core/monitor/TaskCreditInbox.ts +116 -0
  68. package/core/monitor/TaskDrainOutbox.ts +122 -0
  69. package/core/monitor/TaskSendOffline.ts +123 -0
  70. package/core/monitor/unfailRetry.ts +116 -0
  71. package/core/net/chainMatch.ts +34 -0
  72. package/core/net/online.ts +34 -0
  73. package/core/offline/cancelParked.ts +56 -0
  74. package/core/offline/hold.ts +127 -0
  75. package/core/offline/order.ts +109 -0
  76. package/core/offline/payerHold.ts +144 -0
  77. package/core/offline/plan.ts +264 -0
  78. package/core/offline/queueGrace.ts +52 -0
  79. package/core/parsePeerPayURI.ts +119 -0
  80. package/core/pay/beefRepair.ts +106 -0
  81. package/core/pay/creditErrors.ts +46 -0
  82. package/core/pay/creditInbox.ts +202 -0
  83. package/core/pay/damagedInbox.ts +64 -0
  84. package/core/pay/proofNudge.ts +23 -0
  85. package/core/pay/provenTxFromBump.ts +31 -0
  86. package/core/pay/rails/address.ts +329 -0
  87. package/core/pay/rails/handle.ts +617 -0
  88. package/core/pay/rails/index.ts +197 -0
  89. package/core/pay/rails/nearby.ts +79 -0
  90. package/core/pay/receiveFocus.ts +13 -0
  91. package/core/pay/recordProof.ts +91 -0
  92. package/core/pay/refreshProofGuard.ts +34 -0
  93. package/core/pay/sweeper.ts +75 -0
  94. package/core/pay/tokenAmount.ts +18 -0
  95. package/core/pay/userError.ts +18 -0
  96. package/core/pay/watchlist.ts +126 -0
  97. package/core/peerpay/control.ts +122 -0
  98. package/core/peerpay/handleResendRequests.ts +475 -0
  99. package/core/peerpay/inboxAttempts.ts +33 -0
  100. package/core/peerpay/metadataDecryptor.ts +42 -0
  101. package/core/peerpay/offlineNacks.ts +96 -0
  102. package/core/peerpay/outbox.ts +209 -0
  103. package/core/peerpay/rebuildToken.ts +76 -0
  104. package/core/peerpay/resendBeef.ts +115 -0
  105. package/core/services/arcadeBroadcastProvider.ts +214 -0
  106. package/core/services/capWalletArgs.ts +99 -0
  107. package/core/services/exchangeRate.ts +63 -0
  108. package/core/services/secrets/envelope.ts +102 -0
  109. package/core/services/secrets/hkdf.ts +37 -0
  110. package/core/services/secrets/index.ts +63 -0
  111. package/core/services/secrets/kek.ts +274 -0
  112. package/core/services/secrets/migration.ts +188 -0
  113. package/core/services/secrets/policy.ts +120 -0
  114. package/core/services/secrets/storage.ts +54 -0
  115. package/core/services/secrets/store.ts +125 -0
  116. package/core/services/secrets/types.ts +85 -0
  117. package/core/services/usdFxRates.ts +101 -0
  118. package/core/services/vault/VaultKeyService.ts +312 -0
  119. package/core/services/vault/backupAttestation.ts +136 -0
  120. package/core/services/vault/ceremony.ts +972 -0
  121. package/core/services/vault/ceremonyHost.ts +46 -0
  122. package/core/services/vault/devMock.ts +22 -0
  123. package/core/services/vault/driver.ts +197 -0
  124. package/core/services/vault/guard.ts +90 -0
  125. package/core/services/vault/k1.ts +75 -0
  126. package/core/services/vault/mockYubiKey.ts +217 -0
  127. package/core/services/vault/random.ts +20 -0
  128. package/core/services/vault/sealing.ts +84 -0
  129. package/core/services/vault/session.ts +59 -0
  130. package/core/services/vault/transfers.ts +1151 -0
  131. package/core/services/vault/types.ts +109 -0
  132. package/core/services/vault/vaultDerivation.ts +152 -0
  133. package/core/services/vault/vaultPassphrase.ts +287 -0
  134. package/core/services/vault/vaultStore.ts +104 -0
  135. package/core/services/walletArgLimits.ts +234 -0
  136. package/core/services/walletServiceConfig.ts +170 -0
  137. package/core/storage/LocalStorageAdapter.ts +58 -0
  138. package/core/storage/README.md +391 -0
  139. package/core/storage/StorageExpoSQLite.ts +2008 -0
  140. package/core/storage/errors.ts +73 -0
  141. package/core/storage/index.ts +3 -0
  142. package/core/storage/methods/findSql.ts +286 -0
  143. package/core/storage/methods/historyNotes.ts +61 -0
  144. package/core/storage/methods/listActionsSql.ts +212 -0
  145. package/core/storage/methods/listOutputsSql.ts +211 -0
  146. package/core/storage/methods/offlineActions.ts +156 -0
  147. package/core/storage/methods/processOfflineActions.ts +503 -0
  148. package/core/storage/methods/reclaim.ts +135 -0
  149. package/core/storage/methods/reviewStatusSql.ts +167 -0
  150. package/core/storage/methods/unprovenWithoutReqSql.ts +26 -0
  151. package/core/storage/methods/walletBalanceSql.ts +55 -0
  152. package/core/storage/schema/createTables.ts +385 -0
  153. package/core/storage/skipQueuedAncestors.ts +29 -0
  154. package/core/storage/sqlUpdateValue.ts +12 -0
  155. package/core/stores/ConnectionStore.ts +71 -0
  156. package/core/theme/ThemeContext.tsx +182 -0
  157. package/core/theme/assertThemeContrast.ts +109 -0
  158. package/core/theme/motion.ts +50 -0
  159. package/core/theme/tokens.ts +232 -0
  160. package/core/theme/useThemeStyles.tsx +156 -0
  161. package/core/walletDbRegistry.ts +110 -0
  162. package/core/walletMonitor.ts +149 -0
  163. package/core/walletRepair/runWalletCheck.ts +195 -0
  164. package/core/walletRepair/shouldReleaseUtxo.ts +18 -0
  165. package/package.json +86 -0
  166. package/ui/backupShares.ts +367 -0
  167. package/ui/components/QRScanner.tsx +353 -0
  168. package/ui/components/pay/AddressReceive.tsx +507 -0
  169. package/ui/components/pay/AvailableBalance.tsx +61 -0
  170. package/ui/components/pay/HandleReceive.tsx +896 -0
  171. package/ui/components/pay/MessageBoxConfig.tsx +256 -0
  172. package/ui/components/pay/NearbyAdvisoryModal.tsx +111 -0
  173. package/ui/components/pay/NearbyFlow.tsx +2542 -0
  174. package/ui/components/pay/OfflineNotice.tsx +337 -0
  175. package/ui/components/pay/PayCellRow.tsx +101 -0
  176. package/ui/components/pay/PayForm.tsx +223 -0
  177. package/ui/components/pay/PaymentQrDisplay.tsx +105 -0
  178. package/ui/components/pay/PaymentSuccessOverlay.tsx +266 -0
  179. package/ui/components/pay/RecipientField.tsx +308 -0
  180. package/ui/components/pay/RequestHub.tsx +75 -0
  181. package/ui/components/pay/ResultBanner.tsx +69 -0
  182. package/ui/components/pay/UniversalSend.tsx +687 -0
  183. package/ui/components/pay/useRecipientInput.ts +270 -0
  184. package/ui/components/security/WalletLockNotice.tsx +138 -0
  185. package/ui/components/ui/AlertCard.tsx +223 -0
  186. package/ui/components/ui/AppLogo.tsx +166 -0
  187. package/ui/components/ui/BlurChrome.tsx +72 -0
  188. package/ui/components/ui/Celebration.tsx +84 -0
  189. package/ui/components/ui/ChoiceSheet.ts +69 -0
  190. package/ui/components/ui/CustomSafeArea.tsx +74 -0
  191. package/ui/components/ui/ErrorBoundary.tsx +154 -0
  192. package/ui/components/ui/GroupedList.tsx +125 -0
  193. package/ui/components/ui/IconButton.tsx +105 -0
  194. package/ui/components/ui/ListRow.tsx +197 -0
  195. package/ui/components/ui/PermissionSheet.tsx +920 -0
  196. package/ui/components/ui/PresenceRow.tsx +215 -0
  197. package/ui/components/ui/PressableScale.tsx +105 -0
  198. package/ui/components/ui/ScreenGradient.tsx +47 -0
  199. package/ui/components/ui/ScrollFade.tsx +76 -0
  200. package/ui/components/ui/Sheet.tsx +342 -0
  201. package/ui/components/ui/Toast.tsx +142 -0
  202. package/ui/components/ui/index.ts +8 -0
  203. package/ui/components/vault/EnrollWizard.tsx +627 -0
  204. package/ui/components/vault/PassphraseField.tsx +306 -0
  205. package/ui/components/vault/PhraseBackupSheet.tsx +227 -0
  206. package/ui/components/vault/VaultBackdrop.tsx +354 -0
  207. package/ui/components/vault/VaultCeremonySheet.tsx +327 -0
  208. package/ui/components/wallet/ActivityRow.tsx +408 -0
  209. package/ui/components/wallet/AmountDisplay.tsx +48 -0
  210. package/ui/components/wallet/AmountInput.tsx +256 -0
  211. package/ui/components/wallet/BackupReminderSheet.tsx +168 -0
  212. package/ui/components/wallet/Balance.tsx +144 -0
  213. package/ui/components/wallet/BiometricAdvisoryModal.tsx +133 -0
  214. package/ui/components/wallet/ImportFromBackupPrompt.tsx +93 -0
  215. package/ui/exportDatabases.ts +122 -0
  216. package/ui/exportTransactions.ts +129 -0
  217. package/ui/hooks/useOfflineNoticeActions.ts +136 -0
  218. package/ui/hooks/useOnline.ts +70 -0
  219. package/ui/hooks/useSpendableBalance.ts +58 -0
  220. package/ui/hooks/useVaultBalance.ts +50 -0
  221. package/ui/importDatabases.ts +170 -0
  222. package/ui/index.ts +136 -0
  223. package/ui/isImageUrl.ts +10 -0
  224. package/ui/printRecoveryShares.ts +93 -0
  225. package/ui/resolveIdentity.ts +125 -0
  226. package/ui/screens/ConnectionsScreen.tsx +438 -0
  227. package/ui/screens/LogsScreen.tsx +432 -0
  228. package/ui/screens/PairScreen.tsx +288 -0
  229. package/ui/screens/PayScreen.tsx +479 -0
  230. package/ui/screens/SettingsScreen.tsx +180 -0
  231. package/ui/screens/TrustScreen.tsx +831 -0
  232. package/ui/screens/VaultRecoverScreen.tsx +226 -0
  233. package/ui/screens/VaultScreen.tsx +423 -0
  234. package/ui/screens/VaultTransferScreen.tsx +293 -0
  235. package/ui/screens/WalletCheckScreen.tsx +539 -0
  236. package/ui/screens/WalletConfigScreen.tsx +1095 -0
  237. package/ui/screens/WalletHomeScreen.tsx +1597 -0
  238. package/ui/screens/homeBadges.ts +18 -0
  239. package/ui/txStatus.ts +79 -0
  240. package/ui/validateTrust.ts +44 -0
@@ -0,0 +1,215 @@
1
+ /**
2
+ * Presence — the quiet line that says whether another person's device is
3
+ * actually there.
4
+ *
5
+ * This is the only screen in the app with a live peer, and this row is the only
6
+ * place that fact is visible. It is STATUS, not decoration: every state below
7
+ * is entered from a real signal, and there is deliberately no state for "we
8
+ * think they're probably nearby".
9
+ *
10
+ * ── Why there is no separate "device found" ──
11
+ *
12
+ * The AWDL transport surfaces exactly two things to JS: a decoded frame, or an
13
+ * error (see packages/react-native-localpay-transport — `startListening`,
14
+ * `sendFrame`). There is no connection callback, so neither side can observe
15
+ * discovery separately from the TLS-PSK handshake. By the time anything reaches
16
+ * JS, the peer has been found AND the encrypted channel has carried real bytes.
17
+ * Those two facts arrive together, so they are one state — `linked` — rather
18
+ * than an invented pair of steps with a timer between them. Splitting them
19
+ * would be theatre, and on a payment screen theatre is a lie about whether the
20
+ * other device is really there.
21
+ *
22
+ * ── The honest degrades ──
23
+ *
24
+ * `qr` exists because the QR hand-off has no live link at all. It must never
25
+ * animate like a connection or borrow connection language: the payer's device
26
+ * is not talking to the payee's, and pretending otherwise would tell someone a
27
+ * stranger's phone is on the other end of a channel that does not exist.
28
+ *
29
+ * `ready` says a nearby route is *available* — the peer's pairing code claims
30
+ * AWDL and this device supports it — not that anything is open yet.
31
+ *
32
+ * ── Colour ──
33
+ *
34
+ * Green appears on exactly one state, `paid`, because green on this screen
35
+ * means confirmed money and nothing else. `linked` — the moment the other
36
+ * person's device is proven present — earns its emphasis from weight and text
37
+ * colour instead, never from the accent.
38
+ */
39
+ import React, { useEffect } from 'react'
40
+ import { StyleSheet, Text } from 'react-native'
41
+ import Animated, {
42
+ useAnimatedStyle,
43
+ useReducedMotion,
44
+ useSharedValue,
45
+ withRepeat,
46
+ withSequence,
47
+ withSpring,
48
+ withTiming,
49
+ } from 'react-native-reanimated'
50
+ import { useTheme, spacing, typography, durations, easings, springs } from '@bsv/expo-wallet-toolbox'
51
+
52
+ /**
53
+ * @expo/vector-icons' index barrel re-exports every icon set (AntDesign,
54
+ * etc.), one of which reaches expo-font -> expo-asset -- untransformed ESM
55
+ * that Jest cannot parse when eagerly pulled in via the `ui` package barrel.
56
+ * Loaded lazily, only when actually rendering, same pattern as this
57
+ * package's other native-module-boundary fixes (expo-router, expo-blur).
58
+ */
59
+ type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
60
+ let ioniconsComponent: IoniconsComponent | undefined
61
+ function loadIonicons(): IoniconsComponent {
62
+ if (!ioniconsComponent) {
63
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
64
+ ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
65
+ }
66
+ return ioniconsComponent
67
+ }
68
+
69
+ export type PresenceState =
70
+ /** No live link on this path. The QR hand-off. */
71
+ | 'qr'
72
+ /** An encrypted nearby route is available; nothing is open yet. */
73
+ | 'ready'
74
+ /** Genuinely listening or searching for the peer right now. */
75
+ | 'waiting'
76
+ /** An encrypted peer-to-peer link carried real bytes. Found + secured, proven together. */
77
+ | 'linked'
78
+ /** Confirmed money. The only state that may be green. */
79
+ | 'paid'
80
+
81
+ interface PresenceRowProps {
82
+ state: PresenceState
83
+ /** Localized, role-appropriate sentence. The screen owns the wording. */
84
+ label: string
85
+ /** The peer's resolved display name, when identity lookup found one. */
86
+ peer?: string | null
87
+ /**
88
+ * Which radio the `ready`/`waiting` states are about. BLE is the only rung
89
+ * that crosses iOS↔Android, so a Bluetooth link must not wear a Wi-Fi glyph:
90
+ * the glyph is what tells the person paying which radio to look at when the
91
+ * link does not come up. Every other state ignores this — `qr` has no radio,
92
+ * and `linked`/`paid` are claims about the payment, not the pipe.
93
+ */
94
+ medium?: 'wifi' | 'bluetooth'
95
+ }
96
+
97
+ type IconName = keyof IoniconsComponent['glyphMap']
98
+
99
+ function iconFor(state: PresenceState, medium: 'wifi' | 'bluetooth'): IconName {
100
+ switch (state) {
101
+ case 'qr':
102
+ return 'qr-code-outline'
103
+ case 'ready':
104
+ case 'waiting':
105
+ return medium === 'bluetooth' ? 'bluetooth' : 'wifi'
106
+ case 'linked':
107
+ return 'lock-closed'
108
+ case 'paid':
109
+ return 'checkmark-circle'
110
+ }
111
+ }
112
+
113
+ export default function PresenceRow({ state, label, peer, medium = 'wifi' }: PresenceRowProps) {
114
+ const { colors } = useTheme()
115
+ const Ionicons = loadIonicons()
116
+ const reducedMotion = useReducedMotion()
117
+
118
+ // 0 → 1 on every state change. Re-run rather than cross-faded: the row is one
119
+ // short line, so a clean re-entry reads as "this changed" where a dissolve
120
+ // reads as a rendering artifact.
121
+ const enter = useSharedValue(1)
122
+ // Ambient breathing while genuinely waiting. Never runs in any other state —
123
+ // a pulsing glyph beside "Paid" would imply something is still in flight.
124
+ const pulse = useSharedValue(1)
125
+
126
+ useEffect(() => {
127
+ if (reducedMotion) {
128
+ enter.value = 0
129
+ enter.value = withTiming(1, { duration: durations.instant, easing: easings.out })
130
+ return
131
+ }
132
+ enter.value = 0
133
+ enter.value = withSpring(1, springs.snappy)
134
+ }, [state, reducedMotion, enter])
135
+
136
+ useEffect(() => {
137
+ if (state !== 'waiting' || reducedMotion) {
138
+ pulse.value = withTiming(1, { duration: durations.instant, easing: easings.out })
139
+ return
140
+ }
141
+ pulse.value = withRepeat(
142
+ withSequence(
143
+ withTiming(0.35, { duration: durations.moderate, easing: easings.out }),
144
+ withTiming(1, { duration: durations.moderate, easing: easings.out })
145
+ ),
146
+ -1,
147
+ false
148
+ )
149
+ }, [state, reducedMotion, pulse])
150
+
151
+ // Opacity is animated on this row's own content only. It is never an ancestor
152
+ // of LiquidGlass or BlurView — see the guardrail at the top of
153
+ // context/theme/motion.ts — and must not become one.
154
+ const rowStyle = useAnimatedStyle(() => {
155
+ if (reducedMotion) return { opacity: enter.value }
156
+ return {
157
+ opacity: enter.value,
158
+ transform: [{ translateY: (1 - enter.value) * 6 }],
159
+ }
160
+ }, [reducedMotion])
161
+
162
+ const dotStyle = useAnimatedStyle(() => ({ opacity: pulse.value }), [])
163
+
164
+ const paid = state === 'paid'
165
+ const strong = paid || state === 'linked'
166
+ const dotColor = paid ? colors.success : strong ? colors.textPrimary : colors.textTertiary
167
+ const labelColor = paid ? colors.success : strong ? colors.textPrimary : colors.textSecondary
168
+
169
+ return (
170
+ <Animated.View
171
+ // Announced as one string so VoiceOver does not read the peer name as a
172
+ // separate, contextless element.
173
+ accessibilityRole="text"
174
+ accessibilityLabel={peer ? `${label}. ${peer}` : label}
175
+ style={[styles.row, rowStyle]}
176
+ >
177
+ {/* One glyph for every state, breathing only while `waiting` — the pulse
178
+ effect above pins the opacity at 1 in every other state. `waiting`
179
+ used to draw a bare dot, which meant the `medium` prop could not
180
+ reach the one state where naming the radio matters most: the payee
181
+ waiting on a link that may be Bluetooth. */}
182
+ <Animated.View style={dotStyle}>
183
+ <Ionicons name={iconFor(state, medium)} size={13} color={dotColor} />
184
+ </Animated.View>
185
+ <Text style={[styles.label, { color: labelColor }, strong && styles.labelStrong]} numberOfLines={1}>
186
+ {label}
187
+ </Text>
188
+ {!!peer && (
189
+ <>
190
+ <Text style={[styles.sep, { color: colors.textQuaternary }]}>·</Text>
191
+ <Text style={[styles.peer, { color: colors.textSecondary }]} numberOfLines={1}>
192
+ {peer}
193
+ </Text>
194
+ </>
195
+ )}
196
+ </Animated.View>
197
+ )
198
+ }
199
+
200
+ const styles = StyleSheet.create({
201
+ row: {
202
+ flexDirection: 'row',
203
+ alignItems: 'center',
204
+ justifyContent: 'center',
205
+ gap: spacing.sm,
206
+ // Held constant across every state so the content beneath never shifts as
207
+ // the status changes.
208
+ minHeight: 20,
209
+ paddingHorizontal: spacing.sm,
210
+ },
211
+ label: { ...typography.footnote, flexShrink: 1 },
212
+ labelStrong: { fontWeight: '600' },
213
+ sep: { ...typography.footnote },
214
+ peer: { ...typography.footnote, flexShrink: 1 },
215
+ })
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Standard press feedback (spec Part 2): scale 0.97 driven by a UI-thread
3
+ * spring. Replaces bare TouchableOpacity / opacity-only Pressable in
4
+ * interactive chrome. Optional semantic haptic on press.
5
+ *
6
+ * The Pressable itself is animated (via createAnimatedComponent) so the style
7
+ * prop lands directly on the animated node — no inner Animated.View wrapper.
8
+ *
9
+ * animateOpacity (default false):
10
+ * WARNING — fractional opacity animation on an ancestor of LiquidGlass /
11
+ * BlurView freezes UIVisualEffectView on iOS. Scale-only is safe everywhere.
12
+ * Only set animateOpacity=true when you are certain no BlurView lives inside
13
+ * or behind this pressable.
14
+ *
15
+ * Reduced motion:
16
+ * When the system "Reduce Motion" accessibility setting is on, both the scale
17
+ * transform and opacity animation are suppressed entirely. Haptic feedback and
18
+ * onPress still fire normally.
19
+ */
20
+ import React, { useCallback } from 'react'
21
+ import { Pressable, StyleProp, ViewStyle, GestureResponderEvent } from 'react-native'
22
+ import type { PressableProps } from 'react-native'
23
+ import Animated, {
24
+ useSharedValue,
25
+ useAnimatedStyle,
26
+ withSpring,
27
+ useReducedMotion,
28
+ } from 'react-native-reanimated'
29
+ import { springs, haptics, type HapticName } from '@bsv/expo-wallet-toolbox'
30
+
31
+ const AnimatedPressable = Animated.createAnimatedComponent(Pressable)
32
+
33
+ interface PressableScaleProps extends PressableProps {
34
+ /** Style applied directly to the animated Pressable node. */
35
+ style?: StyleProp<ViewStyle>
36
+ haptic?: HapticName
37
+ scaleTo?: number
38
+ /**
39
+ * When true, opacity animates from 1 → 0.85 together with the scale spring.
40
+ *
41
+ * WARNING: fractional opacity animation on an ancestor of LiquidGlass /
42
+ * BlurView freezes UIVisualEffectView on iOS. Leave this false (the default)
43
+ * whenever a BlurView lives inside or behind this pressable.
44
+ */
45
+ animateOpacity?: boolean
46
+ children?: React.ReactNode
47
+ }
48
+
49
+ export default function PressableScale({
50
+ style,
51
+ haptic,
52
+ scaleTo = 0.97,
53
+ animateOpacity = false,
54
+ onPressIn,
55
+ onPressOut,
56
+ onPress,
57
+ children,
58
+ ...rest
59
+ }: PressableScaleProps) {
60
+ const pressed = useSharedValue(0)
61
+ const reducedMotion = useReducedMotion()
62
+
63
+ const animatedStyle = useAnimatedStyle(() => {
64
+ if (reducedMotion) {
65
+ return {}
66
+ }
67
+ if (animateOpacity) {
68
+ return {
69
+ transform: [{ scale: 1 - (1 - scaleTo) * pressed.value }],
70
+ opacity: 1 - 0.15 * pressed.value,
71
+ }
72
+ }
73
+ return {
74
+ transform: [{ scale: 1 - (1 - scaleTo) * pressed.value }],
75
+ }
76
+ }, [scaleTo, animateOpacity, reducedMotion])
77
+
78
+ const handlePressIn = useCallback((e: GestureResponderEvent) => {
79
+ pressed.value = withSpring(1, springs.snappy)
80
+ onPressIn?.(e)
81
+ }, [onPressIn, pressed])
82
+
83
+ const handlePressOut = useCallback((e: GestureResponderEvent) => {
84
+ pressed.value = withSpring(0, springs.snappy)
85
+ onPressOut?.(e)
86
+ }, [onPressOut, pressed])
87
+
88
+ const handlePress = useCallback((e: GestureResponderEvent) => {
89
+ if (haptic) haptics[haptic]()
90
+ onPress?.(e)
91
+ }, [haptic, onPress])
92
+
93
+ return (
94
+ <AnimatedPressable
95
+ {...rest}
96
+ accessibilityRole={rest.accessibilityRole ?? 'button'}
97
+ onPressIn={handlePressIn}
98
+ onPressOut={handlePressOut}
99
+ onPress={handlePress}
100
+ style={[style, animatedStyle]}
101
+ >
102
+ {children}
103
+ </AnimatedPressable>
104
+ )
105
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * A shallow vertical gradient painted behind a screen's content.
3
+ *
4
+ * The whole effect is one step of value between the top of the screen and the
5
+ * rest of it — enough that the balance block reads as sitting in its own light,
6
+ * not enough to be seen as a gradient. Below `height` the view is a flat `to`
7
+ * fill, so the transition is invisible no matter how far the list scrolls.
8
+ *
9
+ * Drawn with react-native-svg rather than stacked translucent Views: stacking
10
+ * bands this close in value produces visible steps on OLED panels.
11
+ */
12
+ import React, { useId } from 'react'
13
+ import { StyleSheet, View } from 'react-native'
14
+ import Svg, { Defs, LinearGradient, Rect, Stop } from 'react-native-svg'
15
+
16
+ interface Props {
17
+ /** Colour at the very top of the screen. */
18
+ from: string
19
+ /** Colour everything below `height` is filled with. */
20
+ to: string
21
+ /** How far down the gradient finishes resolving into `to`. */
22
+ height?: number
23
+ }
24
+
25
+ export default function ScreenGradient({ from, to, height = 320 }: Props) {
26
+ // Gradient ids share a document on some renderers, so a fixed id would let two
27
+ // gradients on one screen pick up each other's stops.
28
+ const id = `screen-gradient-${useId()}`
29
+ return (
30
+ <View
31
+ pointerEvents="none"
32
+ style={[StyleSheet.absoluteFill, { backgroundColor: to }]}
33
+ accessible={false}
34
+ importantForAccessibility="no-hide-descendants"
35
+ >
36
+ <Svg width="100%" height={height}>
37
+ <Defs>
38
+ <LinearGradient id={id} x1="0" y1="0" x2="0" y2="1">
39
+ <Stop offset="0" stopColor={from} />
40
+ <Stop offset="1" stopColor={to} />
41
+ </LinearGradient>
42
+ </Defs>
43
+ <Rect x="0" y="0" width="100%" height="100%" fill={`url(#${id})`} />
44
+ </Svg>
45
+ </View>
46
+ )
47
+ }
@@ -0,0 +1,76 @@
1
+ /**
2
+ * A short fade at the top of a scrolling list, so rows dissolve into the
3
+ * backdrop as they pass under whatever is pinned above them.
4
+ *
5
+ * Without it the list has a hard edge: a row is fully drawn, then abruptly
6
+ * clipped mid-glyph. The fade is drawn in the backdrop's own colour rather
7
+ * than as a translucent black or white, because the screen behind it is a
8
+ * gradient — anything else banded against it.
9
+ *
10
+ * `color` must therefore be the backdrop colour AT this strip's position, not
11
+ * the screen's base colour: use `sampleScreenGradient` to work it out.
12
+ */
13
+ import React, { useId } from 'react'
14
+ import { StyleSheet, View } from 'react-native'
15
+ import Svg, { Defs, LinearGradient, Rect, Stop } from 'react-native-svg'
16
+
17
+ /**
18
+ * The colour ScreenGradient paints at `y`.
19
+ *
20
+ * ScreenGradient resolves `from` into `to` over `height` and is a flat `to`
21
+ * below that, so this is the same linear interpolation, clamped.
22
+ */
23
+ export function sampleScreenGradient(from: string, to: string, y: number, height = 320): string {
24
+ const parse = (hex: string): [number, number, number] | undefined => {
25
+ const m = /^#([0-9a-f]{6})$/i.exec(hex.trim())
26
+ if (!m) return undefined
27
+ const n = parseInt(m[1], 16)
28
+ return [(n >> 16) & 255, (n >> 8) & 255, n & 255]
29
+ }
30
+ const a = parse(from)
31
+ const b = parse(to)
32
+ // A non-hex theme colour (rgba(), a named colour) is not worth guessing at:
33
+ // the flat base is the honest answer everywhere below the gradient anyway.
34
+ if (!a || !b || height <= 0) return to
35
+ const ratio = Math.max(0, Math.min(1, y / height))
36
+ const mix = (i: number) => Math.round(a[i] + (b[i] - a[i]) * ratio)
37
+ return `#${[0, 1, 2].map(i => mix(i).toString(16).padStart(2, '0')).join('')}`
38
+ }
39
+
40
+ interface Props {
41
+ /** The backdrop colour where this strip sits. */
42
+ color: string
43
+ height?: number
44
+ }
45
+
46
+ export default function ScrollFade({ color, height = 24 }: Props) {
47
+ const id = `scroll-fade-${useId()}`
48
+ return (
49
+ <View
50
+ pointerEvents="none"
51
+ style={[styles.fade, { height }]}
52
+ accessible={false}
53
+ importantForAccessibility="no-hide-descendants"
54
+ >
55
+ <Svg width="100%" height={height}>
56
+ <Defs>
57
+ <LinearGradient id={id} x1="0" y1="0" x2="0" y2="1">
58
+ <Stop offset="0" stopColor={color} stopOpacity={1} />
59
+ <Stop offset="1" stopColor={color} stopOpacity={0} />
60
+ </LinearGradient>
61
+ </Defs>
62
+ <Rect x="0" y="0" width="100%" height="100%" fill={`url(#${id})`} />
63
+ </Svg>
64
+ </View>
65
+ )
66
+ }
67
+
68
+ const styles = StyleSheet.create({
69
+ fade: {
70
+ position: 'absolute',
71
+ top: 0,
72
+ left: 0,
73
+ right: 0,
74
+ zIndex: 1
75
+ }
76
+ })