@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,78 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useId, useMemo, useRef, useState } from 'react';
|
|
4
|
+
import { formatNumber } from '@bloxwap/hig/contracts';
|
|
5
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
6
|
+
import { useHIG } from '../provider.js';
|
|
7
|
+
import { Button, IconButton } from '../button.js';
|
|
8
|
+
import { Input, SearchInput } from '../field.js';
|
|
9
|
+
import { Filter } from '../selection.js';
|
|
10
|
+
import { SwapIcon, TokenIcon, addressGradient, chainsOf, fuzzyMatch, shortAddress } from './swap/shared.js';
|
|
11
|
+
function TokenList({ tokens, chains, chainFilter = true, hotTokenIds, selected = null, onSelect, loading, autoFocus, label }) {
|
|
12
|
+
const { messages, locale } = useHIG();
|
|
13
|
+
const id = useId();
|
|
14
|
+
const [query, setQuery] = useState('');
|
|
15
|
+
const [chainId, setChainId] = useState(null);
|
|
16
|
+
const [active, setActive] = useState(0);
|
|
17
|
+
const list = useRef(null);
|
|
18
|
+
const search = useRef(null);
|
|
19
|
+
useEffect(() => { if (autoFocus && window.matchMedia?.('(pointer: fine)').matches)
|
|
20
|
+
search.current?.focus(); }, []);
|
|
21
|
+
const options = useMemo(() => chains ?? chainsOf(tokens), [chains, tokens]);
|
|
22
|
+
// Hot tokens lead the unfiltered list; any search or chain filter shows one flat list.
|
|
23
|
+
const { rows, hotCount } = useMemo(() => {
|
|
24
|
+
const text = query.trim();
|
|
25
|
+
const filtered = tokens.filter(token => (chainId === null || token.chainId === chainId) && (text === '' || fuzzyMatch(text, `${token.name} ${token.symbol} ${token.chain} ${token.keywords ?? ''}`)));
|
|
26
|
+
if (text !== '' || chainId !== null || !hotTokenIds?.length)
|
|
27
|
+
return { rows: filtered, hotCount: 0 };
|
|
28
|
+
const hot = hotTokenIds.map(id => filtered.find(token => token.id === id)).filter((token) => !!token);
|
|
29
|
+
if (!hot.length || hot.length === filtered.length)
|
|
30
|
+
return { rows: filtered, hotCount: 0 };
|
|
31
|
+
return { rows: [...hot, ...filtered.filter(token => !hot.includes(token))], hotCount: hot.length };
|
|
32
|
+
}, [tokens, hotTokenIds, query, chainId]);
|
|
33
|
+
useEffect(() => { setActive(0); }, [query, chainId]);
|
|
34
|
+
useEffect(() => { list.current?.querySelector('[data-active="true"]')?.scrollIntoView?.({ block: 'nearest' }); }, [active]);
|
|
35
|
+
const onKeyDown = (event) => {
|
|
36
|
+
if (event.key === 'ArrowDown') {
|
|
37
|
+
event.preventDefault();
|
|
38
|
+
setActive(index => Math.min(index + 1, rows.length - 1));
|
|
39
|
+
}
|
|
40
|
+
else if (event.key === 'ArrowUp') {
|
|
41
|
+
event.preventDefault();
|
|
42
|
+
setActive(index => Math.max(index - 1, 0));
|
|
43
|
+
}
|
|
44
|
+
else if (event.key === 'Enter' && rows[active]) {
|
|
45
|
+
event.preventDefault();
|
|
46
|
+
onSelect(rows[active]);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
// An empty value is the unfiltered list.
|
|
50
|
+
const filters = [{ value: '', label: messages.swapAllChains ?? en.swapAllChains }, ...options.map(chain => ({ value: String(chain.chainId), label: chain.name, icon: chain.icon }))];
|
|
51
|
+
const row = (token, index) => {
|
|
52
|
+
const isSelected = selected?.id === token.id;
|
|
53
|
+
return _jsx("div", { role: 'listitem', children: _jsxs("button", { type: 'button', className: 'hig-swap-row', "data-active": index === active, "data-selected": isSelected || undefined, onClick: () => onSelect(token), onPointerMove: () => setActive(index), children: [_jsx(TokenIcon, { token: token }), _jsxs("span", { className: 'hig-swap-row-text', children: [_jsx("strong", { children: token.name }), _jsxs("span", { children: [token.chain, isSelected ? ' · ' + (messages.swapSelected ?? en.swapSelected) : ''] })] }), (token.balance ?? 0) > 0 && _jsxs("span", { className: 'hig-swap-row-balance', children: [_jsx("strong", { className: 'hig-number', children: formatNumber(token.balance, locale, { maximumFractionDigits: 6 }) }), (token.price ?? 0) > 0 && _jsx("span", { className: 'hig-number', children: formatNumber((token.balance ?? 0) * (token.price ?? 0), locale, { style: 'currency', currency: 'USD' }) })] })] }) }, token.id);
|
|
54
|
+
};
|
|
55
|
+
return _jsxs(_Fragment, { children: [_jsx(SearchInput, { ref: search, "aria-label": messages.swapSearchTokens ?? en.swapSearchTokens, placeholder: messages.swapSearchTokens ?? en.swapSearchTokens, value: query, onChange: event => setQuery(event.target.value), onKeyDown: onKeyDown, enterKeyHint: 'search', autoComplete: 'off', autoCapitalize: 'none', autoCorrect: 'off', spellCheck: false }), chainFilter && options.length > 1 && _jsx(Filter, { label: messages.swapChains ?? en.swapChains, options: filters, value: chainId === null ? '' : String(chainId), onValueChange: next => setChainId(options.find(chain => String(chain.chainId) === next)?.chainId ?? null) }), _jsxs("div", { ref: list, className: 'hig-swap-list', "aria-busy": loading || undefined, children: [rows.length === 0 && _jsx("p", { className: 'hig-swap-empty', role: 'status', children: loading ? (messages.loading ?? en.loading) + '…' : messages.swapNoTokens ?? en.swapNoTokens }), hotCount > 0 && _jsxs("p", { className: 'hig-swap-section', id: `${id}-hot`, children: [_jsx(SwapIcon, { name: 'flame', size: 14 }), messages.swapHot ?? en.swapHot] }), hotCount > 0 && _jsx("div", { role: 'list', "aria-labelledby": `${id}-hot`, children: rows.slice(0, hotCount).map((token, index) => row(token, index)) }), hotCount > 0 && _jsx("p", { className: 'hig-swap-section', id: `${id}-all`, children: messages.swapAllTokens ?? en.swapAllTokens }), rows.length > hotCount && _jsx("div", { role: 'list', ...(hotCount > 0 ? { 'aria-labelledby': `${id}-all` } : { 'aria-label': label }), children: rows.slice(hotCount).map((token, index) => row(token, index + hotCount)) })] })] });
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Where the assets come from. A connected wallet shows its address, with a disconnect button the host can leave out, above
|
|
59
|
+
* the tokens it holds (or a whitelist). With no wallet it offers Connect wallet and a Generate address switch above the list.
|
|
60
|
+
* The host owns the wallet, the token data and the generated address.
|
|
61
|
+
*/
|
|
62
|
+
export function FromPicker({ wallet, onConnect, onDisconnect, generateAddress = false, onGenerateAddressChange, className, ...list }) {
|
|
63
|
+
const { messages } = useHIG();
|
|
64
|
+
const id = useId();
|
|
65
|
+
const label = messages.swapFrom ?? en.swapFrom;
|
|
66
|
+
return _jsxs("div", { className: `hig-picker${className ? ` ${className}` : ''}`, role: 'group', "aria-label": label, children: [wallet?.connected
|
|
67
|
+
? _jsxs("div", { className: 'hig-swap-wallet', children: [_jsxs("span", { className: 'hig-swap-wallet-id', children: [_jsx("span", { className: 'hig-swap-avatar', "aria-hidden": 'true', style: { background: addressGradient(wallet.address ?? '') } }), _jsx("span", { children: wallet.address ? shortAddress(wallet.address) : '' }), _jsx(SwapIcon, { name: 'lock', size: 16 })] }), onDisconnect && _jsx(IconButton, { intent: 'secondary', label: messages.swapDisconnect ?? en.swapDisconnect, onClick: onDisconnect, children: _jsx(SwapIcon, { name: 'logout' }) })] })
|
|
68
|
+
: (onConnect || onGenerateAddressChange) && _jsxs("div", { className: 'hig-swap-wallet', children: [onConnect && _jsxs(Button, { onClick: onConnect, children: [_jsx(SwapIcon, { name: 'wallet' }), messages.swapConnectWallet ?? en.swapConnectWallet] }), onGenerateAddressChange && _jsxs("label", { className: 'hig-picker-toggle hig-choice hig-switch', htmlFor: id, children: [_jsx("span", { children: messages.swapGenerateAddress ?? en.swapGenerateAddress }), _jsx("input", { id: id, type: 'checkbox', role: 'switch', checked: generateAddress, onChange: event => onGenerateAddressChange(event.target.checked) })] })] }), _jsx(TokenList, { ...list, label: label })] });
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Where the assets go. On its own it is a destination address field with a scan button. With `tokens` it adds the
|
|
72
|
+
* searchable token list, with the chain filter or, with `chainFilter={false}`, without it.
|
|
73
|
+
*/
|
|
74
|
+
export function ToPicker({ address, onAddressChange, addressPlaceholder, onScan, className, tokens, onSelect, ...list }) {
|
|
75
|
+
const { messages } = useHIG();
|
|
76
|
+
const label = messages.swapTo ?? en.swapTo;
|
|
77
|
+
return _jsxs("div", { className: `hig-picker${className ? ` ${className}` : ''}`, role: 'group', "aria-label": label, children: [onAddressChange && _jsxs("div", { className: 'hig-swap-wallet', children: [_jsx(Input, { "aria-label": messages.swapRecipient ?? en.swapRecipient, placeholder: addressPlaceholder ?? messages.swapRecipient ?? en.swapRecipient, value: address ?? '', onChange: event => onAddressChange(event.target.value), autoComplete: 'off', autoCapitalize: 'none', autoCorrect: 'off', spellCheck: false }), onScan && _jsx(IconButton, { intent: 'secondary', label: messages.swapScan ?? en.swapScan, onClick: onScan, children: _jsx(SwapIcon, { name: 'scan' }) })] }), tokens && onSelect && _jsx(TokenList, { ...list, tokens: tokens, onSelect: onSelect, label: label })] });
|
|
78
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface SwapAmountCardProps {
|
|
3
|
+
/** Asset name, drawn in the slot. */
|
|
4
|
+
name: string;
|
|
5
|
+
/** Asset symbol; its first letters stand in when there is no `icon`. */
|
|
6
|
+
symbol: string;
|
|
7
|
+
/** Asset artwork: an image URL, or a node the host draws. */
|
|
8
|
+
icon?: string | React.ReactNode;
|
|
9
|
+
/** Chain or venue artwork, stacked above the asset. */
|
|
10
|
+
chainIcon?: string;
|
|
11
|
+
/** Line above the name: the chain, venue or account the amount comes from. */
|
|
12
|
+
context?: React.ReactNode;
|
|
13
|
+
/** Capsule actions on the trailing edge, such as Max. Use `SwapPill`. */
|
|
14
|
+
actions?: React.ReactNode;
|
|
15
|
+
/** Supporting line under the actions, such as the available balance. */
|
|
16
|
+
meta?: React.ReactNode;
|
|
17
|
+
/** The entered amount. */
|
|
18
|
+
value: number;
|
|
19
|
+
/** Accessible name of the amount. */
|
|
20
|
+
amountLabel: string;
|
|
21
|
+
/** Text before the amount, such as a currency sign. */
|
|
22
|
+
prefix?: string;
|
|
23
|
+
/** Text after the amount, such as a percent sign. */
|
|
24
|
+
suffix?: string;
|
|
25
|
+
/** Decimal places typed so far, so `1.50` keeps its zero. */
|
|
26
|
+
fractionDigits?: number;
|
|
27
|
+
/** Set while the entry ends with a decimal point that has no digits after it yet. */
|
|
28
|
+
trailingDot?: boolean;
|
|
29
|
+
/** Most decimal places the amount can show. */
|
|
30
|
+
maximumFractionDigits?: number;
|
|
31
|
+
/** Capsule under the amount, such as the converted value. Use `SwapPill`. */
|
|
32
|
+
conversion?: React.ReactNode;
|
|
33
|
+
/** Makes the slot a button that chooses the asset. Requires `selectLabel`. */
|
|
34
|
+
onSelect?: () => void;
|
|
35
|
+
selectLabel?: string;
|
|
36
|
+
className?: string;
|
|
37
|
+
style?: React.CSSProperties;
|
|
38
|
+
}
|
|
39
|
+
/** The swap panel's From card on its own: the asset with its actions and balance in the slot, the entered amount under it. The host owns the entry, the keypad and what the amount means. */
|
|
40
|
+
export declare function SwapAmountCard({ name, symbol, icon, chainIcon, context, actions, meta, value, amountLabel, prefix, suffix, fractionDigits, trailingDot, maximumFractionDigits, conversion, onSelect, selectLabel, className, style }: SwapAmountCardProps): React.JSX.Element;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { AnimatedNumberReadout } from '../../animated-number.js';
|
|
4
|
+
/** The swap panel's From card on its own: the asset with its actions and balance in the slot, the entered amount under it. The host owns the entry, the keypad and what the amount means. */
|
|
5
|
+
export function SwapAmountCard({ name, symbol, icon, chainIcon, context, actions, meta, value, amountLabel, prefix = '', suffix = '', fractionDigits = 0, trailingDot = false, maximumFractionDigits = 8, conversion, onSelect, selectLabel, className, style }) {
|
|
6
|
+
return _jsxs("div", { className: `hig-swap-card${className ? ` ${className}` : ''}`, style: style, "data-side": 'from', children: [_jsxs("div", { className: 'hig-swap-slot', children: [onSelect && _jsx("button", { type: 'button', className: 'hig-swap-hit', "aria-label": selectLabel, onClick: onSelect }), _jsx("div", { className: 'hig-swap-slot-content', children: _jsxs("div", { className: 'hig-swap-selected', children: [_jsxs("span", { className: 'hig-swap-stack', "aria-hidden": 'true', children: [chainIcon && _jsx("img", { src: chainIcon, alt: '' }), typeof icon === 'string' ? _jsx("img", { src: icon, alt: '' }) : icon ?? _jsx("span", { className: 'hig-swap-initials', children: symbol.slice(0, 3) })] }), _jsxs("span", { className: 'hig-swap-identity', children: [context != null && _jsx("span", { children: context }), _jsx("strong", { children: name })] }), (actions != null || meta != null) && _jsxs("span", { className: 'hig-swap-meta', children: [actions != null && _jsx("span", { className: 'hig-swap-pills', children: actions }), meta != null && _jsx("span", { className: 'hig-number', children: meta })] })] }) })] }), _jsx("div", { className: 'hig-swap-amount-area', children: _jsxs("div", { className: 'hig-swap-amount-content', children: [_jsx("div", { className: 'hig-swap-amount', role: 'textbox', tabIndex: 0, "aria-readonly": 'true', "aria-label": amountLabel, children: _jsx(AnimatedNumberReadout, { value: value, prefix: prefix, suffix: (trailingDot ? '.' : '') + suffix, options: { minimumFractionDigits: Math.min(fractionDigits, maximumFractionDigits), maximumFractionDigits, useGrouping: false } }) }), conversion] }) })] });
|
|
7
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type SwapWallet } from '../pickers.js';
|
|
3
|
+
import { type SwapChain, type SwapToken } from './shared.js';
|
|
4
|
+
export type { SwapWallet } from '../pickers.js';
|
|
5
|
+
export interface SwapPickerProps {
|
|
6
|
+
side: 'from' | 'to'; /** Pops the view. Choosing a token pops it too. */
|
|
7
|
+
onBack: () => void;
|
|
8
|
+
tokens: readonly SwapToken[];
|
|
9
|
+
chains: readonly SwapChain[];
|
|
10
|
+
hotTokenIds?: readonly string[];
|
|
11
|
+
selected: SwapToken | null;
|
|
12
|
+
onSelect: (token: SwapToken) => void;
|
|
13
|
+
loading?: boolean;
|
|
14
|
+
wallet?: SwapWallet;
|
|
15
|
+
onConnect?: () => void;
|
|
16
|
+
onDisconnect?: () => void;
|
|
17
|
+
/** From side, before a wallet is connected: the Generate address switch, which puts the panel in its receive view. */
|
|
18
|
+
receiving?: boolean;
|
|
19
|
+
onReceivingChange?: (receiving: boolean) => void;
|
|
20
|
+
/** To side: where the assets are sent. Omit `onRecipientChange` to hide the field. */
|
|
21
|
+
recipient?: string;
|
|
22
|
+
onRecipientChange?: (address: string) => void;
|
|
23
|
+
onScanRecipient?: () => void;
|
|
24
|
+
}
|
|
25
|
+
/** The panel's pushed picker view: a header with Back above the From or To picker recipe. */
|
|
26
|
+
export declare function SwapPicker({ side, onBack, selected, onSelect, wallet, onConnect, onDisconnect, receiving, onReceivingChange, recipient, onRecipientChange, onScanRecipient, ...list }: SwapPickerProps): React.JSX.Element;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef } from 'react';
|
|
4
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
5
|
+
import { useHIG } from '../../provider.js';
|
|
6
|
+
import { FromPicker, ToPicker } from '../pickers.js';
|
|
7
|
+
import { SwapViewHeader, shortAddress } from './shared.js';
|
|
8
|
+
/** The panel's pushed picker view: a header with Back above the From or To picker recipe. */
|
|
9
|
+
export function SwapPicker({ side, onBack, selected, onSelect, wallet, onConnect, onDisconnect, receiving, onReceivingChange, recipient, onRecipientChange, onScanRecipient, ...list }) {
|
|
10
|
+
const { messages } = useHIG();
|
|
11
|
+
const title = side === 'from' ? messages.swapFrom ?? en.swapFrom : messages.swapTo ?? en.swapTo;
|
|
12
|
+
// On touch the header takes focus, so no keyboard opens over the list; with a hardware pointer the picker focuses its search.
|
|
13
|
+
const heading = useRef(null);
|
|
14
|
+
useEffect(() => { if (!window.matchMedia?.('(pointer: fine)').matches)
|
|
15
|
+
heading.current?.focus(); }, []);
|
|
16
|
+
const choose = (token) => { onSelect(token); onBack(); };
|
|
17
|
+
return _jsxs("div", { className: 'hig-swap-picker', children: [_jsx(SwapViewHeader, { title: title, titleRef: heading, backLabel: messages.back ?? en.back, onBack: onBack }), side === 'from'
|
|
18
|
+
? _jsx(FromPicker, { ...list, autoFocus: true, selected: selected, onSelect: choose, wallet: wallet ?? { connected: false }, onConnect: onConnect, onDisconnect: onDisconnect, generateAddress: !!receiving, onGenerateAddressChange: onReceivingChange })
|
|
19
|
+
: _jsx(ToPicker, { ...list, autoFocus: true, selected: selected, onSelect: choose, address: recipient, onAddressChange: onRecipientChange, addressPlaceholder: wallet?.address ? shortAddress(wallet.address) : undefined, onScan: onScanRecipient })] });
|
|
20
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type SwapDenomination } from './shared.js';
|
|
3
|
+
export interface SwapFee {
|
|
4
|
+
label: string;
|
|
5
|
+
usd: number;
|
|
6
|
+
}
|
|
7
|
+
export declare const slippagePresets: readonly [0.001, 0.005, 0.01];
|
|
8
|
+
export type SwapSettingsView = 'settings' | 'slippage' | 'fees';
|
|
9
|
+
export interface SwapSettingsProps {
|
|
10
|
+
view: SwapSettingsView;
|
|
11
|
+
onViewChange: (view: SwapSettingsView) => void; /** Pops to the settings list from a sub-setting, or out of settings from the list. */
|
|
12
|
+
onBack: () => void;
|
|
13
|
+
denomination: SwapDenomination; /** Omit to hide the denomination setting. */
|
|
14
|
+
onDenominationChange?: (denomination: SwapDenomination) => void;
|
|
15
|
+
slippage: number;
|
|
16
|
+
onSlippageChange?: (slippage: number) => void;
|
|
17
|
+
fee?: number | null;
|
|
18
|
+
fees?: readonly SwapFee[];
|
|
19
|
+
quoteLoading?: boolean;
|
|
20
|
+
/** Host rows shown under the built-in settings, such as language or theme. */
|
|
21
|
+
children?: React.ReactNode;
|
|
22
|
+
}
|
|
23
|
+
/** The panel's settings as pushed views: the list, then slippage and the fee breakdown one level deeper. */
|
|
24
|
+
export declare function SwapSettings({ view, onViewChange, onBack, denomination, onDenominationChange, slippage, onSlippageChange, fee, fees, quoteLoading, children }: SwapSettingsProps): React.JSX.Element;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef, useState } from 'react';
|
|
4
|
+
import { formatNumber } from '@bloxwap/hig/contracts';
|
|
5
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
6
|
+
import { useHIG } from '../../provider.js';
|
|
7
|
+
import { Field, Input } from '../../field.js';
|
|
8
|
+
import { SegmentedControl } from '../../selection.js';
|
|
9
|
+
import { SwapIcon, SwapViewHeader, formatPercent } from './shared.js';
|
|
10
|
+
export const slippagePresets = [0.001, 0.005, 0.01];
|
|
11
|
+
/** The panel's settings as pushed views: the list, then slippage and the fee breakdown one level deeper. */
|
|
12
|
+
export function SwapSettings({ view, onViewChange, onBack, denomination, onDenominationChange, slippage, onSlippageChange, fee, fees, quoteLoading, children }) {
|
|
13
|
+
const { messages, locale } = useHIG();
|
|
14
|
+
const heading = useRef(null);
|
|
15
|
+
useEffect(() => { heading.current?.focus(); }, [view]);
|
|
16
|
+
const usd = (value) => formatNumber(value, locale, { style: 'currency', currency: 'USD' });
|
|
17
|
+
const [custom, setCustom] = useState(null);
|
|
18
|
+
const title = view === 'slippage' ? (messages.swapSlippageTitle ?? en.swapSlippageTitle) : view === 'fees' ? (messages.swapFees ?? en.swapFees) : (messages.swapSettings ?? en.swapSettings);
|
|
19
|
+
const feeText = quoteLoading ? '…' : fee != null ? usd(fee) : '—';
|
|
20
|
+
const preset = slippagePresets.find(value => Math.abs(value - slippage) < 1e-9);
|
|
21
|
+
const row = (label, value, target) => _jsxs("button", { type: 'button', className: 'hig-swap-setting', onClick: () => onViewChange(target), children: [_jsx("span", { children: label }), _jsxs("span", { className: 'hig-swap-setting-value', children: [value, _jsx(SwapIcon, { name: 'chevron', size: 16 })] })] });
|
|
22
|
+
const slippageRow = row(messages.swapSlippageTitle ?? en.swapSlippageTitle, formatPercent(slippage), 'slippage'), feesRow = row(messages.swapFees ?? en.swapFees, feeText, 'fees');
|
|
23
|
+
return _jsxs("div", { className: 'hig-swap-settings-view', role: 'group', "aria-label": title, children: [_jsx(SwapViewHeader, { title: title, titleRef: heading, backLabel: messages.back ?? en.back, onBack: onBack }), view === 'settings' && _jsxs("div", { className: 'hig-swap-settings', children: [onDenominationChange && _jsx(SegmentedControl, { label: (messages.swapDenomination ?? en.swapDenomination), options: [{ value: 'usd', label: (messages.swapDollars ?? en.swapDollars) }, { value: 'token', label: (messages.swapUnits ?? en.swapUnits) }], value: denomination, onValueChange: value => onDenominationChange(value) }), onSlippageChange && slippageRow, feesRow, children] }), view === 'slippage' && onSlippageChange && _jsxs("div", { className: 'hig-swap-settings hig-swap-presets', children: [_jsx(SegmentedControl, { label: (messages.swapSlippageTitle ?? en.swapSlippageTitle), options: slippagePresets.map(value => ({ value: String(value), label: formatPercent(value) })), value: preset === undefined ? '' : String(preset), onValueChange: value => { setCustom(null); onSlippageChange(Number(value)); } }), _jsx(Field, { label: (messages.swapSlippageCustom ?? en.swapSlippageCustom), children: _jsx(Input, { inputMode: 'decimal', value: custom ?? String(Number((slippage * 100).toFixed(4))), onChange: event => { const raw = event.target.value.replace(/[^0-9.]/g, ''); setCustom(raw); const percent = Number.parseFloat(raw); if (Number.isFinite(percent) && percent >= 0 && percent <= 50)
|
|
24
|
+
onSlippageChange(percent / 100); } }) })] }), view === 'fees' && _jsxs("dl", { className: 'hig-swap-fees', children: [fees?.map(item => _jsxs("div", { children: [_jsx("dt", { children: item.label }), _jsx("dd", { className: 'hig-number', children: usd(item.usd) })] }, item.label)), _jsxs("div", { className: 'hig-swap-fees-total', children: [_jsx("dt", { children: (messages.swapFeeTotal ?? en.swapFeeTotal) }), _jsx("dd", { className: 'hig-number', children: feeText })] })] })] });
|
|
25
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/** An asset on one chain. The host supplies every value; HIG formats and lays it out. */
|
|
3
|
+
export interface SwapToken {
|
|
4
|
+
/** Unique per asset and chain, for example `${chainId}-${address}`. */
|
|
5
|
+
id: string;
|
|
6
|
+
symbol: string;
|
|
7
|
+
name: string;
|
|
8
|
+
/** Chain display name and identity. Two tokens on the same `chainId` swap; different chains bridge. */
|
|
9
|
+
chain: string;
|
|
10
|
+
chainId: string | number;
|
|
11
|
+
/** Image URLs. A missing token icon falls back to the symbol's first letters. */
|
|
12
|
+
icon?: string;
|
|
13
|
+
chainIcon?: string;
|
|
14
|
+
/** Holdings in token units, when the host knows them. Enables Max, Test and the balance check. */
|
|
15
|
+
balance?: number | null;
|
|
16
|
+
/** USD per unit, when the host knows it. Enables the dollar and unit conversion. */
|
|
17
|
+
price?: number | null;
|
|
18
|
+
/** 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. */
|
|
19
|
+
caption?: string;
|
|
20
|
+
/** Extra text matched by the picker search, such as the contract address. */
|
|
21
|
+
keywords?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface SwapChain {
|
|
24
|
+
chainId: string | number;
|
|
25
|
+
name: string;
|
|
26
|
+
icon?: string;
|
|
27
|
+
}
|
|
28
|
+
/** Same asset: send. Different asset on one chain: swap. Different asset across chains: bridge. */
|
|
29
|
+
export type SwapAction = 'send' | 'swap' | 'bridge';
|
|
30
|
+
export type SwapDenomination = 'usd' | 'token';
|
|
31
|
+
export declare function swapAction(from: SwapToken | null, to: SwapToken | null): SwapAction;
|
|
32
|
+
/** A clean numeric string: no trailing zeros, at most `digits` decimals. */
|
|
33
|
+
export declare const trimNumber: (value: number, digits?: number) => string;
|
|
34
|
+
/** Keeps digits and one decimal point, and strips leading zeros; never returns an empty string. */
|
|
35
|
+
export declare function sanitizeAmount(raw: string): string;
|
|
36
|
+
/** Token units shown in the active denomination. Dollars floor to the cent so Max never resolves to more than the balance. */
|
|
37
|
+
export declare function unitsToEntry(units: number, mode: SwapDenomination, price: number): string;
|
|
38
|
+
/** Applies one keypad or keyboard key (`0`–`9`, `.`, `back`) to an amount string. Dollars stop at two decimals. */
|
|
39
|
+
export declare function applyAmountKey(current: string, key: string, mode: SwapDenomination): string;
|
|
40
|
+
/** Case-insensitive substring or in-order subsequence match. */
|
|
41
|
+
export declare function fuzzyMatch(query: string, text: string): boolean;
|
|
42
|
+
/** A slippage fraction as a percent string: 0.005 is `0.5%`. */
|
|
43
|
+
export declare const formatPercent: (fraction: number) => string;
|
|
44
|
+
/** A small trial amount: 1% of holdings, capped at about one dollar's worth. */
|
|
45
|
+
export declare function testAmount(token: SwapToken): number;
|
|
46
|
+
export declare const shortAddress: (address: string) => string;
|
|
47
|
+
/** A stable two-stop gradient for a wallet address, so the same wallet always looks the same. */
|
|
48
|
+
export declare function addressGradient(address: string): string;
|
|
49
|
+
declare const paths: {
|
|
50
|
+
flip: React.JSX.Element;
|
|
51
|
+
down: React.JSX.Element;
|
|
52
|
+
reset: React.JSX.Element;
|
|
53
|
+
menu: React.JSX.Element;
|
|
54
|
+
close: React.JSX.Element;
|
|
55
|
+
back: React.JSX.Element;
|
|
56
|
+
chevron: React.JSX.Element;
|
|
57
|
+
expand: React.JSX.Element;
|
|
58
|
+
delete: React.JSX.Element;
|
|
59
|
+
sliders: React.JSX.Element;
|
|
60
|
+
flask: React.JSX.Element;
|
|
61
|
+
scan: React.JSX.Element;
|
|
62
|
+
flame: React.JSX.Element;
|
|
63
|
+
logout: React.JSX.Element;
|
|
64
|
+
wallet: React.JSX.Element;
|
|
65
|
+
lock: React.JSX.Element;
|
|
66
|
+
};
|
|
67
|
+
export type SwapIconName = keyof typeof paths;
|
|
68
|
+
/** Outline symbol on a 20 unit grid; decorative, so the control that holds it carries the name. */
|
|
69
|
+
export declare function SwapIcon({ name, size }: {
|
|
70
|
+
name: SwapIconName;
|
|
71
|
+
size?: number;
|
|
72
|
+
}): React.JSX.Element;
|
|
73
|
+
/** Token artwork with its chain badge. */
|
|
74
|
+
export declare function TokenIcon({ token, size }: {
|
|
75
|
+
token: SwapToken;
|
|
76
|
+
size?: number;
|
|
77
|
+
}): React.JSX.Element;
|
|
78
|
+
/** Small capsule action that sits on a card: Max, Test, the slippage setting and the denomination switch. */
|
|
79
|
+
export declare function SwapPill({ children, ...props }: React.ButtonHTMLAttributes<HTMLButtonElement>): React.JSX.Element;
|
|
80
|
+
/** Numeric keypad. Emits `0`–`9`, `.` or `back`. */
|
|
81
|
+
export declare function SwapKeypad({ onKey, label, deleteLabel }: {
|
|
82
|
+
onKey: (key: string) => void;
|
|
83
|
+
label: string;
|
|
84
|
+
deleteLabel: string;
|
|
85
|
+
}): React.JSX.Element;
|
|
86
|
+
/** Chains present in a token list, in first-seen order. */
|
|
87
|
+
export declare function chainsOf(tokens: readonly SwapToken[]): SwapChain[];
|
|
88
|
+
export type SwapView = 'main' | 'from' | 'to' | 'settings' | 'slippage' | 'fees';
|
|
89
|
+
/** Where Back leads from a pushed view. */
|
|
90
|
+
export declare const parentView: (view: SwapView) => SwapView;
|
|
91
|
+
/** Header of a pushed view: Back on the leading edge, then the title, which takes focus when the view arrives. */
|
|
92
|
+
export declare function SwapViewHeader({ title, titleRef, backLabel, onBack }: {
|
|
93
|
+
title: string;
|
|
94
|
+
titleRef: React.Ref<HTMLHeadingElement>;
|
|
95
|
+
backLabel: string;
|
|
96
|
+
onBack: () => void;
|
|
97
|
+
}): React.JSX.Element;
|
|
98
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
export function swapAction(from, to) {
|
|
4
|
+
if (!from || !to || from.symbol === to.symbol)
|
|
5
|
+
return 'send';
|
|
6
|
+
return from.chainId === to.chainId ? 'swap' : 'bridge';
|
|
7
|
+
}
|
|
8
|
+
/** A clean numeric string: no trailing zeros, at most `digits` decimals. */
|
|
9
|
+
export const trimNumber = (value, digits = 8) => String(Number((Number.isFinite(value) ? value : 0).toFixed(digits)));
|
|
10
|
+
/** Keeps digits and one decimal point, and strips leading zeros; never returns an empty string. */
|
|
11
|
+
export function sanitizeAmount(raw) {
|
|
12
|
+
let value = raw.replace(/[^0-9.]/g, '');
|
|
13
|
+
const dot = value.indexOf('.');
|
|
14
|
+
if (dot !== -1)
|
|
15
|
+
value = value.slice(0, dot + 1) + value.slice(dot + 1).replace(/\./g, '');
|
|
16
|
+
value = value.replace(/^0+(\d)/, '$1');
|
|
17
|
+
return value === '' || value === '.' ? '0' : value;
|
|
18
|
+
}
|
|
19
|
+
/** Token units shown in the active denomination. Dollars floor to the cent so Max never resolves to more than the balance. */
|
|
20
|
+
export function unitsToEntry(units, mode, price) {
|
|
21
|
+
if (mode === 'token')
|
|
22
|
+
return trimNumber(units);
|
|
23
|
+
return price > 0 ? String(Math.floor(units * price * 100) / 100) : '0';
|
|
24
|
+
}
|
|
25
|
+
/** Applies one keypad or keyboard key (`0`–`9`, `.`, `back`) to an amount string. Dollars stop at two decimals. */
|
|
26
|
+
export function applyAmountKey(current, key, mode) {
|
|
27
|
+
if (key === 'back')
|
|
28
|
+
return current.length <= 1 ? '0' : current.slice(0, -1);
|
|
29
|
+
if (key === '.')
|
|
30
|
+
return current.includes('.') ? current : `${current}.`;
|
|
31
|
+
if (!/^[0-9]$/.test(key))
|
|
32
|
+
return current;
|
|
33
|
+
const next = sanitizeAmount(current === '0' ? key : current + key);
|
|
34
|
+
const dot = next.indexOf('.');
|
|
35
|
+
return mode === 'usd' && dot !== -1 && next.length - dot - 1 > 2 ? current : next;
|
|
36
|
+
}
|
|
37
|
+
/** Case-insensitive substring or in-order subsequence match. */
|
|
38
|
+
export function fuzzyMatch(query, text) {
|
|
39
|
+
const needle = query.toLowerCase().replace(/\s+/g, ''), haystack = text.toLowerCase();
|
|
40
|
+
if (haystack.includes(needle))
|
|
41
|
+
return true;
|
|
42
|
+
let matched = 0;
|
|
43
|
+
for (let index = 0; index < haystack.length && matched < needle.length; index++)
|
|
44
|
+
if (haystack[index] === needle[matched])
|
|
45
|
+
matched++;
|
|
46
|
+
return matched === needle.length;
|
|
47
|
+
}
|
|
48
|
+
/** A slippage fraction as a percent string: 0.005 is `0.5%`. */
|
|
49
|
+
export const formatPercent = (fraction) => `${Number((fraction * 100).toFixed(4))}%`;
|
|
50
|
+
/** A small trial amount: 1% of holdings, capped at about one dollar's worth. */
|
|
51
|
+
export function testAmount(token) {
|
|
52
|
+
const balance = token.balance ?? 0, price = token.price ?? 0;
|
|
53
|
+
if (!(balance > 0))
|
|
54
|
+
return 0;
|
|
55
|
+
return Number(Math.min(balance * 0.01, price > 0 ? 1 / price : balance * 0.01).toFixed(8));
|
|
56
|
+
}
|
|
57
|
+
export const shortAddress = (address) => address.length <= 12 ? address : `${address.slice(0, 6)}…${address.slice(-4)}`;
|
|
58
|
+
/** A stable two-stop gradient for a wallet address, so the same wallet always looks the same. */
|
|
59
|
+
export function addressGradient(address) {
|
|
60
|
+
let hash = 0;
|
|
61
|
+
for (const character of address)
|
|
62
|
+
hash = (hash * 31 + character.charCodeAt(0)) >>> 0;
|
|
63
|
+
return `linear-gradient(135deg,hsl(${hash % 360} 80% 62%),hsl(${(hash >>> 8) % 360} 75% 42%))`;
|
|
64
|
+
}
|
|
65
|
+
const stroke = { fill: 'none', stroke: 'currentColor', strokeWidth: 1.75, strokeLinecap: 'round', strokeLinejoin: 'round' };
|
|
66
|
+
const paths = {
|
|
67
|
+
flip: _jsx("path", { d: 'M6.5 3.5v13m0 0-3-3m3 3 3-3M13.5 16.5v-13m0 0-3 3m3-3 3 3' }),
|
|
68
|
+
down: _jsx("path", { d: 'M10 3.5v13m0 0-4.5-4.5M10 16.5l4.5-4.5' }),
|
|
69
|
+
reset: _jsx("path", { d: 'M4 10a6 6 0 1 0 2-4.5M4 4v3h3' }),
|
|
70
|
+
menu: _jsx("path", { d: 'M4 6h12M4 10h12M4 14h12' }),
|
|
71
|
+
close: _jsx("path", { d: 'm5.5 5.5 9 9m0-9-9 9' }),
|
|
72
|
+
back: _jsx("path", { d: 'm12 4.5-5.5 5.5 5.5 5.5' }),
|
|
73
|
+
chevron: _jsx("path", { d: 'm7.5 4.5 5.5 5.5-5.5 5.5' }),
|
|
74
|
+
expand: _jsx("path", { d: 'm5 7.5 5 5 5-5' }),
|
|
75
|
+
delete: _jsx("path", { d: 'M7.5 4.5h8a1.5 1.5 0 0 1 1.5 1.5v8a1.5 1.5 0 0 1-1.5 1.5h-8L2.5 10ZM10 8l4 4m0-4-4 4' }),
|
|
76
|
+
sliders: _jsx("path", { d: 'M4 6h6m4 0h2M4 14h2m4 0h6M12 4v4M8 12v4' }),
|
|
77
|
+
flask: _jsx("path", { d: 'M8 3.5h4M8.75 3.5v4.75L4.5 15.5a1 1 0 0 0 .9 1.5h9.2a1 1 0 0 0 .9-1.5l-4.25-7.25V3.5M6.5 12.5h7' }),
|
|
78
|
+
scan: _jsx("path", { d: 'M4 7V5a1 1 0 0 1 1-1h2M13 4h2a1 1 0 0 1 1 1v2M16 13v2a1 1 0 0 1-1 1h-2M7 16H5a1 1 0 0 1-1-1v-2M4 10h12' }),
|
|
79
|
+
flame: _jsx("path", { d: 'M10 17a5 5 0 0 0 5-5c0-3-2.5-4.5-3-8-2 1-3.5 3-3.5 5.5C7.5 8.5 7 7.5 7 7c-1.5 1.5-2 3-2 5a5 5 0 0 0 5 5Z' }),
|
|
80
|
+
logout: _jsx("path", { d: 'M8 4H5.5A1.5 1.5 0 0 0 4 5.5v9A1.5 1.5 0 0 0 5.5 16H8M12.5 6.5 16 10l-3.5 3.5M16 10H8' }),
|
|
81
|
+
wallet: _jsx("path", { d: 'M3.5 6.5A1.5 1.5 0 0 1 5 5h9.5A1.5 1.5 0 0 1 16 6.5v.75M3.5 6.5v7A1.5 1.5 0 0 0 5 15h10.5a1 1 0 0 0 1-1V8.25a1 1 0 0 0-1-1H5a1.5 1.5 0 0 1-1.5-.75M13.25 11.25v.01' }),
|
|
82
|
+
lock: _jsx("path", { d: 'M5.5 9h9a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1h-9a1 1 0 0 1-1-1v-5a1 1 0 0 1 1-1ZM7 9V6.5a3 3 0 0 1 6 0V9' }),
|
|
83
|
+
};
|
|
84
|
+
/** Outline symbol on a 20 unit grid; decorative, so the control that holds it carries the name. */
|
|
85
|
+
export function SwapIcon({ name, size = 20 }) { return _jsx("svg", { className: 'hig-swap-icon', "aria-hidden": 'true', focusable: 'false', width: size, height: size, viewBox: '0 0 20 20', ...stroke, children: paths[name] }); }
|
|
86
|
+
/** Token artwork with its chain badge. */
|
|
87
|
+
export function TokenIcon({ token, size = 44 }) {
|
|
88
|
+
return _jsxs("span", { className: 'hig-swap-token-icon', style: { width: size, height: size }, children: [token.icon ? _jsx("img", { src: token.icon, alt: '', loading: 'lazy' }) : _jsx("span", { "aria-hidden": 'true', children: token.symbol.slice(0, 3) }), token.chainIcon && _jsx("img", { className: 'hig-swap-chain-badge', src: token.chainIcon, alt: '', loading: 'lazy' })] });
|
|
89
|
+
}
|
|
90
|
+
/** Small capsule action that sits on a card: Max, Test, the slippage setting and the denomination switch. */
|
|
91
|
+
export function SwapPill({ children, ...props }) { return _jsx("button", { type: 'button', ...props, className: 'hig-swap-pill', children: children }); }
|
|
92
|
+
const keys = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '0', 'back'];
|
|
93
|
+
/** Numeric keypad. Emits `0`–`9`, `.` or `back`. */
|
|
94
|
+
export function SwapKeypad({ onKey, label, deleteLabel }) {
|
|
95
|
+
return _jsx("div", { className: 'hig-swap-keypad', role: 'group', "aria-label": label, children: keys.map(key => _jsx("button", { type: 'button', className: 'hig-swap-key', "aria-label": key === 'back' ? deleteLabel : undefined, onClick: () => onKey(key), children: key === 'back' ? _jsx(SwapIcon, { name: 'delete', size: 24 }) : key }, key)) });
|
|
96
|
+
}
|
|
97
|
+
/** Chains present in a token list, in first-seen order. */
|
|
98
|
+
export function chainsOf(tokens) { const seen = new Map(); for (const token of tokens)
|
|
99
|
+
if (!seen.has(token.chainId))
|
|
100
|
+
seen.set(token.chainId, { chainId: token.chainId, name: token.chain, icon: token.chainIcon }); return [...seen.values()]; }
|
|
101
|
+
/** Where Back leads from a pushed view. */
|
|
102
|
+
export const parentView = (view) => view === 'slippage' || view === 'fees' ? 'settings' : 'main';
|
|
103
|
+
/** Header of a pushed view: Back on the leading edge, then the title, which takes focus when the view arrives. */
|
|
104
|
+
export function SwapViewHeader({ title, titleRef, backLabel, onBack }) {
|
|
105
|
+
return _jsxs("div", { className: 'hig-swap-view-header', children: [_jsx("button", { type: 'button', className: 'hig-swap-back', "aria-label": backLabel, onClick: onBack, children: _jsx(SwapIcon, { name: 'back' }) }), _jsx("h2", { ref: titleRef, tabIndex: -1, className: 'hig-swap-view-title', children: title })] });
|
|
106
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type SwapWallet } from './swap/picker.js';
|
|
3
|
+
import { type SwapFee } from './swap/settings.js';
|
|
4
|
+
import { type SwapAction, type SwapChain, type SwapDenomination, type SwapToken, type SwapView } from './swap/shared.js';
|
|
5
|
+
export { swapAction, type SwapAction, type SwapChain, type SwapDenomination, type SwapToken, type SwapView } from './swap/shared.js';
|
|
6
|
+
export type { SwapWallet } from './swap/picker.js';
|
|
7
|
+
export type { SwapFee } from './swap/settings.js';
|
|
8
|
+
export { SwapAmountCard, type SwapAmountCardProps } from './swap/amount-card.js';
|
|
9
|
+
export { SwapPill, SwapKeypad } from './swap/shared.js';
|
|
10
|
+
/** A fixed place the assets go, in place of a token the user picks: a wallet, a staking pool, a trading account. Shown as a compact To card with no amount. */
|
|
11
|
+
export interface SwapDestination {
|
|
12
|
+
title: string;
|
|
13
|
+
/** One muted line above the title, such as the chain or a rate. */
|
|
14
|
+
subtitle?: string;
|
|
15
|
+
/** Image URL. Without one, `address` draws the wallet's colour disc. */
|
|
16
|
+
icon?: string;
|
|
17
|
+
/** A wallet address; shown shortened under the subtitle. */
|
|
18
|
+
address?: string;
|
|
19
|
+
/** Muted trailing text, such as an arrival time or a rate. */
|
|
20
|
+
detail?: string;
|
|
21
|
+
/** Makes the card a button with a trailing chevron, for example to change the recipient. */
|
|
22
|
+
onPress?: () => void;
|
|
23
|
+
/** Still to be chosen: the card shows `title` / `subtitle` as a placeholder and the action stays disabled, asking for a destination. */
|
|
24
|
+
pending?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/** One label and value row of the details card. */
|
|
27
|
+
export interface SwapDetail {
|
|
28
|
+
label: string;
|
|
29
|
+
value: string;
|
|
30
|
+
}
|
|
31
|
+
/** The receive view: the host's address and its rendered QR code. HIG ships no QR encoder. */
|
|
32
|
+
export interface SwapReceive {
|
|
33
|
+
address: string;
|
|
34
|
+
qr?: React.ReactNode; /** Host clipboard adapter. When set, the whole view copies the address. */
|
|
35
|
+
onCopy?: () => Promise<void> | void;
|
|
36
|
+
}
|
|
37
|
+
export interface SwapPanelProps {
|
|
38
|
+
/** Catalog for the To side, and for the From side unless `fromTokens` is given. */
|
|
39
|
+
tokens: readonly SwapToken[];
|
|
40
|
+
/** Assets offered on the From side, typically the connected wallet's holdings. */
|
|
41
|
+
fromTokens?: readonly SwapToken[];
|
|
42
|
+
fromTokensLoading?: boolean;
|
|
43
|
+
/** Chain filter chips. Derived from the tokens, in first-seen order, when omitted. */
|
|
44
|
+
chains?: readonly SwapChain[];
|
|
45
|
+
/** Token ids for the picker's Hot section, in rank order. */
|
|
46
|
+
hotTokenIds?: readonly string[];
|
|
47
|
+
/** The chosen pair. Controlled when `from` / `to` is set (`null` is an empty side); otherwise the panel keeps it, seeded from the defaults. */
|
|
48
|
+
from?: SwapToken | null;
|
|
49
|
+
to?: SwapToken | null;
|
|
50
|
+
defaultFrom?: SwapToken | null;
|
|
51
|
+
defaultTo?: SwapToken | null;
|
|
52
|
+
onFromChange?: (token: SwapToken | null) => void;
|
|
53
|
+
onToChange?: (token: SwapToken | null) => void;
|
|
54
|
+
/** From amount in token units. Optional: set it to resync the entry, for example to `'0'` after a submit. */
|
|
55
|
+
amount?: string;
|
|
56
|
+
/** Reports the From amount in token units whenever the entry, denomination or price changes it. */
|
|
57
|
+
onAmountChange?: (units: string) => void;
|
|
58
|
+
/** To amount in token units from the host's quote. Until it arrives the panel shows a price estimate. */
|
|
59
|
+
received?: number | null;
|
|
60
|
+
/** Total fee in USD from the host's quote, and its breakdown for the settings sheet. */
|
|
61
|
+
fee?: number | null;
|
|
62
|
+
fees?: readonly SwapFee[];
|
|
63
|
+
quoteLoading?: boolean;
|
|
64
|
+
/** Slippage tolerance as a fraction (0.005 is 0.5%). Omit `onSlippageChange` to show it read-only. */
|
|
65
|
+
slippage?: number;
|
|
66
|
+
onSlippageChange?: (slippage: number) => void;
|
|
67
|
+
/** Default denomination of both amounts. Uncontrolled when omitted. */
|
|
68
|
+
denomination?: SwapDenomination;
|
|
69
|
+
onDenominationChange?: (denomination: SwapDenomination) => void;
|
|
70
|
+
wallet?: SwapWallet;
|
|
71
|
+
onConnect?: () => void;
|
|
72
|
+
onDisconnect?: () => void;
|
|
73
|
+
recipient?: string;
|
|
74
|
+
onRecipientChange?: (address: string) => void;
|
|
75
|
+
onScanRecipient?: () => void;
|
|
76
|
+
/** Enables the receive view, offered in the From picker before a wallet is connected. */
|
|
77
|
+
receive?: SwapReceive;
|
|
78
|
+
receiving?: boolean;
|
|
79
|
+
onReceivingChange?: (receiving: boolean) => void;
|
|
80
|
+
/** The host validates, quotes and executes. HIG never submits a transaction. */
|
|
81
|
+
onSubmit: (action: SwapAction) => void;
|
|
82
|
+
submitting?: boolean;
|
|
83
|
+
/** Called after the panel clears its entry and both tokens (through `onFromChange(null)` / `onToChange(null)`), so the host can drop its quote. */
|
|
84
|
+
onReset?: () => void;
|
|
85
|
+
/** `false` fixes both amounts to `denomination` (dollars by default): the conversion capsule under each amount and the denomination setting are not shown. For hosts that only have one of the two, for example no token price. */
|
|
86
|
+
denominationSwitch?: boolean;
|
|
87
|
+
/** A fixed destination in place of the To token. The To card becomes compact (no picker, no amount), the panel is one-way, and the action is ready once the From side is. `onSubmit` receives `'send'`. */
|
|
88
|
+
destination?: SwapDestination;
|
|
89
|
+
/** Label and value rows on the bottom card, such as a staked balance or a fee tier. With no To token and no destination they are the bottom card on their own, and the panel behaves as it does for a destination. */
|
|
90
|
+
details?: readonly SwapDetail[];
|
|
91
|
+
/** A line under the cards: a limit, a delay, a warning. `noteTone` tints it. */
|
|
92
|
+
note?: React.ReactNode;
|
|
93
|
+
noteTone?: 'muted' | 'warning' | 'negative';
|
|
94
|
+
/** Heading above the cards, for a panel that is its own screen or sheet (“Withdraw from Papertrade”). `onBack` adds a Back control beside it. */
|
|
95
|
+
title?: string;
|
|
96
|
+
onBack?: () => void;
|
|
97
|
+
/** `false` leaves the action button on its own, full width: no settings and no reset button. */
|
|
98
|
+
controls?: boolean;
|
|
99
|
+
/** Decoration before the action text. */
|
|
100
|
+
actionIcon?: React.ReactNode;
|
|
101
|
+
/** Keep a side's token fixed: its card shows the token but does not open the picker. Use with `from` / `to` or their defaults. */
|
|
102
|
+
lockFrom?: boolean;
|
|
103
|
+
lockTo?: boolean;
|
|
104
|
+
/** Names the action when it is ready, in place of Send, Swap or Bridge: for example Stake, Deposit or Withdraw. The host supplies the translated text. */
|
|
105
|
+
actionLabel?: string;
|
|
106
|
+
/** One direction only, top to bottom: the control between the cards becomes a down arrow instead of the flip button, and the pair cannot be exchanged. */
|
|
107
|
+
oneWay?: boolean;
|
|
108
|
+
/** `auto` shows the keypad for a coarse pointer (touch), where there is no hardware keyboard. */
|
|
109
|
+
keypad?: 'auto' | 'always' | 'never';
|
|
110
|
+
/** ⌘F / Ctrl+F opens the From picker and ⌘K / Ctrl+K the To picker while the panel is mounted. */
|
|
111
|
+
shortcuts?: boolean;
|
|
112
|
+
/** Digits typed anywhere on the page (outside a text field) drive the amount, not only inside the panel. */
|
|
113
|
+
captureKeyboard?: boolean;
|
|
114
|
+
/** The view on show. The panel pushes its token pickers and settings as views inside its own bounds; `main` is the cards. Uncontrolled when omitted. */
|
|
115
|
+
view?: SwapView;
|
|
116
|
+
onViewChange?: (view: SwapView) => void;
|
|
117
|
+
/** Host rows for the settings view, such as language or theme. */
|
|
118
|
+
settings?: React.ReactNode;
|
|
119
|
+
className?: string;
|
|
120
|
+
style?: React.CSSProperties;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Send, swap and bridge in one panel: a From card and a To card joined by a flip control, an amount entered in dollars
|
|
124
|
+
* or token units, token pickers, settings, and one action that names itself from the chosen pair.
|
|
125
|
+
* Presentation only. The host owns tokens, balances, prices, the quote, the wallet and the transaction.
|
|
126
|
+
*/
|
|
127
|
+
export declare function SwapPanel({ tokens, fromTokens, fromTokensLoading, chains, hotTokenIds, from: fromProp, to: toProp, defaultFrom, defaultTo, onFromChange, onToChange, amount, onAmountChange, received, fee, fees, quoteLoading, slippage, onSlippageChange, denomination, onDenominationChange, wallet, onConnect, onDisconnect, recipient, onRecipientChange, onScanRecipient, receive, receiving, onReceivingChange, onSubmit, submitting, onReset, destination, details, note, noteTone, title, onBack, controls, actionIcon, lockFrom, lockTo, actionLabel, oneWay: oneWayProp, denominationSwitch, keypad, shortcuts, captureKeyboard, view: viewProp, onViewChange, settings, className, style }: SwapPanelProps): React.JSX.Element;
|