@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.
- package/CHANGELOG.md +547 -0
- package/README.md +19 -1
- package/assets/sounds/vault-deposit.wav +0 -0
- package/assets/sounds/vault-withdraw.wav +0 -0
- package/core/amountFormatHelpers.ts +238 -34
- package/core/backup/RemoteSyncReader.ts +2 -5
- package/core/backup/codec.ts +2 -2
- package/core/backup/push.ts +1 -1
- package/core/config.tsx +16 -1
- package/core/contacts/contactActivity.ts +153 -0
- package/core/contacts/contactCache.ts +41 -0
- package/core/contacts/contactsStore.ts +183 -0
- package/core/context/VaultContext.tsx +8 -11
- package/core/context/WalletConnectionContext.tsx +137 -52
- package/core/context/WalletContext.tsx +464 -30
- package/core/demo/demoAssets.ts +60 -0
- package/core/demo/demoLedger.ts +240 -0
- package/core/demo/demoMandalaRuntime.ts +96 -0
- package/core/demo/demoMode.ts +38 -0
- package/core/demo/demoWallet.ts +25 -0
- package/core/demo/index.ts +26 -0
- package/core/demo/useDemo.ts +59 -0
- package/core/headers/OfflineFirstChaintracks.ts +52 -14
- package/core/headers/headerStore.ts +7 -10
- package/core/hooks/useConfirmationSound.ts +14 -8
- package/core/i18n/translations.tsx +4562 -986
- package/core/identity/contactLink.ts +36 -0
- package/core/identity/handleRegistry/client.ts +285 -0
- package/core/identity/handleRegistry/profileCert.ts +254 -0
- package/core/identity/handleRegistry/registration.ts +559 -0
- package/core/identity/handleRegistry/resolver.ts +247 -0
- package/core/identity/handleRegistry/rules.ts +104 -0
- package/core/index.ts +116 -15
- package/core/localpay/build.ts +674 -37
- package/core/localpay/codec.ts +68 -5
- package/core/localpay/pending.ts +240 -22
- package/core/localpay/pendingAborts.ts +5 -1
- package/core/localpay/settlementAck.ts +149 -0
- package/core/localpay/types.ts +14 -1
- package/core/localpay/verify.ts +118 -69
- package/core/mandala/abortGuard.ts +134 -0
- package/core/mandala/basketMigration.ts +166 -0
- package/core/mandala/bundle.ts +244 -0
- package/core/mandala/createRuntime.ts +2437 -0
- package/core/mandala/drain.ts +670 -0
- package/core/mandala/permissionModule.ts +642 -0
- package/core/mandala/resendTransfer.ts +175 -0
- package/core/mandala/runtime.ts +357 -0
- package/core/mandala/settlementStore.ts +412 -0
- package/core/mandala/types.ts +290 -0
- package/core/monitor/MonitorSupervisor.ts +121 -0
- package/core/monitor/TaskBackupPush.ts +1 -1
- package/core/monitor/TaskCreditInbox.ts +1 -1
- package/core/monitor/TaskDrainOutbox.ts +1 -1
- package/core/monitor/TaskSendOffline.ts +1 -1
- package/core/net/online.ts +49 -0
- package/core/numberFormat.ts +19 -0
- package/core/offline/cancelParked.ts +94 -1
- package/core/offline/payerHold.ts +152 -12
- package/core/offline/plan.ts +1 -1
- package/core/offline/tokenFrames.ts +197 -0
- package/core/parsePeerPayURI.ts +70 -17
- package/core/pay/rails/address.ts +51 -3
- package/core/pay/rails/handle.ts +88 -9
- package/core/pay/rails/index.ts +16 -6
- package/core/pay/rails/nearby.ts +114 -4
- package/core/pay/recordProof.ts +2 -6
- package/core/services/arcadeBroadcastProvider.ts +1 -4
- package/core/services/capWalletArgs.ts +8 -9
- package/core/services/exchangeRate.ts +1 -1
- package/core/services/externalOrigin.ts +42 -0
- package/core/services/vault/VaultKeyService.ts +912 -251
- package/core/services/vault/ceremony.ts +435 -367
- package/core/services/vault/ceremonyHost.ts +27 -21
- package/core/services/vault/devMock.ts +30 -7
- package/core/services/vault/driver.ts +95 -41
- package/core/services/vault/guard.ts +514 -56
- package/core/services/vault/hardwareLease.ts +22 -0
- package/core/services/vault/mockYubiKey.ts +258 -90
- package/core/services/vault/pivReset.ts +145 -0
- package/core/services/vault/r1comb.ts +976 -0
- package/core/services/vault/session.ts +93 -26
- package/core/services/vault/transfers.ts +2617 -747
- package/core/services/vault/types.ts +100 -43
- package/core/services/vault/vaultStore.ts +991 -74
- package/core/services/walletConnectionValidation.ts +293 -0
- package/core/services/walletServiceConfig.ts +31 -20
- package/core/storage/StorageExpoSQLite.ts +420 -87
- package/core/storage/dbImage.ts +48 -0
- package/core/storage/methods/findSql.ts +3 -54
- package/core/storage/methods/listActionsSql.ts +8 -5
- package/core/storage/methods/listOutputsSql.ts +9 -5
- package/core/storage/methods/offlineActions.ts +15 -0
- package/core/storage/methods/processOfflineActions.ts +265 -9
- package/core/storage/methods/reviewStatusSql.ts +7 -2
- package/core/storage/methods/walletBalanceSql.ts +16 -4
- package/core/storage/schema/createTables.ts +152 -0
- package/core/storage/sqlUpdateValue.ts +24 -0
- package/core/toolboxConfig.ts +182 -1
- package/core/toolboxTypes.ts +40 -0
- package/core/userAvatar.ts +79 -0
- package/core/walletMonitor.ts +8 -3
- package/core/walletRepair/runWalletCheck.ts +19 -2
- package/package.json +31 -30
- package/ui/activityFilter.ts +115 -0
- package/ui/components/QRScanner.tsx +1 -1
- package/ui/components/pay/AdmissionNotice.tsx +99 -0
- package/ui/components/pay/AssetPicker.tsx +184 -0
- package/ui/components/pay/AvailableBalance.tsx +33 -2
- package/ui/components/pay/HandleReceive.tsx +213 -50
- package/ui/components/pay/NearbyFlow.tsx +616 -69
- package/ui/components/pay/PayForm.tsx +73 -8
- package/ui/components/pay/PaymentSuccessOverlay.tsx +89 -8
- package/ui/components/pay/RecipientField.tsx +132 -73
- package/ui/components/pay/RequestHub.tsx +68 -8
- package/ui/components/pay/ResultBanner.tsx +41 -4
- package/ui/components/pay/StepBar.tsx +32 -0
- package/ui/components/pay/UniversalSend.tsx +1118 -86
- package/ui/components/pay/tokenSendCopy.ts +116 -0
- package/ui/components/pay/useRecipientInput.ts +36 -7
- package/ui/components/ui/PencilEditField.tsx +109 -0
- package/ui/components/ui/PermissionSheet.tsx +65 -4
- package/ui/components/ui/Sheet.tsx +9 -2
- package/ui/components/ui/SlideOverFromRight.tsx +86 -0
- package/ui/components/vault/EnrollWizard.tsx +1432 -488
- package/ui/components/vault/KeyChooser.tsx +96 -0
- package/ui/components/vault/VaultCeremonySheet.tsx +107 -43
- package/ui/components/vault/vaultErrorCopy.ts +145 -0
- package/ui/components/wallet/ActivityRow.tsx +283 -97
- package/ui/components/wallet/AmountInput.tsx +92 -28
- package/ui/components/wallet/AssetAmount.tsx +95 -0
- package/ui/components/wallet/AssetSwitcherDropdown.tsx +261 -0
- package/ui/components/wallet/ContactActivityList.tsx +149 -0
- package/ui/components/wallet/ContactSigil.tsx +49 -0
- package/ui/components/wallet/EditPictureSheet.tsx +99 -0
- package/ui/components/wallet/FitAmount.tsx +148 -0
- package/ui/components/wallet/IconPickerSheet.tsx +168 -0
- package/ui/components/wallet/IdentifierRow.tsx +69 -0
- package/ui/components/wallet/ImportFromBackupPrompt.tsx +35 -13
- package/ui/components/wallet/ProfileButton.tsx +62 -0
- package/ui/components/wallet/UserAvatar.tsx +85 -0
- package/ui/components/wallet/avatarIcons.ts +122 -0
- package/ui/components/wallet/tokenEviction.ts +65 -0
- package/ui/hooks/useContactsStore.ts +10 -0
- package/ui/hooks/useExportWalletData.ts +39 -0
- package/ui/hooks/useMandala.ts +320 -0
- package/ui/hooks/useOnline.ts +65 -20
- package/ui/hooks/useVaultBalance.ts +105 -7
- package/ui/hooks/useVaultCoverage.ts +52 -0
- package/ui/importDatabases.ts +7 -3
- package/ui/index.ts +75 -7
- package/ui/screens/ConnectionsScreen.tsx +46 -29
- package/ui/screens/ContactScreen.tsx +289 -0
- package/ui/screens/ContactsScreen.tsx +373 -0
- package/ui/screens/IdentifierScreen.tsx +234 -0
- package/ui/screens/NewContactScreen.tsx +362 -0
- package/ui/screens/PairScreen.tsx +12 -12
- package/ui/screens/PayScreen.tsx +145 -12
- package/ui/screens/ProfileScreen.tsx +783 -0
- package/ui/screens/SettingsScreen.tsx +18 -9
- package/ui/screens/TransactionDetailScreen.tsx +419 -0
- package/ui/screens/TrustScreen.tsx +1 -1
- package/ui/screens/VaultScreen.tsx +925 -171
- package/ui/screens/VaultTransferScreen.tsx +376 -123
- package/ui/screens/WalletCheckScreen.tsx +10 -1
- package/ui/screens/WalletConfigScreen.tsx +80 -16
- package/ui/screens/WalletHomeScreen.tsx +915 -139
- package/ui/screens/homeBadges.ts +9 -1
- package/ui/screens/tokenRowTitle.ts +68 -0
- package/ui/tokenFormat.ts +108 -0
- package/ui/tokenSeen.ts +75 -0
- package/ui/tokenStatus.ts +100 -0
- package/ui/txStatus.ts +43 -5
- package/assets/sounds/vault-close.wav +0 -0
- package/assets/sounds/vault-open.wav +0 -0
- package/core/services/vault/k1.ts +0 -75
- package/core/services/vault/sealing.ts +0 -84
- package/core/services/vault/vaultDerivation.ts +0 -152
- package/core/services/vault/vaultPassphrase.ts +0 -287
- package/ui/components/vault/PassphraseField.tsx +0 -306
- package/ui/components/vault/PhraseBackupSheet.tsx +0 -227
- package/ui/screens/VaultRecoverScreen.tsx +0 -226
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
fiatFractionDigits,
|
|
17
17
|
satoshisPerFiatUnit
|
|
18
18
|
} from '@bsv/expo-wallet-toolbox'
|
|
19
|
+
import { parseTokenAmount, tokenAmountInputText, tokenAmountMask } from '../../tokenFormat'
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* @expo/vector-icons' index barrel re-exports every icon set (AntDesign,
|
|
@@ -36,6 +37,12 @@ function loadIonicons(): IoniconsComponent {
|
|
|
36
37
|
|
|
37
38
|
export const SEND_MAX_VALUE = '2099999999999999'
|
|
38
39
|
|
|
40
|
+
/** The denomination an amount is being typed in, when it is not satoshis. */
|
|
41
|
+
export interface AmountInputAsset {
|
|
42
|
+
ticker: string
|
|
43
|
+
decimals: number
|
|
44
|
+
}
|
|
45
|
+
|
|
39
46
|
interface AmountInputProps {
|
|
40
47
|
/**
|
|
41
48
|
* Show the "Send Max" shortcut. Defaults to true for send flows.
|
|
@@ -51,6 +58,22 @@ interface AmountInputProps {
|
|
|
51
58
|
maxLabelKey?: string
|
|
52
59
|
value: string
|
|
53
60
|
onChangeText: (text: string) => void
|
|
61
|
+
/**
|
|
62
|
+
* Token mode. When present the field takes and emits BASE UNITS of this
|
|
63
|
+
* asset instead of satoshis, and — this is the whole of the change — every
|
|
64
|
+
* fiat branch below goes inert, because `isFiat` is conjoined with
|
|
65
|
+
* `asset == null`. Without that single conjunction the fiat resync effect
|
|
66
|
+
* would take base units, divide them by a satoshi/fiat rate and clobber the
|
|
67
|
+
* figure the user typed.
|
|
68
|
+
*/
|
|
69
|
+
asset?: AmountInputAsset
|
|
70
|
+
/**
|
|
71
|
+
* Token mode only: what Max writes. The satoshi sentinel is a satoshi-domain
|
|
72
|
+
* concept and never enters token code — here Max writes the real spendable
|
|
73
|
+
* figure, which is exact because a token output carries 1 satoshi and the
|
|
74
|
+
* fee comes out of BSV.
|
|
75
|
+
*/
|
|
76
|
+
maxValue?: string
|
|
54
77
|
}
|
|
55
78
|
|
|
56
79
|
/**
|
|
@@ -67,7 +90,9 @@ export const AmountInput: React.FC<AmountInputProps> = ({
|
|
|
67
90
|
value,
|
|
68
91
|
onChangeText,
|
|
69
92
|
showMax = true,
|
|
70
|
-
maxLabelKey = 'entire_wallet_balance'
|
|
93
|
+
maxLabelKey = 'entire_wallet_balance',
|
|
94
|
+
asset,
|
|
95
|
+
maxValue
|
|
71
96
|
}) => {
|
|
72
97
|
const { t } = useTranslation()
|
|
73
98
|
const { colors } = useTheme()
|
|
@@ -77,22 +102,25 @@ export const AmountInput: React.FC<AmountInputProps> = ({
|
|
|
77
102
|
const Ionicons = loadIonicons()
|
|
78
103
|
|
|
79
104
|
const currency = settings?.currency || 'BSV'
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const
|
|
105
|
+
// ONE conjunction, and it is what keeps three denominations from colliding:
|
|
106
|
+
// in asset mode every fiat branch below is unreachable, unchanged.
|
|
107
|
+
const isFiat = asset == null && isFiatCurrency(currency)
|
|
108
|
+
const fractionDigits = asset ? asset.decimals : isFiat ? fiatFractionDigits(currency) : 0
|
|
109
|
+
const isSendMax = asset == null && value === SEND_MAX_VALUE
|
|
83
110
|
|
|
84
|
-
// In fiat
|
|
85
|
-
|
|
86
|
-
const
|
|
111
|
+
// In fiat and asset modes alike, the text being typed is not the value being
|
|
112
|
+
// emitted, so the field keeps its own display string.
|
|
113
|
+
const [displayText, setDisplayText] = useState('')
|
|
114
|
+
const lastEmitted = useRef('')
|
|
87
115
|
|
|
88
116
|
// Sync fiat display value when the satoshi value changes externally (e.g., cleared by parent)
|
|
89
117
|
useEffect(() => {
|
|
90
118
|
if (!isFiat) return
|
|
91
119
|
// Avoid re-syncing when we caused the change ourselves
|
|
92
|
-
if (value ===
|
|
120
|
+
if (value === lastEmitted.current) return
|
|
93
121
|
|
|
94
122
|
if (!value || value === '0') {
|
|
95
|
-
|
|
123
|
+
setDisplayText('')
|
|
96
124
|
} else if (value === SEND_MAX_VALUE) {
|
|
97
125
|
// Don't try to convert SEND_MAX_VALUE to fiat
|
|
98
126
|
} else {
|
|
@@ -101,27 +129,55 @@ export const AmountInput: React.FC<AmountInputProps> = ({
|
|
|
101
129
|
if (!isNaN(sats) && per > 0) {
|
|
102
130
|
const amount = sats / per
|
|
103
131
|
if (fractionDigits === 0) {
|
|
104
|
-
|
|
132
|
+
setDisplayText(String(Math.round(amount)))
|
|
105
133
|
} else {
|
|
106
|
-
|
|
107
|
-
amount % 1 === 0
|
|
108
|
-
? amount.toFixed(0)
|
|
109
|
-
: amount.toFixed(fractionDigits).replace(/0+$/, '').replace(/\.$/, '')
|
|
134
|
+
setDisplayText(
|
|
135
|
+
amount % 1 === 0 ? amount.toFixed(0) : amount.toFixed(fractionDigits).replace(/0+$/, '').replace(/\.$/, '')
|
|
110
136
|
)
|
|
111
137
|
}
|
|
112
138
|
}
|
|
113
139
|
}
|
|
114
|
-
|
|
140
|
+
lastEmitted.current = value
|
|
115
141
|
}, [value, isFiat, currency, satoshisPerUSD, usdToFiat, fractionDigits])
|
|
116
142
|
|
|
143
|
+
// The asset-mode twin of the effect above, with the same self-resync guard.
|
|
144
|
+
// The two are mutually exclusive by mode and neither can run in the other's.
|
|
145
|
+
useEffect(() => {
|
|
146
|
+
if (!asset) return
|
|
147
|
+
if (value === lastEmitted.current) return
|
|
148
|
+
setDisplayText(!value || value === '0' ? '' : tokenAmountInputText(Number(value), asset.decimals))
|
|
149
|
+
lastEmitted.current = value
|
|
150
|
+
// `asset` is a fresh object literal on every render of most callers
|
|
151
|
+
// (e.g. `asset={{ ticker, decimals }}`), so depending on it directly
|
|
152
|
+
// reruns this effect on EVERY parent render, not just when the figure
|
|
153
|
+
// actually changes. Two such reruns queued back to back can interleave
|
|
154
|
+
// out of order — an older render's effect (with a stale `value`) firing
|
|
155
|
+
// AFTER a newer one clobbers `lastEmitted.current` back down, which then
|
|
156
|
+
// makes the newer render's own effect think it must resync and reformats
|
|
157
|
+
// what the user just typed. Depending on the primitive that the effect
|
|
158
|
+
// body actually reads keeps it from firing on an unrelated re-render.
|
|
159
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
160
|
+
}, [value, asset?.decimals, !!asset])
|
|
161
|
+
|
|
117
162
|
const handleChangeText = (text: string) => {
|
|
163
|
+
if (asset) {
|
|
164
|
+
if (text && !tokenAmountMask(asset.decimals).test(text)) return
|
|
165
|
+
setDisplayText(text)
|
|
166
|
+
const baseUnits = parseTokenAmount(text, asset.decimals)
|
|
167
|
+
// The field never emits a fraction: the wire takes whole base units, and
|
|
168
|
+
// a rounded figure would pay an amount other than the one on screen.
|
|
169
|
+
const next = baseUnits === null ? '' : String(baseUnits)
|
|
170
|
+
lastEmitted.current = next
|
|
171
|
+
onChangeText(next)
|
|
172
|
+
return
|
|
173
|
+
}
|
|
118
174
|
if (isFiat) {
|
|
119
175
|
const allowed = fractionDigits === 0 ? /^\d*$/ : new RegExp(`^\\d*\\.?\\d{0,${fractionDigits}}$`)
|
|
120
176
|
if (text && !allowed.test(text)) return
|
|
121
|
-
|
|
177
|
+
setDisplayText(text)
|
|
122
178
|
const sats = parseDisplayToSatoshis(text, currency, satoshisPerUSD, usdToFiat)
|
|
123
179
|
const satsStr = text ? String(sats) : ''
|
|
124
|
-
|
|
180
|
+
lastEmitted.current = satsStr
|
|
125
181
|
onChangeText(satsStr)
|
|
126
182
|
} else {
|
|
127
183
|
onChangeText(text)
|
|
@@ -137,7 +193,7 @@ export const AmountInput: React.FC<AmountInputProps> = ({
|
|
|
137
193
|
</View>
|
|
138
194
|
<TouchableOpacity
|
|
139
195
|
onPress={() => {
|
|
140
|
-
if (isFiat)
|
|
196
|
+
if (isFiat) setDisplayText('')
|
|
141
197
|
onChangeText('')
|
|
142
198
|
}}
|
|
143
199
|
style={[styles.clearButton, { backgroundColor: colors.fill }]}
|
|
@@ -148,16 +204,24 @@ export const AmountInput: React.FC<AmountInputProps> = ({
|
|
|
148
204
|
)
|
|
149
205
|
}
|
|
150
206
|
|
|
151
|
-
const displayValue = isFiat ?
|
|
152
|
-
const placeholder =
|
|
153
|
-
const keyboardType =
|
|
154
|
-
const unitLabel = isFiat ? currency : 'satoshis'
|
|
207
|
+
const displayValue = isFiat || asset ? displayText : value
|
|
208
|
+
const placeholder = fractionDigits === 0 ? '0' : `0.${'0'.repeat(Math.min(fractionDigits, 8))}`
|
|
209
|
+
const keyboardType = fractionDigits > 0 ? ('decimal-pad' as const) : ('number-pad' as const)
|
|
210
|
+
const unitLabel = asset ? asset.ticker : isFiat ? currency : 'satoshis'
|
|
155
211
|
|
|
156
|
-
// Secondary converted-currency line: BSV when showing fiat, USD when showing BSV
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
212
|
+
// Secondary converted-currency line: BSV when showing fiat, USD when showing BSV.
|
|
213
|
+
// Suppressed entirely in asset mode — this wallet has no price for a token,
|
|
214
|
+
// and a converted line under a stablecoin figure would be invented.
|
|
215
|
+
const satsForConversion = !asset && value ? parseInt(value, 10) : 0
|
|
216
|
+
const secondaryText = asset
|
|
217
|
+
? null
|
|
218
|
+
: isFiat
|
|
219
|
+
? satsForConversion > 0
|
|
220
|
+
? formatAmount(satsForConversion, 'BSV', satoshisPerUSD)
|
|
221
|
+
: null
|
|
222
|
+
: satsForConversion > 0 && satoshisPerUSD > 0
|
|
223
|
+
? formatAmount(satsForConversion, 'USD', satoshisPerUSD)
|
|
224
|
+
: null
|
|
161
225
|
|
|
162
226
|
const entering = reducedMotion ? undefined : FadeInUp.duration(durations.instant)
|
|
163
227
|
const exiting = reducedMotion ? undefined : FadeOutDown.duration(durations.instant)
|
|
@@ -181,7 +245,7 @@ export const AmountInput: React.FC<AmountInputProps> = ({
|
|
|
181
245
|
</View>
|
|
182
246
|
{showMax && (
|
|
183
247
|
<TouchableOpacity
|
|
184
|
-
onPress={() => onChangeText(SEND_MAX_VALUE)}
|
|
248
|
+
onPress={() => onChangeText(asset ? (maxValue ?? '') : SEND_MAX_VALUE)}
|
|
185
249
|
style={[styles.maxButton, { backgroundColor: colors.fill }]}
|
|
186
250
|
>
|
|
187
251
|
<Text style={[styles.maxText, { color: colors.accent }]}>{t('send_max')}</Text>
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A token money figure — the sibling of `AmountDisplay`, and deliberately not a
|
|
3
|
+
* mode of it.
|
|
4
|
+
*
|
|
5
|
+
* `AmountDisplay` is a satoshi component: it reads `settings.currency`, asks
|
|
6
|
+
* the exchange-rate context for a cross, and formats with the BSV thresholds.
|
|
7
|
+
* None of that is true of a token, and every one of those behaviours would be a
|
|
8
|
+
* lie if it fired here — there is no price for a stablecoin in this wallet and
|
|
9
|
+
* a ticker is not a currency code (ux §6.1).
|
|
10
|
+
*
|
|
11
|
+
* Three states, and only one of them prints a number:
|
|
12
|
+
* · a figure, in the asset's own fixed decimals;
|
|
13
|
+
* · a spinner while the balance is UNKNOWN (`null`), because "0 USDX" is a
|
|
14
|
+
* claim about someone's money and a cold read is not entitled to make it;
|
|
15
|
+
* · nothing at all when the figure cannot be formatted, rather than `NaN`.
|
|
16
|
+
*
|
|
17
|
+
* VoiceOver reads one composed label ("1,240.00 USDX"), never two fragments:
|
|
18
|
+
* the value and its unit are separate `<Text>`s only so the unit can be
|
|
19
|
+
* demoted visually.
|
|
20
|
+
*/
|
|
21
|
+
import React from 'react'
|
|
22
|
+
import { ActivityIndicator, StyleSheet, Text, View } from 'react-native'
|
|
23
|
+
import { spacing, typography, useTheme } from '@bsv/expo-wallet-toolbox'
|
|
24
|
+
import { formatTokenAmountWithUnit, tokenAmountParts } from '../../tokenFormat'
|
|
25
|
+
|
|
26
|
+
export interface AssetAmountProps {
|
|
27
|
+
/** Base units. `null` means UNKNOWN and renders a spinner, never a zero. */
|
|
28
|
+
baseUnits: number | null
|
|
29
|
+
asset: { decimals: number; ticker: string }
|
|
30
|
+
/** `row` is the balances/activity figure; `sheet` is the Asset sheet's headline. */
|
|
31
|
+
size?: 'row' | 'sheet'
|
|
32
|
+
showPlus?: boolean
|
|
33
|
+
/** `incoming` is the one place green appears on a figure: money that arrived. */
|
|
34
|
+
tone?: 'primary' | 'incoming' | 'secondary'
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default function AssetAmount({
|
|
38
|
+
baseUnits,
|
|
39
|
+
asset,
|
|
40
|
+
size = 'row',
|
|
41
|
+
showPlus = false,
|
|
42
|
+
tone = 'primary'
|
|
43
|
+
}: AssetAmountProps) {
|
|
44
|
+
const { colors } = useTheme()
|
|
45
|
+
|
|
46
|
+
if (baseUnits === null) {
|
|
47
|
+
return <ActivityIndicator size="small" color={colors.textTertiary} accessibilityRole="progressbar" />
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const parts = tokenAmountParts(baseUnits, asset, { showPlus })
|
|
51
|
+
if (!parts) return null
|
|
52
|
+
const label = formatTokenAmountWithUnit(baseUnits, asset, { showPlus }) ?? ''
|
|
53
|
+
|
|
54
|
+
const color =
|
|
55
|
+
tone === 'incoming' ? colors.successAmount : tone === 'secondary' ? colors.textSecondary : colors.textPrimary
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<View
|
|
59
|
+
style={styles.wrap}
|
|
60
|
+
accessible
|
|
61
|
+
accessibilityRole="text"
|
|
62
|
+
accessibilityLabel={label}
|
|
63
|
+
// The figure and the ticker are one money fact. Read apart they become
|
|
64
|
+
// "one thousand two hundred forty point zero zero" … "U S D X", with a
|
|
65
|
+
// pause in the middle that invites the listener to act on the first half.
|
|
66
|
+
importantForAccessibility="yes"
|
|
67
|
+
>
|
|
68
|
+
<Text
|
|
69
|
+
style={[size === 'sheet' ? styles.sheetValue : styles.rowValue, { color }]}
|
|
70
|
+
numberOfLines={1}
|
|
71
|
+
adjustsFontSizeToFit
|
|
72
|
+
maxFontSizeMultiplier={1.3}
|
|
73
|
+
importantForAccessibility="no-hide-descendants"
|
|
74
|
+
>
|
|
75
|
+
{parts.value}
|
|
76
|
+
</Text>
|
|
77
|
+
<Text
|
|
78
|
+
style={[size === 'sheet' ? styles.sheetUnit : styles.rowUnit, { color: colors.textSecondary }]}
|
|
79
|
+
numberOfLines={1}
|
|
80
|
+
maxFontSizeMultiplier={1.3}
|
|
81
|
+
importantForAccessibility="no-hide-descendants"
|
|
82
|
+
>
|
|
83
|
+
{parts.unit}
|
|
84
|
+
</Text>
|
|
85
|
+
</View>
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const styles = StyleSheet.create({
|
|
90
|
+
wrap: { flexDirection: 'row', alignItems: 'baseline', gap: spacing.xs, flexShrink: 1 },
|
|
91
|
+
rowValue: { ...typography.title3, fontVariant: ['tabular-nums'] },
|
|
92
|
+
rowUnit: { ...typography.footnote },
|
|
93
|
+
sheetValue: { ...typography.title1, fontVariant: ['tabular-nums'] },
|
|
94
|
+
sheetUnit: { ...typography.subhead }
|
|
95
|
+
})
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The coin switcher dropdown (design 4a, 2026-09-16).
|
|
3
|
+
*
|
|
4
|
+
* Home's coin pill, now in the top bar, IS the switcher; this is what it
|
|
5
|
+
* opens — a small card anchored just under the top bar, with a tail
|
|
6
|
+
* pointing back at the pill, rather than a bottom drawer. One row per kind
|
|
7
|
+
* of money the wallet holds — BSV first, then every stablecoin — each with
|
|
8
|
+
* its figure, and a checkmark on the one the screen is currently showing.
|
|
9
|
+
* Picking a row swaps the whole wallet to that coin: hero figure, activity
|
|
10
|
+
* list, and what Pay / Get paid are armed with. The asset question is asked
|
|
11
|
+
* here, once, so the Pay screen never has to ask it again.
|
|
12
|
+
*
|
|
13
|
+
* Each row is the ticker over the asset's full name — "BSV" / "Bitcoin SV",
|
|
14
|
+
* "CHFB" / "CHF on BSV" — so the figure on the right always reads against a
|
|
15
|
+
* denomination you can pronounce, not just a four-letter code.
|
|
16
|
+
*
|
|
17
|
+
* Rendered only when something is held — a wallet that has never held a token
|
|
18
|
+
* never mounts this, so it keeps today's screen byte for byte.
|
|
19
|
+
*/
|
|
20
|
+
import React, { useEffect, useRef, useState } from 'react'
|
|
21
|
+
import { Pressable, StyleSheet, Text, TouchableOpacity, View } from 'react-native'
|
|
22
|
+
import Animated, { runOnJS, useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated'
|
|
23
|
+
import { hitTargets, radii, spacing, typography, useTheme } from '@bsv/expo-wallet-toolbox'
|
|
24
|
+
import type { TokenBalance } from '../../../core/mandala/runtime'
|
|
25
|
+
import { tokenAmountParts } from '../../tokenFormat'
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @expo/vector-icons' index barrel re-exports every icon set, one of which
|
|
29
|
+
* reaches expo-font -> expo-asset -- untransformed ESM Jest cannot parse when
|
|
30
|
+
* eagerly pulled in via the `ui` package barrel. Loaded lazily, same pattern
|
|
31
|
+
* as this package's other native-module-boundary fixes.
|
|
32
|
+
*/
|
|
33
|
+
type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
|
|
34
|
+
let ioniconsComponent: IoniconsComponent | 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
|
+
|
|
43
|
+
/** The literal, like `mainnet`/`testnet`: a translated "BSV" would be byte-identical in every locale. */
|
|
44
|
+
export const BSV_LABEL = 'BSV'
|
|
45
|
+
/** BSV's own full name, the way a token's `asset.label` names it — a proper noun, not translated. */
|
|
46
|
+
export const BSV_FULL_NAME = 'Bitcoin SV'
|
|
47
|
+
|
|
48
|
+
export interface AssetSwitcherDropdownProps {
|
|
49
|
+
visible: boolean
|
|
50
|
+
onClose: () => void
|
|
51
|
+
/** Where the top bar ends, in the same coordinate space this component is
|
|
52
|
+
* mounted in — the card hangs just under it, tail pointing up at the pill. */
|
|
53
|
+
top: number
|
|
54
|
+
/** Held stablecoins, in the order the runtime reports them. */
|
|
55
|
+
balances: TokenBalance[]
|
|
56
|
+
/** `null` is BSV. */
|
|
57
|
+
selected: string | null
|
|
58
|
+
onSelect: (assetId: string | null) => void
|
|
59
|
+
/** The BSV figure as the hero draws it; `null` is UNKNOWN and prints nothing. */
|
|
60
|
+
bsv: { value: string; unit: string } | null
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export default function AssetSwitcherDropdown({
|
|
64
|
+
visible,
|
|
65
|
+
onClose,
|
|
66
|
+
top,
|
|
67
|
+
balances,
|
|
68
|
+
selected,
|
|
69
|
+
onSelect,
|
|
70
|
+
bsv
|
|
71
|
+
}: AssetSwitcherDropdownProps) {
|
|
72
|
+
const { colors } = useTheme()
|
|
73
|
+
|
|
74
|
+
// Fade + scale in place, no gesture — this is a dropdown, not a draggable
|
|
75
|
+
// drawer. Mirrors Sheet's rendered/visible split so content unmounts only
|
|
76
|
+
// once the close animation actually finishes, not the instant the prop flips.
|
|
77
|
+
const [rendered, setRendered] = useState(false)
|
|
78
|
+
const wasVisibleRef = useRef(false)
|
|
79
|
+
const progress = useSharedValue(0)
|
|
80
|
+
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
if (visible) {
|
|
83
|
+
setRendered(true)
|
|
84
|
+
if (!wasVisibleRef.current) {
|
|
85
|
+
progress.value = 0
|
|
86
|
+
progress.value = withTiming(1, { duration: 160 })
|
|
87
|
+
}
|
|
88
|
+
} else if (wasVisibleRef.current) {
|
|
89
|
+
progress.value = withTiming(0, { duration: 120 }, finished => {
|
|
90
|
+
if (finished) runOnJS(setRendered)(false)
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
wasVisibleRef.current = visible
|
|
94
|
+
}, [visible, progress])
|
|
95
|
+
|
|
96
|
+
const animatedStyle = useAnimatedStyle(() => ({
|
|
97
|
+
opacity: progress.value,
|
|
98
|
+
transform: [{ scale: 0.95 + progress.value * 0.05 }, { translateY: (1 - progress.value) * -4 }]
|
|
99
|
+
}))
|
|
100
|
+
|
|
101
|
+
const isVisible = visible || rendered
|
|
102
|
+
if (!isVisible) return null
|
|
103
|
+
|
|
104
|
+
const choose = (assetId: string | null) => {
|
|
105
|
+
onSelect(assetId)
|
|
106
|
+
onClose()
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<View style={[StyleSheet.absoluteFill, { zIndex: 50 }]} pointerEvents="box-none">
|
|
111
|
+
<Pressable
|
|
112
|
+
style={[StyleSheet.absoluteFill, { zIndex: 10 }]}
|
|
113
|
+
onPress={onClose}
|
|
114
|
+
accessible={true}
|
|
115
|
+
accessibilityRole="button"
|
|
116
|
+
accessibilityLabel="Close"
|
|
117
|
+
accessibilityHint="Dismisses the coin switcher"
|
|
118
|
+
/>
|
|
119
|
+
<Animated.View
|
|
120
|
+
style={[
|
|
121
|
+
styles.card,
|
|
122
|
+
{
|
|
123
|
+
top: top + spacing.xs,
|
|
124
|
+
backgroundColor: colors.surfaceRaised,
|
|
125
|
+
borderColor: colors.surfaceRaisedBorder,
|
|
126
|
+
shadowColor: colors.textPrimary
|
|
127
|
+
},
|
|
128
|
+
animatedStyle
|
|
129
|
+
]}
|
|
130
|
+
>
|
|
131
|
+
{/* The tail: a rotated square peeking out the top edge, pointing back
|
|
132
|
+
at the pill that opened this — the pill sits centred in the top
|
|
133
|
+
bar, and so does this card, so the tail needs no measurement. */}
|
|
134
|
+
<View
|
|
135
|
+
style={[styles.tail, { backgroundColor: colors.surfaceRaised, borderColor: colors.surfaceRaisedBorder }]}
|
|
136
|
+
/>
|
|
137
|
+
<View style={styles.list}>
|
|
138
|
+
<CoinRow
|
|
139
|
+
ticker={BSV_LABEL}
|
|
140
|
+
fullName={BSV_FULL_NAME}
|
|
141
|
+
figure={bsv}
|
|
142
|
+
selected={selected === null}
|
|
143
|
+
onPress={() => choose(null)}
|
|
144
|
+
/>
|
|
145
|
+
{balances.map(b => (
|
|
146
|
+
<CoinRow
|
|
147
|
+
key={b.asset.assetId}
|
|
148
|
+
ticker={b.asset.ticker}
|
|
149
|
+
fullName={b.asset.label}
|
|
150
|
+
figure={tokenAmountParts(b.baseUnits, b.asset)}
|
|
151
|
+
selected={selected === b.asset.assetId}
|
|
152
|
+
onPress={() => choose(b.asset.assetId)}
|
|
153
|
+
/>
|
|
154
|
+
))}
|
|
155
|
+
</View>
|
|
156
|
+
</Animated.View>
|
|
157
|
+
</View>
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function CoinRow({
|
|
162
|
+
ticker,
|
|
163
|
+
fullName,
|
|
164
|
+
figure,
|
|
165
|
+
selected,
|
|
166
|
+
onPress
|
|
167
|
+
}: {
|
|
168
|
+
ticker: string
|
|
169
|
+
fullName?: string
|
|
170
|
+
figure: { value: string; unit: string } | null
|
|
171
|
+
selected: boolean
|
|
172
|
+
onPress: () => void
|
|
173
|
+
}) {
|
|
174
|
+
const { colors } = useTheme()
|
|
175
|
+
const Ionicons = loadIonicons()
|
|
176
|
+
const figureText = figure ? `${figure.value} ${figure.unit}`.trim() : ''
|
|
177
|
+
return (
|
|
178
|
+
<TouchableOpacity
|
|
179
|
+
style={[styles.row, selected && { backgroundColor: colors.fill }]}
|
|
180
|
+
onPress={onPress}
|
|
181
|
+
activeOpacity={0.6}
|
|
182
|
+
accessibilityRole="button"
|
|
183
|
+
// The checkmark is not the only signal: state travels with the element.
|
|
184
|
+
accessibilityState={{ selected }}
|
|
185
|
+
accessibilityLabel={[ticker, fullName, figureText].filter(Boolean).join(', ')}
|
|
186
|
+
>
|
|
187
|
+
<View style={styles.body}>
|
|
188
|
+
<Text style={[styles.name, { color: colors.textPrimary }]} numberOfLines={1}>
|
|
189
|
+
{ticker}
|
|
190
|
+
</Text>
|
|
191
|
+
{!!fullName && (
|
|
192
|
+
<Text style={[styles.detail, { color: colors.textSecondary }]} numberOfLines={1}>
|
|
193
|
+
{fullName}
|
|
194
|
+
</Text>
|
|
195
|
+
)}
|
|
196
|
+
</View>
|
|
197
|
+
{figure && (
|
|
198
|
+
<Text style={[styles.figure, { color: colors.textPrimary }]} numberOfLines={1} accessibilityLabel={figureText}>
|
|
199
|
+
{figure.value}
|
|
200
|
+
{figure.unit ? <Text style={[styles.unit, { color: colors.textSecondary }]}> {figure.unit}</Text> : null}
|
|
201
|
+
</Text>
|
|
202
|
+
)}
|
|
203
|
+
<View style={styles.check}>{selected && <Ionicons name="checkmark" size={20} color={colors.accent} />}</View>
|
|
204
|
+
</TouchableOpacity>
|
|
205
|
+
)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const styles = StyleSheet.create({
|
|
209
|
+
card: {
|
|
210
|
+
position: 'absolute',
|
|
211
|
+
left: spacing.lg,
|
|
212
|
+
right: spacing.lg,
|
|
213
|
+
// 20, not the sheet radius scale's 24 — this is the design file's own
|
|
214
|
+
// number (Multi-currency wallet options.dc.html, option 4a), chosen so
|
|
215
|
+
// it stays concentric with the row radius below: 20 = 14 (row) + 6 (inset).
|
|
216
|
+
borderRadius: 20,
|
|
217
|
+
borderWidth: StyleSheet.hairlineWidth,
|
|
218
|
+
overflow: 'visible',
|
|
219
|
+
zIndex: 20,
|
|
220
|
+
elevation: 12,
|
|
221
|
+
// Deep and soft rather than tight — the card has to sit clearly in front
|
|
222
|
+
// of the dimmed page behind it, and a small shadow reads as a seam.
|
|
223
|
+
shadowOffset: { width: 0, height: 16 },
|
|
224
|
+
shadowOpacity: 0.22,
|
|
225
|
+
shadowRadius: 30
|
|
226
|
+
},
|
|
227
|
+
tail: {
|
|
228
|
+
position: 'absolute',
|
|
229
|
+
top: -6,
|
|
230
|
+
alignSelf: 'center',
|
|
231
|
+
width: 12,
|
|
232
|
+
height: 12,
|
|
233
|
+
borderTopWidth: StyleSheet.hairlineWidth,
|
|
234
|
+
borderLeftWidth: StyleSheet.hairlineWidth,
|
|
235
|
+
borderTopLeftRadius: 3,
|
|
236
|
+
transform: [{ rotate: '45deg' }]
|
|
237
|
+
},
|
|
238
|
+
list: {
|
|
239
|
+
// 6, so the clipped corner here stays concentric with the card's 20 above
|
|
240
|
+
// (20 = 14 + 6) — a smaller inset left the row's own 14px corner cutting
|
|
241
|
+
// across the card's wider sweep instead of following it.
|
|
242
|
+
padding: 6,
|
|
243
|
+
borderRadius: 20,
|
|
244
|
+
overflow: 'hidden'
|
|
245
|
+
},
|
|
246
|
+
row: {
|
|
247
|
+
flexDirection: 'row',
|
|
248
|
+
alignItems: 'center',
|
|
249
|
+
gap: spacing.md,
|
|
250
|
+
minHeight: hitTargets.minimum,
|
|
251
|
+
paddingVertical: 11,
|
|
252
|
+
paddingHorizontal: 10,
|
|
253
|
+
borderRadius: radii.lg
|
|
254
|
+
},
|
|
255
|
+
body: { flex: 1, minWidth: 0 },
|
|
256
|
+
name: { ...typography.body, fontWeight: '600' },
|
|
257
|
+
detail: { ...typography.footnote, marginTop: 2, fontVariant: ['tabular-nums'] },
|
|
258
|
+
figure: { ...typography.body, fontWeight: '600', fontVariant: ['tabular-nums'] },
|
|
259
|
+
unit: { ...typography.footnote },
|
|
260
|
+
check: { width: 20, alignItems: 'center' }
|
|
261
|
+
})
|