@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,342 @@
1
+ import React, { memo, useEffect, useRef } from 'react'
2
+ import { Dimensions, Keyboard, Platform, Pressable, StyleSheet, Text, TouchableOpacity, View } from 'react-native'
3
+ import Animated, { useSharedValue, useAnimatedStyle, withSpring, withTiming, runOnJS } from 'react-native-reanimated'
4
+ import { Gesture, GestureDetector } from 'react-native-gesture-handler'
5
+ import { useSafeAreaInsets } from 'react-native-safe-area-context'
6
+ import { useTheme, spacing, typography } from '@bsv/expo-wallet-toolbox'
7
+ import ScreenGradient from './ScreenGradient'
8
+
9
+ /**
10
+ * @expo/vector-icons' index barrel re-exports every icon set (AntDesign,
11
+ * etc.), one of which reaches expo-font -> expo-asset -- untransformed ESM
12
+ * that Jest cannot parse when eagerly pulled in via the `ui` package barrel.
13
+ * Loaded lazily, only when actually rendering, same pattern as this
14
+ * package's other native-module-boundary fixes (expo-router, expo-blur).
15
+ */
16
+ type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
17
+ let ioniconsComponent: IoniconsComponent | undefined
18
+ function loadIonicons(): IoniconsComponent {
19
+ if (!ioniconsComponent) {
20
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
21
+ ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
22
+ }
23
+ return ioniconsComponent
24
+ }
25
+
26
+ interface SheetProps {
27
+ visible: boolean
28
+ onClose: () => void
29
+ title?: string
30
+ onBack?: () => void
31
+ heightPercent?: number
32
+ fullPage?: boolean
33
+ /** When true the sheet sizes to its content (up to heightPercent max). */
34
+ fitContent?: boolean
35
+ children?: React.ReactNode
36
+ }
37
+
38
+ /**
39
+ * Unified bottom sheet.
40
+ * Uses Reanimated 4 + Gesture v2 so the swipe-to-close spring
41
+ * is never interrupted by a stale Animated.event reset.
42
+ *
43
+ * When `fullPage` is true the sheet covers the entire screen with a
44
+ * Transactions-style navigation header (safe-area aware, hairline separator,
45
+ * no drag handle, no backdrop dimming).
46
+ */
47
+ const Sheet: React.FC<SheetProps> = ({
48
+ visible,
49
+ onClose,
50
+ title,
51
+ onBack,
52
+ heightPercent = 0.75,
53
+ fullPage = false,
54
+ fitContent = false,
55
+ children
56
+ }) => {
57
+ const { colors } = useTheme()
58
+ const Ionicons = loadIonicons()
59
+ const insets = useSafeAreaInsets()
60
+ const { height: windowHeight } = Dimensions.get('window')
61
+ const maxSheetHeight = fullPage ? windowHeight : Math.max(0, Math.min(1, heightPercent)) * windowHeight
62
+
63
+ // For fitContent mode we measure the actual rendered height; fall back to max.
64
+ const [measuredHeight, setMeasuredHeight] = React.useState(0)
65
+ const sheetHeight = fitContent && measuredHeight > 0 ? Math.min(measuredHeight, maxSheetHeight) : maxSheetHeight
66
+
67
+ // 0 = fully open, sheetHeight = fully hidden (below screen)
68
+ const translateY = useSharedValue(sheetHeight)
69
+ // Track whether the sheet is visible for rendering children
70
+ const [rendered, setRendered] = React.useState(false)
71
+
72
+ // Open / close driven by `visible` prop. Only PLAY the enter animation on an
73
+ // actual closed→open transition — not on every re-run of this effect. In
74
+ // fitContent mode, sheetHeight tracks onLayout-measured content height, which
75
+ // jitters by a pixel or two on ordinary re-renders (e.g. a secureTextEntry
76
+ // keystroke). Without this guard, each jitter re-ran "jump to hidden, spring
77
+ // back to 0", flickering the whole sheet on every character typed.
78
+ const wasVisibleRef = useRef(false)
79
+ useEffect(() => {
80
+ if (visible) {
81
+ setRendered(true)
82
+ if (!wasVisibleRef.current) {
83
+ translateY.value = sheetHeight
84
+ translateY.value = withSpring(0, { mass: 1, stiffness: 280, damping: 32 })
85
+ }
86
+ } else {
87
+ translateY.value = withSpring(sheetHeight, { mass: 1, stiffness: 400, damping: 38 }, finished => {
88
+ if (finished) runOnJS(setRendered)(false)
89
+ })
90
+ }
91
+ wasVisibleRef.current = visible
92
+ }, [visible, sheetHeight]) // eslint-disable-line react-hooks/exhaustive-deps
93
+
94
+ // Lift the sheet above the software keyboard so bottom-anchored content
95
+ // (PIN field, primary button) stays visible. Without this a number-pad — which
96
+ // has no "done" key — hides the submit button, forcing a tap-outside that
97
+ // reads as a backdrop dismiss. Standard bottom-sheet mode only; full-page
98
+ // sheets manage their own scrolling.
99
+ const kbShift = useSharedValue(0)
100
+ useEffect(() => {
101
+ if (fullPage) return
102
+ const showEvt = Platform.OS === 'ios' ? 'keyboardWillShow' : 'keyboardDidShow'
103
+ const hideEvt = Platform.OS === 'ios' ? 'keyboardWillHide' : 'keyboardDidHide'
104
+ const show = Keyboard.addListener(showEvt, e => {
105
+ kbShift.value = withTiming(e.endCoordinates?.height ?? 0, { duration: e.duration || 250 })
106
+ })
107
+ const hide = Keyboard.addListener(hideEvt, e => {
108
+ kbShift.value = withTiming(0, { duration: e.duration || 200 })
109
+ })
110
+ return () => {
111
+ show.remove()
112
+ hide.remove()
113
+ }
114
+ }, [fullPage, kbShift])
115
+
116
+ const animatedStyle = useAnimatedStyle(() => ({
117
+ transform: [{ translateY: translateY.value - kbShift.value }]
118
+ }))
119
+
120
+ const panGesture = Gesture.Pan()
121
+ .activeOffsetY(10)
122
+ .failOffsetX([-25, 25])
123
+ .onUpdate(e => {
124
+ translateY.value = Math.max(0, e.translationY)
125
+ })
126
+ .onEnd(e => {
127
+ const shouldClose = e.translationY > sheetHeight / 3 || e.velocityY > 800
128
+ if (shouldClose) {
129
+ translateY.value = withSpring(
130
+ sheetHeight,
131
+ {
132
+ mass: 1,
133
+ stiffness: 400,
134
+ damping: 38,
135
+ velocity: e.velocityY
136
+ },
137
+ () => runOnJS(onClose)()
138
+ )
139
+ } else {
140
+ translateY.value = withSpring(0, { mass: 1, stiffness: 400, damping: 38 })
141
+ }
142
+ })
143
+
144
+ const isVisible = visible || rendered
145
+
146
+ if (!isVisible) return null
147
+
148
+ /* ------------------------------------------------------------------ */
149
+ /* Full-page mode — matches the Transactions screen style */
150
+ /* ------------------------------------------------------------------ */
151
+ if (fullPage) {
152
+ return (
153
+ <Animated.View
154
+ style={[
155
+ styles.fullPageSheet,
156
+ {
157
+ backgroundColor: colors.backgroundSecondary,
158
+ height: sheetHeight,
159
+ paddingTop: insets.top
160
+ },
161
+ animatedStyle
162
+ ]}
163
+ >
164
+ {/* Header */}
165
+ <View style={[styles.fullPageHeader, { borderBottomColor: colors.separator }]}>
166
+ {onBack ? (
167
+ <TouchableOpacity style={styles.fullPageBack} onPress={onBack} activeOpacity={0.6}>
168
+ <Ionicons name="chevron-back" size={24} color={colors.textSecondary} />
169
+ </TouchableOpacity>
170
+ ) : (
171
+ <View style={styles.fullPageBack} />
172
+ )}
173
+ {title && (
174
+ <Text style={[styles.fullPageTitle, { color: colors.textPrimary }]} numberOfLines={1}>
175
+ {title}
176
+ </Text>
177
+ )}
178
+ <View style={styles.fullPageBack} />
179
+ </View>
180
+
181
+ <View style={{ flex: 1 }}>{rendered ? children : null}</View>
182
+ </Animated.View>
183
+ )
184
+ }
185
+
186
+ /* ------------------------------------------------------------------ */
187
+ /* Standard bottom-sheet mode */
188
+ /* ------------------------------------------------------------------ */
189
+ return (
190
+ <View style={[StyleSheet.absoluteFill, { zIndex: 50 }]}>
191
+ {isVisible && (
192
+ <Pressable
193
+ style={[styles.backdrop, { backgroundColor: colors.scrim }]}
194
+ onPress={onClose}
195
+ accessible={true}
196
+ accessibilityRole="button"
197
+ accessibilityLabel="Close"
198
+ accessibilityHint="Dismisses this sheet"
199
+ />
200
+ )}
201
+ <Animated.View
202
+ style={[
203
+ styles.sheet,
204
+ {
205
+ backgroundColor: colors.sheetBase,
206
+ borderTopColor: colors.surfaceRaisedBorder,
207
+ ...(fitContent ? { maxHeight: maxSheetHeight } : { height: sheetHeight })
208
+ },
209
+ animatedStyle
210
+ ]}
211
+ onLayout={
212
+ fitContent
213
+ ? e => {
214
+ const h = e.nativeEvent.layout.height
215
+ if (h > 0 && h !== measuredHeight) setMeasuredHeight(h)
216
+ }
217
+ : undefined
218
+ }
219
+ >
220
+ {/* The drawer is lit from its own top edge — a shallow ramp down to
221
+ `sheetBase`, which the View's own background already paints below. */}
222
+ <ScreenGradient from={colors.sheetTop} to={colors.sheetBase} height={480} />
223
+
224
+ {/* Draggable handle + header */}
225
+ <GestureDetector gesture={panGesture}>
226
+ <View style={styles.handleArea}>
227
+ <View style={[styles.handleBar, { backgroundColor: colors.fillSecondary }]} />
228
+ {(title || onBack) && (
229
+ <View style={styles.headerRow}>
230
+ {onBack ? (
231
+ <TouchableOpacity style={styles.backButton} onPress={onBack} activeOpacity={0.6}>
232
+ <Ionicons name="chevron-back" size={22} color={colors.textSecondary} />
233
+ </TouchableOpacity>
234
+ ) : (
235
+ <View style={styles.backButton} />
236
+ )}
237
+ {title && (
238
+ <Text style={[styles.headerTitle, { color: colors.textPrimary }]} numberOfLines={1}>
239
+ {title}
240
+ </Text>
241
+ )}
242
+ <View style={styles.backButton} />
243
+ </View>
244
+ )}
245
+ </View>
246
+ </GestureDetector>
247
+
248
+ <View style={fitContent ? undefined : { flex: 1 }}>{rendered ? children : null}</View>
249
+ </Animated.View>
250
+ </View>
251
+ )
252
+ }
253
+
254
+ const styles = StyleSheet.create({
255
+ /* Full-page styles */
256
+ fullPageSheet: {
257
+ position: 'absolute',
258
+ left: 0,
259
+ right: 0,
260
+ bottom: 0,
261
+ zIndex: 50,
262
+ elevation: 12,
263
+ shadowColor: '#000',
264
+ shadowOffset: { width: 0, height: -2 },
265
+ shadowOpacity: 0.15,
266
+ shadowRadius: 10
267
+ },
268
+ fullPageHeader: {
269
+ flexDirection: 'row',
270
+ alignItems: 'center',
271
+ justifyContent: 'space-between',
272
+ paddingHorizontal: spacing.sm,
273
+ paddingVertical: spacing.md,
274
+ borderBottomWidth: StyleSheet.hairlineWidth
275
+ },
276
+ fullPageBack: {
277
+ width: 44,
278
+ height: 44,
279
+ alignItems: 'center',
280
+ justifyContent: 'center'
281
+ },
282
+ fullPageTitle: {
283
+ ...typography.headline,
284
+ flex: 1,
285
+ textAlign: 'center'
286
+ },
287
+
288
+ /* Standard sheet styles */
289
+ sheet: {
290
+ position: 'absolute',
291
+ left: 0,
292
+ right: 0,
293
+ bottom: 0,
294
+ borderTopLeftRadius: 24,
295
+ borderTopRightRadius: 24,
296
+ borderTopWidth: StyleSheet.hairlineWidth,
297
+ overflow: 'hidden',
298
+ zIndex: 20,
299
+ elevation: 12,
300
+ // Deep and soft rather than tight: the drawer has to sit clearly in front of
301
+ // a dimmed page, and a small shadow reads as a seam instead of a lift.
302
+ shadowColor: '#000',
303
+ shadowOffset: { width: 0, height: -12 },
304
+ shadowOpacity: 0.45,
305
+ shadowRadius: 30
306
+ },
307
+ backdrop: {
308
+ ...StyleSheet.absoluteFillObject,
309
+ zIndex: 10
310
+ },
311
+ handleArea: {
312
+ alignItems: 'center',
313
+ justifyContent: 'center',
314
+ paddingTop: spacing.sm
315
+ },
316
+ handleBar: {
317
+ width: 36,
318
+ height: 4,
319
+ borderRadius: 2
320
+ },
321
+ headerRow: {
322
+ flexDirection: 'row',
323
+ alignItems: 'center',
324
+ width: '100%',
325
+ paddingHorizontal: spacing.md,
326
+ paddingTop: spacing.sm,
327
+ paddingBottom: spacing.md,
328
+ minHeight: 36
329
+ },
330
+ backButton: {
331
+ flexDirection: 'row',
332
+ alignItems: 'center',
333
+ minWidth: 60
334
+ },
335
+ headerTitle: {
336
+ ...typography.headline,
337
+ flex: 1,
338
+ textAlign: 'center'
339
+ }
340
+ })
341
+
342
+ export default memo(Sheet)
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Non-modal notice capsule (spec Part 2). For FYI messages only — decisions
3
+ * use showAlert. Queue of 1: newest replaces current. Auto-dismiss 2s.
4
+ *
5
+ * showToast('Copied')
6
+ * showToast(t('export_failed'), { type: 'error' })
7
+ *
8
+ * <ToastHost /> must be mounted once, inside ThemeProvider, ABOVE the Stack
9
+ * (app/_layout.tsx). Near-solid background — no BlurView (see motion.ts).
10
+ */
11
+ import React, { useEffect, useRef, useState } from 'react'
12
+ import { StyleSheet, Text, View } from 'react-native'
13
+ import { useSafeAreaInsets } from 'react-native-safe-area-context'
14
+ import Animated, {
15
+ useSharedValue,
16
+ useAnimatedStyle,
17
+ withSpring,
18
+ withTiming,
19
+ useReducedMotion,
20
+ } from 'react-native-reanimated'
21
+ import { useTheme, spacing, radii, typography, springs, durations, haptics } from '@bsv/expo-wallet-toolbox'
22
+
23
+ /**
24
+ * @expo/vector-icons' index barrel re-exports every icon set (AntDesign,
25
+ * etc.), one of which reaches expo-font -> expo-asset -- untransformed ESM
26
+ * that Jest cannot parse when eagerly pulled in via the `ui` package barrel.
27
+ * Loaded lazily, only when actually rendering, same pattern as this
28
+ * package's other native-module-boundary fixes (expo-router, expo-blur).
29
+ */
30
+ type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
31
+ let ioniconsComponent: IoniconsComponent | undefined
32
+ function loadIonicons(): IoniconsComponent {
33
+ if (!ioniconsComponent) {
34
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
35
+ ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
36
+ }
37
+ return ioniconsComponent
38
+ }
39
+
40
+ export type ToastType = 'info' | 'success' | 'error'
41
+ interface ToastData { id: number; message: string; type: ToastType }
42
+
43
+ const TOAST_MS = 2000
44
+
45
+ let push: ((message: string, type: ToastType) => void) | null = null
46
+ let nextId = 1
47
+
48
+ export function showToast(message: string, opts?: { type?: ToastType }) {
49
+ const type = opts?.type ?? 'info'
50
+ if (type === 'success') haptics.success()
51
+ if (type === 'error') haptics.error()
52
+ if (!push) { console.warn('[Toast] ToastHost not mounted:', message); return }
53
+ push(message, type)
54
+ }
55
+
56
+ export function ToastHost() {
57
+ const { colors } = useTheme()
58
+ const Ionicons = loadIonicons()
59
+ const insets = useSafeAreaInsets()
60
+ const reducedMotion = useReducedMotion()
61
+ const [toast, setToast] = useState<ToastData | null>(null)
62
+ const hideTimer = useRef<ReturnType<typeof setTimeout> | null>(null)
63
+ const progress = useSharedValue(0)
64
+
65
+ useEffect(() => {
66
+ push = (message, type) => {
67
+ if (hideTimer.current) clearTimeout(hideTimer.current)
68
+ progress.value = 0
69
+ setToast({ id: nextId++, message, type })
70
+ }
71
+ return () => { push = null }
72
+ }, [])
73
+
74
+ useEffect(() => {
75
+ if (!toast) return
76
+ progress.value = 0
77
+ progress.value = reducedMotion
78
+ ? withTiming(1, { duration: durations.instant })
79
+ : withSpring(1, springs.snappy)
80
+ hideTimer.current = setTimeout(() => {
81
+ progress.value = withTiming(0, { duration: durations.quick })
82
+ hideTimer.current = setTimeout(() => setToast(null), durations.quick)
83
+ }, TOAST_MS)
84
+ return () => { if (hideTimer.current) clearTimeout(hideTimer.current) }
85
+ }, [toast, progress, reducedMotion])
86
+
87
+ const animatedStyle = useAnimatedStyle(() => ({
88
+ opacity: progress.value,
89
+ transform: [{ translateY: -12 * (1 - progress.value) }],
90
+ }))
91
+
92
+ if (!toast) return null
93
+
94
+ const icon = toast.type === 'success' ? 'checkmark-circle'
95
+ : toast.type === 'error' ? 'alert-circle'
96
+ : null
97
+ const iconColor = toast.type === 'success' ? colors.success : colors.error
98
+
99
+ return (
100
+ <View pointerEvents="none" style={[styles.wrap, { top: insets.top + spacing.sm }]}>
101
+ <Animated.View
102
+ key={toast.id}
103
+ style={[
104
+ styles.capsule,
105
+ { backgroundColor: colors.sheetBackground, borderColor: colors.separator },
106
+ animatedStyle,
107
+ ]}
108
+ >
109
+ {icon && <Ionicons name={icon} size={18} color={iconColor} style={styles.icon} />}
110
+ <Text numberOfLines={2} style={[styles.text, { color: colors.textPrimary }]}>
111
+ {toast.message}
112
+ </Text>
113
+ </Animated.View>
114
+ </View>
115
+ )
116
+ }
117
+
118
+ const styles = StyleSheet.create({
119
+ wrap: {
120
+ position: 'absolute',
121
+ left: 0,
122
+ right: 0,
123
+ alignItems: 'center',
124
+ zIndex: 10000,
125
+ },
126
+ capsule: {
127
+ flexDirection: 'row',
128
+ alignItems: 'center',
129
+ maxWidth: '86%',
130
+ paddingHorizontal: spacing.lg,
131
+ paddingVertical: spacing.md,
132
+ borderRadius: radii.pill,
133
+ borderWidth: StyleSheet.hairlineWidth,
134
+ shadowColor: '#000',
135
+ shadowOpacity: 0.15,
136
+ shadowRadius: 12,
137
+ shadowOffset: { width: 0, height: 4 },
138
+ elevation: 6,
139
+ },
140
+ icon: { marginRight: spacing.sm },
141
+ text: { ...typography.subhead, flexShrink: 1 },
142
+ })
@@ -0,0 +1,8 @@
1
+ export { default as AppLogo } from './AppLogo'
2
+ export { BlurChrome } from './BlurChrome'
3
+ export { default as CustomSafeArea } from './CustomSafeArea'
4
+ export { ErrorBoundary } from './ErrorBoundary'
5
+ export { GroupedList, GroupedSection } from './GroupedList'
6
+ export { IconButton } from './IconButton'
7
+ export { ListRow } from './ListRow'
8
+ export { default as Sheet } from './Sheet'