@bloxwap/hig 0.7.0 → 0.9.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/README.md +2 -2
- package/chart/README.md +13 -2
- package/chart/dist/altimeter-burst.d.ts +4 -0
- package/chart/dist/altimeter-burst.js +43 -0
- package/chart/dist/altimeter-chart.d.ts +52 -0
- package/chart/dist/altimeter-chart.js +275 -0
- package/chart/dist/altimeter-model.d.ts +43 -0
- package/chart/dist/altimeter-model.js +148 -0
- package/chart/dist/altimeter-targets.d.ts +33 -0
- package/chart/dist/altimeter-targets.js +88 -0
- package/chart/dist/bitcoin-price.d.ts +8 -0
- package/chart/dist/bitcoin-price.js +41 -0
- package/chart/dist/champions-league.d.ts +19 -0
- package/chart/dist/champions-league.js +104 -0
- package/chart/dist/index.d.ts +6 -0
- package/chart/dist/index.js +5 -0
- package/chart/dist/outcome-chart.d.ts +37 -0
- package/chart/dist/outcome-chart.js +212 -0
- package/chart/dist/outcome-model.d.ts +43 -0
- package/chart/dist/outcome-model.js +71 -0
- package/chart/dist/plus-grid.d.ts +6 -0
- package/chart/dist/plus-grid.js +29 -0
- package/contracts/README.md +1 -1
- package/contracts/dist/avatar.d.ts +68 -0
- package/contracts/dist/avatar.js +93 -0
- package/contracts/dist/confetti.d.ts +174 -0
- package/contracts/dist/confetti.js +138 -0
- package/contracts/dist/decimal.d.ts +7 -0
- package/contracts/dist/decimal.js +35 -0
- package/contracts/dist/index.d.ts +29 -2
- package/contracts/dist/index.js +123 -4
- package/contracts/dist/invariants.d.ts +17 -0
- package/contracts/dist/invariants.js +24 -0
- package/contracts/dist/login.d.ts +34 -0
- package/contracts/dist/login.js +43 -0
- package/contracts/dist/messages.d.ts +57 -3
- package/contracts/dist/messages.js +20 -2
- package/contracts/dist/number-flow.d.ts +90 -0
- package/contracts/dist/number-flow.js +150 -0
- package/contracts/dist/qr.d.ts +151 -0
- package/contracts/dist/qr.js +581 -0
- package/contracts/dist/toast.d.ts +168 -0
- package/contracts/dist/toast.js +171 -0
- package/feedback/README.md +1 -1
- package/feedback/dist/contract.js +1 -1
- package/feedback/dist/react.js +2 -4
- package/native/README.md +6 -1
- package/native/dist/account-block.d.ts +10 -1
- package/native/dist/account-block.js +17 -7
- package/native/dist/animated-number-model.d.ts +41 -1
- package/native/dist/animated-number-model.js +201 -23
- package/native/dist/animated-number.d.ts +39 -1
- package/native/dist/animated-number.js +164 -17
- package/native/dist/announce.d.ts +2 -0
- package/native/dist/announce.js +10 -0
- package/native/dist/asset-balance-row.d.ts +3 -1
- package/native/dist/asset-balance-row.js +15 -4
- package/native/dist/assets-block.d.ts +115 -0
- package/native/dist/assets-block.js +87 -0
- package/native/dist/async-result.d.ts +2 -0
- package/native/dist/async-result.js +11 -0
- package/native/dist/avatar-frame.d.ts +29 -0
- package/native/dist/avatar-frame.js +56 -0
- package/native/dist/avatar.d.ts +21 -0
- package/native/dist/avatar.js +31 -0
- package/native/dist/bar-mark.d.ts +2 -0
- package/native/dist/bar-mark.js +4 -2
- package/native/dist/bar-pnl.js +2 -1
- package/native/dist/blocks.d.ts +9 -2
- package/native/dist/blocks.js +8 -1
- package/native/dist/brand.js +2 -1
- package/native/dist/button.d.ts +7 -2
- package/native/dist/button.js +13 -3
- package/native/dist/checkbox.js +2 -1
- package/native/dist/confetti.d.ts +33 -0
- package/native/dist/confetti.js +143 -0
- package/native/dist/confirm-block.d.ts +98 -0
- package/native/dist/confirm-block.js +48 -0
- package/native/dist/data.d.ts +1 -1
- package/native/dist/data.js +5 -1
- package/native/dist/deposit-block.d.ts +19 -0
- package/native/dist/deposit-block.js +17 -0
- package/native/dist/explainer-block.d.ts +91 -0
- package/native/dist/explainer-block.js +34 -0
- package/native/dist/field.d.ts +5 -1
- package/native/dist/field.js +27 -6
- package/native/dist/gesture-sheet-model.d.ts +50 -0
- package/native/dist/gesture-sheet-model.js +105 -0
- package/native/dist/gesture-sheet-next.d.ts +82 -0
- package/native/dist/gesture-sheet-next.js +315 -0
- package/native/dist/gesture-sheet.d.ts +5 -1
- package/native/dist/gesture-sheet.js +13 -6
- package/native/dist/icons.d.ts +9 -6
- package/native/dist/icons.js +25 -24
- package/native/dist/language-block.d.ts +10 -1
- package/native/dist/language-block.js +11 -4
- package/native/dist/list-group.d.ts +3 -1
- package/native/dist/list-group.js +26 -13
- package/native/dist/login-block.d.ts +4 -0
- package/native/dist/login-block.js +22 -0
- package/native/dist/manage-position-block.d.ts +8 -1
- package/native/dist/manage-position-block.js +7 -2
- package/native/dist/market-row.js +19 -8
- package/native/dist/navigation.js +5 -3
- package/native/dist/number-format.d.ts +6 -0
- package/native/dist/number-format.js +9 -0
- package/native/dist/pickers.d.ts +8 -0
- package/native/dist/pickers.js +3 -3
- package/native/dist/position-block.d.ts +5 -5
- package/native/dist/preset-group.d.ts +31 -0
- package/native/dist/preset-group.js +39 -0
- package/native/dist/preset-picker-block.d.ts +107 -0
- package/native/dist/preset-picker-block.js +43 -0
- package/native/dist/profile-block.d.ts +10 -1
- package/native/dist/profile-block.js +8 -3
- package/native/dist/provider.d.ts +5 -2
- package/native/dist/provider.js +27 -5
- package/native/dist/qr-code.d.ts +33 -0
- package/native/dist/qr-code.js +29 -0
- package/native/dist/radio-group.d.ts +19 -7
- package/native/dist/radio-group.js +39 -10
- package/native/dist/reward-block.d.ts +10 -7
- package/native/dist/reward-block.js +9 -4
- package/native/dist/screen-header.d.ts +13 -3
- package/native/dist/screen-header.js +12 -4
- package/native/dist/select.js +4 -2
- package/native/dist/selection.d.ts +2 -1
- package/native/dist/selection.js +1 -0
- package/native/dist/setting-switch.d.ts +1 -1
- package/native/dist/setting-switch.js +7 -3
- package/native/dist/slider.js +5 -1
- package/native/dist/sound-haptics-block.js +1 -1
- package/native/dist/status.d.ts +41 -9
- package/native/dist/status.js +34 -17
- package/native/dist/sticky-header.js +9 -1
- package/native/dist/swap-amount-card.d.ts +57 -0
- package/native/dist/swap-amount-card.js +31 -0
- package/native/dist/{swap-panel-block.d.ts → swap-block.d.ts} +18 -8
- package/native/dist/{swap-panel-block.js → swap-block.js} +63 -35
- package/native/dist/swap-parts.d.ts +3 -10
- package/native/dist/swap-parts.js +22 -24
- package/native/dist/swap-shared.d.ts +2 -2
- package/native/dist/swap-shared.js +10 -6
- package/native/dist/swap-sheet.d.ts +3 -3
- package/native/dist/swap-sheet.js +3 -3
- package/native/dist/swap-views.js +1 -1
- package/native/dist/target-block.d.ts +7 -1
- package/native/dist/target-block.js +13 -6
- package/native/dist/toast.d.ts +47 -0
- package/native/dist/toast.js +386 -0
- package/native/dist/token-action-block.d.ts +11 -2
- package/native/dist/token-action-block.js +10 -4
- package/native/dist/trade-history-list-block.js +7 -4
- package/native/dist/wallet-address-core.js +6 -3
- package/native-fonts/README.md +1 -1
- package/og-fonts/README.md +1 -1
- package/package.json +155 -11
- package/react/README.md +3 -1
- package/react/dist/animated-number-flow.d.ts +72 -0
- package/react/dist/animated-number-flow.js +316 -0
- package/react/dist/animated-number-model.d.ts +18 -0
- package/react/dist/animated-number-model.js +75 -5
- package/react/dist/animated-number.d.ts +45 -1
- package/react/dist/animated-number.js +137 -6
- package/react/dist/asset-balance-row.d.ts +3 -1
- package/react/dist/asset-balance-row.js +10 -4
- package/react/dist/async-result.d.ts +2 -0
- package/react/dist/async-result.js +11 -0
- package/react/dist/avatar.d.ts +25 -0
- package/react/dist/avatar.js +50 -0
- package/react/dist/blocks/account-block.d.ts +5 -1
- package/react/dist/blocks/account-block.js +11 -6
- package/react/dist/blocks/assets-block.d.ts +106 -0
- package/react/dist/blocks/assets-block.js +135 -0
- package/react/dist/blocks/confirm-block.d.ts +91 -0
- package/react/dist/blocks/confirm-block.js +31 -0
- package/react/dist/blocks/deposit-block.d.ts +19 -0
- package/react/dist/blocks/deposit-block.js +15 -0
- package/react/dist/blocks/explainer-block.d.ts +80 -0
- package/react/dist/blocks/explainer-block.js +20 -0
- package/react/dist/blocks/install-command.js +3 -1
- package/react/dist/blocks/language-block.d.ts +5 -1
- package/react/dist/blocks/language-block.js +4 -3
- package/react/dist/blocks/login-block.d.ts +4 -0
- package/react/dist/blocks/login-block.js +14 -0
- package/react/dist/blocks/manage-position-block.d.ts +3 -1
- package/react/dist/blocks/manage-position-block.js +2 -2
- package/react/dist/blocks/market-row.js +8 -3
- package/react/dist/blocks/notifications-block.d.ts +3 -1
- package/react/dist/blocks/notifications-block.js +2 -2
- package/react/dist/blocks/pickers.d.ts +9 -0
- package/react/dist/blocks/pickers.js +4 -2
- package/react/dist/blocks/position-block.d.ts +3 -3
- package/react/dist/blocks/preset-picker-block.d.ts +85 -0
- package/react/dist/blocks/preset-picker-block.js +19 -0
- package/react/dist/blocks/profile-block.d.ts +5 -1
- package/react/dist/blocks/profile-block.js +12 -13
- package/react/dist/blocks/reward-block.d.ts +13 -8
- package/react/dist/blocks/reward-block.js +7 -4
- package/react/dist/blocks/screen-header.d.ts +10 -2
- package/react/dist/blocks/screen-header.js +7 -4
- package/react/dist/blocks/setting-switch.js +6 -3
- package/react/dist/blocks/signals-block.d.ts +3 -1
- package/react/dist/blocks/signals-block.js +4 -3
- package/react/dist/blocks/sound-haptics-block.d.ts +3 -1
- package/react/dist/blocks/sound-haptics-block.js +2 -2
- package/react/dist/blocks/sticky-header.d.ts +14 -4
- package/react/dist/blocks/sticky-header.js +68 -8
- package/react/dist/blocks/swap/settings.js +2 -1
- package/react/dist/blocks/swap/shared.d.ts +22 -22
- package/react/dist/blocks/swap/shared.js +30 -28
- package/react/dist/blocks/{swap-panel-block.d.ts → swap-block.d.ts} +19 -8
- package/react/dist/blocks/swap-block.js +215 -0
- package/react/dist/blocks/swap-sheet.d.ts +3 -3
- package/react/dist/blocks/swap-sheet.js +3 -3
- package/react/dist/blocks/target-block.d.ts +7 -1
- package/react/dist/blocks/target-block.js +10 -4
- package/react/dist/blocks/token-action-block.d.ts +6 -2
- package/react/dist/blocks/token-action-block.js +3 -2
- package/react/dist/blocks/trade-history-detail-block.d.ts +3 -1
- package/react/dist/blocks/trade-history-detail-block.js +2 -2
- package/react/dist/blocks/trade-history-list-block.d.ts +3 -1
- package/react/dist/blocks/trade-history-list-block.js +7 -4
- package/react/dist/blocks.d.ts +8 -2
- package/react/dist/blocks.js +7 -1
- package/react/dist/brand.js +2 -1
- package/react/dist/button.d.ts +9 -3
- package/react/dist/button.js +8 -3
- package/react/dist/confetti.d.ts +27 -0
- package/react/dist/confetti.js +240 -0
- package/react/dist/data.js +8 -1
- package/react/dist/field.d.ts +6 -1
- package/react/dist/field.js +18 -9
- package/react/dist/gesture-sheet.d.ts +15 -1
- package/react/dist/gesture-sheet.js +53 -8
- package/react/dist/list-group.js +11 -7
- package/react/dist/navigation.js +11 -3
- package/react/dist/overlay.d.ts +1 -4
- package/react/dist/overlay.js +1 -3
- package/react/dist/popover.d.ts +30 -0
- package/react/dist/popover.js +34 -0
- package/react/dist/preset-group.d.ts +30 -0
- package/react/dist/preset-group.js +13 -0
- package/react/dist/provider.d.ts +2 -2
- package/react/dist/provider.js +23 -6
- package/react/dist/qr-code.d.ts +32 -0
- package/react/dist/qr-code.js +28 -0
- package/react/dist/select.js +10 -3
- package/react/dist/selection.d.ts +13 -5
- package/react/dist/selection.js +13 -8
- package/react/dist/slider.js +5 -1
- package/react/dist/status.d.ts +14 -10
- package/react/dist/status.js +17 -9
- package/react/dist/styles.css +260 -165
- package/react/dist/toast.d.ts +19 -12
- package/react/dist/toast.js +29 -7
- package/react/dist/wallet-address-core.d.ts +8 -4
- package/react/dist/wallet-address-core.js +10 -5
- package/tokens/README.md +2 -2
- package/tokens/assets/onramps/apple-pay.svg +33 -0
- package/tokens/assets/onramps/bank.svg +98 -0
- package/tokens/assets/onramps/blink.svg +37 -0
- package/tokens/assets/onramps/cashapp.svg +33 -0
- package/tokens/assets/onramps/crypto.svg +121 -0
- package/tokens/assets/onramps/exchange.svg +105 -0
- package/tokens/dist/deposit-icons.d.ts +1 -0
- package/tokens/dist/deposit-icons.js +28 -0
- package/tokens/dist/index.d.ts +16 -0
- package/tokens/dist/index.js +16 -0
- package/tokens/dist/manifest.json +8 -0
- package/tokens/dist/tokens.css +6 -0
- package/react/dist/blocks/swap-panel-block.js +0 -178
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { decimal, decimalDivide, decimalCompare, localizeDecimal } from '@bloxwap/hig/contracts';
|
|
3
|
+
import { useAsyncResult } from './async-result.js';
|
|
2
4
|
import { useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
5
|
import { Animated, BackHandler, Easing, Platform, Pressable, StyleSheet, View } from 'react-native';
|
|
4
|
-
import { formatNumber } from '
|
|
6
|
+
import { formatNumber } from './number-format.js';
|
|
5
7
|
import { Raised, useColors, useControllable, useHIG, useMessages, useNumberLocale, usePresentNumber } from './provider.js';
|
|
6
8
|
import { Text } from './surface.js';
|
|
7
9
|
import { Button, IconButton } from './button.js';
|
|
@@ -10,18 +12,20 @@ import { figureProps } from './figure.js';
|
|
|
10
12
|
import { Toast, useTransientNotice } from './status.js';
|
|
11
13
|
import { VerticalAddress, addressKind } from './data.js';
|
|
12
14
|
import { withAlpha } from '@bloxwap/hig/tokens';
|
|
13
|
-
import { DownIcon, FlipIcon, MenuIcon, ResetIcon, SmallChevron, SwapCapsule,
|
|
15
|
+
import { DownIcon, FlipIcon, MenuIcon, ResetIcon, SmallChevron, SwapCapsule, SwapHostContext, SwapKeypad, SwapNumberText, TokenArt } from './swap-parts.js';
|
|
16
|
+
import { ScreenHeader } from './screen-header.js';
|
|
14
17
|
import { SwapPicker, SwapSettings } from './swap-views.js';
|
|
15
|
-
import { addressColor, applyAmountKey, formatPercent, shortAddress, swapAction, swapParentView, testAmount,
|
|
18
|
+
import { addressColor, applyAmountKey, formatPercent, shortAddress, swapAction, swapParentView, testAmount, unitsToEntry } from './swap-shared.js';
|
|
16
19
|
export { swapAction, swapParentView } from './swap-shared.js';
|
|
17
20
|
/** What a host surface lends the panel. A sheet passes its backend's list, so list drags hand off to the sheet, and sizes itself, so the panel does not animate its own height. */
|
|
18
21
|
export { SwapHostContext } from './swap-parts.js';
|
|
22
|
+
export { SwapAmountCard, SwapPill } from './swap-amount-card.js';
|
|
19
23
|
/**
|
|
20
24
|
* Send, swap and bridge in one panel: a From card and a To card joined by a flip control, an amount entered in dollars
|
|
21
25
|
* or token units through the keypad, token pickers, settings, and one action that names itself from the chosen pair.
|
|
22
26
|
* Presentation only. The host owns tokens, balances, prices, the quote, the wallet and the transaction.
|
|
23
27
|
*/
|
|
24
|
-
export function
|
|
28
|
+
export function SwapBlock({ tokens, fromTokens, fromTokensLoading, chains, hotTokenIds, from: fromProp, to: toProp, defaultFrom = null, defaultTo = null, onFromChange, onToChange, amount, onAmountChange, received, fee, fees, quoteLoading, slippage = 0.005, onSlippageChange, denomination, onDenominationChange, wallet, onConnect, onDisconnect, recipient, onRecipientChange, onScanRecipient, receive, receiving, onReceivingChange, onSubmit, submitting = false, submittingLabel, onReset, keypad = 'auto', destination, details, note, noteTone = 'muted', title, onBack, headingId, controls = true, actionIcon, lockFrom = false, lockTo = false, actionLabel, actionDisabled = false, actionStatus, actionIntent = 'primary', limitToBalance = false, banner, footer, oneWay: oneWayProp = false, denominationSwitch = true, settings, view: viewProp, onViewChange, style }) {
|
|
25
29
|
const env = useHIG();
|
|
26
30
|
const { direction } = env;
|
|
27
31
|
const locale = useNumberLocale();
|
|
@@ -30,10 +34,11 @@ export function SwapPanelBlock({ tokens, fromTokens, fromTokensLoading, chains,
|
|
|
30
34
|
const t = useMessages();
|
|
31
35
|
const [from, setFrom] = useControllable(fromProp, defaultFrom, onFromChange);
|
|
32
36
|
const [to, setTo] = useControllable(toProp, defaultTo, onToChange);
|
|
37
|
+
const boundedUnits = (raw) => { const canonical = decimal(raw, from?.decimals ?? 100); return limitToBalance && from?.balance != null && Number.isFinite(from.balance) && from.balance >= 0 && decimalCompare(canonical, from.balance) > 0 ? decimal(from.balance, from?.decimals ?? 100) : canonical; };
|
|
33
38
|
const [defaultMode, setDefaultMode] = useControllable(denomination, 'usd', onDenominationChange);
|
|
34
39
|
const [isReceiving, setReceiving] = useControllable(receiving, false, onReceivingChange);
|
|
35
40
|
// `amount` seeds the first render too, in the default denomination at the initial From token's price.
|
|
36
|
-
const [entry, setEntry] = useState(() => amount === undefined ? '0' : unitsToEntry(
|
|
41
|
+
const [entry, setEntry] = useState(() => amount === undefined ? '0' : unitsToEntry(boundedUnits(amount), defaultMode, from?.price ?? 0));
|
|
37
42
|
const [fromMode, setFromMode] = useState(defaultMode);
|
|
38
43
|
const [toMode, applyToMode] = useState(defaultMode);
|
|
39
44
|
const host = useContext(SwapHostContext);
|
|
@@ -50,7 +55,9 @@ export function SwapPanelBlock({ tokens, fromTokens, fromTokensLoading, chains,
|
|
|
50
55
|
return; const subscription = BackHandler.addEventListener('hardwareBackPress', () => { pop.current(); return true; }); return () => subscription.remove(); }, [view === 'main']);
|
|
51
56
|
const { notice, show: showNotice, dismiss: dismissNotice } = useTransientNotice();
|
|
52
57
|
const fromPrice = from?.price ?? 0, toPrice = to?.price ?? 0, input = Number(entry) || 0;
|
|
53
|
-
const
|
|
58
|
+
const exact = useRef(amount === undefined ? null : { entry, mode: fromMode, units: boundedUnits(amount), asset: from?.id });
|
|
59
|
+
const unitsText = exact.current && exact.current.entry === entry && exact.current.mode === fromMode && exact.current.asset === from?.id ? exact.current.units : fromMode === 'token' ? decimal(entry, from?.decimals ?? 100) : decimalDivide(entry, fromPrice, from?.decimals ?? 18);
|
|
60
|
+
const units = Number(unitsText), usd = units * fromPrice;
|
|
54
61
|
const showReceive = isReceiving && !!receive;
|
|
55
62
|
// Report the amount in token units; resync the entry when the host sets a different amount.
|
|
56
63
|
const reported = useRef(amount ?? '0');
|
|
@@ -58,42 +65,53 @@ export function SwapPanelBlock({ tokens, fromTokens, fromTokensLoading, chains,
|
|
|
58
65
|
reported.current = unitsText;
|
|
59
66
|
onAmountChange?.(unitsText);
|
|
60
67
|
} }, [unitsText]);
|
|
61
|
-
useEffect(() => { if (amount === undefined ||
|
|
62
|
-
return;
|
|
63
|
-
|
|
68
|
+
useEffect(() => { if (amount === undefined || boundedUnits(amount) === reported.current)
|
|
69
|
+
return; const canonical = boundedUnits(amount), next = unitsToEntry(canonical, fromMode, fromPrice); reported.current = canonical; if (decimal(amount) !== canonical)
|
|
70
|
+
onAmountChange?.(canonical); exact.current = { entry: next, mode: fromMode, units: canonical, asset: from?.id }; setEntry(next); }, [amount]);
|
|
71
|
+
const sameAsset = !!from && !!to && swapAction(from, to) === 'send';
|
|
64
72
|
const receivedUnits = sameAsset ? units : received ?? (toPrice > 0 ? usd / toPrice : 0);
|
|
65
73
|
const receivedUsd = toPrice > 0 ? receivedUnits * toPrice : sameAsset ? usd : 0;
|
|
66
74
|
const action = swapAction(from, to);
|
|
67
|
-
const insufficient = !!from &&
|
|
75
|
+
const insufficient = !!from && from.balance != null && (!Number.isFinite(from.balance) || from.balance < 0 || decimalCompare(unitsText, from.balance) > 0);
|
|
68
76
|
// A destination or a details card stands in for the To token: one way, and ready from the From side alone.
|
|
69
77
|
const fixed = !!destination || (!!details && !to);
|
|
70
78
|
const oneWay = oneWayProp || fixed;
|
|
71
|
-
const eligible = !!from && (!!to || fixed) && !destination?.pending && units > 0 && !insufficient;
|
|
79
|
+
const eligible = !!from && (!!to || fixed) && !destination?.pending && Number.isFinite(units) && units > 0 && !insufficient;
|
|
72
80
|
const ready = eligible && !actionDisabled;
|
|
73
|
-
const
|
|
81
|
+
const readyText = actionLabel ?? (action === 'swap' && !fixed ? t.swapActionSwap : action === 'bridge' && !fixed ? t.swapActionBridge : t.swapActionSend);
|
|
82
|
+
// While the host's submit is in flight the amount may already be cleared: the action keeps its name rather than asking for an amount.
|
|
83
|
+
const actionText = showReceive ? t.swapSendFromWallet : !from || (!to && !fixed) ? t.swapChooseToken : destination?.pending ? t.swapChooseDestination : submitting ? submittingLabel ?? (actionDisabled && actionStatus ? actionStatus : readyText) : units <= 0 ? t.swapEnterAmount : insufficient ? t.swapInsufficient(from.symbol) : actionDisabled && actionStatus ? actionStatus : readyText;
|
|
74
84
|
const pristine = (lockFrom || !from) && (lockTo || !to) && input === 0;
|
|
75
85
|
// Updater form: several keys can land before the next render, and each must build on the last.
|
|
76
86
|
const latest = useRef(fromMode);
|
|
77
87
|
latest.current = fromMode;
|
|
78
88
|
// Read at key time: several keys can land in one render.
|
|
79
|
-
const limits = useRef({ decimals: from?.decimals, balance: from?.balance
|
|
80
|
-
limits.current = { decimals: from?.decimals, balance: from?.balance
|
|
81
|
-
const over = (next) => { const { balance, price, cap } = limits.current; if (!cap ||
|
|
82
|
-
return false;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
89
|
+
const limits = useRef({ decimals: from?.decimals, balance: from?.balance, price: from?.price ?? 0, cap: limitToBalance });
|
|
90
|
+
limits.current = { decimals: from?.decimals, balance: from?.balance, price: from?.price ?? 0, cap: limitToBalance };
|
|
91
|
+
const over = (next) => { const { balance, price, cap } = limits.current; if (!cap || balance == null)
|
|
92
|
+
return false; if (!Number.isFinite(balance) || balance < 0)
|
|
93
|
+
return true; const value = latest.current === 'token' ? next : decimalDivide(next, price, limits.current.decimals ?? 18); return decimalCompare(value, balance) > 0; };
|
|
94
|
+
// While the host's submit is in flight the keypad, Max and Test leave the amount as it is.
|
|
95
|
+
const typed = next => { if (!submitting)
|
|
96
|
+
setEntry(current => { const value = typeof next === 'function' ? next(current) : next; if (value === current || value.length > 1000)
|
|
97
|
+
return current; const normalized = decimal(value, latest.current === 'usd' ? 2 : limits.current.decimals ?? 100); if (over(normalized))
|
|
98
|
+
return current; exact.current = null; const [whole, fraction] = value.split('.'); const places = latest.current === 'usd' ? 2 : limits.current.decimals ?? 100; return fraction === undefined ? whole : places > 0 ? whole + '.' + fraction.slice(0, places) : whole; }); };
|
|
99
|
+
const press = (key) => typed(current => { const next = applyAmountKey(current, key, latest.current, limits.current.decimals); return key !== 'back' && over(next) ? current : next; });
|
|
100
|
+
const switchFromMode = (mode) => { if (submitting || mode === fromMode)
|
|
101
|
+
return; const next = unitsToEntry(unitsText, mode, fromPrice); exact.current = { entry: next, mode, units: unitsText, asset: from?.id }; setEntry(next); setFromMode(mode); };
|
|
102
|
+
const changeDenomination = (mode) => { if (submitting)
|
|
103
|
+
return; setDefaultMode(mode); switchFromMode(mode); applyToMode(mode); };
|
|
87
104
|
// A new default applies to an untouched entry at once; a typed amount keeps its denomination until reset.
|
|
88
105
|
useEffect(() => { if (input === 0) {
|
|
89
106
|
setFromMode(defaultMode);
|
|
90
107
|
applyToMode(defaultMode);
|
|
91
108
|
} }, [defaultMode]);
|
|
92
|
-
const reset = () => {
|
|
109
|
+
const reset = () => { if (submitting)
|
|
110
|
+
return; exact.current = null; setEntry('0'); setFromMode(defaultMode); applyToMode(defaultMode); if (isReceiving)
|
|
93
111
|
setReceiving(false); if (!lockFrom)
|
|
94
112
|
setFrom(null); if (!lockTo)
|
|
95
113
|
setTo(null); onReset?.(); };
|
|
96
|
-
const flip = () => { if (!from || !to)
|
|
114
|
+
const flip = () => { if (submitting || !from || !to)
|
|
97
115
|
return; setFrom(to); setTo(from); };
|
|
98
116
|
const submit = () => { if (submitting)
|
|
99
117
|
return; if (showReceive) {
|
|
@@ -102,8 +120,10 @@ export function SwapPanelBlock({ tokens, fromTokens, fromTokensLoading, chains,
|
|
|
102
120
|
} if (ready)
|
|
103
121
|
onSubmit(fixed ? 'send' : action); };
|
|
104
122
|
// A copied address shows as a transient toast capsule (about 4s, dismissible), announced the way Toast announces any notice.
|
|
105
|
-
const
|
|
106
|
-
|
|
123
|
+
const beginCopy = useAsyncResult(receive?.address);
|
|
124
|
+
const copyAddress = () => { const current = beginCopy(); if (!receive?.onCopy)
|
|
125
|
+
return; Promise.resolve().then(receive.onCopy).then(() => { if (current())
|
|
126
|
+
showNotice(t.addressCopied); }).catch(() => { }); };
|
|
107
127
|
const chainList = useMemo(() => { if (chains)
|
|
108
128
|
return chains; const seen = new Map(); for (const token of tokens)
|
|
109
129
|
if (!seen.has(token.chainId))
|
|
@@ -114,9 +134,9 @@ export function SwapPanelBlock({ tokens, fromTokens, fromTokensLoading, chains,
|
|
|
114
134
|
// Live numbers: the fee and slippage sentences keep their translated wording around a number that updates in place.
|
|
115
135
|
const usdOptions = { style: 'currency', currency: 'USD' }, feeKnown = !quoteLoading && fee != null, feeAmount = quoteLoading ? '…' : fee != null ? usdText(fee) : '—', slippageText = formatPercent(slippage);
|
|
116
136
|
// An account (a token with a `caption`) reads name over caption beside one disc, and offers Max only.
|
|
117
|
-
const account = (side, token, locked) => _jsxs(_Fragment, { children: [_jsxs(View, { pointerEvents: 'none', testID: `swap-account-${side}`, style: { flex: 1, minWidth: 0, flexDirection: 'row', alignItems: 'center', gap: 12 }, children: [_jsx(View, { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', children: _jsx(TokenArt, { uri: token.icon, symbol: token.symbol, size: 40 }) }), _jsxs(View, { style: { flex: 1, minWidth: 0 }, children: [_jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: 4 }, children: [_jsx(Text, { style: { fontWeight: '600', lineHeight: 21, flexShrink: 1 }, children: token.name }), locked ? null : _jsx(View, { testID: `swap-account-chevron-${side}`, children: _jsx(SmallChevron, { color: colors.muted }) })] }), typeof token.caption === 'object' ? _jsx(AnimatedNumberReadout, { testID: 'swap-caption', ...figureProps(token.caption), tone: 'muted', style: smallType }) : _jsx(Text, { style: small, children: token.caption })] })] }), side === 'from' && (token.balance ?? 0) > 0 ? _jsx(SwapCapsule, { testID: 'swap-max', onPress: () =>
|
|
118
|
-
const header = (side, token) => _jsxs(_Fragment, { children: [_jsxs(View, { pointerEvents: 'none', style: { flex: 1, minWidth: 0, flexDirection: 'row', alignItems: 'flex-start', gap: 12 }, children: [_jsx(View, { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', style: { alignItems: 'center' }, children: [wallet?.address ? _jsx(View, { style: { width: 28, height: 28, borderRadius: 14, backgroundColor: addressColor(wallet.address), borderWidth: 2, borderColor: colors.surface } }) : null, token.chainIcon ? _jsx(TokenArt, { uri: token.chainIcon, size: 28, ring: colors.surface }) : null, _jsx(TokenArt, { uri: token.icon, symbol: token.symbol, size: 28, ring: colors.surface })].filter(Boolean).map((layer, index) => _jsx(View, { style: { marginTop: index ? -14 : 0 }, children: layer }, index)) }), _jsxs(View, { style: { flex: 1, minWidth: 0 }, children: [wallet?.address ? _jsx(Text, { style: small, children: shortAddress(wallet.address) }) : null, _jsx(Text, { style: small, children: token.chain }), _jsx(Text, { style: { fontWeight: '600', lineHeight: 21 }, children: token.name })] })] }), side === 'from' ? ((token.balance ?? 0) > 0 ? _jsxs(View, { pointerEvents: 'box-none', style: { alignItems: 'flex-end', gap: 8, maxWidth: '60%' }, children: [_jsxs(View, { pointerEvents: 'box-none', style: { flexDirection: 'row', flexWrap: 'wrap', justifyContent: 'flex-end', gap: 8 }, children: [_jsx(SwapCapsule, { testID: 'swap-test', onPress: () =>
|
|
119
|
-
: _jsxs(View, { pointerEvents: 'box-none', style: { alignItems: 'flex-end', gap: 8, maxWidth: '60%' }, children: [_jsx(SwapCapsule, { testID: 'swap-slippage', label: t.swapSlippage(slippageText), onPress: () => show(onSlippageChange ? 'slippage' : 'settings'), children: _jsx(SwapNumberText, { template: t.swapSlippage, text: slippageText, value: slippage * 100, formattedValue: slippageText.slice(0, -1), suffix: '%' }) }), _jsx(View, { pointerEvents: 'none', children: _jsx(SwapNumberText, { testID: 'swap-fee', template: t.swapFee, text: feeAmount, value: feeKnown ? fee : null, options: usdOptions }) })] })] });
|
|
137
|
+
const account = (side, token, locked) => _jsxs(_Fragment, { children: [_jsxs(View, { pointerEvents: 'none', testID: `swap-account-${side}`, style: { flex: 1, minWidth: 0, flexDirection: 'row', alignItems: 'center', gap: 12 }, children: [_jsx(View, { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', children: _jsx(TokenArt, { uri: token.icon, symbol: token.symbol, size: 40 }) }), _jsxs(View, { style: { flex: 1, minWidth: 0 }, children: [_jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: 4 }, children: [_jsx(Text, { style: { fontWeight: '600', lineHeight: 21, flexShrink: 1 }, children: token.name }), locked ? null : _jsx(View, { testID: `swap-account-chevron-${side}`, children: _jsx(SmallChevron, { color: colors.muted }) })] }), typeof token.caption === 'object' ? _jsx(AnimatedNumberReadout, { testID: 'swap-caption', ...figureProps(token.caption), tone: 'muted', style: smallType }) : _jsx(Text, { style: small, children: token.caption })] })] }), side === 'from' && (token.balance ?? 0) > 0 ? _jsx(SwapCapsule, { disabled: submitting, testID: 'swap-max', onPress: () => typed(unitsToEntry(token.balance ?? 0, fromMode, fromPrice)), children: _jsx(Text, { style: small, children: t.swapMax }) }) : null] });
|
|
138
|
+
const header = (side, token) => _jsxs(_Fragment, { children: [_jsxs(View, { pointerEvents: 'none', style: { flex: 1, minWidth: 0, flexDirection: 'row', alignItems: 'flex-start', gap: 12 }, children: [_jsx(View, { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', style: { alignItems: 'center' }, children: [wallet?.address ? _jsx(View, { style: { width: 28, height: 28, borderRadius: 14, backgroundColor: addressColor(wallet.address), borderWidth: 2, borderColor: colors.surface } }) : null, token.chainIcon ? _jsx(TokenArt, { uri: token.chainIcon, size: 28, ring: colors.surface }) : null, _jsx(TokenArt, { uri: token.icon, symbol: token.symbol, size: 28, ring: colors.surface })].filter(Boolean).map((layer, index) => _jsx(View, { style: { marginTop: index ? -14 : 0 }, children: layer }, index)) }), _jsxs(View, { style: { flex: 1, minWidth: 0 }, children: [wallet?.address ? _jsx(Text, { style: small, children: shortAddress(wallet.address) }) : null, _jsx(Text, { style: small, children: token.chain }), _jsx(Text, { style: { fontWeight: '600', lineHeight: 21 }, children: token.name })] })] }), side === 'from' ? ((token.balance ?? 0) > 0 ? _jsxs(View, { pointerEvents: 'box-none', style: { alignItems: 'flex-end', gap: 8, maxWidth: '60%' }, children: [_jsxs(View, { pointerEvents: 'box-none', style: { flexDirection: 'row', flexWrap: 'wrap', justifyContent: 'flex-end', gap: 8 }, children: [_jsx(SwapCapsule, { disabled: submitting, testID: 'swap-test', onPress: () => typed(unitsToEntry(testAmount(token), fromMode, fromPrice)), children: _jsx(Text, { style: small, children: t.swapTest }) }), _jsx(SwapCapsule, { disabled: submitting, testID: 'swap-max', onPress: () => typed(unitsToEntry(token.balance ?? 0, fromMode, fromPrice)), children: _jsx(Text, { style: small, children: t.swapMax }) })] }), _jsx(View, { pointerEvents: 'none', children: _jsx(AnimatedNumberReadout, { testID: 'swap-balance', value: token.balance, options: { maximumFractionDigits: 6 }, suffix: ` ${token.symbol}`, tone: 'muted', style: smallType }) })] }) : null)
|
|
139
|
+
: _jsxs(View, { pointerEvents: 'box-none', style: { alignItems: 'flex-end', gap: 8, maxWidth: '60%' }, children: [_jsx(SwapCapsule, { disabled: submitting, testID: 'swap-slippage', label: t.swapSlippage(slippageText), onPress: () => !submitting && show(onSlippageChange ? 'slippage' : 'settings'), children: _jsx(SwapNumberText, { template: t.swapSlippage, text: slippageText, value: slippage * 100, formattedValue: slippageText.slice(0, -1), suffix: '%' }) }), _jsx(View, { pointerEvents: 'none', children: _jsx(SwapNumberText, { testID: 'swap-fee', template: t.swapFee, text: feeAmount, value: feeKnown ? fee : null, options: usdOptions }) })] })] });
|
|
120
140
|
const receiveView = (view) => {
|
|
121
141
|
const body = _jsxs(_Fragment, { children: [view.qr ? _jsx(View, { style: { width: 132, height: 132, padding: 8, borderRadius: 16, backgroundColor: colors.background }, children: view.qr }) : null, _jsx(View, { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', children: _jsx(VerticalAddress, { address: view.address, rowHeight: addressKind(view.address) === 'ethereum' ? 22 : 16 }) })] });
|
|
122
142
|
const layout = { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-evenly', gap: 12, paddingTop: 8, paddingHorizontal: 16, paddingBottom: 20 };
|
|
@@ -128,7 +148,7 @@ export function SwapPanelBlock({ tokens, fromTokens, fromTokensLoading, chains,
|
|
|
128
148
|
const shown = side === 'from' ? input : mode === 'token' ? receivedUnits : receivedUsd;
|
|
129
149
|
const options = { minimumFractionDigits: side === 'from' ? fraction : 0, maximumFractionDigits: mode === 'usd' ? 2 : 8, useGrouping: false };
|
|
130
150
|
const prefix = mode === 'usd' ? '$' : '', suffix = side === 'from' && entry.endsWith('.') ? '.' : '';
|
|
131
|
-
return _jsx(View, { testID: `swap-card-${side}`, style: { backgroundColor: colors.surface, borderRadius: 24, overflow: 'hidden' }, children: _jsxs(Raised, { children: [_jsxs(View, { children: [locked ? null : _jsx(Pressable, { accessibilityRole: 'button', accessibilityLabel: t.swapSelectToken(label), testID: `swap-slot-${side}`, onPress: () => show(side), style: StyleSheet.absoluteFill }), _jsx(View, { pointerEvents: 'box-none', style: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', gap: 12, minHeight: 84, padding: 16 }, children: token ? token.caption !== undefined ? account(side, token, locked) : header(side, token) : _jsx(View, { pointerEvents: 'none', children: _jsxs(Text, { accessible: false, style: { fontSize: 40, lineHeight: 46, fontWeight: '500', letterSpacing: -0.8, color: colors.faint }, children: [label, "\u2026"] }) }) })] }), side === 'from' && showReceive && receive ? receiveView(receive) : side === 'to' && showReceive ? null : _jsxs(View, { children: [locked ? null : _jsx(Pressable, { accessible: false, importantForAccessibility: 'no', testID: `swap-area-${side}`, onPress: () => show(side), style: StyleSheet.absoluteFill }), _jsxs(View, { pointerEvents: 'box-none', style: { alignItems: 'center', gap: 8, paddingTop: 4, paddingHorizontal: 16, paddingBottom: 20 }, children: [_jsx(View, { pointerEvents: 'none', accessible: true, accessibilityLabel: t.swapAmount(label), accessibilityValue: { text: `${prefix}${formatNumber(shown, locale, options)}${suffix}` }, testID: `swap-amount-${side}`, children: _jsx(AnimatedNumberReadout, { value: shown, prefix: prefix, suffix: suffix, options: options, tone: side === 'to' ? 'muted' : 'text', maxFontSizeMultiplier: 1.5, style: { fontSize: 44, lineHeight: 50, fontWeight: '700', letterSpacing: -0.9, textAlign: 'center' } }) }), denominationSwitch && _jsxs(SwapCapsule, { label: t.swapSwitchDenomination, testID: `swap-mode-${side}`, onPress: () => side === 'from' ? switchFromMode(fromMode === 'usd' ? 'token' : 'usd') : applyToMode(toMode === 'usd' ? 'token' : 'usd'), children: [_jsx(Text, { accessible: false, style: [small, { opacity: 0.5 }], children: "=" }), mode === 'token' ? _jsx(AnimatedNumberReadout, { testID: `swap-conversion-${side}`, value: cardUsd, options: usdOptions, tone: 'muted', style: smallType }) : _jsx(AnimatedNumberReadout, { testID: `swap-conversion-${side}`, value: cardUnits, options: { maximumFractionDigits: 8, useGrouping: false }, suffix: token ? ` ${token.symbol}` : '', tone: 'muted', style: smallType }), _jsx(FlipIcon, { color: colors.muted, size: 14 })] })] })] })] }) });
|
|
151
|
+
return _jsx(View, { testID: `swap-card-${side}`, style: { backgroundColor: colors.surface, borderRadius: 24, overflow: 'hidden' }, children: _jsxs(Raised, { children: [_jsxs(View, { children: [locked ? null : _jsx(Pressable, { accessibilityRole: 'button', accessibilityLabel: t.swapSelectToken(label), disabled: submitting, testID: `swap-slot-${side}`, onPress: () => !submitting && show(side), style: StyleSheet.absoluteFill }), _jsx(View, { pointerEvents: 'box-none', style: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', gap: 12, minHeight: 84, padding: 16 }, children: token ? token.caption !== undefined ? account(side, token, locked) : header(side, token) : _jsx(View, { pointerEvents: 'none', children: _jsxs(Text, { accessible: false, style: { fontSize: 40, lineHeight: 46, fontWeight: '500', letterSpacing: -0.8, color: colors.faint }, children: [label, "\u2026"] }) }) })] }), side === 'from' && showReceive && receive ? receiveView(receive) : side === 'to' && showReceive ? null : _jsxs(View, { children: [locked ? null : _jsx(Pressable, { accessible: false, importantForAccessibility: 'no', testID: `swap-area-${side}`, onPress: () => !submitting && show(side), style: StyleSheet.absoluteFill }), _jsxs(View, { pointerEvents: 'box-none', style: { alignItems: 'center', gap: 8, paddingTop: 4, paddingHorizontal: 16, paddingBottom: 20 }, children: [_jsx(View, { pointerEvents: 'none', accessible: true, accessibilityLabel: t.swapAmount(label), accessibilityValue: { text: side === 'from' && mode === 'token' ? localizeDecimal(entry, locale) : `${prefix}${formatNumber(shown, locale, options)}${suffix}` }, testID: `swap-amount-${side}`, children: _jsx(AnimatedNumberReadout, { value: shown, formattedValue: side === 'from' && mode === 'token' ? localizeDecimal(entry, locale) : undefined, prefix: prefix, suffix: side === 'from' && mode === 'token' ? '' : suffix, options: options, tone: side === 'to' ? 'muted' : 'text', maxFontSizeMultiplier: 1.5, style: { fontSize: 44, lineHeight: 50, fontWeight: '700', letterSpacing: -0.9, textAlign: 'center' } }) }), denominationSwitch && _jsxs(SwapCapsule, { disabled: submitting, label: t.swapSwitchDenomination, testID: `swap-mode-${side}`, onPress: () => !submitting && (side === 'from' ? switchFromMode(fromMode === 'usd' ? 'token' : 'usd') : applyToMode(toMode === 'usd' ? 'token' : 'usd')), children: [_jsx(Text, { accessible: false, style: [small, { opacity: 0.5 }], children: "=" }), mode === 'token' ? _jsx(AnimatedNumberReadout, { testID: `swap-conversion-${side}`, value: cardUsd, options: usdOptions, tone: 'muted', style: smallType }) : _jsx(AnimatedNumberReadout, { testID: `swap-conversion-${side}`, value: cardUnits, options: { maximumFractionDigits: 8, useGrouping: false }, suffix: token ? ` ${token.symbol}` : '', tone: 'muted', style: smallType }), _jsx(FlipIcon, { color: colors.muted, size: 14 })] })] })] })] }) });
|
|
132
152
|
};
|
|
133
153
|
// The fixed bottom card is one compact row for the destination (artwork, where it goes, a trailing detail and fee), label and value rows, or both.
|
|
134
154
|
const fixedCard = () => {
|
|
@@ -139,15 +159,21 @@ export function SwapPanelBlock({ tokens, fromTokens, fromTokensLoading, chains,
|
|
|
139
159
|
const rows = details && details.length > 0 ? _jsx(View, { testID: 'swap-details', style: { gap: 12, padding: 16, paddingTop: destination ? 0 : 16 }, children: details.map(detail => _jsxs(View, { style: { flexDirection: 'row', justifyContent: 'space-between', gap: 12 }, children: [_jsx(Text, { style: { color: colors.muted, lineHeight: 21 }, children: detail.label }), typeof detail.value === 'number' ? _jsx(AnimatedNumberReadout, { value: detail.value, options: detail.options, prefix: detail.prefix, suffix: detail.suffix, formattedValue: detail.formattedValue, animateFormatted: !!detail.formattedValue, style: { lineHeight: 21, textAlign: 'right' } }) : _jsx(Text, { style: { lineHeight: 21, textAlign: 'right', flexShrink: 1 }, children: detail.value })] }, detail.label)) }) : null;
|
|
140
160
|
const shape = { backgroundColor: colors.surface, borderRadius: 24, overflow: 'hidden' };
|
|
141
161
|
// With a pressable destination the whole card is the button; the rows inside it are read as part of it.
|
|
142
|
-
return destination?.onPress ? _jsx(Pressable, { accessibilityRole: 'button', accessibilityLabel: destination.title, testID: 'swap-destination',
|
|
162
|
+
return destination?.onPress ? _jsx(Pressable, { accessibilityRole: 'button', accessibilityLabel: destination.title, testID: 'swap-destination', disabled: submitting, onPress: () => { if (!submitting)
|
|
163
|
+
destination.onPress?.(); }, style: ({ pressed }) => [shape, { opacity: pressed ? 0.85 : 1 }], children: _jsxs(Raised, { children: [row, rows] }) }) : _jsx(View, { testID: 'swap-destination', style: shape, children: _jsxs(Raised, { children: [row, rows] }) });
|
|
143
164
|
};
|
|
144
165
|
const fromCard = card('from'), toCard = fixedCard() ?? card('to');
|
|
145
166
|
const tone = noteTone === 'warning' ? colors.warning : noteTone === 'negative' ? colors.negative : null;
|
|
146
|
-
const main = _jsxs(View, { testID: 'swap-view-main', children: [title ? _jsx(View, { style: { marginBottom: 12 }, children: _jsx(
|
|
167
|
+
const main = _jsxs(View, { testID: 'swap-view-main', children: [title ? _jsx(View, { style: { marginBottom: 12 }, children: _jsx(ScreenHeader, { testID: 'swap', title: title, onBack: onBack, headingId: headingId }) }) : null, banner ? _jsx(View, { testID: 'swap-banner', style: { marginBottom: 8 }, children: banner }) : null, fromCard, _jsx(View, { style: { height: 8, zIndex: 1, alignItems: 'center' }, children: _jsx(View, { style: { position: 'absolute', top: -15, width: 38, height: 38, borderRadius: 19, backgroundColor: colors.background, alignItems: 'center', justifyContent: 'center' }, children: oneWay ? _jsx(View, { testID: 'swap-one-way', style: { width: 32, height: 32, borderRadius: 16, alignItems: 'center', justifyContent: 'center', backgroundColor: colors.nested }, children: _jsx(DownIcon, { color: colors.muted }) }) : _jsx(Pressable, { accessibilityRole: 'button', accessibilityLabel: t.swapFlip, accessibilityState: { disabled: submitting || !from || !to }, disabled: submitting || !from || !to, testID: 'swap-flip', onPress: flip, hitSlop: 6, style: ({ pressed }) => ({ width: 32, height: 32, borderRadius: 16, alignItems: 'center', justifyContent: 'center', backgroundColor: !from || !to ? colors.surface : colors.nested, opacity: pressed ? 0.85 : 1 }), children: _jsx(FlipIcon, { color: !from || !to ? colors.faint : colors.muted }) }) }) }), toCard, note ? _jsx(View, { testID: 'swap-note', style: tone ? { marginTop: 8, paddingVertical: 12, paddingHorizontal: 16, borderRadius: 16, backgroundColor: withAlpha(tone, 0.1) } : { marginTop: 8, paddingHorizontal: 4 }, children: _jsx(Text, { style: { fontSize: 14, lineHeight: 21, color: tone ?? colors.muted }, children: note }) }) : null, !showReceive && keypad !== 'never' ? _jsx(SwapKeypad, { onKey: press, label: t.swapKeypad, deleteLabel: t.swapDelete }) : null, _jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: 8, marginTop: 16 }, children: [controls ? _jsx(IconButton, { intent: 'secondary', label: t.swapSettings, suppressFeedback: true, testID: 'swap-settings-button', disabled: submitting, onPress: () => !submitting && show('settings'), children: _jsx(MenuIcon, { color: colors.text }) }) : null, _jsxs(Button, { intent: actionIntent, busy: submitting, disabled: !showReceive && !ready, testID: 'swap-action', onPress: submit, style: { flex: 1, alignSelf: 'auto' }, children: [actionIcon ? _jsx(View, { testID: 'swap-action-icon', accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', children: actionIcon }, 'icon') : null, actionText] }), controls ? _jsx(IconButton, { intent: 'secondary', label: t.swapReset, disabled: pristine || submitting, testID: 'swap-reset', onPress: reset, children: _jsx(ResetIcon, { color: colors.text }) }) : null] }), notice ? _jsx(View, { style: { marginTop: 8, alignItems: 'center' }, children: _jsx(Toast, { notices: [notice], onDismiss: dismissNotice }) }) : null, footer ? _jsx(View, { testID: 'swap-footer', style: { marginTop: 16 }, children: footer }) : null] });
|
|
147
168
|
const body = view === 'main' ? main
|
|
148
|
-
: view === 'from' ? _jsx(SwapPicker, { side: view, onBack: back, tokens: fromTokens ?? tokens, loading: fromTokensLoading, chains: chainList, hotTokenIds: hotTokenIds, selected: from, onSelect:
|
|
149
|
-
|
|
150
|
-
|
|
169
|
+
: view === 'from' ? _jsx(SwapPicker, { side: view, onBack: back, tokens: fromTokens ?? tokens, loading: fromTokensLoading, chains: chainList, hotTokenIds: hotTokenIds, selected: from, onSelect: token => { if (!submitting)
|
|
170
|
+
setFrom(token); }, wallet: wallet, onConnect: submitting ? undefined : onConnect, onDisconnect: submitting ? undefined : onDisconnect, receiving: isReceiving, onReceivingChange: receive ? value => { if (!submitting)
|
|
171
|
+
setReceiving(value); } : undefined })
|
|
172
|
+
: view === 'to' ? _jsx(SwapPicker, { side: view, onBack: back, tokens: tokens, chains: chainList, hotTokenIds: hotTokenIds, selected: to, onSelect: token => { if (!submitting)
|
|
173
|
+
setTo(token); }, wallet: wallet, recipient: recipient, onRecipientChange: value => { if (!submitting)
|
|
174
|
+
onRecipientChange?.(value); }, onScanRecipient: submitting ? undefined : onScanRecipient })
|
|
175
|
+
: _jsx(SwapSettings, { view: view, onViewChange: show, onBack: back, denomination: defaultMode, onDenominationChange: denominationSwitch ? changeDenomination : undefined, slippage: slippage, onSlippageChange: value => { if (!submitting)
|
|
176
|
+
onSlippageChange?.(value); }, fee: fee, fees: fees, quoteLoading: quoteLoading, children: settings });
|
|
151
177
|
return _jsx(View, { testID: 'swap-panel', style: [{ direction, width: '100%', maxWidth: 448, alignSelf: 'center' }, style], children: _jsx(SwapStage, { view: view, animateHeight: host.animateHeight !== false, children: body }) });
|
|
152
178
|
}
|
|
153
179
|
const viewDepth = (view) => view === 'main' ? 0 : view === 'slippage' || view === 'fees' ? 2 : 1;
|
|
@@ -186,5 +212,7 @@ function SwapStage({ view, animateHeight, children }) {
|
|
|
186
212
|
const fitted = sizing && sized;
|
|
187
213
|
return _jsx(Animated.View, { testID: 'swap-stage', style: fitted ? { height, overflow: 'hidden' } : undefined, children: _jsx(Animated.View, { onLayout: onLayout, style: [fitted ? { position: 'absolute', left: 0, right: 0, top: 0 } : null, { opacity: slide, transform: [{ translateX: slide.interpolate({ inputRange: [0, 1], outputRange: [travel.current * 48, 0] }) }] }], children: children }) });
|
|
188
214
|
}
|
|
189
|
-
/** @deprecated Renamed `
|
|
190
|
-
export const SwapPanel =
|
|
215
|
+
/** @deprecated Renamed `SwapBlock`. The old name keeps working until the next major release. */
|
|
216
|
+
export const SwapPanel = SwapBlock;
|
|
217
|
+
/** @deprecated Use SwapBlock. */
|
|
218
|
+
export const SwapPanelBlock = SwapBlock;
|
|
@@ -6,12 +6,10 @@ export declare const SwapHostContext: React.Context<{
|
|
|
6
6
|
listComponent?: React.ComponentType<FlatListProps<SwapToken>>;
|
|
7
7
|
animateHeight?: boolean;
|
|
8
8
|
}>;
|
|
9
|
-
/** One arrow, top to bottom: a one-way panel. */
|
|
10
9
|
export declare function DownIcon({ color, size }: {
|
|
11
10
|
color: string;
|
|
12
11
|
size?: number;
|
|
13
12
|
}): React.JSX.Element;
|
|
14
|
-
/** Two opposed arrows: exchange the pair, or switch the denomination. */
|
|
15
13
|
export declare function FlipIcon({ color, size }: {
|
|
16
14
|
color: string;
|
|
17
15
|
size?: number;
|
|
@@ -19,27 +17,21 @@ export declare function FlipIcon({ color, size }: {
|
|
|
19
17
|
export declare function MenuIcon({ color }: {
|
|
20
18
|
color: string;
|
|
21
19
|
}): React.JSX.Element;
|
|
22
|
-
/** An open ring with an arrowhead at its gap. */
|
|
23
20
|
export declare function ResetIcon({ color }: {
|
|
24
21
|
color: string;
|
|
25
22
|
}): React.JSX.Element;
|
|
26
|
-
/** Keypad delete: a key outline holding an x. */
|
|
27
23
|
export declare function DeleteIcon({ color }: {
|
|
28
24
|
color: string;
|
|
29
25
|
}): React.JSX.Element;
|
|
30
|
-
/** Four viewfinder corners. */
|
|
31
26
|
export declare function ScanIcon({ color }: {
|
|
32
27
|
color: string;
|
|
33
28
|
}): React.JSX.Element;
|
|
34
|
-
/** A wallet: a rounded body with a clasp on the trailing edge. */
|
|
35
29
|
export declare function WalletIcon({ color }: {
|
|
36
30
|
color: string;
|
|
37
31
|
}): React.JSX.Element;
|
|
38
|
-
/** A padlock: a shackle over a body. */
|
|
39
32
|
export declare function LockIcon({ color }: {
|
|
40
33
|
color: string;
|
|
41
34
|
}): React.JSX.Element;
|
|
42
|
-
/** A doorway with an arrow leaving it. */
|
|
43
35
|
export declare function LeaveIcon({ color }: {
|
|
44
36
|
color: string;
|
|
45
37
|
}): React.JSX.Element;
|
|
@@ -56,11 +48,12 @@ export declare function TokenIcon({ token, size }: {
|
|
|
56
48
|
size?: number;
|
|
57
49
|
}): React.JSX.Element;
|
|
58
50
|
/** Small capsule action that sits on a card: Max, Test, the slippage setting and the denomination switch. 32dp tall with a 44dp target. */
|
|
59
|
-
export declare function SwapCapsule({ children, onPress, label, testID, hitSlop, ref }: {
|
|
51
|
+
export declare function SwapCapsule({ children, onPress, label, testID, disabled, hitSlop, ref }: {
|
|
60
52
|
children: React.ReactNode;
|
|
61
53
|
onPress: () => void;
|
|
62
54
|
label?: string;
|
|
63
|
-
testID?: string;
|
|
55
|
+
testID?: string;
|
|
56
|
+
disabled?: boolean; /** Defaults to a 44dp target, as on the swap card. */
|
|
64
57
|
hitSlop?: Insets; /** Reaches the capsule, for example to move accessibility focus back to it. */
|
|
65
58
|
ref?: React.Ref<View>;
|
|
66
59
|
}): React.JSX.Element;
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ArrowDown } from '@bloxwap/icons/native/arrow-down';
|
|
3
|
+
import { ArrowUpDown } from '@bloxwap/icons/native/arrow-up-down';
|
|
4
|
+
import { ChevronDown } from '@bloxwap/icons/native/chevron-down';
|
|
5
|
+
import { Delete } from '@bloxwap/icons/native/delete';
|
|
6
|
+
import { Lock } from '@bloxwap/icons/native/lock';
|
|
7
|
+
import { LogOut } from '@bloxwap/icons/native/log-out';
|
|
8
|
+
import { Menu } from '@bloxwap/icons/native/menu';
|
|
9
|
+
import { RotateCcw } from '@bloxwap/icons/native/rotate-ccw';
|
|
10
|
+
import { ScanLine } from '@bloxwap/icons/native/scan-line';
|
|
11
|
+
import { Wallet } from '@bloxwap/icons/native/wallet';
|
|
2
12
|
import { createContext } from 'react';
|
|
3
13
|
import { Image, Pressable, View } from 'react-native';
|
|
4
14
|
import { useColors, useFills, useHIG, useMessages } from './provider.js';
|
|
@@ -8,29 +18,17 @@ import { ChevronIcon } from './icons.js';
|
|
|
8
18
|
import { AnimatedNumberReadout } from './animated-number.js';
|
|
9
19
|
/** What a host surface supplies to the swap views: a sheet passes its backend's list so drags hand off to the sheet, and turns off the panel's own height animation. */
|
|
10
20
|
export const SwapHostContext = createContext({});
|
|
11
|
-
// Outline symbols drawn from plain views, like ./icons: decorative, so the control that holds them carries the name.
|
|
12
21
|
const hidden = { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', pointerEvents: 'none' };
|
|
13
|
-
const stroke = 1.75;
|
|
14
22
|
const centre = { alignItems: 'center', justifyContent: 'center' };
|
|
15
|
-
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
export function
|
|
19
|
-
|
|
20
|
-
export function
|
|
21
|
-
export function
|
|
22
|
-
|
|
23
|
-
export function
|
|
24
|
-
/** Keypad delete: a key outline holding an x. */
|
|
25
|
-
export function DeleteIcon({ color }) { return _jsx(View, { ...hidden, style: { width: 26, height: 18, borderRadius: 5, borderWidth: stroke, borderColor: color, ...centre }, children: crossAngles.map(angle => _jsx(View, { style: { position: 'absolute', width: 9, height: stroke, borderRadius: stroke, backgroundColor: color, transform: [{ rotate: angle }] } }, angle)) }); }
|
|
26
|
-
/** Four viewfinder corners. */
|
|
27
|
-
export function ScanIcon({ color }) { const corner = (style) => _jsx(View, { style: [{ position: 'absolute', width: 6, height: 6, borderColor: color }, style] }); return _jsxs(View, { ...hidden, style: { width: 18, height: 18 }, children: [corner({ left: 0, top: 0, borderLeftWidth: stroke, borderTopWidth: stroke, borderTopLeftRadius: 3 }), corner({ right: 0, top: 0, borderRightWidth: stroke, borderTopWidth: stroke, borderTopRightRadius: 3 }), corner({ left: 0, bottom: 0, borderLeftWidth: stroke, borderBottomWidth: stroke, borderBottomLeftRadius: 3 }), corner({ right: 0, bottom: 0, borderRightWidth: stroke, borderBottomWidth: stroke, borderBottomRightRadius: 3 }), _jsx(View, { style: { position: 'absolute', left: 0, right: 0, top: 8, height: stroke, borderRadius: stroke, backgroundColor: color } })] }); }
|
|
28
|
-
/** A wallet: a rounded body with a clasp on the trailing edge. */
|
|
29
|
-
export function WalletIcon({ color }) { return _jsx(View, { ...hidden, style: { width: 20, height: 20, ...centre }, children: _jsx(View, { style: { width: 16, height: 12, borderRadius: 3, borderWidth: stroke, borderColor: color, alignItems: 'flex-end', justifyContent: 'center' }, children: _jsx(View, { style: { width: 5, height: 4, borderTopLeftRadius: 2, borderBottomLeftRadius: 2, borderWidth: stroke, borderRightWidth: 0, borderColor: color, marginEnd: -stroke } }) }) }); }
|
|
30
|
-
/** A padlock: a shackle over a body. */
|
|
31
|
-
export function LockIcon({ color }) { return _jsxs(View, { ...hidden, style: { width: 16, height: 16, alignItems: 'center', justifyContent: 'flex-end' }, children: [_jsx(View, { style: { width: 8, height: 7, borderTopLeftRadius: 4, borderTopRightRadius: 4, borderWidth: stroke, borderBottomWidth: 0, borderColor: color } }), _jsx(View, { style: { width: 12, height: 8, borderRadius: 2, borderWidth: stroke, borderColor: color } })] }); }
|
|
32
|
-
/** A doorway with an arrow leaving it. */
|
|
33
|
-
export function LeaveIcon({ color }) { return _jsxs(View, { ...hidden, style: { width: 20, height: 20, flexDirection: 'row', alignItems: 'center' }, children: [_jsx(View, { style: { width: 8, height: 14, borderWidth: stroke, borderRightWidth: 0, borderColor: color, borderTopLeftRadius: 3, borderBottomLeftRadius: 3 } }), _jsx(View, { style: { width: 9, height: stroke, borderRadius: stroke, backgroundColor: color, marginStart: -2 } }), _jsx(View, { style: { width: 5, height: 5, borderRightWidth: stroke, borderTopWidth: stroke, borderColor: color, marginStart: -5, transform: [{ rotate: '45deg' }] } })] }); }
|
|
23
|
+
export function DownIcon({ color, size = 16 }) { return _jsx(ArrowDown, { size: size, color: color }); }
|
|
24
|
+
export function FlipIcon({ color, size = 16 }) { return _jsx(ArrowUpDown, { size: size, color: color }); }
|
|
25
|
+
export function MenuIcon({ color }) { return _jsx(Menu, { size: 20, color: color }); }
|
|
26
|
+
export function ResetIcon({ color }) { return _jsx(RotateCcw, { size: 20, color: color }); }
|
|
27
|
+
export function DeleteIcon({ color }) { return _jsx(Delete, { size: 24, color: color }); }
|
|
28
|
+
export function ScanIcon({ color }) { return _jsx(ScanLine, { size: 18, color: color }); }
|
|
29
|
+
export function WalletIcon({ color }) { return _jsx(Wallet, { size: 20, color: color }); }
|
|
30
|
+
export function LockIcon({ color }) { return _jsx(Lock, { size: 16, color: color }); }
|
|
31
|
+
export function LeaveIcon({ color }) { return _jsx(LogOut, { size: 20, color: color }); }
|
|
34
32
|
/** Circular artwork from a URL or the host's own element, or the symbol's first letters when the host has none. */
|
|
35
33
|
export function TokenArt({ uri, symbol, size, ring }) {
|
|
36
34
|
const colors = useColors();
|
|
@@ -42,10 +40,10 @@ export function TokenArt({ uri, symbol, size, ring }) {
|
|
|
42
40
|
/** Token artwork with its chain badge. */
|
|
43
41
|
export function TokenIcon({ token, size = 44 }) { const colors = useColors(); return _jsxs(View, { ...hidden, style: { width: size, height: size }, children: [_jsx(TokenArt, { uri: token.icon, symbol: token.symbol, size: size }), token.chainIcon ? _jsx(View, { style: { position: 'absolute', end: 0, bottom: 0 }, children: _jsx(TokenArt, { uri: token.chainIcon, size: 18, ring: colors.overlay }) }) : null] }); }
|
|
44
42
|
/** Small capsule action that sits on a card: Max, Test, the slippage setting and the denomination switch. 32dp tall with a 44dp target. */
|
|
45
|
-
export function SwapCapsule({ children, onPress, label, testID, hitSlop = { top: 6, bottom: 6 }, ref }) {
|
|
43
|
+
export function SwapCapsule({ children, onPress, label, testID, disabled = false, hitSlop = { top: 6, bottom: 6 }, ref }) {
|
|
46
44
|
const fills = useFills();
|
|
47
45
|
const { direction } = useHIG();
|
|
48
|
-
return _jsx(Pressable, { ref: ref, accessibilityRole: 'button', accessibilityLabel: label, testID: testID, onPress: onPress, hitSlop: hitSlop, style: ({ pressed }) => ({ direction, flexDirection: 'row', alignItems: 'center', gap: 6, minHeight: 32, paddingVertical: 4, paddingHorizontal: 12, borderRadius: 9999, backgroundColor: pressed ? fills.raised : fills.well }), children: children });
|
|
46
|
+
return _jsx(Pressable, { disabled: disabled, accessibilityState: { disabled }, ref: ref, accessibilityRole: 'button', accessibilityLabel: label, testID: testID, onPress: onPress, hitSlop: hitSlop, style: ({ pressed }) => ({ direction, flexDirection: 'row', alignItems: 'center', gap: 6, minHeight: 32, paddingVertical: 4, paddingHorizontal: 12, borderRadius: 9999, backgroundColor: pressed ? fills.raised : fills.well }), children: children });
|
|
49
47
|
}
|
|
50
48
|
const keys = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '0', 'back'];
|
|
51
49
|
/** Numeric keypad: a 3 by 4 grid of 56dp keys. Emits `0`–`9`, `.` or `back`. */
|
|
@@ -62,7 +60,7 @@ export function SwapHeader({ title, onBack }) {
|
|
|
62
60
|
return _jsxs(View, { testID: 'swap-header', style: { flexDirection: 'row', alignItems: 'center', gap: 4, minHeight: 44, paddingStart: onBack ? 0 : 4 }, children: [onBack ? _jsx(IconButton, { intent: 'ghost', label: t.back, suppressFeedback: true, testID: 'swap-back', onPress: onBack, children: _jsx(View, { style: { transform: [{ rotate: direction === 'rtl' ? '-90deg' : '90deg' }] }, children: _jsx(ChevronIcon, { color: colors.text }) }) }) : null, _jsx(Heading, { style: { fontWeight: '700', flexShrink: 1 }, children: title })] });
|
|
63
61
|
}
|
|
64
62
|
/** A small chevron: down marks a side that can be changed, trailing marks a card that opens something. Mirrors in RTL. */
|
|
65
|
-
export function SmallChevron({ color, trailing }) { const { direction } = useHIG(); return _jsx(
|
|
63
|
+
export function SmallChevron({ color, trailing }) { const { direction } = useHIG(); return _jsx(ChevronDown, { size: 16, color: color, style: { transform: trailing ? [{ rotate: direction === 'rtl' ? '90deg' : '-90deg' }] : undefined } }); }
|
|
66
64
|
/** A pushed view inside the panel: Back and the view title, then the body. There is no close control; Back pops. */
|
|
67
65
|
export function SwapSubview({ title, onBack, testID, children }) {
|
|
68
66
|
return _jsxs(View, { testID: testID, style: { gap: 16 }, children: [_jsx(SwapHeader, { title: title, onBack: onBack }), children] });
|
|
@@ -20,7 +20,7 @@ export interface SwapToken {
|
|
|
20
20
|
/** Artwork: an image URL, or the host's own element (an SVG component, say), which fills the disc. A missing token icon falls back to the symbol's first letters. */
|
|
21
21
|
icon?: SwapArtwork;
|
|
22
22
|
chainIcon?: SwapArtwork;
|
|
23
|
-
/** Most decimal places a token amount may be typed with, for example 6 for USDC.
|
|
23
|
+
/** Most decimal places a token amount may be typed with, for example 6 for USDC. Up to 100 when omitted; explicit precision must be an integer from 0 to 100. Dollars always stop at two. */
|
|
24
24
|
decimals?: number;
|
|
25
25
|
/** Holdings in token units, when the host knows them. Enables Max, Test and the balance check. */
|
|
26
26
|
balance?: number | null;
|
|
@@ -64,7 +64,7 @@ export declare const trimNumber: (value: number, digits?: number) => string;
|
|
|
64
64
|
/** Keeps digits and one decimal point, and strips leading zeros; never returns an empty string. */
|
|
65
65
|
export declare function sanitizeAmount(raw: string): string;
|
|
66
66
|
/** Token units shown in the active denomination. Dollars floor to the cent so Max never resolves to more than the balance. */
|
|
67
|
-
export declare function unitsToEntry(units: number, mode: SwapDenomination, price: number): string;
|
|
67
|
+
export declare function unitsToEntry(units: number | string, mode: SwapDenomination, price: number): string;
|
|
68
68
|
/** Applies one keypad key (`0`–`9`, `.`, `back`) to an amount string. Dollars stop at two decimals. */
|
|
69
69
|
export declare function applyAmountKey(current: string, key: string, mode: SwapDenomination, decimals?: number): string;
|
|
70
70
|
/** Case-insensitive substring or in-order subsequence match. */
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import { decimal, decimalMultiply, decimalDivide } from '@bloxwap/hig/contracts';
|
|
1
2
|
/** Where Back leads: slippage and fees return to settings, everything else to the main form. */
|
|
2
3
|
export const swapParentView = (view) => view === 'slippage' || view === 'fees' ? 'settings' : 'main';
|
|
3
4
|
export const slippagePresets = [0.001, 0.005, 0.01];
|
|
4
5
|
export function swapAction(from, to) {
|
|
5
|
-
if (!from || !to
|
|
6
|
+
if (!from || !to)
|
|
6
7
|
return 'send';
|
|
7
|
-
|
|
8
|
+
if (String(from.chainId) !== String(to.chainId))
|
|
9
|
+
return 'bridge';
|
|
10
|
+
return from.id === to.id ? 'send' : 'swap';
|
|
8
11
|
}
|
|
9
12
|
/** A clean numeric string: no trailing zeros, at most `digits` decimals. */
|
|
10
13
|
export const trimNumber = (value, digits = 8) => String(Number((Number.isFinite(value) ? value : 0).toFixed(digits)));
|
|
@@ -20,8 +23,8 @@ export function sanitizeAmount(raw) {
|
|
|
20
23
|
/** Token units shown in the active denomination. Dollars floor to the cent so Max never resolves to more than the balance. */
|
|
21
24
|
export function unitsToEntry(units, mode, price) {
|
|
22
25
|
if (mode === 'token')
|
|
23
|
-
return
|
|
24
|
-
return price > 0 ?
|
|
26
|
+
return decimal(units);
|
|
27
|
+
return price > 0 ? decimalMultiply(units, price, 2) : '0';
|
|
25
28
|
}
|
|
26
29
|
/** Applies one keypad key (`0`–`9`, `.`, `back`) to an amount string. Dollars stop at two decimals. */
|
|
27
30
|
export function applyAmountKey(current, key, mode, decimals) {
|
|
@@ -52,9 +55,10 @@ export const formatPercent = (fraction) => `${Number((fraction * 100).toFixed(4)
|
|
|
52
55
|
/** A small trial amount: 1% of holdings, capped at about one dollar's worth. */
|
|
53
56
|
export function testAmount(token) {
|
|
54
57
|
const balance = token.balance ?? 0, price = token.price ?? 0;
|
|
55
|
-
if (!(balance > 0))
|
|
58
|
+
if (!(balance > 0) || !Number.isFinite(balance))
|
|
56
59
|
return 0;
|
|
57
|
-
|
|
60
|
+
const fraction = decimalDivide(balance, 100, token.decimals ?? 18);
|
|
61
|
+
return Number(decimal(price > 0 ? Math.min(Number(fraction), Number(decimalDivide(1, price, token.decimals ?? 18))) : fraction, token.decimals ?? 18));
|
|
58
62
|
}
|
|
59
63
|
export const shortAddress = (address) => address.length <= 12 ? address : `${address.slice(0, 6)}…${address.slice(-4)}`;
|
|
60
64
|
/** A stable flat colour for a wallet address, so the same wallet always looks the same. */
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { type
|
|
3
|
-
export interface SwapSheetProps extends
|
|
2
|
+
import { type SwapBlockProps } from './swap-block.js';
|
|
3
|
+
export interface SwapSheetProps extends SwapBlockProps {
|
|
4
4
|
open: boolean;
|
|
5
5
|
onOpenChange: (open: boolean) => void;
|
|
6
6
|
/** Accessible name of the sheet. */
|
|
7
7
|
title: string;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* SwapBlock presented in the gesture sheet. Pickers and settings push inside the same sheet, which resizes to the view
|
|
11
11
|
* on show. A back press or a dismiss gesture pops a pushed view first and closes the sheet only from the main form;
|
|
12
12
|
* closing always returns to the main form. Needs the optional gesture-sheet backend, which `blocks` does not load.
|
|
13
13
|
*/
|
|
@@ -2,9 +2,9 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { useEffect, useMemo, useState } from 'react';
|
|
3
3
|
import { BottomSheetFlatList } from '@gorhom/bottom-sheet';
|
|
4
4
|
import { GestureSheet } from './gesture-sheet.js';
|
|
5
|
-
import { SwapHostContext,
|
|
5
|
+
import { SwapHostContext, SwapBlock, swapParentView } from './swap-block.js';
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* SwapBlock presented in the gesture sheet. Pickers and settings push inside the same sheet, which resizes to the view
|
|
8
8
|
* on show. A back press or a dismiss gesture pops a pushed view first and closes the sheet only from the main form;
|
|
9
9
|
* closing always returns to the main form. Needs the optional gesture-sheet backend, which `blocks` does not load.
|
|
10
10
|
*/
|
|
@@ -22,5 +22,5 @@ export function SwapSheet({ open, onOpenChange, title, view: viewProp, onViewCha
|
|
|
22
22
|
return false; show(swapParentView(view)); return true; };
|
|
23
23
|
return _jsx(GestureSheet, { open: open, onOpenChange: next => { if (!next && leave())
|
|
24
24
|
return; onOpenChange(next); }, title: title, contentMode: 'custom', enableDynamicSizing: true, keyboardBehavior: 'interactive', onHardwareBackPress: () => { if (!leave())
|
|
25
|
-
onOpenChange(false); return true; }, children: _jsx(SwapHostContext.Provider, { value: host, children: _jsx(
|
|
25
|
+
onOpenChange(false); return true; }, children: _jsx(SwapHostContext.Provider, { value: host, children: _jsx(SwapBlock, { ...panel, view: view, onViewChange: show, style: [{ paddingHorizontal: 12, paddingBottom: 16 }, style] }) }) });
|
|
26
26
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useState } from 'react';
|
|
3
3
|
import { Pressable, View } from 'react-native';
|
|
4
|
-
import { formatNumber } from '
|
|
4
|
+
import { formatNumber } from './number-format.js';
|
|
5
5
|
import { useColors, useFills, useHIG, useMessages, useNumberLocale, usePresentNumber } from './provider.js';
|
|
6
6
|
import { Text } from './surface.js';
|
|
7
7
|
import { Field, Input } from './field.js';
|
|
@@ -24,6 +24,8 @@ export interface TargetBlockLabels {
|
|
|
24
24
|
custom: string;
|
|
25
25
|
/** Accessible name of the info button that shows `note`: How this order fills. Without it the note is always shown. */
|
|
26
26
|
info?: string;
|
|
27
|
+
/** Accessible name of the quick choices, not drawn: Quick targets. Defaults to `title`. */
|
|
28
|
+
presets?: string;
|
|
27
29
|
}
|
|
28
30
|
export interface TargetBlockProps {
|
|
29
31
|
kind: TargetKind;
|
|
@@ -90,7 +92,11 @@ export interface TargetUnitOption {
|
|
|
90
92
|
export declare function targetPresets(presets: readonly (number | TargetPreset)[]): TargetPreset[];
|
|
91
93
|
/** The units as `{unit, disabled}`, whichever form the host gave. */
|
|
92
94
|
export declare function targetUnits(units: readonly (TargetUnit | TargetUnitOption)[]): TargetUnitOption[];
|
|
93
|
-
/**
|
|
95
|
+
/**
|
|
96
|
+
* Number format of a target in a unit. Dollars and percents carry their sign. `short` is a preset's value: a whole dollar amount
|
|
97
|
+
* or a whole price drops its fraction digits (`+$10`, `$63,000`), whatever fraction digits `priceOptions` fix, so a preset reads
|
|
98
|
+
* the same on web and native; a price formatted by significant digits keeps `priceOptions`.
|
|
99
|
+
*/
|
|
94
100
|
export declare function targetFormat(unit: TargetUnit, priceOptions?: Intl.NumberFormatOptions, short?: number): Intl.NumberFormatOptions;
|
|
95
101
|
/**
|
|
96
102
|
* Where each known price sits on the bar, as a fraction of its width from the low-price edge, the prices in price order, and
|