@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,178 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
4
|
-
import * as en from '@bloxwap/hig/contracts/messages';
|
|
5
|
-
import { PressDecoration, useControllable, useHIG } from '../provider.js';
|
|
6
|
-
import { Button, IconButton } from '../button.js';
|
|
7
|
-
import { AnimatedNumberReadout } from '../animated-number.js';
|
|
8
|
-
import { notify } from '../notify.js';
|
|
9
|
-
import { VerticalAddress } from '../data.js';
|
|
10
|
-
import { SwapPicker } from './swap/picker.js';
|
|
11
|
-
import { SwapSettings } from './swap/settings.js';
|
|
12
|
-
import { SwapIcon, SwapKeypad, SwapNumber, SwapPill, percentNumber, swapArt, swapFigure, usdNumber, addressGradient, applyAmountKey, chainsOf, parentView, sanitizeAmount, shortAddress, swapAction, testAmount, trimNumber, unitsToEntry } from './swap/shared.js';
|
|
13
|
-
export { swapAction } from './swap/shared.js';
|
|
14
|
-
export { SwapAmountCard } from './swap/amount-card.js';
|
|
15
|
-
export { SwapPill, SwapKeypad, SwapNumber } from './swap/shared.js';
|
|
16
|
-
const textTarget = (target) => { const element = target; return !!element && (/^(INPUT|TEXTAREA|SELECT)$/.test(element.tagName) || element.isContentEditable); };
|
|
17
|
-
const amountKey = (event) => event.metaKey || event.ctrlKey || event.altKey ? null : /^[0-9.]$/.test(event.key) ? event.key : event.key === 'Backspace' ? 'back' : null;
|
|
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, 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 SwapPanelBlock({ 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, destination, details, note, noteTone = 'muted', title, onBack, controls = true, actionIcon, lockFrom = false, lockTo = false, actionLabel, actionDisabled = false, actionStatus, actionIntent = 'primary', limitToBalance = false, banner, footer, oneWay: oneWayProp = false, denominationSwitch = true, keypad = 'auto', shortcuts = true, captureKeyboard = false, view: viewProp, onViewChange, settings, className, style }) {
|
|
24
|
-
const { messages } = useHIG();
|
|
25
|
-
const [from, setFrom] = useControllable(fromProp, defaultFrom, onFromChange);
|
|
26
|
-
const [to, setTo] = useControllable(toProp, defaultTo, onToChange);
|
|
27
|
-
const [defaultMode, setDefaultMode] = useControllable(denomination, 'usd', onDenominationChange);
|
|
28
|
-
const [isReceiving, setReceiving] = useControllable(receiving, false, onReceivingChange);
|
|
29
|
-
// A mounted `amount` seeds the entry, in the default denomination at the initial From token's price.
|
|
30
|
-
const [entry, setEntry] = useState(() => amount === undefined ? '0' : unitsToEntry(Number(amount) || 0, defaultMode, from?.price ?? 0));
|
|
31
|
-
const [fromMode, applyFromMode] = useState(defaultMode);
|
|
32
|
-
const [toMode, applyToMode] = useState(defaultMode);
|
|
33
|
-
const [view, show] = useControllable(viewProp, 'main', onViewChange);
|
|
34
|
-
const root = useRef(null);
|
|
35
|
-
const previous = useRef('main');
|
|
36
|
-
const openPicker = (side) => show(side);
|
|
37
|
-
const back = () => show(parentView(view));
|
|
38
|
-
// A push slides in from the trailing edge and a pop from the leading edge. Popping to the cards returns focus to the control that pushed.
|
|
39
|
-
const direction = view === 'main' || (view === 'settings' && previous.current !== 'main') ? 'pop' : 'push';
|
|
40
|
-
useEffect(() => { const from = previous.current; previous.current = view; if (view !== 'main' || from === 'main')
|
|
41
|
-
return; root.current?.querySelector(from === 'from' || from === 'to' ? `[data-side='${from}'] .hig-swap-hit` : '.hig-swap-settings-button')?.focus(); }, [view]);
|
|
42
|
-
const [touch, setTouch] = useState(false);
|
|
43
|
-
const [hint, showHint] = useState(null);
|
|
44
|
-
const [copied, setCopied] = useState('');
|
|
45
|
-
useEffect(() => {
|
|
46
|
-
const coarse = window.matchMedia?.('(pointer: coarse)');
|
|
47
|
-
const update = () => setTouch(!!coarse?.matches);
|
|
48
|
-
update();
|
|
49
|
-
coarse?.addEventListener('change', update);
|
|
50
|
-
if (window.matchMedia?.('(hover: hover) and (pointer: fine)').matches)
|
|
51
|
-
showHint(/Mac|iPhone|iPad/.test(navigator.platform) ? 'mac' : 'pc');
|
|
52
|
-
return () => coarse?.removeEventListener('change', update);
|
|
53
|
-
}, []);
|
|
54
|
-
const fromPrice = from?.price ?? 0, toPrice = to?.price ?? 0, input = Number(entry) || 0;
|
|
55
|
-
const units = fromMode === 'token' ? input : fromPrice > 0 ? input / fromPrice : 0, usd = units * fromPrice, unitsText = trimNumber(units);
|
|
56
|
-
const showReceive = isReceiving && !!receive;
|
|
57
|
-
// Report the amount in token units; resync the entry when the host sets a different amount.
|
|
58
|
-
const reported = useRef(amount ?? '0');
|
|
59
|
-
useEffect(() => { if (reported.current !== unitsText) {
|
|
60
|
-
reported.current = unitsText;
|
|
61
|
-
onAmountChange?.(unitsText);
|
|
62
|
-
} }, [unitsText]);
|
|
63
|
-
useEffect(() => { if (amount === undefined || Number(amount) === Number(reported.current))
|
|
64
|
-
return; reported.current = trimNumber(Number(amount) || 0); setEntry(unitsToEntry(Number(amount) || 0, fromMode, fromPrice)); }, [amount]);
|
|
65
|
-
const sameAsset = !!from && !!to && from.id === to.id;
|
|
66
|
-
const receivedUnits = sameAsset ? units : received ?? (toPrice > 0 ? usd / toPrice : 0);
|
|
67
|
-
const receivedUsd = toPrice > 0 ? receivedUnits * toPrice : sameAsset ? usd : 0;
|
|
68
|
-
const action = swapAction(from, to);
|
|
69
|
-
const insufficient = !!from && (from.balance ?? 0) > 0 && units > (from.balance ?? 0);
|
|
70
|
-
// A destination or a details card stands in for the To token: one way, and ready from the From side alone.
|
|
71
|
-
const fixed = !!destination || (!!details && !to);
|
|
72
|
-
const oneWay = oneWayProp || fixed;
|
|
73
|
-
const eligible = !!from && (!!to || fixed) && !destination?.pending && units > 0 && !insufficient;
|
|
74
|
-
const ready = eligible && !actionDisabled;
|
|
75
|
-
const actionText = showReceive ? (messages.swapSendFromWallet ?? en.swapSendFromWallet) : !from || (!to && !fixed) ? (messages.swapChooseToken ?? en.swapChooseToken) : destination?.pending ? (messages.swapChooseDestination ?? en.swapChooseDestination) : units <= 0 ? (messages.swapEnterAmount ?? en.swapEnterAmount) : insufficient ? (messages.swapInsufficient ?? en.swapInsufficient)(from.symbol) : actionDisabled && actionStatus ? actionStatus : actionLabel ?? (action === 'swap' && !fixed ? messages.swapActionSwap ?? en.swapActionSwap : action === 'bridge' && !fixed ? messages.swapActionBridge ?? en.swapActionBridge : messages.swapActionSend ?? en.swapActionSend);
|
|
76
|
-
const pristine = (lockFrom || !from) && (lockTo || !to) && input === 0;
|
|
77
|
-
// Updater form: several keys can land before the next render, and each must build on the last.
|
|
78
|
-
const latest = useRef(fromMode);
|
|
79
|
-
latest.current = fromMode;
|
|
80
|
-
const latestView = useRef(view);
|
|
81
|
-
latestView.current = view;
|
|
82
|
-
// Read at key time: several keys can land in one render.
|
|
83
|
-
const limits = useRef({ decimals: from?.decimals, balance: from?.balance ?? 0, price: fromPrice, cap: limitToBalance });
|
|
84
|
-
limits.current = { decimals: from?.decimals, balance: from?.balance ?? 0, price: fromPrice, cap: limitToBalance };
|
|
85
|
-
const over = (next) => { const { balance, price, cap } = limits.current; if (!cap || !(balance > 0))
|
|
86
|
-
return false; const value = Number(next) || 0; return (latest.current === 'token' ? value : price > 0 ? value / price : 0) > balance; };
|
|
87
|
-
const press = (key) => setEntry(current => { const next = applyAmountKey(current, key, latest.current, limits.current.decimals); return key !== 'back' && over(next) ? current : next; });
|
|
88
|
-
const paste = (text) => { const clean = text.trim().replace(/,/g, ''); if (clean === '' || !/^[0-9]*\.?[0-9]*$/.test(clean))
|
|
89
|
-
return false; const next = sanitizeAmount(clean); setEntry(latest.current === 'usd' ? trimNumber(Number(next) || 0, 2) : next); return true; };
|
|
90
|
-
const switchFromMode = (mode) => { if (mode === fromMode)
|
|
91
|
-
return; setEntry(mode === 'usd' ? trimNumber(usd, 2) : trimNumber(units)); applyFromMode(mode); };
|
|
92
|
-
const changeDenomination = (mode) => { setDefaultMode(mode); switchFromMode(mode); applyToMode(mode); };
|
|
93
|
-
// A new default applies to an untouched entry at once; a typed amount keeps its denomination until reset.
|
|
94
|
-
useEffect(() => { if (input === 0) {
|
|
95
|
-
applyFromMode(defaultMode);
|
|
96
|
-
applyToMode(defaultMode);
|
|
97
|
-
} }, [defaultMode]);
|
|
98
|
-
const reset = () => { setEntry('0'); applyFromMode(defaultMode); applyToMode(defaultMode); if (isReceiving)
|
|
99
|
-
setReceiving(false); if (!lockFrom)
|
|
100
|
-
setFrom(null); if (!lockTo)
|
|
101
|
-
setTo(null); onReset?.(); };
|
|
102
|
-
const flip = () => { if (!from || !to)
|
|
103
|
-
return; setFrom(to); setTo(from); };
|
|
104
|
-
const submit = () => { if (submitting)
|
|
105
|
-
return; if (showReceive) {
|
|
106
|
-
onConnect?.();
|
|
107
|
-
return;
|
|
108
|
-
} if (ready)
|
|
109
|
-
onSubmit(fixed ? 'send' : action); };
|
|
110
|
-
const copyAddress = () => { if (!receive?.onCopy)
|
|
111
|
-
return; Promise.resolve().then(receive.onCopy).then(() => { const text = (messages.addressCopied ?? en.addressCopied); setCopied(notify(text, { severity: 'success', id: 'hig-swap-address', dismissName: (messages.dismissNotice ?? en.dismissNotice)(text, (messages.dismiss ?? en.dismiss)) }) ? text : ''); }).catch(() => setCopied('')); };
|
|
112
|
-
useEffect(() => {
|
|
113
|
-
if (!shortcuts && !captureKeyboard)
|
|
114
|
-
return;
|
|
115
|
-
const onKeyDown = (event) => {
|
|
116
|
-
const key = event.key.toLowerCase();
|
|
117
|
-
if (shortcuts && (event.metaKey || event.ctrlKey) && !event.altKey && !event.shiftKey && (key === 'f' || key === 'k')) {
|
|
118
|
-
const side = key === 'f' ? 'from' : 'to';
|
|
119
|
-
if (side === 'from' ? lockFrom : lockTo || fixed)
|
|
120
|
-
return;
|
|
121
|
-
event.preventDefault();
|
|
122
|
-
show(side);
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
if (!captureKeyboard || event.defaultPrevented || textTarget(event.target) || latestView.current !== 'main')
|
|
126
|
-
return;
|
|
127
|
-
const pressed = amountKey(event);
|
|
128
|
-
if (pressed) {
|
|
129
|
-
event.preventDefault();
|
|
130
|
-
press(pressed);
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
const onPaste = (event) => { if (captureKeyboard && !event.defaultPrevented && !textTarget(event.target) && paste(event.clipboardData?.getData('text') ?? ''))
|
|
134
|
-
event.preventDefault(); };
|
|
135
|
-
window.addEventListener('keydown', onKeyDown);
|
|
136
|
-
document.addEventListener('paste', onPaste);
|
|
137
|
-
return () => { window.removeEventListener('keydown', onKeyDown); document.removeEventListener('paste', onPaste); };
|
|
138
|
-
}, [shortcuts, captureKeyboard, lockFrom, lockTo, fixed]);
|
|
139
|
-
// Keys typed while focus is inside the cards drive the amount; in a pushed view Escape pops it.
|
|
140
|
-
const inPanel = (event) => view === 'main' && !textTarget(event.target);
|
|
141
|
-
const onKeyDown = (event) => { if (view !== 'main' && event.key === 'Escape') {
|
|
142
|
-
event.preventDefault();
|
|
143
|
-
event.stopPropagation();
|
|
144
|
-
back();
|
|
145
|
-
return;
|
|
146
|
-
} if (captureKeyboard || !inPanel(event))
|
|
147
|
-
return; const pressed = amountKey(event); if (pressed) {
|
|
148
|
-
event.preventDefault();
|
|
149
|
-
press(pressed);
|
|
150
|
-
} };
|
|
151
|
-
const onPaste = (event) => { if (!captureKeyboard && inPanel(event) && paste(event.clipboardData.getData('text')))
|
|
152
|
-
event.preventDefault(); };
|
|
153
|
-
const chainList = useMemo(() => chains ?? chainsOf(tokens), [chains, tokens]);
|
|
154
|
-
// The fee keeps its sentence; only a known amount moves. Loading and unknown are plain placeholders.
|
|
155
|
-
const feeLine = quoteLoading || fee == null ? (messages.swapFee ?? en.swapFee)(quoteLoading ? '…' : '—') : _jsx(SwapNumber, { template: messages.swapFee ?? en.swapFee, ...usdNumber(fee) });
|
|
156
|
-
const fraction = entry.includes('.') ? Math.min(entry.length - entry.indexOf('.') - 1, fromMode === 'usd' ? 2 : 8) : 0;
|
|
157
|
-
// An account (a token with a `caption`) reads name over caption beside one disc, and offers Max only.
|
|
158
|
-
const account = (side, token, locked) => _jsxs("div", { className: 'hig-swap-selected', "data-account": 'true', children: [_jsx("span", { className: 'hig-swap-stack', "aria-hidden": 'true', children: token.icon ? swapArt(token.icon) : _jsx("span", { className: 'hig-swap-initials', children: token.symbol.slice(0, 3) }) }), _jsxs("span", { className: 'hig-swap-identity', children: [_jsxs("strong", { children: [token.name, !locked && _jsx(SwapIcon, { name: 'expand', size: 16 })] }), _jsx("span", { children: swapFigure(token.caption ?? '') })] }), side === 'from' && (token.balance ?? 0) > 0 && _jsx("span", { className: 'hig-swap-meta', children: _jsx(SwapPill, { onClick: () => setEntry(unitsToEntry(token.balance ?? 0, fromMode, fromPrice)), children: (messages.swapMax ?? en.swapMax) }) })] });
|
|
159
|
-
const header = (side, token) => _jsxs("div", { className: 'hig-swap-selected', children: [_jsxs("span", { className: 'hig-swap-stack', "aria-hidden": 'true', children: [wallet?.address && _jsx("span", { className: 'hig-swap-avatar', style: { background: addressGradient(wallet.address) } }), token.chainIcon && swapArt(token.chainIcon), token.icon ? swapArt(token.icon) : _jsx("span", { className: 'hig-swap-initials', children: token.symbol.slice(0, 3) })] }), _jsxs("span", { className: 'hig-swap-identity', children: [wallet?.address && _jsx("span", { children: shortAddress(wallet.address) }), _jsx("span", { children: token.chain }), _jsx("strong", { children: token.name })] }), side === 'from' ? (token.balance ?? 0) > 0 && _jsxs("span", { className: 'hig-swap-meta', children: [_jsxs("span", { className: 'hig-swap-pills', children: [_jsxs(SwapPill, { onClick: () => setEntry(unitsToEntry(testAmount(token), fromMode, fromPrice)), children: [_jsx(SwapIcon, { name: 'flask', size: 14 }), (messages.swapTest ?? en.swapTest)] }), _jsx(SwapPill, { onClick: () => setEntry(unitsToEntry(token.balance ?? 0, fromMode, fromPrice)), children: (messages.swapMax ?? en.swapMax) })] }), _jsx(SwapNumber, { value: token.balance, suffix: ' ' + token.symbol, options: { maximumFractionDigits: 6 } })] })
|
|
160
|
-
: _jsxs("span", { className: 'hig-swap-meta', children: [_jsxs(SwapPill, { onClick: () => show(onSlippageChange ? 'slippage' : 'settings'), children: [_jsx(SwapIcon, { name: 'sliders', size: 14 }), _jsx(SwapNumber, { template: messages.swapSlippage ?? en.swapSlippage, ...percentNumber(slippage) })] }), _jsx("span", { children: feeLine })] })] });
|
|
161
|
-
const receiveView = (view) => { const content = _jsxs(_Fragment, { children: [view.qr && _jsx("span", { className: 'hig-swap-qr', children: view.qr }), _jsx(VerticalAddress, { address: view.address })] }); return view.onCopy ? _jsxs("button", { type: 'button', className: 'hig-swap-receive', "aria-label": (messages.copyAddress ?? en.copyAddress) + ': ' + view.address, onClick: copyAddress, children: [content, _jsx(PressDecoration, { kind: 'row' })] }) : _jsx("div", { className: 'hig-swap-receive', children: content }); };
|
|
162
|
-
const card = (side) => {
|
|
163
|
-
const token = side === 'from' ? from : to, label = side === 'from' ? (messages.swapFrom ?? en.swapFrom) : (messages.swapTo ?? en.swapTo), mode = side === 'from' ? fromMode : toMode, locked = side === 'from' ? lockFrom : lockTo;
|
|
164
|
-
const cardUnits = side === 'from' ? units : receivedUnits, cardUsd = side === 'from' ? usd : receivedUsd;
|
|
165
|
-
const shown = side === 'from' ? input : mode === 'token' ? receivedUnits : receivedUsd;
|
|
166
|
-
return _jsxs("div", { className: 'hig-swap-card', "data-side": side, "data-locked": locked || undefined, children: [_jsxs("div", { className: 'hig-swap-slot', children: [!locked && _jsx("button", { type: 'button', className: 'hig-swap-hit', "aria-label": (messages.swapSelectToken ?? en.swapSelectToken)(label), onClick: () => openPicker(side), children: _jsx(PressDecoration, { kind: 'row' }) }), _jsx("div", { className: 'hig-swap-slot-content', children: token ? token.caption !== undefined ? account(side, token, locked) : header(side, token) : _jsxs(_Fragment, { children: [_jsxs("span", { className: 'hig-swap-placeholder', children: [label, "\u2026"] }), shortcuts && hint && !locked && _jsxs("kbd", { className: 'hig-swap-kbd', children: [hint === 'mac' ? '⌘' : messages.swapControlKey ?? en.swapControlKey, " ", side === 'from' ? 'F' : 'K'] })] }) })] }), side === 'from' && showReceive && receive ? receiveView(receive) :
|
|
167
|
-
!(side === 'to' && showReceive) && _jsxs("div", { className: 'hig-swap-amount-area', children: [!locked && _jsx("button", { type: 'button', className: 'hig-swap-hit', tabIndex: -1, "aria-hidden": 'true', onClick: () => openPicker(side), children: _jsx(PressDecoration, { kind: 'row' }) }), _jsxs("div", { className: 'hig-swap-amount-content', children: [_jsx("div", { className: 'hig-swap-amount', "data-muted": side === 'to' || undefined, ...(side === 'from' ? { role: 'textbox', tabIndex: 0, 'aria-label': (messages.swapAmount ?? en.swapAmount)(label) } : {}), children: _jsx(AnimatedNumberReadout, { value: shown, label: side === 'to' ? (messages.swapAmount ?? en.swapAmount)(label) : undefined, prefix: mode === 'usd' ? '$' : '', suffix: side === 'from' && entry.endsWith('.') ? '.' : '', options: { minimumFractionDigits: side === 'from' ? fraction : 0, maximumFractionDigits: mode === 'usd' ? 2 : 8, useGrouping: false } }) }), denominationSwitch && _jsxs(SwapPill, { "aria-label": (messages.swapSwitchDenomination ?? en.swapSwitchDenomination), onClick: () => side === 'from' ? switchFromMode(fromMode === 'usd' ? 'token' : 'usd') : applyToMode(toMode === 'usd' ? 'token' : 'usd'), children: [_jsx("span", { "aria-hidden": 'true', className: 'hig-swap-equals', children: "=" }), mode === 'token' ? _jsx(AnimatedNumberReadout, { value: cardUsd, options: { style: 'currency', currency: 'USD' } }) : _jsx(AnimatedNumberReadout, { value: cardUnits, suffix: token ? ` ${token.symbol}` : '', options: { maximumFractionDigits: 8, useGrouping: false } }), _jsx(SwapIcon, { name: 'flip', size: 14 })] })] })] })] });
|
|
168
|
-
};
|
|
169
|
-
// 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.
|
|
170
|
-
const fixedCard = fixed && _jsxs("div", { className: 'hig-swap-card', "data-side": 'to', "data-compact": 'true', "data-pending": destination?.pending || undefined, children: [destination && _jsxs("div", { className: 'hig-swap-slot', children: [destination.onPress && _jsx("button", { type: 'button', className: 'hig-swap-hit', "aria-label": destination.title, onClick: destination.onPress, children: _jsx(PressDecoration, { kind: 'row' }) }), _jsx("div", { className: 'hig-swap-slot-content', children: _jsxs("div", { className: 'hig-swap-selected', children: [_jsx("span", { className: 'hig-swap-stack', "aria-hidden": 'true', children: destination.icon ? swapArt(destination.icon) : destination.address ? _jsx("span", { className: 'hig-swap-avatar', style: { background: addressGradient(destination.address) } }) : _jsx("span", { className: 'hig-swap-initials', children: destination.title.slice(0, 2) }) }), _jsxs("span", { className: 'hig-swap-identity', children: [_jsx("strong", { children: destination.title }), destination.subtitle && _jsx("span", { children: destination.subtitle }), destination.address && _jsx("span", { children: shortAddress(destination.address) })] }), (destination.detail || fee !== undefined || destination.onPress) && _jsxs("span", { className: 'hig-swap-meta', "data-row": destination.onPress ? 'true' : undefined, children: [_jsxs("span", { children: [destination.detail && _jsx("span", { children: swapFigure(destination.detail) }), fee !== undefined && _jsx("span", { children: feeLine })] }), destination.onPress && _jsx(SwapIcon, { name: 'chevron', size: 16 })] })] }) })] }), details && details.length > 0 && _jsx("dl", { className: 'hig-swap-details', children: details.map(row => _jsxs("div", { children: [_jsx("dt", { children: row.label }), _jsx("dd", { children: typeof row.value === 'number' ? _jsx(SwapNumber, { value: row.value, options: row.options, prefix: row.prefix, suffix: row.suffix, formattedValue: row.formattedValue, animateFormatted: !!row.formattedValue }) : row.value })] }, row.label)) })] });
|
|
171
|
-
const fromCard = card('from'), toCard = fixedCard || card('to');
|
|
172
|
-
const body = view === 'main' ? _jsxs(_Fragment, { children: [title && _jsxs("div", { className: 'hig-swap-view-header', "data-plain": onBack ? undefined : 'true', children: [onBack && _jsxs("button", { type: 'button', className: 'hig-swap-back', "aria-label": messages.back ?? en.back, onClick: onBack, children: [_jsx(SwapIcon, { name: 'back' }), _jsx(PressDecoration, { kind: 'back' })] }), _jsx("h2", { className: 'hig-swap-view-title', children: title })] }), banner, fromCard, _jsx("div", { className: 'hig-swap-flip', children: oneWay ? _jsx("span", { "aria-hidden": 'true', children: _jsx(SwapIcon, { name: 'down', size: 16 }) }) : _jsxs("button", { type: 'button', "aria-label": (messages.swapFlip ?? en.swapFlip), disabled: !from || !to, onClick: flip, children: [_jsx(SwapIcon, { name: 'flip', size: 16 }), _jsx(PressDecoration, { kind: 'icon-button', disabled: !from || !to })] }) }), toCard, !showReceive && (keypad === 'always' || (keypad === 'auto' && touch)) && _jsx(SwapKeypad, { onKey: press, label: (messages.swapKeypad ?? en.swapKeypad), deleteLabel: (messages.swapDelete ?? en.swapDelete) }), note && _jsx("p", { className: 'hig-swap-note', "data-tone": noteTone, role: 'note', children: note }), _jsxs("div", { className: 'hig-swap-actions', children: [controls && _jsx(IconButton, { className: 'hig-swap-settings-button', intent: 'secondary', label: (messages.swapSettings ?? en.swapSettings), suppressFeedback: true, onClick: () => show('settings'), children: _jsx(SwapIcon, { name: 'menu' }) }), _jsxs(Button, { fullWidth: true, intent: actionIntent, busy: submitting, disabled: !showReceive && !ready, onClick: submit, children: [actionIcon, actionText] }), controls && _jsx(IconButton, { intent: 'secondary', label: (messages.swapReset ?? en.swapReset), disabled: pristine || submitting, onClick: reset, children: _jsx(SwapIcon, { name: 'reset' }) })] }), footer] }) : 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 })
|
|
173
|
-
: 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 })
|
|
174
|
-
: _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 });
|
|
175
|
-
return _jsxs("section", { ref: root, className: `hig-swap-panel${className ? ` ${className}` : ''}`, style: style, "data-view": view, "data-receiving": showReceive || undefined, onKeyDown: onKeyDown, onPaste: onPaste, children: [_jsx("div", { className: 'hig-swap-view', "data-direction": direction, children: body }, view), _jsx("p", { className: 'hig-sr-only', role: 'status', children: copied })] });
|
|
176
|
-
}
|
|
177
|
-
/** @deprecated Renamed `SwapPanelBlock`. The old name and the `blocks/swap-panel` and `recipes/swap-panel` import paths keep working until the next major release. */
|
|
178
|
-
export const SwapPanel = SwapPanelBlock;
|