@bsv/expo-wallet-toolbox 0.4.0 → 0.7.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 (182) hide show
  1. package/CHANGELOG.md +547 -0
  2. package/README.md +19 -1
  3. package/assets/sounds/vault-deposit.wav +0 -0
  4. package/assets/sounds/vault-withdraw.wav +0 -0
  5. package/core/amountFormatHelpers.ts +238 -34
  6. package/core/backup/RemoteSyncReader.ts +2 -5
  7. package/core/backup/codec.ts +2 -2
  8. package/core/backup/push.ts +1 -1
  9. package/core/config.tsx +16 -1
  10. package/core/contacts/contactActivity.ts +153 -0
  11. package/core/contacts/contactCache.ts +41 -0
  12. package/core/contacts/contactsStore.ts +183 -0
  13. package/core/context/VaultContext.tsx +8 -11
  14. package/core/context/WalletConnectionContext.tsx +137 -52
  15. package/core/context/WalletContext.tsx +464 -30
  16. package/core/demo/demoAssets.ts +60 -0
  17. package/core/demo/demoLedger.ts +240 -0
  18. package/core/demo/demoMandalaRuntime.ts +96 -0
  19. package/core/demo/demoMode.ts +38 -0
  20. package/core/demo/demoWallet.ts +25 -0
  21. package/core/demo/index.ts +26 -0
  22. package/core/demo/useDemo.ts +59 -0
  23. package/core/headers/OfflineFirstChaintracks.ts +52 -14
  24. package/core/headers/headerStore.ts +7 -10
  25. package/core/hooks/useConfirmationSound.ts +14 -8
  26. package/core/i18n/translations.tsx +4562 -986
  27. package/core/identity/contactLink.ts +36 -0
  28. package/core/identity/handleRegistry/client.ts +285 -0
  29. package/core/identity/handleRegistry/profileCert.ts +254 -0
  30. package/core/identity/handleRegistry/registration.ts +559 -0
  31. package/core/identity/handleRegistry/resolver.ts +247 -0
  32. package/core/identity/handleRegistry/rules.ts +104 -0
  33. package/core/index.ts +116 -15
  34. package/core/localpay/build.ts +674 -37
  35. package/core/localpay/codec.ts +68 -5
  36. package/core/localpay/pending.ts +240 -22
  37. package/core/localpay/pendingAborts.ts +5 -1
  38. package/core/localpay/settlementAck.ts +149 -0
  39. package/core/localpay/types.ts +14 -1
  40. package/core/localpay/verify.ts +118 -69
  41. package/core/mandala/abortGuard.ts +134 -0
  42. package/core/mandala/basketMigration.ts +166 -0
  43. package/core/mandala/bundle.ts +244 -0
  44. package/core/mandala/createRuntime.ts +2437 -0
  45. package/core/mandala/drain.ts +670 -0
  46. package/core/mandala/permissionModule.ts +642 -0
  47. package/core/mandala/resendTransfer.ts +175 -0
  48. package/core/mandala/runtime.ts +357 -0
  49. package/core/mandala/settlementStore.ts +412 -0
  50. package/core/mandala/types.ts +290 -0
  51. package/core/monitor/MonitorSupervisor.ts +121 -0
  52. package/core/monitor/TaskBackupPush.ts +1 -1
  53. package/core/monitor/TaskCreditInbox.ts +1 -1
  54. package/core/monitor/TaskDrainOutbox.ts +1 -1
  55. package/core/monitor/TaskSendOffline.ts +1 -1
  56. package/core/net/online.ts +49 -0
  57. package/core/numberFormat.ts +19 -0
  58. package/core/offline/cancelParked.ts +94 -1
  59. package/core/offline/payerHold.ts +152 -12
  60. package/core/offline/plan.ts +1 -1
  61. package/core/offline/tokenFrames.ts +197 -0
  62. package/core/parsePeerPayURI.ts +70 -17
  63. package/core/pay/rails/address.ts +51 -3
  64. package/core/pay/rails/handle.ts +88 -9
  65. package/core/pay/rails/index.ts +16 -6
  66. package/core/pay/rails/nearby.ts +114 -4
  67. package/core/pay/recordProof.ts +2 -6
  68. package/core/services/arcadeBroadcastProvider.ts +1 -4
  69. package/core/services/capWalletArgs.ts +8 -9
  70. package/core/services/exchangeRate.ts +1 -1
  71. package/core/services/externalOrigin.ts +42 -0
  72. package/core/services/vault/VaultKeyService.ts +912 -251
  73. package/core/services/vault/ceremony.ts +435 -367
  74. package/core/services/vault/ceremonyHost.ts +27 -21
  75. package/core/services/vault/devMock.ts +30 -7
  76. package/core/services/vault/driver.ts +95 -41
  77. package/core/services/vault/guard.ts +514 -56
  78. package/core/services/vault/hardwareLease.ts +22 -0
  79. package/core/services/vault/mockYubiKey.ts +258 -90
  80. package/core/services/vault/pivReset.ts +145 -0
  81. package/core/services/vault/r1comb.ts +976 -0
  82. package/core/services/vault/session.ts +93 -26
  83. package/core/services/vault/transfers.ts +2617 -747
  84. package/core/services/vault/types.ts +100 -43
  85. package/core/services/vault/vaultStore.ts +991 -74
  86. package/core/services/walletConnectionValidation.ts +293 -0
  87. package/core/services/walletServiceConfig.ts +31 -20
  88. package/core/storage/StorageExpoSQLite.ts +420 -87
  89. package/core/storage/dbImage.ts +48 -0
  90. package/core/storage/methods/findSql.ts +3 -54
  91. package/core/storage/methods/listActionsSql.ts +8 -5
  92. package/core/storage/methods/listOutputsSql.ts +9 -5
  93. package/core/storage/methods/offlineActions.ts +15 -0
  94. package/core/storage/methods/processOfflineActions.ts +265 -9
  95. package/core/storage/methods/reviewStatusSql.ts +7 -2
  96. package/core/storage/methods/walletBalanceSql.ts +16 -4
  97. package/core/storage/schema/createTables.ts +152 -0
  98. package/core/storage/sqlUpdateValue.ts +24 -0
  99. package/core/toolboxConfig.ts +182 -1
  100. package/core/toolboxTypes.ts +40 -0
  101. package/core/userAvatar.ts +79 -0
  102. package/core/walletMonitor.ts +8 -3
  103. package/core/walletRepair/runWalletCheck.ts +19 -2
  104. package/package.json +31 -30
  105. package/ui/activityFilter.ts +115 -0
  106. package/ui/components/QRScanner.tsx +1 -1
  107. package/ui/components/pay/AdmissionNotice.tsx +99 -0
  108. package/ui/components/pay/AssetPicker.tsx +184 -0
  109. package/ui/components/pay/AvailableBalance.tsx +33 -2
  110. package/ui/components/pay/HandleReceive.tsx +213 -50
  111. package/ui/components/pay/NearbyFlow.tsx +616 -69
  112. package/ui/components/pay/PayForm.tsx +73 -8
  113. package/ui/components/pay/PaymentSuccessOverlay.tsx +89 -8
  114. package/ui/components/pay/RecipientField.tsx +132 -73
  115. package/ui/components/pay/RequestHub.tsx +68 -8
  116. package/ui/components/pay/ResultBanner.tsx +41 -4
  117. package/ui/components/pay/StepBar.tsx +32 -0
  118. package/ui/components/pay/UniversalSend.tsx +1118 -86
  119. package/ui/components/pay/tokenSendCopy.ts +116 -0
  120. package/ui/components/pay/useRecipientInput.ts +36 -7
  121. package/ui/components/ui/PencilEditField.tsx +109 -0
  122. package/ui/components/ui/PermissionSheet.tsx +65 -4
  123. package/ui/components/ui/Sheet.tsx +9 -2
  124. package/ui/components/ui/SlideOverFromRight.tsx +86 -0
  125. package/ui/components/vault/EnrollWizard.tsx +1432 -488
  126. package/ui/components/vault/KeyChooser.tsx +96 -0
  127. package/ui/components/vault/VaultCeremonySheet.tsx +107 -43
  128. package/ui/components/vault/vaultErrorCopy.ts +145 -0
  129. package/ui/components/wallet/ActivityRow.tsx +283 -97
  130. package/ui/components/wallet/AmountInput.tsx +92 -28
  131. package/ui/components/wallet/AssetAmount.tsx +95 -0
  132. package/ui/components/wallet/AssetSwitcherDropdown.tsx +261 -0
  133. package/ui/components/wallet/ContactActivityList.tsx +149 -0
  134. package/ui/components/wallet/ContactSigil.tsx +49 -0
  135. package/ui/components/wallet/EditPictureSheet.tsx +99 -0
  136. package/ui/components/wallet/FitAmount.tsx +148 -0
  137. package/ui/components/wallet/IconPickerSheet.tsx +168 -0
  138. package/ui/components/wallet/IdentifierRow.tsx +69 -0
  139. package/ui/components/wallet/ImportFromBackupPrompt.tsx +35 -13
  140. package/ui/components/wallet/ProfileButton.tsx +62 -0
  141. package/ui/components/wallet/UserAvatar.tsx +85 -0
  142. package/ui/components/wallet/avatarIcons.ts +122 -0
  143. package/ui/components/wallet/tokenEviction.ts +65 -0
  144. package/ui/hooks/useContactsStore.ts +10 -0
  145. package/ui/hooks/useExportWalletData.ts +39 -0
  146. package/ui/hooks/useMandala.ts +320 -0
  147. package/ui/hooks/useOnline.ts +65 -20
  148. package/ui/hooks/useVaultBalance.ts +105 -7
  149. package/ui/hooks/useVaultCoverage.ts +52 -0
  150. package/ui/importDatabases.ts +7 -3
  151. package/ui/index.ts +75 -7
  152. package/ui/screens/ConnectionsScreen.tsx +46 -29
  153. package/ui/screens/ContactScreen.tsx +289 -0
  154. package/ui/screens/ContactsScreen.tsx +373 -0
  155. package/ui/screens/IdentifierScreen.tsx +234 -0
  156. package/ui/screens/NewContactScreen.tsx +362 -0
  157. package/ui/screens/PairScreen.tsx +12 -12
  158. package/ui/screens/PayScreen.tsx +145 -12
  159. package/ui/screens/ProfileScreen.tsx +783 -0
  160. package/ui/screens/SettingsScreen.tsx +18 -9
  161. package/ui/screens/TransactionDetailScreen.tsx +419 -0
  162. package/ui/screens/TrustScreen.tsx +1 -1
  163. package/ui/screens/VaultScreen.tsx +925 -171
  164. package/ui/screens/VaultTransferScreen.tsx +376 -123
  165. package/ui/screens/WalletCheckScreen.tsx +10 -1
  166. package/ui/screens/WalletConfigScreen.tsx +80 -16
  167. package/ui/screens/WalletHomeScreen.tsx +915 -139
  168. package/ui/screens/homeBadges.ts +9 -1
  169. package/ui/screens/tokenRowTitle.ts +68 -0
  170. package/ui/tokenFormat.ts +108 -0
  171. package/ui/tokenSeen.ts +75 -0
  172. package/ui/tokenStatus.ts +100 -0
  173. package/ui/txStatus.ts +43 -5
  174. package/assets/sounds/vault-close.wav +0 -0
  175. package/assets/sounds/vault-open.wav +0 -0
  176. package/core/services/vault/k1.ts +0 -75
  177. package/core/services/vault/sealing.ts +0 -84
  178. package/core/services/vault/vaultDerivation.ts +0 -152
  179. package/core/services/vault/vaultPassphrase.ts +0 -287
  180. package/ui/components/vault/PassphraseField.tsx +0 -306
  181. package/ui/components/vault/PhraseBackupSheet.tsx +0 -227
  182. package/ui/screens/VaultRecoverScreen.tsx +0 -226
@@ -0,0 +1,149 @@
1
+ /**
2
+ * The "ACTIVITY" block of a contact: every interaction with them, drawn with
3
+ * the SAME row Home uses (sigil tile, description, status dot + time, the
4
+ * figure in the display currency with the other denomination beneath), so a
5
+ * payment looks identical whether you find it on Home or on the person.
6
+ *
7
+ * A token settlement has no wallet action of its own here — `getContactActivity`
8
+ * reads it straight off `token_settlements` — so this builds the minimal
9
+ * action `ActivityRow` needs around it and hands the token facts through the
10
+ * row's own `token` prop, exactly as Home does for a `'mandala'`-labelled row.
11
+ */
12
+ import React, { useCallback, useMemo, useState } from 'react'
13
+ import { Linking, StyleSheet, Text, View } from 'react-native'
14
+ import { useTranslation } from 'react-i18next'
15
+ import { useTheme, spacing, typography, useWallet } from '@bsv/expo-wallet-toolbox'
16
+ import ActivityRow, { type ActivityAction } from './ActivityRow'
17
+ import { showToast } from '../ui/Toast'
18
+ import { useMandala } from '../../hooks/useMandala'
19
+ import { formatTokenAmount } from '../../tokenFormat'
20
+ import { tokenRowStatusView } from '../../tokenStatus'
21
+ import type { TokenActivityStatus } from '../../../core/mandala/runtime'
22
+ import type { ContactActivityItem, ContactSettlementRow } from '../../../core/contacts/contactActivity'
23
+
24
+ /** Same reading of a settlement's `state` as the runtime's `activityStatusOf`,
25
+ * minus the "stuck after N hours" clock — a contact page is a record, not a
26
+ * queue, so an old unsettled row reads as "settling" rather than as a fault
27
+ * to act on (the acting happens on Home). */
28
+ function statusOf(row: ContactSettlementRow): TokenActivityStatus {
29
+ switch (row.state) {
30
+ case 'broadcast':
31
+ case 'admitted':
32
+ return 'settled'
33
+ case 'refused':
34
+ return 'refused'
35
+ case 'orphaned':
36
+ return 'reversed'
37
+ default:
38
+ return 'settling'
39
+ }
40
+ }
41
+
42
+ const noop = () => {}
43
+
44
+ export default function ContactActivityList({
45
+ items,
46
+ identityKey
47
+ }: {
48
+ items: ContactActivityItem[]
49
+ identityKey: string
50
+ }) {
51
+ const { t } = useTranslation()
52
+ const { colors } = useTheme()
53
+ const { settings, selectedNetwork } = useWallet()
54
+ const mandala = useMandala()
55
+ const currency = settings?.currency || 'BSV'
56
+ const [expanded, setExpanded] = useState<string | null>(null)
57
+ const onToggle = useCallback((key: string) => setExpanded(prev => (prev === key ? null : key)), [])
58
+
59
+ const onExplorer = useCallback(
60
+ (txid: string) => {
61
+ const base =
62
+ selectedNetwork === 'main'
63
+ ? 'https://whatsonchain.com'
64
+ : selectedNetwork === 'teratest'
65
+ ? 'https://woc-ttn.bsvblockchain.tech'
66
+ : 'https://test.whatsonchain.com'
67
+ Linking.openURL(`${base}/tx/${txid}`).catch(() => showToast(t('explorer_open_failed'), { type: 'error' }))
68
+ },
69
+ [selectedNetwork, t]
70
+ )
71
+
72
+ const rows = useMemo(
73
+ () =>
74
+ items.map(item => {
75
+ const key = `${item.kind}:${item.txid}`
76
+ if (item.kind === 'bsv') {
77
+ return { key, action: item as unknown as ActivityAction, token: undefined }
78
+ }
79
+ const holding = (mandala.balances ?? []).find(b => b.asset.assetId === item.assetId)
80
+ const ticker = holding?.asset.ticker ?? item.assetId.slice(0, 8)
81
+ const incoming = item.role === 'received'
82
+ const figure =
83
+ holding && item.amountBaseUnits !== undefined
84
+ ? formatTokenAmount(incoming ? item.amountBaseUnits : -item.amountBaseUnits, holding.asset.decimals, {
85
+ showPlus: incoming
86
+ })
87
+ : undefined
88
+ const action: ActivityAction = {
89
+ txid: item.txid,
90
+ satoshis: 0,
91
+ status: 'completed',
92
+ isOutgoing: !incoming,
93
+ description: '',
94
+ labels: ['mandala'],
95
+ created_at: item.createdAt
96
+ } as unknown as ActivityAction
97
+ return {
98
+ key,
99
+ action,
100
+ token: {
101
+ title: t(incoming ? 'token_row_received' : 'token_row_sent', { ticker }),
102
+ amount: figure ? { value: figure, unit: ticker } : undefined,
103
+ incoming,
104
+ counterpartyKey: identityKey,
105
+ status: tokenRowStatusView(statusOf(item), incoming),
106
+ statusText: t(tokenRowStatusView(statusOf(item), incoming).key)
107
+ }
108
+ }
109
+ }),
110
+ [items, mandala.balances, identityKey, t]
111
+ )
112
+
113
+ if (rows.length === 0) {
114
+ return <Text style={[styles.empty, { color: colors.textSecondary }]}>{t('contact_activity_empty')}</Text>
115
+ }
116
+
117
+ return (
118
+ <View>
119
+ {rows.map(({ key, action, token }, idx) => (
120
+ <View
121
+ key={key}
122
+ style={
123
+ idx < rows.length - 1 && {
124
+ borderBottomWidth: StyleSheet.hairlineWidth,
125
+ borderBottomColor: colors.separator
126
+ }
127
+ }
128
+ >
129
+ <ActivityRow
130
+ currency={currency}
131
+ action={action}
132
+ rowKey={key}
133
+ token={token}
134
+ expanded={expanded === key}
135
+ busy={false}
136
+ onToggle={onToggle}
137
+ onExplorer={onExplorer}
138
+ onRefreshTx={noop}
139
+ onAbort={noop}
140
+ />
141
+ </View>
142
+ ))}
143
+ </View>
144
+ )
145
+ }
146
+
147
+ const styles = StyleSheet.create({
148
+ empty: { ...typography.footnote, paddingHorizontal: spacing.xl, paddingVertical: spacing.sm }
149
+ })
@@ -0,0 +1,49 @@
1
+ /**
2
+ * A counterparty's face: their avatar when one is known, otherwise always
3
+ * their generative sigil — never an initials placeholder (2026-09-18 design
4
+ * ruling). Shared by Contacts, Contact, New Contact and Pay's recipient card,
5
+ * so all four draw the same face for the same identity key.
6
+ */
7
+ import React from 'react'
8
+ import { Image, StyleSheet, View } from 'react-native'
9
+ import { useTheme, counterpartyHue, sigilPointOf, sigilPalette, type Counterparty } from '@bsv/expo-wallet-toolbox'
10
+ import Sigil from '../ui/Sigil'
11
+
12
+ export default function ContactSigil({
13
+ identityKey,
14
+ avatarUrl,
15
+ size = 38,
16
+ radius = 12
17
+ }: {
18
+ identityKey: string
19
+ avatarUrl?: string
20
+ size?: number
21
+ radius?: number
22
+ }) {
23
+ const { isDark } = useTheme()
24
+ if (avatarUrl) {
25
+ return (
26
+ <Image source={{ uri: avatarUrl }} style={[styles.tile, { width: size, height: size, borderRadius: radius }]} />
27
+ )
28
+ }
29
+ const cp: Counterparty = { kind: 'identityKey', value: identityKey }
30
+ const point = sigilPointOf(cp)
31
+ const palette = sigilPalette(counterpartyHue(cp), isDark)
32
+ return (
33
+ <View
34
+ style={[styles.tile, { width: size, height: size, borderRadius: radius, backgroundColor: palette.background }]}
35
+ >
36
+ <Sigil
37
+ point={point}
38
+ size={size}
39
+ foreground={palette.foreground}
40
+ background={palette.background}
41
+ detail="default"
42
+ />
43
+ </View>
44
+ )
45
+ }
46
+
47
+ const styles = StyleSheet.create({
48
+ tile: { alignItems: 'center', justifyContent: 'center', overflow: 'hidden' }
49
+ })
@@ -0,0 +1,99 @@
1
+ /**
2
+ * "Edit picture" — the stacked pill buttons that choose where an avatar comes
3
+ * from.
4
+ *
5
+ * Today that is one source: a picked icon. Take Photo and Photo Library are
6
+ * deliberately ABSENT rather than present-and-inert — they need
7
+ * `expo-image-picker`, a native dependency this build does not carry, and a
8
+ * button that does nothing when tapped is worse than a button that is not
9
+ * there (the same reasoning that kept a dead "Add photo" control off this
10
+ * screen originally). Add the two entries here once the dependency lands.
11
+ */
12
+ import React from 'react'
13
+ import { Modal, Pressable, StyleSheet, Text, View } from 'react-native'
14
+ import { useTranslation } from 'react-i18next'
15
+ import Animated, { useAnimatedStyle, useReducedMotion, useSharedValue, withTiming } from 'react-native-reanimated'
16
+ import { durations, easings, radii, spacing, typography, useTheme } from '@bsv/expo-wallet-toolbox'
17
+ import PressableScale from '../ui/PressableScale'
18
+
19
+ export interface EditPictureOption {
20
+ key: string
21
+ label: string
22
+ onPress: () => void
23
+ }
24
+
25
+ export default function EditPictureSheet({
26
+ visible,
27
+ options,
28
+ onClose
29
+ }: {
30
+ visible: boolean
31
+ options: EditPictureOption[]
32
+ onClose: () => void
33
+ }) {
34
+ const { colors } = useTheme()
35
+ const { t } = useTranslation()
36
+ const reduced = useReducedMotion()
37
+ const progress = useSharedValue(0)
38
+
39
+ React.useEffect(() => {
40
+ progress.value = withTiming(visible ? 1 : 0, {
41
+ duration: visible ? durations.quick : durations.instant,
42
+ easing: easings.out
43
+ })
44
+ }, [visible, progress])
45
+
46
+ const cardStyle = useAnimatedStyle(() =>
47
+ reduced
48
+ ? { opacity: progress.value, transform: [{ translateY: 0 }] }
49
+ : { opacity: progress.value, transform: [{ translateY: (1 - progress.value) * 24 }] }
50
+ )
51
+ const scrimStyle = useAnimatedStyle(() => ({ opacity: progress.value }))
52
+
53
+ return (
54
+ <Modal visible={visible} transparent animationType="none" onRequestClose={onClose}>
55
+ <View style={StyleSheet.absoluteFill}>
56
+ <Animated.View style={[StyleSheet.absoluteFill, scrimStyle]}>
57
+ <Pressable style={[StyleSheet.absoluteFill, { backgroundColor: colors.scrim }]} onPress={onClose} />
58
+ </Animated.View>
59
+ <Animated.View style={[styles.wrap, cardStyle]} pointerEvents="box-none">
60
+ <View style={[styles.card, { backgroundColor: colors.sheetBackground }]}>
61
+ {options.map(opt => (
62
+ <PressableScale
63
+ key={opt.key}
64
+ haptic="tap"
65
+ onPress={() => {
66
+ onClose()
67
+ opt.onPress()
68
+ }}
69
+ accessibilityRole="button"
70
+ style={[styles.pill, { backgroundColor: colors.fillTertiary }]}
71
+ >
72
+ <Text style={[styles.pillLabel, { color: colors.textPrimary }]}>{opt.label}</Text>
73
+ </PressableScale>
74
+ ))}
75
+ </View>
76
+ <PressableScale
77
+ haptic="tap"
78
+ onPress={onClose}
79
+ accessibilityRole="button"
80
+ style={[styles.cancel, { backgroundColor: colors.sheetBackground }]}
81
+ >
82
+ <Text style={[styles.pillLabel, styles.cancelLabel, { color: colors.accent }]}>
83
+ {t('cancel', { defaultValue: 'Cancel' })}
84
+ </Text>
85
+ </PressableScale>
86
+ </Animated.View>
87
+ </View>
88
+ </Modal>
89
+ )
90
+ }
91
+
92
+ const styles = StyleSheet.create({
93
+ wrap: { position: 'absolute', left: 0, right: 0, bottom: 0, padding: spacing.md, paddingBottom: spacing.xxxl },
94
+ card: { borderRadius: radii.xl, padding: spacing.sm, gap: spacing.sm },
95
+ pill: { borderRadius: radii.lg, paddingVertical: spacing.lg, alignItems: 'center' },
96
+ pillLabel: { ...typography.title3, fontWeight: '600' },
97
+ cancel: { borderRadius: radii.xl, paddingVertical: spacing.lg, alignItems: 'center', marginTop: spacing.sm },
98
+ cancelLabel: { fontWeight: '700' }
99
+ })
@@ -0,0 +1,148 @@
1
+ import React, { useCallback, useState } from 'react'
2
+ import {
3
+ StyleSheet,
4
+ Text,
5
+ View,
6
+ type LayoutChangeEvent,
7
+ type NativeSyntheticEvent,
8
+ type StyleProp,
9
+ type TextLayoutEventData,
10
+ type TextStyle
11
+ } from 'react-native'
12
+ import { splitAmountFraction } from '../../../core/amountFormatHelpers'
13
+
14
+ /**
15
+ * Never let a figure be smaller than this, so a pathological value stays
16
+ * legible rather than collapsing (iOS Fabric's own fit-to-width bottoms out at
17
+ * 4pt and ignores `minimumFontScale`, which is why this measures instead).
18
+ */
19
+ const MIN_FONT_SIZE = 12
20
+
21
+ /** Headroom for rounding and the trailing space a wrapped line drops. */
22
+ const FIT_MARGIN = 0.98
23
+
24
+ /** Ignore width changes smaller than this, so rounding never re-triggers a fit. */
25
+ const WIDTH_EPSILON = 1
26
+
27
+ export interface FitAmountProps {
28
+ value: string
29
+ unit?: string
30
+ /** Style of the figure. Its fontSize, lineHeight and letterSpacing are scaled together. */
31
+ style: StyleProp<TextStyle>
32
+ unitStyle?: StyleProp<TextStyle>
33
+ /**
34
+ * When set, the minor units are drawn in this style and hung from the top,
35
+ * the way a price tag writes cents. Its fontSize, lineHeight and
36
+ * letterSpacing scale with the figure; marginTop stays, matching `style`'s.
37
+ */
38
+ fractionStyle?: StyleProp<TextStyle>
39
+ }
40
+
41
+ /**
42
+ * A figure that always sits on one line: however long `value` is, the type
43
+ * shrinks until it fits the width it is given, and grows back to full size
44
+ * when a shorter value arrives.
45
+ *
46
+ * Two facts drive it: the width of the slot (the wrapper's layout) and the
47
+ * width the figure takes on one line at full size (from `onTextLayout`). Width
48
+ * scales linearly with font size, so the scale is simply their ratio. Each is
49
+ * stored as it arrives and the scale is derived from both, so it does not
50
+ * matter which the platform reports first. Nothing is ellipsized or wrapped, so
51
+ * no digit is ever hidden.
52
+ */
53
+ export function FitAmount({ value, unit, style, unitStyle, fractionStyle }: FitAmountProps) {
54
+ const [available, setAvailable] = useState(0)
55
+ const [fullWidth, setFullWidth] = useState(0)
56
+
57
+ const base = StyleSheet.flatten(style) ?? {}
58
+ const baseSize = base.fontSize ?? 17
59
+ const unitBase = StyleSheet.flatten(unitStyle) ?? {}
60
+ const floor = Math.min(1, MIN_FONT_SIZE / baseSize)
61
+
62
+ const scale = available > 0 && fullWidth > 0 ? Math.min(1, Math.max(floor, (available / fullWidth) * FIT_MARGIN)) : 1
63
+
64
+ const onLayout = useCallback((e: LayoutChangeEvent) => {
65
+ const width = e.nativeEvent.layout.width
66
+ setAvailable(prev => (Math.abs(prev - width) > WIDTH_EPSILON ? width : prev))
67
+ }, [])
68
+
69
+ // `scale` is the size this layout was produced at, which turns the width it
70
+ // reports back into the full-size width.
71
+ const onTextLayout = useCallback(
72
+ (e: NativeSyntheticEvent<TextLayoutEventData>) => {
73
+ // A figure that overflowed wraps, so the widths of all its lines add up to
74
+ // the width it would take on one.
75
+ const natural = e.nativeEvent.lines.reduce((sum, line) => sum + line.width, 0)
76
+ if (natural <= 0) return
77
+ const full = natural / scale
78
+ setFullWidth(prev => (Math.abs(prev - full) > WIDTH_EPSILON ? full : prev))
79
+ },
80
+ [scale]
81
+ )
82
+
83
+ const scaled: TextStyle = {
84
+ fontSize: baseSize * scale,
85
+ ...(base.lineHeight != null ? { lineHeight: base.lineHeight * scale } : null),
86
+ ...(base.letterSpacing != null ? { letterSpacing: base.letterSpacing * scale } : null)
87
+ }
88
+
89
+ const unitScaled = unitBase.fontSize != null ? { fontSize: unitBase.fontSize * scale } : null
90
+ const unitRun = unit ? <Text style={[unitStyle, unitScaled]}> {unit}</Text> : null
91
+
92
+ const parts = fractionStyle ? splitAmountFraction(value) : null
93
+ if (!parts?.frac) {
94
+ return (
95
+ <View onLayout={onLayout} style={styles.fill}>
96
+ <Text style={[style, scaled]} onTextLayout={onTextLayout}>
97
+ {value}
98
+ {unitRun}
99
+ </Text>
100
+ </View>
101
+ )
102
+ }
103
+
104
+ const frac = StyleSheet.flatten(fractionStyle) ?? {}
105
+ const fracScaled: TextStyle = {
106
+ ...(frac.fontSize != null ? { fontSize: frac.fontSize * scale } : null),
107
+ ...(frac.lineHeight != null ? { lineHeight: frac.lineHeight * scale } : null),
108
+ ...(frac.letterSpacing != null ? { letterSpacing: frac.letterSpacing * scale } : null)
109
+ }
110
+
111
+ // Raised cents need separate <Text>s in a row (nested text baseline-aligns
112
+ // and cannot be lifted), but only one <Text> can report a width. So a hidden
113
+ // copy holds the same runs nested, at the same sizes, and does the measuring;
114
+ // its width is the row's width.
115
+ return (
116
+ <View onLayout={onLayout} style={styles.fill}>
117
+ <Text
118
+ style={[style, scaled, styles.measure]}
119
+ onTextLayout={onTextLayout}
120
+ accessibilityElementsHidden
121
+ importantForAccessibility="no-hide-descendants"
122
+ >
123
+ {parts.head}
124
+ <Text style={[fractionStyle, fracScaled, styles.noMargin]}>{parts.frac}</Text>
125
+ {parts.tail}
126
+ {unitRun}
127
+ </Text>
128
+ <View style={styles.row}>
129
+ <Text style={[style, scaled]}>{parts.head}</Text>
130
+ <Text style={[fractionStyle, fracScaled]}>{parts.frac}</Text>
131
+ {parts.tail || unit ? (
132
+ <Text style={[style, scaled]}>
133
+ {parts.tail}
134
+ {unitRun}
135
+ </Text>
136
+ ) : null}
137
+ </View>
138
+ </View>
139
+ )
140
+ }
141
+
142
+ const styles = StyleSheet.create({
143
+ fill: { alignSelf: 'stretch', alignItems: 'center' },
144
+ // `flex-start` hangs the minor units from the top of the figure's line box.
145
+ row: { flexDirection: 'row', alignItems: 'flex-start' },
146
+ measure: { position: 'absolute', opacity: 0 },
147
+ noMargin: { marginTop: 0 }
148
+ })
@@ -0,0 +1,168 @@
1
+ /**
2
+ * Pick an avatar icon — a bottom sheet with a scrollable, grouped grid.
3
+ *
4
+ * Grouped with a heading per section rather than one long grid: 67 glyphs in
5
+ * an undifferentiated wall is a search problem, and the headings turn it into
6
+ * "go to Animals". Same shape as the workspace-icon picker this was modelled
7
+ * on.
8
+ *
9
+ * Six columns, sized from the viewport rather than fixed, so the tiles stay
10
+ * square and tappable from the narrowest phone up.
11
+ */
12
+ import React from 'react'
13
+ import { Modal, Pressable, ScrollView, StyleSheet, Text, useWindowDimensions, View } from 'react-native'
14
+ import { useTranslation } from 'react-i18next'
15
+ import Animated, { useAnimatedStyle, useReducedMotion, useSharedValue, withTiming } from 'react-native-reanimated'
16
+ import {
17
+ durations,
18
+ easings,
19
+ radii,
20
+ spacing,
21
+ typography,
22
+ useTheme,
23
+ useUserAvatarIcon,
24
+ setUserAvatarIcon,
25
+ type AvatarIcon
26
+ } from '@bsv/expo-wallet-toolbox'
27
+ import PressableScale from '../ui/PressableScale'
28
+ import { AvatarGlyph } from './UserAvatar'
29
+ import { AVATAR_ICON_GROUPS } from './avatarIcons'
30
+
31
+ const COLUMNS = 6
32
+
33
+ export default function IconPickerSheet({ visible, onClose }: { visible: boolean; onClose: () => void }) {
34
+ const { colors } = useTheme()
35
+ const { t } = useTranslation()
36
+ const { width, height } = useWindowDimensions()
37
+ const reduced = useReducedMotion()
38
+ const chosen = useUserAvatarIcon()
39
+ const progress = useSharedValue(0)
40
+
41
+ React.useEffect(() => {
42
+ progress.value = withTiming(visible ? 1 : 0, {
43
+ duration: visible ? durations.moderate : durations.quick,
44
+ easing: easings.out
45
+ })
46
+ }, [visible, progress])
47
+
48
+ // Rises from the bottom edge; reduced motion crossfades in place instead.
49
+ const sheetStyle = useAnimatedStyle(() =>
50
+ reduced
51
+ ? { opacity: progress.value, transform: [{ translateY: 0 }] }
52
+ : { opacity: 1, transform: [{ translateY: (1 - progress.value) * height }] }
53
+ )
54
+ const scrimStyle = useAnimatedStyle(() => ({ opacity: progress.value }))
55
+
56
+ const tile = Math.floor((width - spacing.lg * 2 - spacing.sm * (COLUMNS - 1)) / COLUMNS)
57
+
58
+ const pick = (icon: AvatarIcon) => {
59
+ setUserAvatarIcon(icon)
60
+ onClose()
61
+ }
62
+
63
+ return (
64
+ <Modal visible={visible} transparent animationType="none" onRequestClose={onClose}>
65
+ <View style={StyleSheet.absoluteFill}>
66
+ <Animated.View style={[StyleSheet.absoluteFill, scrimStyle]}>
67
+ <Pressable style={[StyleSheet.absoluteFill, { backgroundColor: colors.scrim }]} onPress={onClose} />
68
+ </Animated.View>
69
+ <Animated.View
70
+ style={[
71
+ styles.sheet,
72
+ { backgroundColor: colors.sheetBackground, maxHeight: height * 0.75 },
73
+ sheetStyle
74
+ ]}
75
+ >
76
+ <View style={[styles.grabber, { backgroundColor: colors.separator }]} />
77
+ <Text style={[styles.title, { color: colors.textPrimary }]}>
78
+ {t('avatar_pick_icon', { defaultValue: 'Pick icon' })}
79
+ </Text>
80
+ <ScrollView contentContainerStyle={styles.scroll} showsVerticalScrollIndicator={false}>
81
+ {AVATAR_ICON_GROUPS.map(group => (
82
+ <View key={group.labelKey} style={styles.group}>
83
+ <Text style={[styles.groupLabel, { color: colors.textTertiary }]}>
84
+ {t(group.labelKey, { defaultValue: group.labelFallback })}
85
+ </Text>
86
+ <View style={styles.grid}>
87
+ {group.icons.map(opt => {
88
+ const selected = chosen?.family === opt.family && chosen?.name === opt.name
89
+ return (
90
+ <PressableScale
91
+ key={`${opt.family}/${opt.name}`}
92
+ haptic="tap"
93
+ onPress={() => pick(opt)}
94
+ accessibilityRole="button"
95
+ accessibilityState={{ selected }}
96
+ accessibilityLabel={opt.name}
97
+ style={[
98
+ styles.tile,
99
+ {
100
+ width: tile,
101
+ height: tile,
102
+ borderRadius: radii.md,
103
+ backgroundColor: selected ? colors.accent : colors.fillTertiary,
104
+ borderColor: selected ? colors.accent : colors.separator
105
+ }
106
+ ]}
107
+ >
108
+ <AvatarGlyph
109
+ family={opt.family}
110
+ name={opt.name}
111
+ size={Math.round(tile * 0.55)}
112
+ color={selected ? colors.textOnAccent : colors.textPrimary}
113
+ />
114
+ </PressableScale>
115
+ )
116
+ })}
117
+ </View>
118
+ </View>
119
+ ))}
120
+ {/* Back to the plain disc — an avatar has to be removable, or the
121
+ first pick is permanent. */}
122
+ {chosen ? (
123
+ <PressableScale
124
+ haptic="tap"
125
+ onPress={() => {
126
+ setUserAvatarIcon(null)
127
+ onClose()
128
+ }}
129
+ style={[styles.clear, { borderColor: colors.separator }]}
130
+ >
131
+ <Text style={[styles.clearLabel, { color: colors.error }]}>
132
+ {t('avatar_remove', { defaultValue: 'Remove picture' })}
133
+ </Text>
134
+ </PressableScale>
135
+ ) : null}
136
+ </ScrollView>
137
+ </Animated.View>
138
+ </View>
139
+ </Modal>
140
+ )
141
+ }
142
+
143
+ const styles = StyleSheet.create({
144
+ sheet: {
145
+ position: 'absolute',
146
+ left: 0,
147
+ right: 0,
148
+ bottom: 0,
149
+ borderTopLeftRadius: radii.xl,
150
+ borderTopRightRadius: radii.xl,
151
+ paddingBottom: spacing.xxxl
152
+ },
153
+ grabber: { width: 36, height: 4, borderRadius: 2, alignSelf: 'center', marginTop: spacing.sm },
154
+ title: { ...typography.headline, textAlign: 'center', marginTop: spacing.md, marginBottom: spacing.sm },
155
+ scroll: { paddingHorizontal: spacing.lg, paddingBottom: spacing.lg },
156
+ group: { marginTop: spacing.lg },
157
+ groupLabel: { ...typography.caption1, textTransform: 'uppercase', letterSpacing: 0.6, marginBottom: spacing.sm },
158
+ grid: { flexDirection: 'row', flexWrap: 'wrap', gap: spacing.sm },
159
+ tile: { alignItems: 'center', justifyContent: 'center', borderWidth: StyleSheet.hairlineWidth },
160
+ clear: {
161
+ marginTop: spacing.xl,
162
+ paddingVertical: spacing.md,
163
+ borderRadius: radii.lg,
164
+ borderWidth: StyleSheet.hairlineWidth,
165
+ alignItems: 'center'
166
+ },
167
+ clearLabel: { ...typography.body, fontWeight: '600' }
168
+ })
@@ -0,0 +1,69 @@
1
+ /**
2
+ * The "IDENTIFIER" row of a grouped card: the key abbreviated in monospace
3
+ * with a copy button on the right. Shared by Contact, New Contact and
4
+ * Profile so the same key reads the same way on all three.
5
+ */
6
+ import React, { useCallback } from 'react'
7
+ import { StyleSheet, Text, View } from 'react-native'
8
+ import { useTranslation } from 'react-i18next'
9
+ import { useTheme, spacing, typography } from '@bsv/expo-wallet-toolbox'
10
+ import PressableScale from '../ui/PressableScale'
11
+ import { showToast } from '../ui/Toast'
12
+ import { abbreviateKey } from '../../../core/pay/counterparty'
13
+
14
+ type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
15
+ let ioniconsComponent: IoniconsComponent | undefined
16
+ function loadIonicons(): IoniconsComponent {
17
+ if (!ioniconsComponent) {
18
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
19
+ ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
20
+ }
21
+ return ioniconsComponent
22
+ }
23
+
24
+ /**
25
+ * Loaded lazily for the same reason every native module in this package is:
26
+ * the `ui` barrel must stay parseable under Jest, which cannot load the
27
+ * clipboard module's native binding.
28
+ */
29
+ type ClipboardModule = typeof import('@react-native-clipboard/clipboard').default
30
+ let clipboardModule: ClipboardModule | undefined
31
+ function loadClipboard(): ClipboardModule {
32
+ if (!clipboardModule) {
33
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
34
+ clipboardModule = require('@react-native-clipboard/clipboard').default as ClipboardModule
35
+ }
36
+ return clipboardModule
37
+ }
38
+
39
+ export default function IdentifierRow({ identityKey }: { identityKey: string }) {
40
+ const { t } = useTranslation()
41
+ const { colors } = useTheme()
42
+ const Ionicons = loadIonicons()
43
+ const onCopy = useCallback(() => {
44
+ loadClipboard().setString(identityKey)
45
+ showToast(t('copied'), { type: 'success' })
46
+ }, [identityKey, t])
47
+ return (
48
+ <View style={styles.row}>
49
+ <Text style={[styles.key, { color: colors.textPrimary }]} numberOfLines={1} ellipsizeMode="middle">
50
+ {abbreviateKey(identityKey)}
51
+ </Text>
52
+ <PressableScale
53
+ onPress={onCopy}
54
+ haptic="tap"
55
+ style={styles.copyBtn}
56
+ accessibilityRole="button"
57
+ accessibilityLabel={t('contact_copy_identifier')}
58
+ >
59
+ <Ionicons name="copy-outline" size={18} color={colors.textSecondary} />
60
+ </PressableScale>
61
+ </View>
62
+ )
63
+ }
64
+
65
+ const styles = StyleSheet.create({
66
+ row: { flexDirection: 'row', alignItems: 'center', minHeight: 48, paddingLeft: spacing.lg, paddingRight: spacing.xs },
67
+ key: { ...typography.subhead, fontFamily: 'monospace', flex: 1 },
68
+ copyBtn: { width: 44, height: 44, alignItems: 'center', justifyContent: 'center' }
69
+ })