@bloxwap/hig 0.0.0-stage → 0.5.1
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/LICENSE +5 -0
- package/README.md +44 -2
- package/chart/README.md +23 -0
- package/chart/dist/index.d.ts +8 -0
- package/chart/dist/index.js +12 -0
- package/contracts/README.md +3 -0
- package/contracts/dist/announcements.d.ts +12 -0
- package/contracts/dist/announcements.js +8 -0
- package/contracts/dist/feedback.d.ts +40 -0
- package/contracts/dist/feedback.js +1 -0
- package/contracts/dist/index.d.ts +41 -0
- package/contracts/dist/index.js +52 -0
- package/contracts/dist/messages.d.ts +300 -0
- package/contracts/dist/messages.js +114 -0
- package/css.d.ts +2 -0
- package/feedback/README.md +7 -0
- package/feedback/assets/error.wav +0 -0
- package/feedback/assets/manifest.json +78 -0
- package/feedback/assets/success.wav +0 -0
- package/feedback/assets/tick.wav +0 -0
- package/feedback/assets/toggle.wav +0 -0
- package/feedback/dist/browser-haptic.d.ts +23 -0
- package/feedback/dist/browser-haptic.js +41 -0
- package/feedback/dist/contract.d.ts +40 -0
- package/feedback/dist/contract.js +59 -0
- package/feedback/dist/native.d.ts +28 -0
- package/feedback/dist/native.js +63 -0
- package/feedback/dist/preferences.d.ts +8 -0
- package/feedback/dist/preferences.js +24 -0
- package/feedback/dist/presets.d.ts +57 -0
- package/feedback/dist/presets.js +1 -0
- package/feedback/dist/react.d.ts +19 -0
- package/feedback/dist/react.js +23 -0
- package/feedback/dist/web-haptic.d.ts +6 -0
- package/feedback/dist/web-haptic.js +6 -0
- package/feedback/dist/web-sound.d.ts +5 -0
- package/feedback/dist/web-sound.js +32 -0
- package/feedback/dist/web.d.ts +3 -0
- package/feedback/dist/web.js +4 -0
- package/native/README.md +16 -0
- package/native/android/build.gradle +28 -0
- package/native/android/src/main/java/com/bloxwap/hig/HIGAdjustableView.java +173 -0
- package/native/android/src/main/java/com/bloxwap/hig/HIGAdjustableViewManager.java +23 -0
- package/native/android/src/main/java/com/bloxwap/hig/HIGPackage.java +24 -0
- package/native/dist/animated-number-model.d.ts +24 -0
- package/native/dist/animated-number-model.js +110 -0
- package/native/dist/animated-number.d.ts +9 -0
- package/native/dist/animated-number.js +97 -0
- package/native/dist/brand.d.ts +7 -0
- package/native/dist/brand.js +7 -0
- package/native/dist/button.d.ts +30 -0
- package/native/dist/button.js +36 -0
- package/native/dist/checkbox.d.ts +3 -0
- package/native/dist/checkbox.js +11 -0
- package/native/dist/data.d.ts +57 -0
- package/native/dist/data.js +47 -0
- package/native/dist/field.d.ts +16 -0
- package/native/dist/field.js +26 -0
- package/native/dist/gesture-sheet.d.ts +73 -0
- package/native/dist/gesture-sheet.js +153 -0
- package/native/dist/icons.d.ts +21 -0
- package/native/dist/icons.js +20 -0
- package/native/dist/navigation.d.ts +48 -0
- package/native/dist/navigation.js +58 -0
- package/native/dist/overlay.d.ts +36 -0
- package/native/dist/overlay.js +65 -0
- package/native/dist/pickers.d.ts +54 -0
- package/native/dist/pickers.js +60 -0
- package/native/dist/provider.d.ts +62 -0
- package/native/dist/provider.js +67 -0
- package/native/dist/radio-group.d.ts +21 -0
- package/native/dist/radio-group.js +91 -0
- package/native/dist/recipes.d.ts +45 -0
- package/native/dist/recipes.js +32 -0
- package/native/dist/roles.d.ts +6 -0
- package/native/dist/roles.js +4 -0
- package/native/dist/select.d.ts +3 -0
- package/native/dist/select.js +9 -0
- package/native/dist/selection-types.d.ts +22 -0
- package/native/dist/selection-types.js +1 -0
- package/native/dist/selection.d.ts +8 -0
- package/native/dist/selection.js +7 -0
- package/native/dist/slider.d.ts +11 -0
- package/native/dist/slider.js +42 -0
- package/native/dist/status.d.ts +86 -0
- package/native/dist/status.js +112 -0
- package/native/dist/surface.d.ts +19 -0
- package/native/dist/surface.js +42 -0
- package/native/dist/swap-panel.d.ts +125 -0
- package/native/dist/swap-panel.js +177 -0
- package/native/dist/swap-parts.d.ts +86 -0
- package/native/dist/swap-parts.js +66 -0
- package/native/dist/swap-shared.d.ts +65 -0
- package/native/dist/swap-shared.js +76 -0
- package/native/dist/swap-sheet.d.ts +14 -0
- package/native/dist/swap-sheet.js +26 -0
- package/native/dist/swap-views.d.ts +41 -0
- package/native/dist/swap-views.js +37 -0
- package/native/dist/switch-row.d.ts +8 -0
- package/native/dist/switch-row.js +18 -0
- package/native/dist/switch.d.ts +10 -0
- package/native/dist/switch.js +30 -0
- package/native/dist/text-content.d.ts +5 -0
- package/native/dist/text-content.js +6 -0
- package/native/dist/wallet-address.d.ts +37 -0
- package/native/dist/wallet-address.js +50 -0
- package/native-fonts/README.md +17 -0
- package/native-fonts/dist/index.d.ts +164 -0
- package/native-fonts/dist/index.js +164 -0
- package/native-fonts/fonts/BloxwapMono-Bold.ttf +0 -0
- package/native-fonts/fonts/BloxwapMono-ExtraBold.ttf +0 -0
- package/native-fonts/fonts/BloxwapMono-Medium.ttf +0 -0
- package/native-fonts/fonts/BloxwapMono-SemiBold.ttf +0 -0
- package/native-fonts/fonts/BloxwapMono.ttf +0 -0
- package/native-fonts/fonts/BloxwapSans-Black.ttf +0 -0
- package/native-fonts/fonts/BloxwapSans-Bold.ttf +0 -0
- package/native-fonts/fonts/BloxwapSans-ExtraBold.ttf +0 -0
- package/native-fonts/fonts/BloxwapSans-Medium.ttf +0 -0
- package/native-fonts/fonts/BloxwapSans-SemiBold.ttf +0 -0
- package/native-fonts/fonts/BloxwapSans.ttf +0 -0
- package/native-fonts/fonts/BloxwapSansKR-SemiBold.ttf +0 -0
- package/native-fonts/fonts/BloxwapSansKR.ttf +0 -0
- package/native-fonts/fonts/BloxwapSansSC-SemiBold.ttf +0 -0
- package/native-fonts/fonts/BloxwapSansSC.ttf +0 -0
- package/native-fonts/fonts/OFL.txt +93 -0
- package/native-fonts/fonts/manifest.json +164 -0
- package/og-fonts/README.md +34 -0
- package/og-fonts/dist/index.d.ts +116 -0
- package/og-fonts/dist/index.js +102 -0
- package/og-fonts/dist/node.d.ts +11 -0
- package/og-fonts/dist/node.js +39 -0
- package/og-fonts/fonts/BloxwapMono-Medium.ttf +0 -0
- package/og-fonts/fonts/BloxwapSans-Black.ttf +0 -0
- package/og-fonts/fonts/BloxwapSans-Bold.ttf +0 -0
- package/og-fonts/fonts/BloxwapSans-Medium.ttf +0 -0
- package/og-fonts/fonts/BloxwapSans.ttf +0 -0
- package/og-fonts/fonts/OFL.txt +93 -0
- package/og-fonts/fonts/manifest.json +65 -0
- package/package.json +476 -4
- package/react/README.md +30 -0
- package/react/dist/animated-number-model.d.ts +20 -0
- package/react/dist/animated-number-model.js +92 -0
- package/react/dist/animated-number.d.ts +8 -0
- package/react/dist/animated-number.js +72 -0
- package/react/dist/base.css +9 -0
- package/react/dist/brand.d.ts +7 -0
- package/react/dist/brand.js +5 -0
- package/react/dist/button.d.ts +14 -0
- package/react/dist/button.js +20 -0
- package/react/dist/data.d.ts +78 -0
- package/react/dist/data.js +36 -0
- package/react/dist/dialog.d.ts +29 -0
- package/react/dist/dialog.js +21 -0
- package/react/dist/field.d.ts +16 -0
- package/react/dist/field.js +20 -0
- package/react/dist/gesture-sheet.d.ts +41 -0
- package/react/dist/gesture-sheet.js +128 -0
- package/react/dist/navigation.d.ts +48 -0
- package/react/dist/navigation.js +69 -0
- package/react/dist/notify.d.ts +14 -0
- package/react/dist/notify.js +6 -0
- package/react/dist/overlay.d.ts +17 -0
- package/react/dist/overlay.js +18 -0
- package/react/dist/provider.d.ts +25 -0
- package/react/dist/provider.js +50 -0
- package/react/dist/recipes/activity-list.d.ts +8 -0
- package/react/dist/recipes/activity-list.js +6 -0
- package/react/dist/recipes/balance-card.d.ts +6 -0
- package/react/dist/recipes/balance-card.js +5 -0
- package/react/dist/recipes/code-window.d.ts +4 -0
- package/react/dist/recipes/code-window.js +4 -0
- package/react/dist/recipes/install-command.d.ts +6 -0
- package/react/dist/recipes/install-command.js +15 -0
- package/react/dist/recipes/market-row.d.ts +25 -0
- package/react/dist/recipes/market-row.js +8 -0
- package/react/dist/recipes/marketing-hero.d.ts +7 -0
- package/react/dist/recipes/marketing-hero.js +5 -0
- package/react/dist/recipes/pickers.d.ts +57 -0
- package/react/dist/recipes/pickers.js +78 -0
- package/react/dist/recipes/swap/amount-card.d.ts +40 -0
- package/react/dist/recipes/swap/amount-card.js +7 -0
- package/react/dist/recipes/swap/picker.d.ts +26 -0
- package/react/dist/recipes/swap/picker.js +20 -0
- package/react/dist/recipes/swap/settings.d.ts +24 -0
- package/react/dist/recipes/swap/settings.js +25 -0
- package/react/dist/recipes/swap/shared.d.ts +98 -0
- package/react/dist/recipes/swap/shared.js +106 -0
- package/react/dist/recipes/swap-panel.d.ts +127 -0
- package/react/dist/recipes/swap-panel.js +170 -0
- package/react/dist/recipes/swap-sheet.d.ts +16 -0
- package/react/dist/recipes/swap-sheet.js +22 -0
- package/react/dist/recipes/trade-entry.d.ts +11 -0
- package/react/dist/recipes/trade-entry.js +12 -0
- package/react/dist/recipes.d.ts +10 -0
- package/react/dist/recipes.js +11 -0
- package/react/dist/select.d.ts +4 -0
- package/react/dist/select.js +174 -0
- package/react/dist/selection.d.ts +40 -0
- package/react/dist/selection.js +23 -0
- package/react/dist/slider.d.ts +11 -0
- package/react/dist/slider.js +10 -0
- package/react/dist/status.d.ts +63 -0
- package/react/dist/status.js +47 -0
- package/react/dist/styles.css +542 -0
- package/react/dist/surface.d.ts +291 -0
- package/react/dist/surface.js +9 -0
- package/react/dist/toast.d.ts +17 -0
- package/react/dist/toast.js +21 -0
- package/react/dist/wallet-address.d.ts +23 -0
- package/react/dist/wallet-address.js +24 -0
- package/tokens/README.md +17 -0
- package/tokens/assets/bloxwap-icon.svg +1 -0
- package/tokens/dist/brand.d.ts +19 -0
- package/tokens/dist/brand.js +24 -0
- package/tokens/dist/index.d.ts +437 -0
- package/tokens/dist/index.js +514 -0
- package/tokens/dist/manifest.json +200 -0
- package/tokens/dist/theme.d.ts +11 -0
- package/tokens/dist/theme.js +22 -0
- package/tokens/dist/tokens.css +120 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { Animated, BackHandler, Easing, Platform, Pressable, StyleSheet, View } from 'react-native';
|
|
4
|
+
import { formatNumber } from '@bloxwap/hig/contracts';
|
|
5
|
+
import { Raised, useColors, useControllable, useHIG, useMessages } from './provider.js';
|
|
6
|
+
import { Text } from './surface.js';
|
|
7
|
+
import { Button, IconButton } from './button.js';
|
|
8
|
+
import { AnimatedNumberReadout } from './animated-number.js';
|
|
9
|
+
import { Toast, useTransientNotice } from './status.js';
|
|
10
|
+
import { VerticalAddress, addressKind } from './data.js';
|
|
11
|
+
import { withAlpha } from '@bloxwap/hig/tokens';
|
|
12
|
+
import { DownIcon, FlipIcon, MenuIcon, ResetIcon, SmallChevron, SwapCapsule, SwapHeader, SwapHostContext, SwapKeypad, TokenArt } from './swap-parts.js';
|
|
13
|
+
import { SwapPicker, SwapSettings } from './swap-views.js';
|
|
14
|
+
import { addressColor, applyAmountKey, formatPercent, shortAddress, swapAction, swapParentView, testAmount, trimNumber, unitsToEntry } from './swap-shared.js';
|
|
15
|
+
export { swapAction, swapParentView } from './swap-shared.js';
|
|
16
|
+
/** 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. */
|
|
17
|
+
export { SwapHostContext } from './swap-parts.js';
|
|
18
|
+
/**
|
|
19
|
+
* Send, swap and bridge in one panel: a From card and a To card joined by a flip control, an amount entered in dollars
|
|
20
|
+
* or token units through the keypad, token pickers, settings, and one action that names itself from the chosen pair.
|
|
21
|
+
* Presentation only. The host owns tokens, balances, prices, the quote, the wallet and the transaction.
|
|
22
|
+
*/
|
|
23
|
+
export function SwapPanel({ 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, onReset, keypad = 'auto', destination, details, note, noteTone = 'muted', title, onBack, controls = true, actionIcon, lockFrom = false, lockTo = false, actionLabel, oneWay: oneWayProp = false, denominationSwitch = true, settings, view: viewProp, onViewChange, style }) {
|
|
24
|
+
const env = useHIG();
|
|
25
|
+
const { locale, direction } = env;
|
|
26
|
+
const colors = useColors();
|
|
27
|
+
const t = useMessages();
|
|
28
|
+
const [from, setFrom] = useControllable(fromProp, defaultFrom, onFromChange);
|
|
29
|
+
const [to, setTo] = useControllable(toProp, defaultTo, onToChange);
|
|
30
|
+
const [defaultMode, setDefaultMode] = useControllable(denomination, 'usd', onDenominationChange);
|
|
31
|
+
const [isReceiving, setReceiving] = useControllable(receiving, false, onReceivingChange);
|
|
32
|
+
// `amount` seeds the first render too, in the default denomination at the initial From token's price.
|
|
33
|
+
const [entry, setEntry] = useState(() => amount === undefined ? '0' : unitsToEntry(Number(amount) || 0, defaultMode, from?.price ?? 0));
|
|
34
|
+
const [fromMode, setFromMode] = useState(defaultMode);
|
|
35
|
+
const [toMode, applyToMode] = useState(defaultMode);
|
|
36
|
+
const host = useContext(SwapHostContext);
|
|
37
|
+
const [ownView, keepView] = useState('main');
|
|
38
|
+
const view = viewProp ?? ownView;
|
|
39
|
+
const show = (next) => { if (next === view)
|
|
40
|
+
return; if (viewProp === undefined)
|
|
41
|
+
keepView(next); onViewChange?.(next); };
|
|
42
|
+
const back = () => show(swapParentView(view));
|
|
43
|
+
// Android back pops a pushed view before anything behind the panel handles it.
|
|
44
|
+
const pop = useRef(back);
|
|
45
|
+
pop.current = back;
|
|
46
|
+
useEffect(() => { if (view === 'main')
|
|
47
|
+
return; const subscription = BackHandler.addEventListener('hardwareBackPress', () => { pop.current(); return true; }); return () => subscription.remove(); }, [view === 'main']);
|
|
48
|
+
const { notice, show: showNotice, dismiss: dismissNotice } = useTransientNotice();
|
|
49
|
+
const fromPrice = from?.price ?? 0, toPrice = to?.price ?? 0, input = Number(entry) || 0;
|
|
50
|
+
const units = fromMode === 'token' ? input : fromPrice > 0 ? input / fromPrice : 0, usd = units * fromPrice, unitsText = trimNumber(units);
|
|
51
|
+
const showReceive = isReceiving && !!receive;
|
|
52
|
+
// Report the amount in token units; resync the entry when the host sets a different amount.
|
|
53
|
+
const reported = useRef(amount ?? '0');
|
|
54
|
+
useEffect(() => { if (reported.current !== unitsText) {
|
|
55
|
+
reported.current = unitsText;
|
|
56
|
+
onAmountChange?.(unitsText);
|
|
57
|
+
} }, [unitsText]);
|
|
58
|
+
useEffect(() => { if (amount === undefined || Number(amount) === Number(reported.current))
|
|
59
|
+
return; reported.current = trimNumber(Number(amount) || 0); setEntry(unitsToEntry(Number(amount) || 0, fromMode, fromPrice)); }, [amount]);
|
|
60
|
+
const sameAsset = !!from && !!to && from.id === to.id;
|
|
61
|
+
const receivedUnits = sameAsset ? units : received ?? (toPrice > 0 ? usd / toPrice : 0);
|
|
62
|
+
const receivedUsd = toPrice > 0 ? receivedUnits * toPrice : sameAsset ? usd : 0;
|
|
63
|
+
const action = swapAction(from, to);
|
|
64
|
+
const insufficient = !!from && (from.balance ?? 0) > 0 && units > (from.balance ?? 0);
|
|
65
|
+
// A destination or a details card stands in for the To token: one way, and ready from the From side alone.
|
|
66
|
+
const fixed = !!destination || (!!details && !to);
|
|
67
|
+
const oneWay = oneWayProp || fixed;
|
|
68
|
+
const ready = !!from && (!!to || fixed) && !destination?.pending && units > 0 && !insufficient;
|
|
69
|
+
const actionText = showReceive ? t.swapSendFromWallet : !from || (!to && !fixed) ? t.swapChooseToken : destination?.pending ? t.swapChooseDestination : units <= 0 ? t.swapEnterAmount : insufficient ? t.swapInsufficient(from.symbol) : actionLabel ?? (action === 'swap' && !fixed ? t.swapActionSwap : action === 'bridge' && !fixed ? t.swapActionBridge : t.swapActionSend);
|
|
70
|
+
const pristine = (lockFrom || !from) && (lockTo || !to) && input === 0;
|
|
71
|
+
// Updater form: several keys can land before the next render, and each must build on the last.
|
|
72
|
+
const latest = useRef(fromMode);
|
|
73
|
+
latest.current = fromMode;
|
|
74
|
+
const press = (key) => setEntry(current => applyAmountKey(current, key, latest.current));
|
|
75
|
+
const switchFromMode = (mode) => { if (mode === fromMode)
|
|
76
|
+
return; setEntry(mode === 'usd' ? trimNumber(usd, 2) : trimNumber(units)); setFromMode(mode); };
|
|
77
|
+
const changeDenomination = (mode) => { setDefaultMode(mode); switchFromMode(mode); applyToMode(mode); };
|
|
78
|
+
// A new default applies to an untouched entry at once; a typed amount keeps its denomination until reset.
|
|
79
|
+
useEffect(() => { if (input === 0) {
|
|
80
|
+
setFromMode(defaultMode);
|
|
81
|
+
applyToMode(defaultMode);
|
|
82
|
+
} }, [defaultMode]);
|
|
83
|
+
const reset = () => { setEntry('0'); setFromMode(defaultMode); applyToMode(defaultMode); if (isReceiving)
|
|
84
|
+
setReceiving(false); if (!lockFrom)
|
|
85
|
+
setFrom(null); if (!lockTo)
|
|
86
|
+
setTo(null); onReset?.(); };
|
|
87
|
+
const flip = () => { if (!from || !to)
|
|
88
|
+
return; setFrom(to); setTo(from); };
|
|
89
|
+
const submit = () => { if (submitting)
|
|
90
|
+
return; if (showReceive) {
|
|
91
|
+
onConnect?.();
|
|
92
|
+
return;
|
|
93
|
+
} if (ready)
|
|
94
|
+
onSubmit(fixed ? 'send' : action); };
|
|
95
|
+
// A copied address shows as a transient toast capsule (about 4s, dismissible), announced the way Toast announces any notice.
|
|
96
|
+
const copyAddress = () => { if (!receive?.onCopy)
|
|
97
|
+
return; Promise.resolve().then(receive.onCopy).then(() => showNotice(t.addressCopied)).catch(() => { }); };
|
|
98
|
+
const chainList = useMemo(() => { if (chains)
|
|
99
|
+
return chains; const seen = new Map(); for (const token of tokens)
|
|
100
|
+
if (!seen.has(token.chainId))
|
|
101
|
+
seen.set(token.chainId, { chainId: token.chainId, name: token.chain, icon: token.chainIcon }); return [...seen.values()]; }, [chains, tokens]);
|
|
102
|
+
const usdText = (value) => formatNumber(value, locale, { style: 'currency', currency: 'USD' });
|
|
103
|
+
const fraction = entry.includes('.') ? Math.min(entry.length - entry.indexOf('.') - 1, fromMode === 'usd' ? 2 : 8) : 0;
|
|
104
|
+
const small = { fontSize: 14, lineHeight: 19, color: colors.muted };
|
|
105
|
+
// An account (a token with a `caption`) reads name over caption beside one disc, and offers Max only.
|
|
106
|
+
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 }) })] }), _jsx(Text, { style: small, children: token.caption })] })] }), side === 'from' && (token.balance ?? 0) > 0 ? _jsx(SwapCapsule, { testID: 'swap-max', onPress: () => setEntry(unitsToEntry(token.balance ?? 0, fromMode, fromPrice)), children: _jsx(Text, { style: small, children: t.swapMax }) }) : null] });
|
|
107
|
+
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: () => setEntry(unitsToEntry(testAmount(token), fromMode, fromPrice)), children: _jsx(Text, { style: small, children: t.swapTest }) }), _jsx(SwapCapsule, { testID: 'swap-max', onPress: () => setEntry(unitsToEntry(token.balance ?? 0, fromMode, fromPrice)), children: _jsx(Text, { style: small, children: t.swapMax }) })] }), _jsx(View, { pointerEvents: 'none', children: _jsxs(Text, { style: small, children: [formatNumber(token.balance, locale, { maximumFractionDigits: 6 }), " ", token.symbol] }) })] }) : null)
|
|
108
|
+
: _jsxs(View, { pointerEvents: 'box-none', style: { alignItems: 'flex-end', gap: 8, maxWidth: '60%' }, children: [_jsx(SwapCapsule, { testID: 'swap-slippage', onPress: () => show(onSlippageChange ? 'slippage' : 'settings'), children: _jsx(Text, { style: small, children: t.swapSlippage(formatPercent(slippage)) }) }), _jsx(View, { pointerEvents: 'none', children: _jsx(Text, { style: small, children: t.swapFee(quoteLoading ? '…' : fee != null ? usdText(fee) : '—') }) })] })] });
|
|
109
|
+
const receiveView = (view) => {
|
|
110
|
+
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 }) })] });
|
|
111
|
+
const layout = { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-evenly', gap: 12, paddingTop: 8, paddingHorizontal: 16, paddingBottom: 20 };
|
|
112
|
+
return view.onCopy ? _jsx(Pressable, { accessibilityRole: 'button', accessibilityLabel: `${t.copyAddress}: ${view.address}`, testID: 'swap-receive', onPress: copyAddress, style: ({ pressed }) => [layout, { opacity: pressed ? 0.8 : 1 }], children: body }) : _jsx(View, { accessible: true, accessibilityLabel: view.address, testID: 'swap-receive', style: layout, children: body });
|
|
113
|
+
};
|
|
114
|
+
const card = (side) => {
|
|
115
|
+
const token = side === 'from' ? from : to, label = side === 'from' ? t.swapFrom : t.swapTo, mode = side === 'from' ? fromMode : toMode, locked = side === 'from' ? lockFrom : lockTo;
|
|
116
|
+
const cardUnits = side === 'from' ? units : receivedUnits, cardUsd = side === 'from' ? usd : receivedUsd;
|
|
117
|
+
const shown = side === 'from' ? input : mode === 'token' ? receivedUnits : receivedUsd;
|
|
118
|
+
const options = { minimumFractionDigits: side === 'from' ? fraction : 0, maximumFractionDigits: mode === 'usd' ? 2 : 8, useGrouping: false };
|
|
119
|
+
const prefix = mode === 'usd' ? '$' : '', suffix = side === 'from' && entry.endsWith('.') ? '.' : '';
|
|
120
|
+
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: "=" }), _jsx(Text, { testID: `swap-conversion-${side}`, style: small, children: mode === 'token' ? usdText(cardUsd) : `${formatNumber(cardUnits, locale, { maximumFractionDigits: 8, useGrouping: false })}${token ? ` ${token.symbol}` : ''}` }), _jsx(FlipIcon, { color: colors.muted, size: 14 })] })] })] })] }) });
|
|
121
|
+
};
|
|
122
|
+
// 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.
|
|
123
|
+
const fixedCard = () => {
|
|
124
|
+
if (!fixed)
|
|
125
|
+
return null;
|
|
126
|
+
const art = !destination ? null : destination.icon ? _jsx(TokenArt, { uri: destination.icon, size: 40 }) : destination.address ? _jsx(View, { style: { width: 40, height: 40, borderRadius: 20, backgroundColor: addressColor(destination.address) } }) : _jsx(View, { style: { width: 40, height: 40, borderRadius: 20, backgroundColor: colors.nested, alignItems: 'center', justifyContent: 'center' }, children: _jsx(Text, { style: { fontSize: 12, lineHeight: 16, fontWeight: '600', color: colors.muted }, children: destination.title.slice(0, 2) }) });
|
|
127
|
+
const row = destination ? _jsxs(View, { pointerEvents: 'none', style: { flexDirection: 'row', alignItems: 'center', gap: 12, minHeight: 84, padding: 16 }, children: [_jsx(View, { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', children: art }), _jsxs(View, { style: { flex: 1, minWidth: 0 }, children: [_jsx(Text, { testID: 'swap-destination-title', style: { fontWeight: destination.pending ? '500' : '600', lineHeight: 21 }, children: destination.title }), destination.subtitle ? _jsx(Text, { style: small, children: destination.subtitle }) : null, destination.address ? _jsx(Text, { style: small, children: shortAddress(destination.address) }) : null] }), destination.detail || fee !== undefined || destination.onPress ? _jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: 8, maxWidth: '60%' }, children: [_jsxs(View, { style: { alignItems: 'flex-end', gap: 8, flexShrink: 1 }, children: [destination.detail ? _jsx(Text, { style: [small, { textAlign: 'right' }], children: destination.detail }) : null, fee !== undefined ? _jsx(Text, { testID: 'swap-destination-fee', style: [small, { textAlign: 'right' }], children: t.swapFee(quoteLoading ? '…' : fee != null ? usdText(fee) : '—') }) : null] }), destination.onPress ? _jsx(View, { testID: 'swap-destination-chevron', children: _jsx(SmallChevron, { color: colors.muted, trailing: true }) }) : null] }) : null] }) : null;
|
|
128
|
+
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 }), _jsx(Text, { style: { lineHeight: 21, textAlign: 'right', flexShrink: 1 }, children: detail.value })] }, detail.label)) }) : null;
|
|
129
|
+
const shape = { backgroundColor: colors.surface, borderRadius: 24, overflow: 'hidden' };
|
|
130
|
+
// With a pressable destination the whole card is the button; the rows inside it are read as part of it.
|
|
131
|
+
return destination?.onPress ? _jsx(Pressable, { accessibilityRole: 'button', accessibilityLabel: destination.title, testID: 'swap-destination', onPress: 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] }) });
|
|
132
|
+
};
|
|
133
|
+
const fromCard = card('from'), toCard = fixedCard() ?? card('to');
|
|
134
|
+
const tone = noteTone === 'warning' ? colors.warning : noteTone === 'negative' ? colors.negative : null;
|
|
135
|
+
const main = _jsxs(View, { testID: 'swap-view-main', children: [title ? _jsx(View, { style: { marginBottom: 12 }, children: _jsx(SwapHeader, { title: title, onBack: onBack }) }) : 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: !from || !to }, disabled: !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.14) } : { 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', onPress: () => show('settings'), children: _jsx(MenuIcon, { color: colors.text }) }) : null, _jsxs(Button, { 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] });
|
|
136
|
+
const body = view === 'main' ? main
|
|
137
|
+
: view === 'from' ? _jsx(SwapPicker, { side: view, onBack: back, tokens: fromTokens ?? tokens, loading: fromTokensLoading, chains: chainList, hotTokenIds: hotTokenIds, selected: from, onSelect: setFrom, wallet: wallet, onConnect: onConnect, onDisconnect: onDisconnect, receiving: isReceiving, onReceivingChange: receive ? setReceiving : undefined })
|
|
138
|
+
: view === 'to' ? _jsx(SwapPicker, { side: view, onBack: back, tokens: tokens, chains: chainList, hotTokenIds: hotTokenIds, selected: to, onSelect: setTo, wallet: wallet, recipient: recipient, onRecipientChange: onRecipientChange, onScanRecipient: onScanRecipient })
|
|
139
|
+
: _jsx(SwapSettings, { view: view, onViewChange: show, onBack: back, denomination: defaultMode, onDenominationChange: denominationSwitch ? changeDenomination : undefined, slippage: slippage, onSlippageChange: onSlippageChange, fee: fee, fees: fees, quoteLoading: quoteLoading, children: settings });
|
|
140
|
+
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 }) });
|
|
141
|
+
}
|
|
142
|
+
const viewDepth = (view) => view === 'main' ? 0 : view === 'slippage' || view === 'fees' ? 2 : 1;
|
|
143
|
+
const stageEasing = Easing.bezier(0.22, 1, 0.36, 1);
|
|
144
|
+
/** Shows one view at a time. A push slides in from the trailing side and a pop from the leading side while the container height eases to the new view; reduced motion swaps at once. */
|
|
145
|
+
function SwapStage({ view, animateHeight, children }) {
|
|
146
|
+
const { reducedMotion, direction } = useHIG();
|
|
147
|
+
const shown = useRef(view), travel = useRef(0), slide = useRef(new Animated.Value(1)).current, height = useRef(new Animated.Value(0)).current, measured = useRef(null);
|
|
148
|
+
const [sized, setSized] = useState(false);
|
|
149
|
+
if (shown.current !== view)
|
|
150
|
+
travel.current = (viewDepth(view) >= viewDepth(shown.current) ? 1 : -1) * (direction === 'rtl' ? -1 : 1);
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
if (shown.current === view)
|
|
153
|
+
return;
|
|
154
|
+
shown.current = view;
|
|
155
|
+
if (reducedMotion) {
|
|
156
|
+
slide.setValue(1);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
slide.setValue(0);
|
|
160
|
+
Animated.timing(slide, { toValue: 1, duration: 260, easing: stageEasing, useNativeDriver: Platform.OS !== 'web' }).start();
|
|
161
|
+
}, [view, reducedMotion, slide]);
|
|
162
|
+
const sizing = animateHeight && !reducedMotion;
|
|
163
|
+
const onLayout = (event) => {
|
|
164
|
+
const next = event.nativeEvent.layout.height;
|
|
165
|
+
if (!sizing || !(next > 0))
|
|
166
|
+
return;
|
|
167
|
+
if (measured.current === null)
|
|
168
|
+
height.setValue(next);
|
|
169
|
+
else if (next !== measured.current)
|
|
170
|
+
Animated.timing(height, { toValue: next, duration: 260, easing: stageEasing, useNativeDriver: false }).start();
|
|
171
|
+
measured.current = next;
|
|
172
|
+
if (!sized)
|
|
173
|
+
setSized(true);
|
|
174
|
+
};
|
|
175
|
+
const fitted = sizing && sized;
|
|
176
|
+
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 }) });
|
|
177
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type FlatListProps } from 'react-native';
|
|
3
|
+
import type { SwapToken } from './swap-shared.js';
|
|
4
|
+
/** 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. */
|
|
5
|
+
export declare const SwapHostContext: React.Context<{
|
|
6
|
+
listComponent?: React.ComponentType<FlatListProps<SwapToken>>;
|
|
7
|
+
animateHeight?: boolean;
|
|
8
|
+
}>;
|
|
9
|
+
/** One arrow, top to bottom: a one-way panel. */
|
|
10
|
+
export declare function DownIcon({ color, size }: {
|
|
11
|
+
color: string;
|
|
12
|
+
size?: number;
|
|
13
|
+
}): React.JSX.Element;
|
|
14
|
+
/** Two opposed arrows: exchange the pair, or switch the denomination. */
|
|
15
|
+
export declare function FlipIcon({ color, size }: {
|
|
16
|
+
color: string;
|
|
17
|
+
size?: number;
|
|
18
|
+
}): React.JSX.Element;
|
|
19
|
+
export declare function MenuIcon({ color }: {
|
|
20
|
+
color: string;
|
|
21
|
+
}): React.JSX.Element;
|
|
22
|
+
/** An open ring with an arrowhead at its gap. */
|
|
23
|
+
export declare function ResetIcon({ color }: {
|
|
24
|
+
color: string;
|
|
25
|
+
}): React.JSX.Element;
|
|
26
|
+
/** Keypad delete: a key outline holding an x. */
|
|
27
|
+
export declare function DeleteIcon({ color }: {
|
|
28
|
+
color: string;
|
|
29
|
+
}): React.JSX.Element;
|
|
30
|
+
/** Four viewfinder corners. */
|
|
31
|
+
export declare function ScanIcon({ color }: {
|
|
32
|
+
color: string;
|
|
33
|
+
}): React.JSX.Element;
|
|
34
|
+
/** A wallet: a rounded body with a clasp on the trailing edge. */
|
|
35
|
+
export declare function WalletIcon({ color }: {
|
|
36
|
+
color: string;
|
|
37
|
+
}): React.JSX.Element;
|
|
38
|
+
/** A padlock: a shackle over a body. */
|
|
39
|
+
export declare function LockIcon({ color }: {
|
|
40
|
+
color: string;
|
|
41
|
+
}): React.JSX.Element;
|
|
42
|
+
/** A doorway with an arrow leaving it. */
|
|
43
|
+
export declare function LeaveIcon({ color }: {
|
|
44
|
+
color: string;
|
|
45
|
+
}): React.JSX.Element;
|
|
46
|
+
/** Circular artwork from a URL, or the symbol's first letters when the host has none. */
|
|
47
|
+
export declare function TokenArt({ uri, symbol, size, ring }: {
|
|
48
|
+
uri?: string;
|
|
49
|
+
symbol?: string;
|
|
50
|
+
size: number;
|
|
51
|
+
ring?: string;
|
|
52
|
+
}): React.JSX.Element;
|
|
53
|
+
/** Token artwork with its chain badge. */
|
|
54
|
+
export declare function TokenIcon({ token, size }: {
|
|
55
|
+
token: SwapToken;
|
|
56
|
+
size?: number;
|
|
57
|
+
}): React.JSX.Element;
|
|
58
|
+
/** 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 }: {
|
|
60
|
+
children: React.ReactNode;
|
|
61
|
+
onPress: () => void;
|
|
62
|
+
label?: string;
|
|
63
|
+
testID?: string;
|
|
64
|
+
}): React.JSX.Element;
|
|
65
|
+
/** Numeric keypad: a 3 by 4 grid of 56dp keys. Emits `0`–`9`, `.` or `back`. */
|
|
66
|
+
export declare function SwapKeypad({ onKey, label, deleteLabel }: {
|
|
67
|
+
onKey: (key: string) => void;
|
|
68
|
+
label: string;
|
|
69
|
+
deleteLabel: string;
|
|
70
|
+
}): React.JSX.Element;
|
|
71
|
+
/** A view's heading: the title, with Back before it when the view can be left. Shared by the pushed views and a titled main view. */
|
|
72
|
+
export declare function SwapHeader({ title, onBack }: {
|
|
73
|
+
title: string;
|
|
74
|
+
onBack?: () => void;
|
|
75
|
+
}): React.JSX.Element;
|
|
76
|
+
/** A small chevron: down marks a side that can be changed, trailing marks a card that opens something. Mirrors in RTL. */
|
|
77
|
+
export declare function SmallChevron({ color, trailing }: {
|
|
78
|
+
color: string;
|
|
79
|
+
trailing?: boolean;
|
|
80
|
+
}): React.JSX.Element;
|
|
81
|
+
/** A pushed view inside the panel: Back and the view title, then the body. There is no close control; Back pops. */
|
|
82
|
+
export declare function SwapSubview({ title, onBack, testID, children }: React.PropsWithChildren<{
|
|
83
|
+
title: string;
|
|
84
|
+
onBack: () => void;
|
|
85
|
+
testID?: string;
|
|
86
|
+
}>): React.JSX.Element;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createContext } from 'react';
|
|
3
|
+
import { Image, Pressable, View } from 'react-native';
|
|
4
|
+
import { useColors, useFills, useHIG, useMessages } from './provider.js';
|
|
5
|
+
import { Heading, Text } from './surface.js';
|
|
6
|
+
import { IconButton } from './button.js';
|
|
7
|
+
import { ChevronIcon } from './icons.js';
|
|
8
|
+
/** 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. */
|
|
9
|
+
export const SwapHostContext = createContext({});
|
|
10
|
+
// Outline symbols drawn from plain views, like ./icons: decorative, so the control that holds them carries the name.
|
|
11
|
+
const hidden = { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', pointerEvents: 'none' };
|
|
12
|
+
const stroke = 1.75;
|
|
13
|
+
const centre = { alignItems: 'center', justifyContent: 'center' };
|
|
14
|
+
const crossAngles = ['45deg', '-45deg'];
|
|
15
|
+
function Arrow({ color, down, height }) { return _jsxs(View, { style: { width: 7, height, alignItems: 'center', transform: down ? [{ rotate: '180deg' }] : undefined }, children: [_jsx(View, { style: { position: 'absolute', top: 1, width: 5, height: 5, borderLeftWidth: stroke, borderTopWidth: stroke, borderColor: color, transform: [{ rotate: '45deg' }] } }), _jsx(View, { style: { width: stroke, height, borderRadius: stroke, backgroundColor: color } })] }); }
|
|
16
|
+
/** One arrow, top to bottom: a one-way panel. */
|
|
17
|
+
export function DownIcon({ color, size = 16 }) { return _jsx(View, { ...hidden, style: { width: size, height: size, ...centre }, children: _jsx(Arrow, { color: color, down: true, height: size - 3 }) }); }
|
|
18
|
+
/** Two opposed arrows: exchange the pair, or switch the denomination. */
|
|
19
|
+
export function FlipIcon({ color, size = 16 }) { return _jsxs(View, { ...hidden, style: { width: size, height: size, flexDirection: 'row', gap: 1, ...centre }, children: [_jsx(Arrow, { color: color, down: true, height: size - 3 }), _jsx(Arrow, { color: color, height: size - 3 })] }); }
|
|
20
|
+
export function MenuIcon({ color }) { return _jsx(View, { ...hidden, style: { width: 20, height: 20, gap: 3.5, ...centre }, children: [0, 1, 2].map(index => _jsx(View, { style: { width: 14, height: stroke, borderRadius: stroke, backgroundColor: color } }, index)) }); }
|
|
21
|
+
/** An open ring with an arrowhead at its gap. */
|
|
22
|
+
export function ResetIcon({ color }) { return _jsxs(View, { ...hidden, style: { width: 20, height: 20, ...centre }, children: [_jsx(View, { style: { width: 14, height: 14, borderRadius: 7, borderWidth: stroke, borderColor: color, borderTopColor: 'transparent', transform: [{ rotate: '-45deg' }] } }), _jsx(View, { style: { position: 'absolute', left: 2, top: 3, width: 5, height: 5, borderLeftWidth: stroke, borderBottomWidth: stroke, borderColor: color } })] }); }
|
|
23
|
+
/** Keypad delete: a key outline holding an x. */
|
|
24
|
+
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)) }); }
|
|
25
|
+
/** Four viewfinder corners. */
|
|
26
|
+
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 } })] }); }
|
|
27
|
+
/** A wallet: a rounded body with a clasp on the trailing edge. */
|
|
28
|
+
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 } }) }) }); }
|
|
29
|
+
/** A padlock: a shackle over a body. */
|
|
30
|
+
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 } })] }); }
|
|
31
|
+
/** A doorway with an arrow leaving it. */
|
|
32
|
+
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' }] } })] }); }
|
|
33
|
+
/** Circular artwork from a URL, or the symbol's first letters when the host has none. */
|
|
34
|
+
export function TokenArt({ uri, symbol, size, ring }) {
|
|
35
|
+
const colors = useColors();
|
|
36
|
+
const shape = { width: size, height: size, borderRadius: size / 2, backgroundColor: colors.nested, ...(ring ? { borderWidth: 2, borderColor: ring } : {}) };
|
|
37
|
+
return uri ? _jsx(Image, { accessible: false, accessibilityIgnoresInvertColors: true, source: { uri }, style: shape }) : _jsx(View, { style: [shape, centre], children: symbol ? _jsx(Text, { accessible: false, maxFontSizeMultiplier: 1, style: { fontSize: size >= 40 ? 12 : 9, lineHeight: size >= 40 ? 16 : 12, fontWeight: '600', color: colors.muted }, children: symbol.slice(0, 3) }) : null });
|
|
38
|
+
}
|
|
39
|
+
/** Token artwork with its chain badge. */
|
|
40
|
+
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] }); }
|
|
41
|
+
/** Small capsule action that sits on a card: Max, Test, the slippage setting and the denomination switch. 32dp tall with a 44dp target. */
|
|
42
|
+
export function SwapCapsule({ children, onPress, label, testID }) {
|
|
43
|
+
const fills = useFills();
|
|
44
|
+
const { direction } = useHIG();
|
|
45
|
+
return _jsx(Pressable, { accessibilityRole: 'button', accessibilityLabel: label, testID: testID, onPress: onPress, hitSlop: { top: 6, bottom: 6 }, 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
|
+
}
|
|
47
|
+
const keys = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '0', 'back'];
|
|
48
|
+
/** Numeric keypad: a 3 by 4 grid of 56dp keys. Emits `0`–`9`, `.` or `back`. */
|
|
49
|
+
export function SwapKeypad({ onKey, label, deleteLabel }) {
|
|
50
|
+
const colors = useColors();
|
|
51
|
+
// Always left to right: a keypad keeps its telephone layout in RTL locales.
|
|
52
|
+
return _jsx(View, { accessibilityLabel: label, testID: 'swap-keypad', style: { direction: 'ltr', flexDirection: 'row', flexWrap: 'wrap', paddingTop: 8 }, children: keys.map(key => _jsx(Pressable, { accessibilityRole: 'keyboardkey', accessibilityLabel: key === 'back' ? deleteLabel : key, testID: `swap-key-${key}`, onPress: () => onKey(key), style: ({ pressed }) => ({ width: '33.333%', height: 56, borderRadius: 16, backgroundColor: pressed ? colors.nested : 'transparent', ...centre }), children: key === 'back' ? _jsx(DeleteIcon, { color: colors.text }) : _jsx(Text, { accessible: false, style: { fontSize: 24, lineHeight: 30, fontWeight: '600' }, children: key }) }, key)) });
|
|
53
|
+
}
|
|
54
|
+
/** A view's heading: the title, with Back before it when the view can be left. Shared by the pushed views and a titled main view. */
|
|
55
|
+
export function SwapHeader({ title, onBack }) {
|
|
56
|
+
const colors = useColors();
|
|
57
|
+
const t = useMessages();
|
|
58
|
+
const { direction } = useHIG();
|
|
59
|
+
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 })] });
|
|
60
|
+
}
|
|
61
|
+
/** A small chevron: down marks a side that can be changed, trailing marks a card that opens something. Mirrors in RTL. */
|
|
62
|
+
export function SmallChevron({ color, trailing }) { const { direction } = useHIG(); return _jsx(View, { ...hidden, style: { width: 16, height: 16, ...centre, transform: trailing ? [{ rotate: direction === 'rtl' ? '90deg' : '-90deg' }] : undefined }, children: _jsx(View, { style: { width: 7, height: 7, borderRightWidth: stroke, borderBottomWidth: stroke, borderColor: color, transform: [{ translateY: -1.5 }, { rotate: '45deg' }] } }) }); }
|
|
63
|
+
/** A pushed view inside the panel: Back and the view title, then the body. There is no close control; Back pops. */
|
|
64
|
+
export function SwapSubview({ title, onBack, testID, children }) {
|
|
65
|
+
return _jsxs(View, { testID: testID, style: { gap: 16 }, children: [_jsx(SwapHeader, { title: title, onBack: onBack }), children] });
|
|
66
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/** An asset on one chain. The host supplies every value; HIG formats and lays it out. */
|
|
2
|
+
export interface SwapToken {
|
|
3
|
+
/** Unique per asset and chain, for example `${chainId}-${address}`. */
|
|
4
|
+
id: string;
|
|
5
|
+
symbol: string;
|
|
6
|
+
name: string;
|
|
7
|
+
/** Chain display name and identity. Two tokens on the same `chainId` swap; different chains bridge. */
|
|
8
|
+
chain: string;
|
|
9
|
+
chainId: string | number;
|
|
10
|
+
/** Image URLs. A missing token icon falls back to the symbol's first letters. */
|
|
11
|
+
icon?: string;
|
|
12
|
+
chainIcon?: string;
|
|
13
|
+
/** Holdings in token units, when the host knows them. Enables Max, Test and the balance check. */
|
|
14
|
+
balance?: number | null;
|
|
15
|
+
/** USD per unit, when the host knows it. Enables the dollar and unit conversion. */
|
|
16
|
+
price?: number | null;
|
|
17
|
+
/** Presents the side as an account rather than a token: this line (for example `$22.72 available`) sits under the name, the artwork is a single disc, and only Max is offered. */
|
|
18
|
+
caption?: string;
|
|
19
|
+
/** Extra text matched by the picker search, such as the contract address. */
|
|
20
|
+
keywords?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface SwapChain {
|
|
23
|
+
chainId: string | number;
|
|
24
|
+
name: string;
|
|
25
|
+
icon?: string;
|
|
26
|
+
}
|
|
27
|
+
/** Same asset: send. Different asset on one chain: swap. Different asset across chains: bridge. */
|
|
28
|
+
export type SwapAction = 'send' | 'swap' | 'bridge';
|
|
29
|
+
export type SwapDenomination = 'usd' | 'token';
|
|
30
|
+
/** The panel's view stack: the main form, a side's token picker, or a settings view. Exactly one shows at a time. */
|
|
31
|
+
export type SwapView = 'main' | 'from' | 'to' | 'settings' | 'slippage' | 'fees';
|
|
32
|
+
/** Where Back leads: slippage and fees return to settings, everything else to the main form. */
|
|
33
|
+
export declare const swapParentView: (view: SwapView) => SwapView;
|
|
34
|
+
export interface SwapWallet {
|
|
35
|
+
connected: boolean;
|
|
36
|
+
address?: string | null;
|
|
37
|
+
}
|
|
38
|
+
export interface SwapFee {
|
|
39
|
+
label: string;
|
|
40
|
+
usd: number;
|
|
41
|
+
}
|
|
42
|
+
export declare const slippagePresets: readonly [0.001, 0.005, 0.01];
|
|
43
|
+
export declare function swapAction(from: SwapToken | null, to: SwapToken | null): SwapAction;
|
|
44
|
+
/** A clean numeric string: no trailing zeros, at most `digits` decimals. */
|
|
45
|
+
export declare const trimNumber: (value: number, digits?: number) => string;
|
|
46
|
+
/** Keeps digits and one decimal point, and strips leading zeros; never returns an empty string. */
|
|
47
|
+
export declare function sanitizeAmount(raw: string): string;
|
|
48
|
+
/** Token units shown in the active denomination. Dollars floor to the cent so Max never resolves to more than the balance. */
|
|
49
|
+
export declare function unitsToEntry(units: number, mode: SwapDenomination, price: number): string;
|
|
50
|
+
/** Applies one keypad key (`0`–`9`, `.`, `back`) to an amount string. Dollars stop at two decimals. */
|
|
51
|
+
export declare function applyAmountKey(current: string, key: string, mode: SwapDenomination): string;
|
|
52
|
+
/** Case-insensitive substring or in-order subsequence match. */
|
|
53
|
+
export declare function fuzzyMatch(query: string, text: string): boolean;
|
|
54
|
+
/** A slippage fraction as a percent string: 0.005 is `0.5%`. */
|
|
55
|
+
export declare const formatPercent: (fraction: number) => string;
|
|
56
|
+
/** A small trial amount: 1% of holdings, capped at about one dollar's worth. */
|
|
57
|
+
export declare function testAmount(token: SwapToken): number;
|
|
58
|
+
export declare const shortAddress: (address: string) => string;
|
|
59
|
+
/** A stable flat colour for a wallet address, so the same wallet always looks the same. */
|
|
60
|
+
export declare function addressColor(address: string): string;
|
|
61
|
+
/** Picker rows: hot tokens lead the unfiltered list; any search or chain filter gives one flat list. */
|
|
62
|
+
export declare function pickerRows(tokens: readonly SwapToken[], query: string, chainId: string | number | null, hotTokenIds?: readonly string[]): {
|
|
63
|
+
rows: SwapToken[];
|
|
64
|
+
hotCount: number;
|
|
65
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/** Where Back leads: slippage and fees return to settings, everything else to the main form. */
|
|
2
|
+
export const swapParentView = (view) => view === 'slippage' || view === 'fees' ? 'settings' : 'main';
|
|
3
|
+
export const slippagePresets = [0.001, 0.005, 0.01];
|
|
4
|
+
export function swapAction(from, to) {
|
|
5
|
+
if (!from || !to || from.symbol === to.symbol)
|
|
6
|
+
return 'send';
|
|
7
|
+
return from.chainId === to.chainId ? 'swap' : 'bridge';
|
|
8
|
+
}
|
|
9
|
+
/** A clean numeric string: no trailing zeros, at most `digits` decimals. */
|
|
10
|
+
export const trimNumber = (value, digits = 8) => String(Number((Number.isFinite(value) ? value : 0).toFixed(digits)));
|
|
11
|
+
/** Keeps digits and one decimal point, and strips leading zeros; never returns an empty string. */
|
|
12
|
+
export function sanitizeAmount(raw) {
|
|
13
|
+
let value = raw.replace(/[^0-9.]/g, '');
|
|
14
|
+
const dot = value.indexOf('.');
|
|
15
|
+
if (dot !== -1)
|
|
16
|
+
value = value.slice(0, dot + 1) + value.slice(dot + 1).replace(/\./g, '');
|
|
17
|
+
value = value.replace(/^0+(\d)/, '$1');
|
|
18
|
+
return value === '' || value === '.' ? '0' : value;
|
|
19
|
+
}
|
|
20
|
+
/** Token units shown in the active denomination. Dollars floor to the cent so Max never resolves to more than the balance. */
|
|
21
|
+
export function unitsToEntry(units, mode, price) {
|
|
22
|
+
if (mode === 'token')
|
|
23
|
+
return trimNumber(units);
|
|
24
|
+
return price > 0 ? String(Math.floor(units * price * 100) / 100) : '0';
|
|
25
|
+
}
|
|
26
|
+
/** Applies one keypad key (`0`–`9`, `.`, `back`) to an amount string. Dollars stop at two decimals. */
|
|
27
|
+
export function applyAmountKey(current, key, mode) {
|
|
28
|
+
if (key === 'back')
|
|
29
|
+
return current.length <= 1 ? '0' : current.slice(0, -1);
|
|
30
|
+
if (key === '.')
|
|
31
|
+
return current.includes('.') ? current : `${current}.`;
|
|
32
|
+
if (!/^[0-9]$/.test(key))
|
|
33
|
+
return current;
|
|
34
|
+
const next = sanitizeAmount(current === '0' ? key : current + key);
|
|
35
|
+
const dot = next.indexOf('.');
|
|
36
|
+
return mode === 'usd' && dot !== -1 && next.length - dot - 1 > 2 ? current : next;
|
|
37
|
+
}
|
|
38
|
+
/** Case-insensitive substring or in-order subsequence match. */
|
|
39
|
+
export function fuzzyMatch(query, text) {
|
|
40
|
+
const needle = query.toLowerCase().replace(/\s+/g, ''), haystack = text.toLowerCase();
|
|
41
|
+
if (haystack.includes(needle))
|
|
42
|
+
return true;
|
|
43
|
+
let matched = 0;
|
|
44
|
+
for (let index = 0; index < haystack.length && matched < needle.length; index++)
|
|
45
|
+
if (haystack[index] === needle[matched])
|
|
46
|
+
matched++;
|
|
47
|
+
return matched === needle.length;
|
|
48
|
+
}
|
|
49
|
+
/** A slippage fraction as a percent string: 0.005 is `0.5%`. */
|
|
50
|
+
export const formatPercent = (fraction) => `${Number((fraction * 100).toFixed(4))}%`;
|
|
51
|
+
/** A small trial amount: 1% of holdings, capped at about one dollar's worth. */
|
|
52
|
+
export function testAmount(token) {
|
|
53
|
+
const balance = token.balance ?? 0, price = token.price ?? 0;
|
|
54
|
+
if (!(balance > 0))
|
|
55
|
+
return 0;
|
|
56
|
+
return Number(Math.min(balance * 0.01, price > 0 ? 1 / price : balance * 0.01).toFixed(8));
|
|
57
|
+
}
|
|
58
|
+
export const shortAddress = (address) => address.length <= 12 ? address : `${address.slice(0, 6)}…${address.slice(-4)}`;
|
|
59
|
+
/** A stable flat colour for a wallet address, so the same wallet always looks the same. */
|
|
60
|
+
export function addressColor(address) {
|
|
61
|
+
let hash = 0;
|
|
62
|
+
for (const character of address)
|
|
63
|
+
hash = (hash * 31 + character.charCodeAt(0)) >>> 0;
|
|
64
|
+
return `hsl(${hash % 360}, 75%, 55%)`;
|
|
65
|
+
}
|
|
66
|
+
/** Picker rows: hot tokens lead the unfiltered list; any search or chain filter gives one flat list. */
|
|
67
|
+
export function pickerRows(tokens, query, chainId, hotTokenIds) {
|
|
68
|
+
const text = query.trim();
|
|
69
|
+
const filtered = tokens.filter(token => (chainId === null || token.chainId === chainId) && (text === '' || fuzzyMatch(text, `${token.name} ${token.symbol} ${token.chain} ${token.keywords ?? ''}`)));
|
|
70
|
+
if (text !== '' || chainId !== null || !hotTokenIds?.length)
|
|
71
|
+
return { rows: filtered, hotCount: 0 };
|
|
72
|
+
const hot = hotTokenIds.map(id => filtered.find(token => token.id === id)).filter((token) => !!token);
|
|
73
|
+
if (!hot.length || hot.length === filtered.length)
|
|
74
|
+
return { rows: filtered, hotCount: 0 };
|
|
75
|
+
return { rows: [...hot, ...filtered.filter(token => !hot.includes(token))], hotCount: hot.length };
|
|
76
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type SwapPanelProps } from './swap-panel.js';
|
|
3
|
+
export interface SwapSheetProps extends SwapPanelProps {
|
|
4
|
+
open: boolean;
|
|
5
|
+
onOpenChange: (open: boolean) => void;
|
|
6
|
+
/** Accessible name of the sheet. */
|
|
7
|
+
title: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* SwapPanel presented in the gesture sheet. Pickers and settings push inside the same sheet, which resizes to the view
|
|
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
|
+
* closing always returns to the main form. Needs the optional gesture-sheet backend, which `recipes` does not load.
|
|
13
|
+
*/
|
|
14
|
+
export declare function SwapSheet({ open, onOpenChange, title, view: viewProp, onViewChange, style, ...panel }: SwapSheetProps): React.JSX.Element;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import { BottomSheetFlatList } from '@gorhom/bottom-sheet';
|
|
4
|
+
import { GestureSheet } from './gesture-sheet.js';
|
|
5
|
+
import { SwapHostContext, SwapPanel, swapParentView } from './swap-panel.js';
|
|
6
|
+
/**
|
|
7
|
+
* SwapPanel presented in the gesture sheet. Pickers and settings push inside the same sheet, which resizes to the view
|
|
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
|
+
* closing always returns to the main form. Needs the optional gesture-sheet backend, which `recipes` does not load.
|
|
10
|
+
*/
|
|
11
|
+
export function SwapSheet({ open, onOpenChange, title, view: viewProp, onViewChange, style, ...panel }) {
|
|
12
|
+
const [ownView, keepView] = useState('main');
|
|
13
|
+
const view = viewProp ?? ownView;
|
|
14
|
+
const show = (next) => { if (next === view)
|
|
15
|
+
return; if (viewProp === undefined)
|
|
16
|
+
keepView(next); onViewChange?.(next); };
|
|
17
|
+
useEffect(() => { if (!open)
|
|
18
|
+
show('main'); }, [open]);
|
|
19
|
+
// The backend's list hands drags at its scroll edge to the sheet; the sheet sizes to its content, so the panel keeps its height still.
|
|
20
|
+
const host = useMemo(() => ({ listComponent: BottomSheetFlatList, animateHeight: false }), []);
|
|
21
|
+
const leave = () => { if (view === 'main')
|
|
22
|
+
return false; show(swapParentView(view)); return true; };
|
|
23
|
+
return _jsx(GestureSheet, { open: open, onOpenChange: next => { if (!next && leave())
|
|
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(SwapPanel, { ...panel, view: view, onViewChange: show, style: [{ paddingHorizontal: 12, paddingBottom: 16 }, style] }) }) });
|
|
26
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type SwapChain, type SwapDenomination, type SwapFee, type SwapToken, type SwapWallet } from './swap-shared.js';
|
|
3
|
+
export interface SwapPickerProps {
|
|
4
|
+
side: 'from' | 'to';
|
|
5
|
+
onBack: () => void;
|
|
6
|
+
tokens: readonly SwapToken[];
|
|
7
|
+
chains: readonly SwapChain[];
|
|
8
|
+
hotTokenIds?: readonly string[];
|
|
9
|
+
selected: SwapToken | null;
|
|
10
|
+
onSelect: (token: SwapToken) => void;
|
|
11
|
+
loading?: boolean;
|
|
12
|
+
wallet?: SwapWallet;
|
|
13
|
+
onConnect?: () => void;
|
|
14
|
+
onDisconnect?: () => void;
|
|
15
|
+
/** From side, before a wallet is connected: the Generate address switch, which puts the panel in its receive view. */
|
|
16
|
+
receiving?: boolean;
|
|
17
|
+
onReceivingChange?: (receiving: boolean) => void;
|
|
18
|
+
/** To side: where the assets are sent. Omit `onRecipientChange` to hide the field. */
|
|
19
|
+
recipient?: string;
|
|
20
|
+
onRecipientChange?: (address: string) => void;
|
|
21
|
+
onScanRecipient?: () => void;
|
|
22
|
+
}
|
|
23
|
+
/** The panel's pushed picker view: the sub-view header over the From or To picker recipe. Choosing a token pops back; the Generate address switch does not. */
|
|
24
|
+
export declare function SwapPicker({ side, onBack, selected, onSelect, wallet, onConnect, onDisconnect, receiving, onReceivingChange, recipient, onRecipientChange, onScanRecipient, ...list }: SwapPickerProps): React.JSX.Element;
|
|
25
|
+
export type SwapSettingsView = 'settings' | 'slippage' | 'fees';
|
|
26
|
+
export interface SwapSettingsProps {
|
|
27
|
+
view: SwapSettingsView;
|
|
28
|
+
onViewChange: (view: SwapSettingsView) => void;
|
|
29
|
+
onBack: () => void;
|
|
30
|
+
denomination: SwapDenomination; /** Omit to hide the denomination setting. */
|
|
31
|
+
onDenominationChange?: (denomination: SwapDenomination) => void;
|
|
32
|
+
slippage: number;
|
|
33
|
+
onSlippageChange?: (slippage: number) => void;
|
|
34
|
+
fee?: number | null;
|
|
35
|
+
fees?: readonly SwapFee[];
|
|
36
|
+
quoteLoading?: boolean;
|
|
37
|
+
/** Host rows shown under the built-in settings, such as language or theme. */
|
|
38
|
+
children?: React.ReactNode;
|
|
39
|
+
}
|
|
40
|
+
/** The settings views. Slippage and the fee breakdown push from the settings list, and Back returns to it. */
|
|
41
|
+
export declare function SwapSettings({ view, onViewChange, onBack, denomination, onDenominationChange, slippage, onSlippageChange, fee, fees, quoteLoading, children }: SwapSettingsProps): React.JSX.Element;
|