@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,408 @@
1
+ /**
2
+ * One row of the wallet's activity list.
3
+ *
4
+ * Reading order is direction → what it was → how much, then status and time
5
+ * underneath. The per-transaction utilities (status, explorer, resend, cancel)
6
+ * are NOT on the row: they used to sit permanently on the right, four icons
7
+ * deep, which made every row look equally busy whether or not anything needed
8
+ * doing. They now live behind a tap, and the expanded row lifts onto its own
9
+ * surface so it is obvious which transaction the chips belong to.
10
+ *
11
+ * The chips are what someone can DO about a payment. Copying raw BEEF or a
12
+ * txid to a clipboard is not that — it is debugging, and it used to crowd out
13
+ * the two chips that actually resolve a stuck payment.
14
+ */
15
+ import React, { memo, useContext } from 'react'
16
+ import { View, Text, StyleSheet, ActivityIndicator } from 'react-native'
17
+ import { useTranslation } from 'react-i18next'
18
+ import type { WalletAction } from '@bsv/sdk'
19
+ import { useTheme, spacing, radii, typography, useWallet, ExchangeRateContext, formatAmount, formatAmountParts } from '@bsv/expo-wallet-toolbox'
20
+ import { txStatusView, toneColor } from '../../txStatus'
21
+ import PressableScale from '../ui/PressableScale'
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
+ * Both icon sets are loaded lazily, only when actually rendering, same
28
+ * pattern as this package's other native-module-boundary fixes (expo-router,
29
+ * expo-blur).
30
+ */
31
+ type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
32
+ type MaterialCommunityIconsComponent = typeof import('@expo/vector-icons').MaterialCommunityIcons
33
+ let ioniconsComponent: IoniconsComponent | undefined
34
+ let materialCommunityIconsComponent: MaterialCommunityIconsComponent | undefined
35
+ function loadIonicons(): IoniconsComponent {
36
+ if (!ioniconsComponent) {
37
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
38
+ ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
39
+ }
40
+ return ioniconsComponent
41
+ }
42
+ function loadMaterialCommunityIcons(): MaterialCommunityIconsComponent {
43
+ if (!materialCommunityIconsComponent) {
44
+ materialCommunityIconsComponent = require('@expo/vector-icons')
45
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
46
+ .MaterialCommunityIcons as MaterialCommunityIconsComponent
47
+ }
48
+ return materialCommunityIconsComponent
49
+ }
50
+
51
+ /** A row as storage actually returns it: `reference` and `created_at` are real
52
+ * columns the SDK's WalletAction type does not declare. */
53
+ export type ActivityAction = WalletAction & {
54
+ reference?: string
55
+ created_at?: string | number | Date
56
+ }
57
+
58
+ interface Props {
59
+ action: ActivityAction
60
+ /** Identity of this row in the list's expanded/busy bookkeeping. Passed back
61
+ * to `onToggle` so the handler can stay referentially stable across renders —
62
+ * an inline closure here would defeat the memo below on every poll. */
63
+ rowKey: string
64
+ /** Live offline-queue state for this txid, when it has one. */
65
+ offlineStatus?: string
66
+ expanded: boolean
67
+ busy: boolean
68
+ /** What the spinner is waiting on. A bare spinner on a money row is a
69
+ * question ("is it sending? cancelling?") the row can answer. */
70
+ busyLabel?: string
71
+ onToggle: (rowKey: string) => void
72
+ onExplorer: (txid: string) => void
73
+ onRefreshTx: (txid: string) => void
74
+ onAbort: (reference: string) => void
75
+ /** Rebuild and re-deliver a PeerPay token without waiting for a NACK. */
76
+ onSendPaymentDetails?: (txid: string) => void
77
+ /** Start a new payment (or retryDelivery) for a failed outbound row. */
78
+ onSendAgain?: (action: ActivityAction) => void
79
+ /** Cancel a parked payment: abort the action and retire its queue row. */
80
+ onCancelParked?: (txid: string) => void
81
+ }
82
+
83
+ /** Statuses whose transaction is still local and therefore abortable: nothing
84
+ * has been (successfully) broadcast, so releasing it is safe and frees the
85
+ * inputs it reserved. `failed` is included because a failed action still holds
86
+ * its input reservations until it is cleared. */
87
+ const ABORTABLE_STATUSES = new Set(['unsigned', 'nosend', 'nonfinal', 'failed'])
88
+
89
+ /** Local time of day, e.g. "14:32". Empty when storage gave us no timestamp. */
90
+ export function formatRowTime(value?: string | number | Date): string {
91
+ if (value === undefined || value === null) return ''
92
+ const d = new Date(value as string)
93
+ if (Number.isNaN(d.getTime())) return ''
94
+ try {
95
+ return d.toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit' })
96
+ } catch {
97
+ return `${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`
98
+ }
99
+ }
100
+
101
+ function ActivityRowBase({
102
+ action,
103
+ rowKey,
104
+ offlineStatus,
105
+ expanded,
106
+ busy,
107
+ busyLabel,
108
+ onToggle,
109
+ onExplorer,
110
+ onRefreshTx,
111
+ onAbort,
112
+ onSendPaymentDetails,
113
+ onSendAgain,
114
+ onCancelParked
115
+ }: Props) {
116
+ const { t } = useTranslation()
117
+ const { colors } = useTheme()
118
+ const { settings } = useWallet()
119
+ const { satoshisPerUSD, usdToFiat = {} } = useContext(ExchangeRateContext)
120
+ const MaterialCommunityIcons = loadMaterialCommunityIcons()
121
+
122
+ const currency = settings?.currency || 'BSV'
123
+ const view = txStatusView(action.status, offlineStatus)
124
+ const settled = view.tone === 'settled'
125
+ const tone = toneColor(view.tone, colors as unknown as Record<string, string>)
126
+ const incoming = action.satoshis >= 0
127
+
128
+ const { value, unit } = formatAmountParts(action.satoshis, currency, satoshisPerUSD, {
129
+ abbreviate: true,
130
+ showPlus: true,
131
+ usdToFiat
132
+ })
133
+ // The second denomination — the one the user is NOT currently displaying. It
134
+ // is the answer to "yes, but how much is that really", which is the whole
135
+ // reason a sats-denominated wallet needs a fiat line at all.
136
+ const secondary = formatAmount(action.satoshis, currency === 'BSV' ? 'USD' : 'BSV', satoshisPerUSD, {
137
+ abbreviate: true,
138
+ showPlus: true,
139
+ usdToFiat
140
+ })
141
+
142
+ const time = formatRowTime(action.created_at)
143
+ const amountColor = incoming ? colors.successAmount : colors.textPrimary
144
+ const unitColor = incoming ? colors.successAmount : colors.textSecondary
145
+
146
+ // A parked payment was built and shown as a code, but never released: it is
147
+ // not on chain and no task will put it there. An explorer link would 404 and
148
+ // a Refresh would ask the network about a transaction it has never seen, so
149
+ // the row offers only the two things that apply. Resend goes out over the
150
+ // message box rather than re-showing the code: if the payee is still standing
151
+ // there, cancelling and starting again is both quicker and honest, and if
152
+ // they are not, the remote rail is the only one that can still reach them.
153
+ const parked = offlineStatus === 'parked'
154
+ const canCancelParked = parked && !!action.txid && !!onCancelParked
155
+ const canAbort = !parked && ABORTABLE_STATUSES.has(action.status) && !!action.reference
156
+ // Any outgoing payment this wallet can rebuild: both rails write the payee's
157
+ // identity key as a label and the derivation data as customInstructions, so
158
+ // the details can be re-delivered whether the payment went out through a
159
+ // message box or a nearby code that may never have been scanned.
160
+ const resendableOutbound =
161
+ !!action.txid &&
162
+ (action.isOutgoing ?? !incoming) &&
163
+ !!action.labels?.some(l => l === 'peerpay' || l === 'localpay')
164
+ const canResendDetails = resendableOutbound && !!onSendPaymentDetails
165
+ const canSendAgain = !parked && !incoming && action.status === 'failed' && !!onSendAgain
166
+ const hasUtilities = parked
167
+ ? canResendDetails || canCancelParked
168
+ : !!action.txid || canAbort || canResendDetails || canSendAgain
169
+
170
+ return (
171
+ <View
172
+ style={[
173
+ expanded && {
174
+ backgroundColor: colors.surfaceRowExpanded,
175
+ borderTopWidth: StyleSheet.hairlineWidth,
176
+ borderBottomWidth: StyleSheet.hairlineWidth,
177
+ borderColor: colors.hairline
178
+ }
179
+ ]}
180
+ >
181
+ <PressableScale
182
+ scaleTo={0.99}
183
+ onPress={hasUtilities ? () => onToggle(rowKey) : undefined}
184
+ style={styles.row}
185
+ accessibilityRole="button"
186
+ accessibilityState={{ expanded }}
187
+ accessibilityLabel={action.description || t('transactions')}
188
+ >
189
+ <View
190
+ style={[
191
+ styles.glyph,
192
+ incoming
193
+ ? {
194
+ backgroundColor: colors.successStrong + '1A',
195
+ borderColor: colors.successStrong + '2E'
196
+ }
197
+ : { backgroundColor: colors.surfaceSunken, borderColor: colors.surfaceSunkenBorder }
198
+ ]}
199
+ >
200
+ <MaterialCommunityIcons
201
+ name={incoming ? 'arrow-bottom-left' : 'arrow-top-right'}
202
+ size={16}
203
+ color={incoming ? colors.successStrong : colors.textSecondary}
204
+ />
205
+ </View>
206
+
207
+ <View style={styles.middle}>
208
+ <Text style={[styles.description, { color: colors.textPrimary }]} numberOfLines={1}>
209
+ {action.description || t('transactions')}
210
+ </Text>
211
+ <View style={styles.statusLine}>
212
+ <View
213
+ style={[
214
+ styles.dot,
215
+ { backgroundColor: settled ? colors.successStrong : tone }
216
+ ]}
217
+ />
218
+ <Text
219
+ style={[styles.statusText, { color: settled ? colors.textSecondary : tone }]}
220
+ numberOfLines={1}
221
+ >
222
+ {time ? `${t(view.key)} · ${time}` : t(view.key)}
223
+ </Text>
224
+ </View>
225
+ </View>
226
+
227
+ <View style={styles.amounts}>
228
+ <Text style={[styles.amount, { color: amountColor }]}>
229
+ {value}
230
+ {unit ? <Text style={[styles.amountUnit, { color: unitColor }]}> {unit}</Text> : null}
231
+ </Text>
232
+ <Text style={[styles.amountSecondary, { color: colors.textTertiary }]}>{secondary}</Text>
233
+ </View>
234
+ </PressableScale>
235
+
236
+ {expanded && hasUtilities ? (
237
+ <View style={styles.chips}>
238
+ {busy ? (
239
+ <View style={styles.busyRow}>
240
+ <ActivityIndicator size="small" color={colors.textSecondary} />
241
+ {busyLabel ? (
242
+ <Text style={[styles.busyLabel, { color: colors.textSecondary }]} numberOfLines={1}>
243
+ {busyLabel}
244
+ </Text>
245
+ ) : null}
246
+ </View>
247
+ ) : (
248
+ <>
249
+ {action.txid && !parked && offlineStatus !== 'queued' && offlineStatus !== 'posting' ? (
250
+ <Chip
251
+ icon="refresh-outline"
252
+ label={t('tx_action_refresh_short')}
253
+ accessibilityLabel={t('tx_action_refresh')}
254
+ onPress={() => onRefreshTx(action.txid)}
255
+ />
256
+ ) : null}
257
+ {action.txid && !parked ? (
258
+ <Chip
259
+ icon="link-outline"
260
+ label="WoC"
261
+ accessibilityLabel={t('tx_action_explorer')}
262
+ onPress={() => onExplorer(action.txid)}
263
+ />
264
+ ) : null}
265
+ {canAbort ? (
266
+ <Chip
267
+ icon="close-circle-outline"
268
+ label={t('cancel')}
269
+ accessibilityLabel={t('tx_action_abort')}
270
+ danger
271
+ onPress={() => onAbort(action.reference!)}
272
+ />
273
+ ) : null}
274
+ {canResendDetails ? (
275
+ <Chip
276
+ icon="send-outline"
277
+ label={t('tx_action_resend_short')}
278
+ accessibilityLabel={t('send_payment_details_again')}
279
+ onPress={() => onSendPaymentDetails!(action.txid)}
280
+ />
281
+ ) : null}
282
+ {canCancelParked ? (
283
+ <Chip
284
+ icon="close-circle-outline"
285
+ label={t('cancel')}
286
+ accessibilityLabel={t('pay_parked_cancel')}
287
+ danger
288
+ onPress={() => onCancelParked!(action.txid)}
289
+ />
290
+ ) : null}
291
+ {canSendAgain ? (
292
+ <Chip
293
+ icon="arrow-redo-outline"
294
+ label={t('send_again')}
295
+ accessibilityLabel={t('send_again')}
296
+ onPress={() => onSendAgain!(action)}
297
+ />
298
+ ) : null}
299
+ </>
300
+ )}
301
+ </View>
302
+ ) : null}
303
+
304
+ {/* Inset to the description, not the screen edge: the rule separates the
305
+ text columns, and the glyph tiles already read as separate objects. An
306
+ expanded row is bounded by its own surface, so it needs no rule. */}
307
+ {expanded ? null : (
308
+ <View style={[styles.separator, { backgroundColor: colors.hairline }]} />
309
+ )}
310
+ </View>
311
+ )
312
+ }
313
+
314
+ function Chip({
315
+ icon,
316
+ label,
317
+ accessibilityLabel,
318
+ onPress,
319
+ danger
320
+ }: {
321
+ icon: keyof IoniconsComponent['glyphMap']
322
+ label: string
323
+ accessibilityLabel: string
324
+ onPress: () => void
325
+ danger?: boolean
326
+ }) {
327
+ const { colors } = useTheme()
328
+ const color = danger ? colors.error : colors.textSecondary
329
+ const Ionicons = loadIonicons()
330
+ return (
331
+ <PressableScale
332
+ onPress={onPress}
333
+ haptic="tap"
334
+ style={[
335
+ styles.chip,
336
+ { backgroundColor: colors.surfaceRaised, borderColor: colors.surfaceRaisedBorder }
337
+ ]}
338
+ accessibilityRole="button"
339
+ accessibilityLabel={accessibilityLabel}
340
+ >
341
+ <Ionicons name={icon} size={12} color={color} />
342
+ <Text style={[styles.chipLabel, { color }]}>{label}</Text>
343
+ </PressableScale>
344
+ )
345
+ }
346
+
347
+ const styles = StyleSheet.create({
348
+ row: {
349
+ flexDirection: 'row',
350
+ alignItems: 'center',
351
+ gap: spacing.md,
352
+ paddingHorizontal: spacing.xl,
353
+ paddingTop: 13,
354
+ paddingBottom: 11
355
+ },
356
+ glyph: {
357
+ width: 38,
358
+ height: 38,
359
+ borderRadius: 12,
360
+ borderWidth: StyleSheet.hairlineWidth,
361
+ alignItems: 'center',
362
+ justifyContent: 'center'
363
+ },
364
+ middle: { flex: 1, minWidth: 0 },
365
+ // 14.5/500 rather than body 17/400: the row is scanned, not read, and at 17pt
366
+ // the description crowds the amount on narrow phones.
367
+ description: { fontSize: 14.5, fontWeight: '500', letterSpacing: -0.1, lineHeight: 19 },
368
+ statusLine: { flexDirection: 'row', alignItems: 'center', gap: 6, marginTop: 3 },
369
+ dot: { width: 5, height: 5, borderRadius: 2.5 },
370
+ statusText: { fontSize: 12, lineHeight: 16, flexShrink: 1 },
371
+ amounts: { alignItems: 'flex-end' },
372
+ amount: { fontSize: 14.5, fontWeight: '600', lineHeight: 19, fontVariant: ['tabular-nums'] },
373
+ amountUnit: { fontSize: 12, fontWeight: '500' },
374
+ amountSecondary: { fontSize: 11.5, lineHeight: 15, marginTop: 2, fontVariant: ['tabular-nums'] },
375
+ chips: {
376
+ flexDirection: 'row',
377
+ flexWrap: 'wrap',
378
+ gap: spacing.sm,
379
+ paddingLeft: 70, // aligns the chip row with the description, past the glyph
380
+ paddingRight: spacing.xl,
381
+ paddingTop: 2,
382
+ paddingBottom: 14
383
+ },
384
+ busyRow: { flexDirection: 'row', alignItems: 'center', gap: spacing.sm, marginBottom: 8 },
385
+ busyLabel: { ...typography.subhead },
386
+ separator: { height: StyleSheet.hairlineWidth, marginLeft: 70 },
387
+ chip: {
388
+ flexDirection: 'row',
389
+ alignItems: 'center',
390
+ gap: 6,
391
+ paddingHorizontal: 11,
392
+ paddingVertical: 7,
393
+ borderRadius: radii.md,
394
+ borderWidth: StyleSheet.hairlineWidth
395
+ },
396
+ chipLabel: { fontSize: 12, fontWeight: '600' }
397
+ })
398
+
399
+ /** Rows are re-rendered only when something they actually show changes — the
400
+ * list re-renders on every status poll, and there can be hundreds of them. */
401
+ export default memo(ActivityRowBase, (a, b) =>
402
+ a.action === b.action &&
403
+ a.rowKey === b.rowKey &&
404
+ a.offlineStatus === b.offlineStatus &&
405
+ a.expanded === b.expanded &&
406
+ a.busy === b.busy &&
407
+ a.onToggle === b.onToggle
408
+ )
@@ -0,0 +1,48 @@
1
+ import React, { ReactNode, useState, useEffect, useContext } from 'react'
2
+ import { formatAmount, ExchangeRateContext, useWallet } from '@bsv/expo-wallet-toolbox'
3
+
4
+ type Props = {
5
+ abbreviate?: boolean
6
+ showPlus?: boolean
7
+ description?: string
8
+ color?: string
9
+ children: ReactNode
10
+ showFiatAsInteger?: boolean
11
+ }
12
+
13
+ /**
14
+ * AmountDisplay component shows an amount in the user's preferred currency format.
15
+ *
16
+ * In BSV mode (default): uses smart threshold formatting
17
+ * - < 1 BSV: displays as satoshis (e.g., "50,000 satoshis")
18
+ * - >= 1 BSV: displays as BSV (e.g., "1.5 BSV")
19
+ *
20
+ * In a fiat mode: displays the equivalent using WhatsOnChain USD and, for
21
+ * non-USD currencies, a cached USD cross.
22
+ *
23
+ * All formatting is locale-aware (respects device locale for separators).
24
+ *
25
+ * @param {number|string} props.children - The amount in satoshis to display
26
+ */
27
+ const AmountDisplay: React.FC<Props> = ({ abbreviate, showPlus, children, showFiatAsInteger }) => {
28
+ const [formatted, setFormatted] = useState('...')
29
+
30
+ const { settings } = useWallet()
31
+ const currency = settings?.currency || 'BSV'
32
+
33
+ const { satoshisPerUSD, usdToFiat = {} } = useContext(ExchangeRateContext)
34
+
35
+ useEffect(() => {
36
+ const numValue = Number(children)
37
+ if (!Number.isInteger(numValue)) {
38
+ setFormatted('...')
39
+ return
40
+ }
41
+
42
+ setFormatted(formatAmount(numValue, currency, satoshisPerUSD, { showPlus, abbreviate, showFiatAsInteger, usdToFiat }))
43
+ }, [children, currency, satoshisPerUSD, usdToFiat, showPlus, abbreviate, showFiatAsInteger])
44
+
45
+ return <>{formatted}</>
46
+ }
47
+
48
+ export default AmountDisplay