@bsv/expo-wallet-toolbox 0.3.1 → 0.5.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 +311 -0
- package/README.md +52 -1
- package/assets/sounds/vault-deposit.wav +0 -0
- package/assets/sounds/vault-withdraw.wav +0 -0
- package/core/config.tsx +21 -18
- package/core/context/VaultContext.tsx +8 -11
- package/core/context/WalletConnectionContext.tsx +137 -52
- package/core/context/WalletContext.tsx +413 -23
- package/core/hooks/useConfirmationSound.ts +14 -8
- package/core/i18n/translations.tsx +3368 -952
- package/core/index.ts +107 -14
- package/core/localpay/build.ts +674 -37
- package/core/localpay/codec.ts +68 -5
- package/core/localpay/pending.ts +240 -22
- 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/offline/cancelParked.ts +94 -1
- package/core/offline/payerHold.ts +152 -12
- 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/services/capWalletArgs.ts +8 -9
- package/core/services/externalOrigin.ts +39 -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 +19 -24
- package/core/storage/StorageExpoSQLite.ts +382 -56
- package/core/storage/dbImage.ts +48 -0
- package/core/storage/methods/findSql.ts +0 -54
- package/core/storage/methods/listOutputsSql.ts +7 -3
- package/core/storage/methods/offlineActions.ts +15 -0
- package/core/storage/methods/processOfflineActions.ts +263 -6
- package/core/storage/methods/walletBalanceSql.ts +16 -4
- package/core/storage/schema/createTables.ts +123 -0
- package/core/storage/sqlUpdateValue.ts +24 -0
- package/core/toolboxConfig.ts +240 -0
- package/core/walletRepair/runWalletCheck.ts +19 -2
- package/package.json +25 -24
- 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 +43 -2
- package/ui/components/pay/RecipientField.tsx +49 -4
- package/ui/components/pay/RequestHub.tsx +68 -8
- package/ui/components/pay/ResultBanner.tsx +41 -4
- package/ui/components/pay/UniversalSend.tsx +534 -30
- package/ui/components/pay/tokenSendCopy.ts +116 -0
- package/ui/components/pay/useRecipientInput.ts +36 -7
- package/ui/components/ui/PermissionSheet.tsx +65 -4
- package/ui/components/ui/Sheet.tsx +9 -2
- 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 +101 -17
- package/ui/components/wallet/AmountInput.tsx +77 -25
- package/ui/components/wallet/AssetAmount.tsx +95 -0
- package/ui/components/wallet/AssetSwitcherDropdown.tsx +261 -0
- package/ui/components/wallet/tokenEviction.ts +65 -0
- package/ui/hooks/useExportWalletData.ts +39 -0
- package/ui/hooks/useMandala.ts +303 -0
- package/ui/hooks/useVaultBalance.ts +105 -7
- package/ui/hooks/useVaultCoverage.ts +52 -0
- package/ui/importDatabases.ts +7 -3
- package/ui/index.ts +50 -7
- package/ui/screens/ConnectionsScreen.tsx +46 -29
- package/ui/screens/PairScreen.tsx +12 -12
- package/ui/screens/PayScreen.tsx +130 -10
- package/ui/screens/SettingsScreen.tsx +18 -9
- 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 +42 -20
- package/ui/screens/WalletHomeScreen.tsx +417 -86
- 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 +79 -0
- 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
|
@@ -29,7 +29,8 @@ import {
|
|
|
29
29
|
counterpartyOf,
|
|
30
30
|
counterpartyHue,
|
|
31
31
|
sigilPointOf,
|
|
32
|
-
sigilPalette
|
|
32
|
+
sigilPalette,
|
|
33
|
+
type Counterparty
|
|
33
34
|
} from '@bsv/expo-wallet-toolbox'
|
|
34
35
|
import { txStatusView, toneColor } from '../../txStatus'
|
|
35
36
|
import PressableScale from '../ui/PressableScale'
|
|
@@ -98,6 +99,40 @@ interface Props {
|
|
|
98
99
|
onSendAgain?: (action: ActivityAction) => void
|
|
99
100
|
/** Cancel a parked payment: abort the action and retire its queue row. */
|
|
100
101
|
onCancelParked?: (txid: string) => void
|
|
102
|
+
/**
|
|
103
|
+
* Token denomination for a `'mandala'`-labelled action.
|
|
104
|
+
*
|
|
105
|
+
* Absent, this row is byte-identical to the row it has always been. Present,
|
|
106
|
+
* it overrides three things and only those three:
|
|
107
|
+
*
|
|
108
|
+
* · the DESCRIPTION, because the lib writes a developer string containing a
|
|
109
|
+
* raw 36-byte token id and this row renders `action.description` verbatim;
|
|
110
|
+
* · the AMOUNT, because `action.satoshis` for a token send is the net BSV
|
|
111
|
+
* spent — printing "−64 sats" for a payment of 25.00 USDX would be a
|
|
112
|
+
* plausible wrong number, which is worse than a blank. When the figure
|
|
113
|
+
* cannot be recovered the row says so rather than falling through;
|
|
114
|
+
* · the FACE, because the wallet action's own labels/senderIdentityKey are
|
|
115
|
+
* meaningless for a token transfer (they describe the BSV coin-selection
|
|
116
|
+
* tx, not the counterparty) — `counterpartyKey` is the row's own word for
|
|
117
|
+
* who was on the other side, and the row draws the same generative sigil
|
|
118
|
+
* a BSV row does, keyed on it directly rather than on `counterpartyOf`.
|
|
119
|
+
*/
|
|
120
|
+
token?: {
|
|
121
|
+
title: string
|
|
122
|
+
/** The figure and its unit, or undefined when it could not be recovered. */
|
|
123
|
+
amount?: { value: string; unit: string }
|
|
124
|
+
incoming: boolean
|
|
125
|
+
/**
|
|
126
|
+
* The counterparty's identity key — a received row's sender (the
|
|
127
|
+
* blinded, per-payment A′; deliberately a different key on every payment
|
|
128
|
+
* from the same payer, spec D2) or a sent row's payee. Undefined draws
|
|
129
|
+
* the plain direction arrow instead, the same fallback a BSV row gets for
|
|
130
|
+
* a counterparty it cannot name.
|
|
131
|
+
*/
|
|
132
|
+
counterpartyKey?: string
|
|
133
|
+
/** Settlement status line, in place of the chain-status words. */
|
|
134
|
+
statusText?: string
|
|
135
|
+
}
|
|
101
136
|
}
|
|
102
137
|
|
|
103
138
|
/** Statuses whose transaction is still local and therefore abortable: nothing
|
|
@@ -132,7 +167,8 @@ function ActivityRowBase({
|
|
|
132
167
|
onAbort,
|
|
133
168
|
onSendPaymentDetails,
|
|
134
169
|
onSendAgain,
|
|
135
|
-
onCancelParked
|
|
170
|
+
onCancelParked,
|
|
171
|
+
token
|
|
136
172
|
}: Props & { currency: string }) {
|
|
137
173
|
const { t } = useTranslation()
|
|
138
174
|
const { colors, isDark } = useTheme()
|
|
@@ -142,7 +178,7 @@ function ActivityRowBase({
|
|
|
142
178
|
const view = txStatusView(action.status, offlineStatus)
|
|
143
179
|
const settled = view.tone === 'settled'
|
|
144
180
|
const tone = toneColor(view.tone, colors as unknown as Record<string, string>)
|
|
145
|
-
const incoming = action.satoshis >= 0
|
|
181
|
+
const incoming = token ? token.incoming : action.satoshis >= 0
|
|
146
182
|
|
|
147
183
|
const { value, unit } = formatAmountParts(action.satoshis, currency, satoshisPerUSD, {
|
|
148
184
|
abbreviate: true,
|
|
@@ -169,10 +205,24 @@ function ActivityRowBase({
|
|
|
169
205
|
// is unambiguous.
|
|
170
206
|
const { labels, senderIdentityKey, txid } = action
|
|
171
207
|
const labelsKey = labels?.join('\n') ?? ''
|
|
208
|
+
// Scalars, not the `token` object itself: a fresh `token` reference every
|
|
209
|
+
// poll must not re-derive the face when nothing about it actually changed.
|
|
210
|
+
const isTokenRow = token !== undefined
|
|
211
|
+
const tokenCounterpartyKey = token?.counterpartyKey
|
|
172
212
|
const face = useMemo(() => {
|
|
213
|
+
// A token row is identified by its OWN counterparty key, never by
|
|
214
|
+
// `counterpartyOf(action)`: the action's labels/senderIdentityKey belong
|
|
215
|
+
// to the underlying BSV coin-selection transaction, not to who the token
|
|
216
|
+
// moved with. No key (an unresolvable/blinded counterparty) draws the
|
|
217
|
+
// plain arrow, same as any other row this hook cannot name.
|
|
218
|
+
if (isTokenRow) {
|
|
219
|
+
if (!tokenCounterpartyKey) return null
|
|
220
|
+
const cp: Counterparty = { kind: 'identityKey', value: tokenCounterpartyKey }
|
|
221
|
+
return { point: sigilPointOf(cp), hue: counterpartyHue(cp) }
|
|
222
|
+
}
|
|
173
223
|
const cp = counterpartyOf({ labels: labelsKey === '' ? undefined : labelsKey.split('\n'), senderIdentityKey, txid })
|
|
174
224
|
return cp ? { point: sigilPointOf(cp), hue: counterpartyHue(cp) } : null
|
|
175
|
-
}, [labelsKey, senderIdentityKey, txid])
|
|
225
|
+
}, [labelsKey, senderIdentityKey, txid, isTokenRow, tokenCounterpartyKey])
|
|
176
226
|
// Resolved outside the memo: the hue is a property of the counterparty, the
|
|
177
227
|
// colours it maps to are a property of the theme, and the theme can flip
|
|
178
228
|
// under a mounted row. Two HSL conversions per render are not worth a dep.
|
|
@@ -188,14 +238,16 @@ function ActivityRowBase({
|
|
|
188
238
|
const parked = offlineStatus === 'parked'
|
|
189
239
|
const canCancelParked = parked && !!action.txid && !!onCancelParked
|
|
190
240
|
const canAbort = !parked && ABORTABLE_STATUSES.has(action.status) && !!action.reference
|
|
191
|
-
// Any outgoing payment this wallet can
|
|
192
|
-
// identity key as a label and the derivation data as
|
|
193
|
-
// the details can be
|
|
194
|
-
// message box or a nearby code that may never have been
|
|
241
|
+
// Any outgoing payment this wallet can re-deliver over the message box: both
|
|
242
|
+
// rails write the payee's identity key as a label and the derivation data as
|
|
243
|
+
// customInstructions, so the details can be sent again whether the payment
|
|
244
|
+
// went out through a message box or a nearby code that may never have been
|
|
245
|
+
// scanned. A token row qualifies too — the home screen routes it to the
|
|
246
|
+
// Mandala runtime's own re-delivery rather than a BRC-29 rebuild.
|
|
195
247
|
const resendableOutbound =
|
|
196
248
|
!!action.txid &&
|
|
197
249
|
(action.isOutgoing ?? !incoming) &&
|
|
198
|
-
!!action.labels?.some(l => l === 'peerpay' || l === 'localpay')
|
|
250
|
+
!!action.labels?.some(l => l === 'peerpay' || l === 'localpay' || l === 'mandala')
|
|
199
251
|
const canResendDetails = resendableOutbound && !!onSendPaymentDetails
|
|
200
252
|
const canSendAgain = !parked && !incoming && action.status === 'failed' && !!onSendAgain
|
|
201
253
|
const hasUtilities = parked
|
|
@@ -219,7 +271,16 @@ function ActivityRowBase({
|
|
|
219
271
|
style={styles.row}
|
|
220
272
|
accessibilityRole="button"
|
|
221
273
|
accessibilityState={{ expanded }}
|
|
222
|
-
accessibilityLabel={
|
|
274
|
+
accessibilityLabel={
|
|
275
|
+
token
|
|
276
|
+
? // Never the lib's developer description, which carries a raw
|
|
277
|
+
// 36-byte token id, and never silence for a figure we could not
|
|
278
|
+
// recover: "Sent USDX, amount unavailable" is the honest read.
|
|
279
|
+
`${token.title}, ${
|
|
280
|
+
token.amount ? `${token.amount.value} ${token.amount.unit}` : t('token_row_amount_pending')
|
|
281
|
+
}`
|
|
282
|
+
: action.description || t('transactions')
|
|
283
|
+
}
|
|
223
284
|
>
|
|
224
285
|
{/* The sigil fills the tile, so direction moves to the border tint
|
|
225
286
|
alone: the same tints as the arrow tile, so a mixed list still
|
|
@@ -268,7 +329,7 @@ function ActivityRowBase({
|
|
|
268
329
|
|
|
269
330
|
<View style={styles.middle}>
|
|
270
331
|
<Text style={[styles.description, { color: colors.textPrimary }]} numberOfLines={1}>
|
|
271
|
-
{action.description || t('transactions')}
|
|
332
|
+
{token ? token.title : action.description || t('transactions')}
|
|
272
333
|
</Text>
|
|
273
334
|
<View style={styles.statusLine}>
|
|
274
335
|
<View
|
|
@@ -281,17 +342,40 @@ function ActivityRowBase({
|
|
|
281
342
|
style={[styles.statusText, { color: settled ? colors.textSecondary : tone }]}
|
|
282
343
|
numberOfLines={1}
|
|
283
344
|
>
|
|
284
|
-
{
|
|
345
|
+
{(() => {
|
|
346
|
+
const words = token?.statusText ?? t(view.key)
|
|
347
|
+
return time ? `${words} · ${time}` : words
|
|
348
|
+
})()}
|
|
285
349
|
</Text>
|
|
286
350
|
</View>
|
|
287
351
|
</View>
|
|
288
352
|
|
|
289
353
|
<View style={styles.amounts}>
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
354
|
+
{token ? (
|
|
355
|
+
token.amount ? (
|
|
356
|
+
// No secondary denomination line: this wallet has no price for a
|
|
357
|
+
// token, and a converted figure would be invented.
|
|
358
|
+
<Text
|
|
359
|
+
style={[styles.amount, { color: amountColor }]}
|
|
360
|
+
accessibilityLabel={`${token.amount.value} ${token.amount.unit}`}
|
|
361
|
+
>
|
|
362
|
+
{token.amount.value}
|
|
363
|
+
<Text style={[styles.amountUnit, { color: unitColor }]}> {token.amount.unit}</Text>
|
|
364
|
+
</Text>
|
|
365
|
+
) : (
|
|
366
|
+
<Text style={[styles.amountSecondary, { color: colors.textTertiary }]}>
|
|
367
|
+
{t('token_row_amount_pending')}
|
|
368
|
+
</Text>
|
|
369
|
+
)
|
|
370
|
+
) : (
|
|
371
|
+
<>
|
|
372
|
+
<Text style={[styles.amount, { color: amountColor }]}>
|
|
373
|
+
{value}
|
|
374
|
+
{unit ? <Text style={[styles.amountUnit, { color: unitColor }]}> {unit}</Text> : null}
|
|
375
|
+
</Text>
|
|
376
|
+
<Text style={[styles.amountSecondary, { color: colors.textTertiary }]}>{secondary}</Text>
|
|
377
|
+
</>
|
|
378
|
+
)}
|
|
295
379
|
</View>
|
|
296
380
|
</PressableScale>
|
|
297
381
|
|
|
@@ -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,9 +129,9 @@ 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
|
-
|
|
134
|
+
setDisplayText(
|
|
107
135
|
amount % 1 === 0
|
|
108
136
|
? amount.toFixed(0)
|
|
109
137
|
: amount.toFixed(fractionDigits).replace(/0+$/, '').replace(/\.$/, '')
|
|
@@ -111,17 +139,37 @@ export const AmountInput: React.FC<AmountInputProps> = ({
|
|
|
111
139
|
}
|
|
112
140
|
}
|
|
113
141
|
}
|
|
114
|
-
|
|
142
|
+
lastEmitted.current = value
|
|
115
143
|
}, [value, isFiat, currency, satoshisPerUSD, usdToFiat, fractionDigits])
|
|
116
144
|
|
|
145
|
+
// The asset-mode twin of the effect above, with the same self-resync guard.
|
|
146
|
+
// The two are mutually exclusive by mode and neither can run in the other's.
|
|
147
|
+
useEffect(() => {
|
|
148
|
+
if (!asset) return
|
|
149
|
+
if (value === lastEmitted.current) return
|
|
150
|
+
setDisplayText(!value || value === '0' ? '' : tokenAmountInputText(Number(value), asset.decimals))
|
|
151
|
+
lastEmitted.current = value
|
|
152
|
+
}, [value, asset])
|
|
153
|
+
|
|
117
154
|
const handleChangeText = (text: string) => {
|
|
155
|
+
if (asset) {
|
|
156
|
+
if (text && !tokenAmountMask(asset.decimals).test(text)) return
|
|
157
|
+
setDisplayText(text)
|
|
158
|
+
const baseUnits = parseTokenAmount(text, asset.decimals)
|
|
159
|
+
// The field never emits a fraction: the wire takes whole base units, and
|
|
160
|
+
// a rounded figure would pay an amount other than the one on screen.
|
|
161
|
+
const next = baseUnits === null ? '' : String(baseUnits)
|
|
162
|
+
lastEmitted.current = next
|
|
163
|
+
onChangeText(next)
|
|
164
|
+
return
|
|
165
|
+
}
|
|
118
166
|
if (isFiat) {
|
|
119
167
|
const allowed = fractionDigits === 0 ? /^\d*$/ : new RegExp(`^\\d*\\.?\\d{0,${fractionDigits}}$`)
|
|
120
168
|
if (text && !allowed.test(text)) return
|
|
121
|
-
|
|
169
|
+
setDisplayText(text)
|
|
122
170
|
const sats = parseDisplayToSatoshis(text, currency, satoshisPerUSD, usdToFiat)
|
|
123
171
|
const satsStr = text ? String(sats) : ''
|
|
124
|
-
|
|
172
|
+
lastEmitted.current = satsStr
|
|
125
173
|
onChangeText(satsStr)
|
|
126
174
|
} else {
|
|
127
175
|
onChangeText(text)
|
|
@@ -137,7 +185,7 @@ export const AmountInput: React.FC<AmountInputProps> = ({
|
|
|
137
185
|
</View>
|
|
138
186
|
<TouchableOpacity
|
|
139
187
|
onPress={() => {
|
|
140
|
-
if (isFiat)
|
|
188
|
+
if (isFiat) setDisplayText('')
|
|
141
189
|
onChangeText('')
|
|
142
190
|
}}
|
|
143
191
|
style={[styles.clearButton, { backgroundColor: colors.fill }]}
|
|
@@ -148,16 +196,20 @@ export const AmountInput: React.FC<AmountInputProps> = ({
|
|
|
148
196
|
)
|
|
149
197
|
}
|
|
150
198
|
|
|
151
|
-
const displayValue = isFiat ?
|
|
152
|
-
const placeholder =
|
|
153
|
-
const keyboardType =
|
|
154
|
-
const unitLabel = isFiat ? currency : 'satoshis'
|
|
199
|
+
const displayValue = isFiat || asset ? displayText : value
|
|
200
|
+
const placeholder = fractionDigits === 0 ? '0' : `0.${'0'.repeat(Math.min(fractionDigits, 8))}`
|
|
201
|
+
const keyboardType = fractionDigits > 0 ? ('decimal-pad' as const) : ('number-pad' as const)
|
|
202
|
+
const unitLabel = asset ? asset.ticker : isFiat ? currency : 'satoshis'
|
|
155
203
|
|
|
156
|
-
// Secondary converted-currency line: BSV when showing fiat, USD when showing BSV
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
204
|
+
// Secondary converted-currency line: BSV when showing fiat, USD when showing BSV.
|
|
205
|
+
// Suppressed entirely in asset mode — this wallet has no price for a token,
|
|
206
|
+
// and a converted line under a stablecoin figure would be invented.
|
|
207
|
+
const satsForConversion = !asset && value ? parseInt(value, 10) : 0
|
|
208
|
+
const secondaryText = asset
|
|
209
|
+
? null
|
|
210
|
+
: isFiat
|
|
211
|
+
? (satsForConversion > 0 ? formatAmount(satsForConversion, 'BSV', satoshisPerUSD) : null)
|
|
212
|
+
: (satsForConversion > 0 && satoshisPerUSD > 0 ? formatAmount(satsForConversion, 'USD', satoshisPerUSD) : null)
|
|
161
213
|
|
|
162
214
|
const entering = reducedMotion ? undefined : FadeInUp.duration(durations.instant)
|
|
163
215
|
const exiting = reducedMotion ? undefined : FadeOutDown.duration(durations.instant)
|
|
@@ -181,7 +233,7 @@ export const AmountInput: React.FC<AmountInputProps> = ({
|
|
|
181
233
|
</View>
|
|
182
234
|
{showMax && (
|
|
183
235
|
<TouchableOpacity
|
|
184
|
-
onPress={() => onChangeText(SEND_MAX_VALUE)}
|
|
236
|
+
onPress={() => onChangeText(asset ? (maxValue ?? '') : SEND_MAX_VALUE)}
|
|
185
237
|
style={[styles.maxButton, { backgroundColor: colors.fill }]}
|
|
186
238
|
>
|
|
187
239
|
<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
|
+
})
|