@bloxwap/hig 0.2.0 → 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.
Files changed (119) hide show
  1. package/README.md +1 -1
  2. package/chart/README.md +3 -3
  3. package/contracts/README.md +1 -1
  4. package/contracts/dist/messages.d.ts +138 -0
  5. package/contracts/dist/messages.js +48 -2
  6. package/css.d.ts +2 -0
  7. package/feedback/README.md +1 -1
  8. package/feedback/assets/error.wav +0 -0
  9. package/feedback/assets/manifest.json +29 -19
  10. package/feedback/assets/tick.wav +0 -0
  11. package/feedback/assets/toggle.wav +0 -0
  12. package/feedback/dist/contract.d.ts +1 -57
  13. package/feedback/dist/contract.js +2 -1
  14. package/feedback/dist/native.d.ts +2 -1
  15. package/feedback/dist/presets.d.ts +57 -0
  16. package/feedback/dist/presets.js +1 -0
  17. package/native/README.md +6 -1
  18. package/native/dist/animated-number.js +11 -7
  19. package/native/dist/brand.d.ts +1 -1
  20. package/native/dist/brand.js +4 -3
  21. package/native/dist/button.d.ts +3 -2
  22. package/native/dist/button.js +8 -6
  23. package/native/dist/data.d.ts +18 -1
  24. package/native/dist/data.js +22 -2
  25. package/native/dist/field.d.ts +1 -0
  26. package/native/dist/field.js +18 -5
  27. package/native/dist/gesture-sheet.js +5 -3
  28. package/native/dist/icons.d.ts +21 -0
  29. package/native/dist/icons.js +20 -0
  30. package/native/dist/navigation.d.ts +1 -0
  31. package/native/dist/navigation.js +49 -7
  32. package/native/dist/overlay.js +3 -3
  33. package/native/dist/pickers.d.ts +54 -0
  34. package/native/dist/pickers.js +60 -0
  35. package/native/dist/provider.d.ts +25 -6
  36. package/native/dist/provider.js +19 -4
  37. package/native/dist/radio-group.d.ts +17 -1
  38. package/native/dist/radio-group.js +45 -7
  39. package/native/dist/recipes.d.ts +3 -0
  40. package/native/dist/recipes.js +15 -2
  41. package/native/dist/selection.d.ts +1 -0
  42. package/native/dist/selection.js +1 -0
  43. package/native/dist/slider.js +3 -2
  44. package/native/dist/status.d.ts +16 -5
  45. package/native/dist/status.js +55 -15
  46. package/native/dist/surface.d.ts +2 -1
  47. package/native/dist/surface.js +4 -3
  48. package/native/dist/swap-panel.d.ts +125 -0
  49. package/native/dist/swap-panel.js +177 -0
  50. package/native/dist/swap-parts.d.ts +86 -0
  51. package/native/dist/swap-parts.js +66 -0
  52. package/native/dist/swap-shared.d.ts +65 -0
  53. package/native/dist/swap-shared.js +76 -0
  54. package/native/dist/swap-sheet.d.ts +14 -0
  55. package/native/dist/swap-sheet.js +26 -0
  56. package/native/dist/swap-views.d.ts +41 -0
  57. package/native/dist/swap-views.js +37 -0
  58. package/native/dist/switch.d.ts +1 -1
  59. package/native/dist/switch.js +20 -13
  60. package/native/dist/wallet-address.d.ts +37 -0
  61. package/native/dist/wallet-address.js +50 -0
  62. package/native-fonts/README.md +1 -1
  63. package/native-fonts/dist/index.d.ts +1 -1
  64. package/native-fonts/dist/index.js +1 -1
  65. package/native-fonts/fonts/manifest.json +1 -1
  66. package/og-fonts/README.md +2 -2
  67. package/og-fonts/dist/index.d.ts +1 -1
  68. package/og-fonts/dist/index.js +1 -1
  69. package/og-fonts/fonts/manifest.json +1 -1
  70. package/package.json +181 -63
  71. package/react/README.md +22 -1
  72. package/react/dist/animated-number.js +2 -1
  73. package/react/dist/brand.d.ts +1 -1
  74. package/react/dist/brand.js +3 -2
  75. package/react/dist/button.d.ts +2 -2
  76. package/react/dist/button.js +1 -1
  77. package/react/dist/data.d.ts +15 -0
  78. package/react/dist/data.js +13 -0
  79. package/react/dist/field.d.ts +1 -0
  80. package/react/dist/field.js +2 -1
  81. package/react/dist/navigation.js +1 -1
  82. package/react/dist/notify.d.ts +14 -0
  83. package/react/dist/notify.js +6 -0
  84. package/react/dist/recipes/install-command.d.ts +1 -0
  85. package/react/dist/recipes/install-command.js +8 -1
  86. package/react/dist/recipes/pickers.d.ts +57 -0
  87. package/react/dist/recipes/pickers.js +78 -0
  88. package/react/dist/recipes/swap/amount-card.d.ts +40 -0
  89. package/react/dist/recipes/swap/amount-card.js +7 -0
  90. package/react/dist/recipes/swap/picker.d.ts +26 -0
  91. package/react/dist/recipes/swap/picker.js +20 -0
  92. package/react/dist/recipes/swap/settings.d.ts +24 -0
  93. package/react/dist/recipes/swap/settings.js +25 -0
  94. package/react/dist/recipes/swap/shared.d.ts +98 -0
  95. package/react/dist/recipes/swap/shared.js +106 -0
  96. package/react/dist/recipes/swap-panel.d.ts +127 -0
  97. package/react/dist/recipes/swap-panel.js +170 -0
  98. package/react/dist/recipes/swap-sheet.d.ts +16 -0
  99. package/react/dist/recipes/swap-sheet.js +22 -0
  100. package/react/dist/recipes/trade-entry.js +1 -1
  101. package/react/dist/recipes.d.ts +3 -1
  102. package/react/dist/recipes.js +3 -1
  103. package/react/dist/select.js +2 -0
  104. package/react/dist/selection.d.ts +13 -0
  105. package/react/dist/selection.js +7 -0
  106. package/react/dist/status.d.ts +15 -5
  107. package/react/dist/status.js +8 -4
  108. package/react/dist/styles.css +406 -92
  109. package/react/dist/toast.d.ts +17 -0
  110. package/react/dist/toast.js +21 -0
  111. package/react/dist/wallet-address.d.ts +23 -0
  112. package/react/dist/wallet-address.js +24 -0
  113. package/tokens/README.md +9 -1
  114. package/tokens/dist/brand.d.ts +19 -0
  115. package/tokens/dist/brand.js +24 -0
  116. package/tokens/dist/index.d.ts +9 -1
  117. package/tokens/dist/index.js +8 -1
  118. package/tokens/dist/manifest.json +4 -1
  119. package/tokens/dist/tokens.css +1 -0
@@ -62,7 +62,7 @@ export function Tabs({ label, items, value, defaultValue, onValueChange }) {
62
62
  document.getElementById(`${id}-tab-${enabled[next].value}`)?.focus();
63
63
  } }, children: items.map(item => _jsx("button", { type: 'button', className: 'hig-button hig-tab', role: 'tab', id: `${id}-tab-${item.value}`, "aria-controls": `${id}-panel-${item.value}`, "aria-selected": current === item.value, tabIndex: tabStop === item.value ? 0 : -1, disabled: item.disabled, onClick: () => set(item.value), children: item.label }, item.value)) }), items.map(item => _jsx("div", { ref: current === item.value ? panel : undefined, hidden: current !== item.value, className: 'hig-tab-panel', role: 'tabpanel', id: `${id}-panel-${item.value}`, "aria-labelledby": `${id}-tab-${item.value}`, tabIndex: 0, children: item.content }, item.value))] });
64
64
  }
65
- export function Accordion({ title, children, open, onOpenChange }) { return _jsxs("details", { open: open, className: 'hig-surface hig-accordion', onToggle: e => onOpenChange?.(e.currentTarget.open), children: [_jsx("summary", { className: 'hig-accordion-summary', children: title }), children] }); }
65
+ export function Accordion({ title, children, open, onOpenChange }) { return _jsxs("details", { open: open, className: 'hig-surface hig-accordion', onToggle: e => onOpenChange?.(e.currentTarget.open), children: [_jsxs("summary", { className: 'hig-accordion-summary', children: [_jsx("span", { children: title }), _jsx("svg", { className: 'hig-accordion-chevron', "aria-hidden": 'true', focusable: 'false', viewBox: '0 0 20 20', children: _jsx("path", { d: 'm5 7.5 5 5 5-5' }) })] }), children] }); }
66
66
  export function Breadcrumb({ items }) { const { messages } = useHIG(); return _jsx("nav", { "aria-label": messages.breadcrumb ?? en.breadcrumb, children: _jsx("ol", { role: 'list', className: 'hig-inline hig-breadcrumb', children: items.map((item, i) => _jsxs("li", { children: [i > 0 && _jsx("span", { "aria-hidden": 'true', className: 'hig-breadcrumb-separator', children: "/" }), item.href ? _jsx(Link, { href: item.href, "aria-current": i === items.length - 1 ? 'page' : undefined, children: item.label }) : _jsx("span", { "aria-current": i === items.length - 1 ? 'page' : undefined, children: item.label })] }, i)) }) }); }
67
67
  export function Navigation({ label, items }) { return _jsx("nav", { "aria-label": label, className: 'hig-stack hig-navigation', children: items.map(item => _jsx(Link, { href: item.href, "aria-current": item.active ? 'page' : undefined, children: item.label }, item.href)) }); }
68
68
  export function Pagination({ page, total, onPageChange }) { const { locale, messages } = useHIG(); return _jsxs("nav", { "aria-label": messages.pagination ?? en.pagination, className: 'hig-inline hig-pagination', children: [_jsx(Button, { intent: 'secondary', disabled: page <= 1, onClick: () => onPageChange(page - 1), children: messages.previous ?? en.previous }), _jsx("span", { children: (messages.pageOf ?? en.pageOf)(formatNumber(page, locale), formatNumber(total, locale)) }), _jsx(Button, { intent: 'secondary', disabled: page >= total, onClick: () => onPageChange(page + 1), children: messages.next ?? en.next })] }); }
@@ -0,0 +1,14 @@
1
+ /** Where transient notices go. `Toaster` from `@bloxwap/hig/react/toast` registers itself here on mount, so components
2
+ * can raise a toast without importing the optional Sonner backend. */
3
+ export interface NotifyOptions {
4
+ severity?: 'info' | 'success' | 'warning' | 'error'; /** Accessible name of the notice's close button. */
5
+ dismissName?: string;
6
+ duration?: number;
7
+ id?: string | number;
8
+ }
9
+ type Notifier = (message: string, options?: NotifyOptions) => unknown;
10
+ /** Registers a notifier; returns its unregister function. */
11
+ export declare function registerNotifier(notifier: Notifier): () => void;
12
+ /** Raises a notice on the most recently mounted notifier. Returns false when none is mounted, so the caller can show the result inline. */
13
+ export declare function notify(message: string, options?: NotifyOptions): boolean;
14
+ export {};
@@ -0,0 +1,6 @@
1
+ const notifiers = new Set();
2
+ /** Registers a notifier; returns its unregister function. */
3
+ export function registerNotifier(notifier) { notifiers.add(notifier); return () => { notifiers.delete(notifier); }; }
4
+ /** Raises a notice on the most recently mounted notifier. Returns false when none is mounted, so the caller can show the result inline. */
5
+ export function notify(message, options) { const notifier = [...notifiers].pop(); if (!notifier)
6
+ return false; notifier(message, options); return true; }
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ /** With a mounted `Toaster` (`@bloxwap/hig/react/toast`) the copy result is raised as a toast; without one it shows inline. Either way it is announced. This entry does not load Sonner. */
2
3
  export declare function InstallCommand({ command, onCopy }: {
3
4
  command: string;
4
5
  onCopy: () => Promise<void> | void;
@@ -5,4 +5,11 @@ import * as en from '@bloxwap/hig/contracts/messages';
5
5
  import { useHIG } from '../provider.js';
6
6
  import { Button } from '../button.js';
7
7
  import { Surface } from '../surface.js';
8
- export function InstallCommand({ command, onCopy }) { const { messages } = useHIG(); const [status, setStatus] = useState(''); return _jsxs(Surface, { children: [_jsx("pre", { className: 'hig-code', tabIndex: 0, children: _jsx("code", { children: command }) }), _jsx(Button, { intent: 'secondary', onClick: () => { Promise.resolve().then(onCopy).then(() => setStatus(messages.copied ?? en.copied)).catch(() => setStatus(messages.copyFailed ?? en.copyFailed)); }, children: messages.copyInstallCommand ?? en.copyInstallCommand }), _jsx("p", { role: 'status', children: status })] }); }
8
+ import { notify } from '../notify.js';
9
+ /** With a mounted `Toaster` (`@bloxwap/hig/react/toast`) the copy result is raised as a toast; without one it shows inline. Either way it is announced. This entry does not load Sonner. */
10
+ export function InstallCommand({ command, onCopy }) {
11
+ const { messages } = useHIG();
12
+ const [status, setStatus] = useState({ text: '', toasted: false });
13
+ const report = (text, severity) => setStatus({ text, toasted: notify(text, { severity, id: 'hig-install-command', dismissName: (messages.dismissNotice ?? en.dismissNotice)(text, messages.dismiss ?? en.dismiss) }) });
14
+ return _jsxs(Surface, { children: [_jsx("pre", { className: 'hig-code', tabIndex: 0, children: _jsx("code", { children: command }) }), _jsx(Button, { intent: 'secondary', onClick: () => { Promise.resolve().then(onCopy).then(() => report(messages.copied ?? en.copied, 'success')).catch(() => report(messages.copyFailed ?? en.copyFailed, 'error')); }, children: messages.copyInstallCommand ?? en.copyInstallCommand }), _jsx("p", { role: 'status', className: status.toasted ? 'hig-sr-only' : undefined, children: status.text })] });
15
+ }
@@ -0,0 +1,57 @@
1
+ import React from 'react';
2
+ import { type SwapChain, type SwapToken } from './swap/shared.js';
3
+ export type { SwapChain, SwapToken } from './swap/shared.js';
4
+ export interface SwapWallet {
5
+ connected: boolean;
6
+ address?: string | null;
7
+ }
8
+ /** The searchable token list both pickers share. */
9
+ export interface PickerListProps {
10
+ /** Tokens offered: a wallet's holdings, a whitelist, or a whole catalog. */
11
+ tokens: readonly SwapToken[];
12
+ /** Chain filter options. Derived from the tokens, in first-seen order, when omitted. */
13
+ chains?: readonly SwapChain[];
14
+ /** `false` leaves out the chain filter, for a list on one chain or one that should not be narrowed by chain. */
15
+ chainFilter?: boolean;
16
+ /** Token ids for a Hot section at the top of the unfiltered list, in rank order. */
17
+ hotTokenIds?: readonly string[];
18
+ selected?: SwapToken | null;
19
+ onSelect: (token: SwapToken) => void;
20
+ /** Shows the loading text in place of the empty text while the list is empty. */
21
+ loading?: boolean;
22
+ /** With a hardware pointer, focus the search field on mount so typing filters at once. */
23
+ autoFocus?: boolean;
24
+ }
25
+ export interface FromPickerProps extends PickerListProps {
26
+ /** The connected wallet. Omit for a list with no wallet row at all. */
27
+ wallet?: SwapWallet;
28
+ /** Shows Connect wallet while no wallet is connected. */
29
+ onConnect?: () => void;
30
+ /** Shows the disconnect button beside a connected wallet. Omit it where signing out does not belong. */
31
+ onDisconnect?: () => void;
32
+ /** The Generate address switch, offered while no wallet is connected: the user picks a chain and an asset and the host shows an address to send it to. Omit `onGenerateAddressChange` to hide it. */
33
+ generateAddress?: boolean;
34
+ onGenerateAddressChange?: (generate: boolean) => void;
35
+ className?: string;
36
+ }
37
+ /**
38
+ * Where the assets come from. A connected wallet shows its address, with a disconnect button the host can leave out, above
39
+ * the tokens it holds (or a whitelist). With no wallet it offers Connect wallet and a Generate address switch above the list.
40
+ * The host owns the wallet, the token data and the generated address.
41
+ */
42
+ export declare function FromPicker({ wallet, onConnect, onDisconnect, generateAddress, onGenerateAddressChange, className, ...list }: FromPickerProps): React.JSX.Element;
43
+ export interface ToPickerProps extends Partial<PickerListProps> {
44
+ /** The destination address field. Omit `onAddressChange` to hide it. */
45
+ address?: string;
46
+ onAddressChange?: (address: string) => void;
47
+ /** Shown while the field is empty, for example the connected wallet shortened; defaults to the built-in label. */
48
+ addressPlaceholder?: string;
49
+ /** Shows the scan button. HIG ships no scanner: the host opens its own and writes the result to `address`. */
50
+ onScan?: () => void;
51
+ className?: string;
52
+ }
53
+ /**
54
+ * Where the assets go. On its own it is a destination address field with a scan button. With `tokens` it adds the
55
+ * searchable token list, with the chain filter or, with `chainFilter={false}`, without it.
56
+ */
57
+ export declare function ToPicker({ address, onAddressChange, addressPlaceholder, onScan, className, tokens, onSelect, ...list }: ToPickerProps): React.JSX.Element;
@@ -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
+ }