@bloxwap/hig 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (272) hide show
  1. package/README.md +2 -2
  2. package/chart/README.md +13 -2
  3. package/chart/dist/altimeter-burst.d.ts +4 -0
  4. package/chart/dist/altimeter-burst.js +43 -0
  5. package/chart/dist/altimeter-chart.d.ts +52 -0
  6. package/chart/dist/altimeter-chart.js +275 -0
  7. package/chart/dist/altimeter-model.d.ts +43 -0
  8. package/chart/dist/altimeter-model.js +148 -0
  9. package/chart/dist/altimeter-targets.d.ts +33 -0
  10. package/chart/dist/altimeter-targets.js +88 -0
  11. package/chart/dist/bitcoin-price.d.ts +8 -0
  12. package/chart/dist/bitcoin-price.js +41 -0
  13. package/chart/dist/champions-league.d.ts +19 -0
  14. package/chart/dist/champions-league.js +104 -0
  15. package/chart/dist/index.d.ts +6 -0
  16. package/chart/dist/index.js +5 -0
  17. package/chart/dist/outcome-chart.d.ts +37 -0
  18. package/chart/dist/outcome-chart.js +212 -0
  19. package/chart/dist/outcome-model.d.ts +43 -0
  20. package/chart/dist/outcome-model.js +71 -0
  21. package/chart/dist/plus-grid.d.ts +6 -0
  22. package/chart/dist/plus-grid.js +29 -0
  23. package/contracts/README.md +1 -1
  24. package/contracts/dist/avatar.d.ts +68 -0
  25. package/contracts/dist/avatar.js +93 -0
  26. package/contracts/dist/confetti.d.ts +174 -0
  27. package/contracts/dist/confetti.js +138 -0
  28. package/contracts/dist/decimal.d.ts +7 -0
  29. package/contracts/dist/decimal.js +35 -0
  30. package/contracts/dist/index.d.ts +29 -2
  31. package/contracts/dist/index.js +123 -4
  32. package/contracts/dist/invariants.d.ts +17 -0
  33. package/contracts/dist/invariants.js +24 -0
  34. package/contracts/dist/login.d.ts +34 -0
  35. package/contracts/dist/login.js +43 -0
  36. package/contracts/dist/messages.d.ts +57 -3
  37. package/contracts/dist/messages.js +20 -2
  38. package/contracts/dist/number-flow.d.ts +90 -0
  39. package/contracts/dist/number-flow.js +150 -0
  40. package/contracts/dist/qr.d.ts +151 -0
  41. package/contracts/dist/qr.js +581 -0
  42. package/contracts/dist/toast.d.ts +168 -0
  43. package/contracts/dist/toast.js +171 -0
  44. package/feedback/README.md +1 -1
  45. package/feedback/dist/contract.js +1 -1
  46. package/feedback/dist/react.js +2 -4
  47. package/native/README.md +6 -1
  48. package/native/dist/account-block.d.ts +10 -1
  49. package/native/dist/account-block.js +17 -7
  50. package/native/dist/animated-number-model.d.ts +41 -1
  51. package/native/dist/animated-number-model.js +201 -23
  52. package/native/dist/animated-number.d.ts +39 -1
  53. package/native/dist/animated-number.js +164 -17
  54. package/native/dist/announce.d.ts +2 -0
  55. package/native/dist/announce.js +10 -0
  56. package/native/dist/asset-balance-row.d.ts +3 -1
  57. package/native/dist/asset-balance-row.js +15 -4
  58. package/native/dist/assets-block.d.ts +115 -0
  59. package/native/dist/assets-block.js +87 -0
  60. package/native/dist/async-result.d.ts +2 -0
  61. package/native/dist/async-result.js +11 -0
  62. package/native/dist/avatar-frame.d.ts +29 -0
  63. package/native/dist/avatar-frame.js +56 -0
  64. package/native/dist/avatar.d.ts +21 -0
  65. package/native/dist/avatar.js +31 -0
  66. package/native/dist/bar-mark.d.ts +2 -0
  67. package/native/dist/bar-mark.js +4 -2
  68. package/native/dist/bar-pnl.js +2 -1
  69. package/native/dist/blocks.d.ts +9 -2
  70. package/native/dist/blocks.js +8 -1
  71. package/native/dist/brand.js +2 -1
  72. package/native/dist/button.d.ts +7 -2
  73. package/native/dist/button.js +13 -3
  74. package/native/dist/checkbox.js +2 -1
  75. package/native/dist/confetti.d.ts +33 -0
  76. package/native/dist/confetti.js +143 -0
  77. package/native/dist/confirm-block.d.ts +98 -0
  78. package/native/dist/confirm-block.js +48 -0
  79. package/native/dist/data.d.ts +1 -1
  80. package/native/dist/data.js +5 -1
  81. package/native/dist/deposit-block.d.ts +19 -0
  82. package/native/dist/deposit-block.js +17 -0
  83. package/native/dist/explainer-block.d.ts +91 -0
  84. package/native/dist/explainer-block.js +34 -0
  85. package/native/dist/field.d.ts +5 -1
  86. package/native/dist/field.js +27 -6
  87. package/native/dist/gesture-sheet-model.d.ts +50 -0
  88. package/native/dist/gesture-sheet-model.js +105 -0
  89. package/native/dist/gesture-sheet-next.d.ts +82 -0
  90. package/native/dist/gesture-sheet-next.js +315 -0
  91. package/native/dist/gesture-sheet.d.ts +5 -1
  92. package/native/dist/gesture-sheet.js +13 -6
  93. package/native/dist/icons.d.ts +9 -6
  94. package/native/dist/icons.js +25 -24
  95. package/native/dist/language-block.d.ts +10 -1
  96. package/native/dist/language-block.js +11 -4
  97. package/native/dist/list-group.d.ts +3 -1
  98. package/native/dist/list-group.js +26 -13
  99. package/native/dist/login-block.d.ts +4 -0
  100. package/native/dist/login-block.js +22 -0
  101. package/native/dist/manage-position-block.d.ts +8 -1
  102. package/native/dist/manage-position-block.js +7 -2
  103. package/native/dist/market-row.js +19 -8
  104. package/native/dist/navigation.js +5 -3
  105. package/native/dist/number-format.d.ts +6 -0
  106. package/native/dist/number-format.js +9 -0
  107. package/native/dist/pickers.d.ts +8 -0
  108. package/native/dist/pickers.js +3 -3
  109. package/native/dist/position-block.d.ts +5 -5
  110. package/native/dist/preset-group.d.ts +31 -0
  111. package/native/dist/preset-group.js +39 -0
  112. package/native/dist/preset-picker-block.d.ts +107 -0
  113. package/native/dist/preset-picker-block.js +43 -0
  114. package/native/dist/profile-block.d.ts +10 -1
  115. package/native/dist/profile-block.js +8 -3
  116. package/native/dist/provider.d.ts +5 -2
  117. package/native/dist/provider.js +27 -5
  118. package/native/dist/qr-code.d.ts +33 -0
  119. package/native/dist/qr-code.js +29 -0
  120. package/native/dist/radio-group.d.ts +19 -7
  121. package/native/dist/radio-group.js +39 -10
  122. package/native/dist/reward-block.d.ts +10 -7
  123. package/native/dist/reward-block.js +9 -4
  124. package/native/dist/screen-header.d.ts +13 -3
  125. package/native/dist/screen-header.js +12 -4
  126. package/native/dist/select.js +4 -2
  127. package/native/dist/selection.d.ts +2 -1
  128. package/native/dist/selection.js +1 -0
  129. package/native/dist/setting-switch.d.ts +1 -1
  130. package/native/dist/setting-switch.js +7 -3
  131. package/native/dist/slider.js +5 -1
  132. package/native/dist/sound-haptics-block.js +1 -1
  133. package/native/dist/status.d.ts +41 -9
  134. package/native/dist/status.js +34 -17
  135. package/native/dist/sticky-header.js +9 -1
  136. package/native/dist/swap-amount-card.d.ts +57 -0
  137. package/native/dist/swap-amount-card.js +31 -0
  138. package/native/dist/{swap-panel-block.d.ts → swap-block.d.ts} +18 -8
  139. package/native/dist/{swap-panel-block.js → swap-block.js} +63 -35
  140. package/native/dist/swap-parts.d.ts +3 -10
  141. package/native/dist/swap-parts.js +22 -24
  142. package/native/dist/swap-shared.d.ts +2 -2
  143. package/native/dist/swap-shared.js +10 -6
  144. package/native/dist/swap-sheet.d.ts +3 -3
  145. package/native/dist/swap-sheet.js +3 -3
  146. package/native/dist/swap-views.js +1 -1
  147. package/native/dist/target-block.d.ts +7 -1
  148. package/native/dist/target-block.js +13 -6
  149. package/native/dist/toast.d.ts +47 -0
  150. package/native/dist/toast.js +386 -0
  151. package/native/dist/token-action-block.d.ts +11 -2
  152. package/native/dist/token-action-block.js +10 -4
  153. package/native/dist/trade-history-list-block.js +7 -4
  154. package/native/dist/wallet-address-core.js +6 -3
  155. package/native-fonts/README.md +1 -1
  156. package/og-fonts/README.md +1 -1
  157. package/package.json +155 -11
  158. package/react/README.md +3 -1
  159. package/react/dist/animated-number-flow.d.ts +72 -0
  160. package/react/dist/animated-number-flow.js +316 -0
  161. package/react/dist/animated-number-model.d.ts +18 -0
  162. package/react/dist/animated-number-model.js +75 -5
  163. package/react/dist/animated-number.d.ts +45 -1
  164. package/react/dist/animated-number.js +137 -6
  165. package/react/dist/asset-balance-row.d.ts +3 -1
  166. package/react/dist/asset-balance-row.js +10 -4
  167. package/react/dist/async-result.d.ts +2 -0
  168. package/react/dist/async-result.js +11 -0
  169. package/react/dist/avatar.d.ts +25 -0
  170. package/react/dist/avatar.js +50 -0
  171. package/react/dist/blocks/account-block.d.ts +5 -1
  172. package/react/dist/blocks/account-block.js +11 -6
  173. package/react/dist/blocks/assets-block.d.ts +106 -0
  174. package/react/dist/blocks/assets-block.js +135 -0
  175. package/react/dist/blocks/confirm-block.d.ts +91 -0
  176. package/react/dist/blocks/confirm-block.js +31 -0
  177. package/react/dist/blocks/deposit-block.d.ts +19 -0
  178. package/react/dist/blocks/deposit-block.js +15 -0
  179. package/react/dist/blocks/explainer-block.d.ts +80 -0
  180. package/react/dist/blocks/explainer-block.js +20 -0
  181. package/react/dist/blocks/install-command.js +3 -1
  182. package/react/dist/blocks/language-block.d.ts +5 -1
  183. package/react/dist/blocks/language-block.js +4 -3
  184. package/react/dist/blocks/login-block.d.ts +4 -0
  185. package/react/dist/blocks/login-block.js +14 -0
  186. package/react/dist/blocks/manage-position-block.d.ts +3 -1
  187. package/react/dist/blocks/manage-position-block.js +2 -2
  188. package/react/dist/blocks/market-row.js +8 -3
  189. package/react/dist/blocks/notifications-block.d.ts +3 -1
  190. package/react/dist/blocks/notifications-block.js +2 -2
  191. package/react/dist/blocks/pickers.d.ts +9 -0
  192. package/react/dist/blocks/pickers.js +4 -2
  193. package/react/dist/blocks/position-block.d.ts +3 -3
  194. package/react/dist/blocks/preset-picker-block.d.ts +85 -0
  195. package/react/dist/blocks/preset-picker-block.js +19 -0
  196. package/react/dist/blocks/profile-block.d.ts +5 -1
  197. package/react/dist/blocks/profile-block.js +12 -13
  198. package/react/dist/blocks/reward-block.d.ts +13 -8
  199. package/react/dist/blocks/reward-block.js +7 -4
  200. package/react/dist/blocks/screen-header.d.ts +10 -2
  201. package/react/dist/blocks/screen-header.js +7 -4
  202. package/react/dist/blocks/setting-switch.js +6 -3
  203. package/react/dist/blocks/signals-block.d.ts +3 -1
  204. package/react/dist/blocks/signals-block.js +4 -3
  205. package/react/dist/blocks/sound-haptics-block.d.ts +3 -1
  206. package/react/dist/blocks/sound-haptics-block.js +2 -2
  207. package/react/dist/blocks/sticky-header.d.ts +14 -4
  208. package/react/dist/blocks/sticky-header.js +68 -8
  209. package/react/dist/blocks/swap/settings.js +2 -1
  210. package/react/dist/blocks/swap/shared.d.ts +22 -22
  211. package/react/dist/blocks/swap/shared.js +30 -28
  212. package/react/dist/blocks/{swap-panel-block.d.ts → swap-block.d.ts} +19 -8
  213. package/react/dist/blocks/swap-block.js +215 -0
  214. package/react/dist/blocks/swap-sheet.d.ts +3 -3
  215. package/react/dist/blocks/swap-sheet.js +3 -3
  216. package/react/dist/blocks/target-block.d.ts +7 -1
  217. package/react/dist/blocks/target-block.js +10 -4
  218. package/react/dist/blocks/token-action-block.d.ts +6 -2
  219. package/react/dist/blocks/token-action-block.js +3 -2
  220. package/react/dist/blocks/trade-history-detail-block.d.ts +3 -1
  221. package/react/dist/blocks/trade-history-detail-block.js +2 -2
  222. package/react/dist/blocks/trade-history-list-block.d.ts +3 -1
  223. package/react/dist/blocks/trade-history-list-block.js +7 -4
  224. package/react/dist/blocks.d.ts +8 -2
  225. package/react/dist/blocks.js +7 -1
  226. package/react/dist/brand.js +2 -1
  227. package/react/dist/button.d.ts +9 -3
  228. package/react/dist/button.js +8 -3
  229. package/react/dist/confetti.d.ts +27 -0
  230. package/react/dist/confetti.js +240 -0
  231. package/react/dist/data.js +8 -1
  232. package/react/dist/field.d.ts +6 -1
  233. package/react/dist/field.js +18 -9
  234. package/react/dist/gesture-sheet.d.ts +15 -1
  235. package/react/dist/gesture-sheet.js +53 -8
  236. package/react/dist/list-group.js +11 -7
  237. package/react/dist/navigation.js +11 -3
  238. package/react/dist/overlay.d.ts +1 -4
  239. package/react/dist/overlay.js +1 -3
  240. package/react/dist/popover.d.ts +30 -0
  241. package/react/dist/popover.js +34 -0
  242. package/react/dist/preset-group.d.ts +30 -0
  243. package/react/dist/preset-group.js +13 -0
  244. package/react/dist/provider.d.ts +2 -2
  245. package/react/dist/provider.js +23 -6
  246. package/react/dist/qr-code.d.ts +32 -0
  247. package/react/dist/qr-code.js +28 -0
  248. package/react/dist/select.js +10 -3
  249. package/react/dist/selection.d.ts +13 -5
  250. package/react/dist/selection.js +13 -8
  251. package/react/dist/slider.js +5 -1
  252. package/react/dist/status.d.ts +14 -10
  253. package/react/dist/status.js +17 -9
  254. package/react/dist/styles.css +260 -165
  255. package/react/dist/toast.d.ts +19 -12
  256. package/react/dist/toast.js +29 -7
  257. package/react/dist/wallet-address-core.d.ts +8 -4
  258. package/react/dist/wallet-address-core.js +10 -5
  259. package/tokens/README.md +2 -2
  260. package/tokens/assets/onramps/apple-pay.svg +33 -0
  261. package/tokens/assets/onramps/bank.svg +98 -0
  262. package/tokens/assets/onramps/blink.svg +37 -0
  263. package/tokens/assets/onramps/cashapp.svg +33 -0
  264. package/tokens/assets/onramps/crypto.svg +121 -0
  265. package/tokens/assets/onramps/exchange.svg +105 -0
  266. package/tokens/dist/deposit-icons.d.ts +1 -0
  267. package/tokens/dist/deposit-icons.js +28 -0
  268. package/tokens/dist/index.d.ts +16 -0
  269. package/tokens/dist/index.js +16 -0
  270. package/tokens/dist/manifest.json +8 -0
  271. package/tokens/dist/tokens.css +6 -0
  272. package/react/dist/blocks/swap-panel-block.js +0 -178
@@ -1,178 +0,0 @@
1
- "use client";
2
- import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useEffect, useMemo, useRef, useState } from 'react';
4
- import * as en from '@bloxwap/hig/contracts/messages';
5
- import { PressDecoration, useControllable, useHIG } from '../provider.js';
6
- import { Button, IconButton } from '../button.js';
7
- import { AnimatedNumberReadout } from '../animated-number.js';
8
- import { notify } from '../notify.js';
9
- import { VerticalAddress } from '../data.js';
10
- import { SwapPicker } from './swap/picker.js';
11
- import { SwapSettings } from './swap/settings.js';
12
- import { SwapIcon, SwapKeypad, SwapNumber, SwapPill, percentNumber, swapArt, swapFigure, usdNumber, addressGradient, applyAmountKey, chainsOf, parentView, sanitizeAmount, shortAddress, swapAction, testAmount, trimNumber, unitsToEntry } from './swap/shared.js';
13
- export { swapAction } from './swap/shared.js';
14
- export { SwapAmountCard } from './swap/amount-card.js';
15
- export { SwapPill, SwapKeypad, SwapNumber } from './swap/shared.js';
16
- const textTarget = (target) => { const element = target; return !!element && (/^(INPUT|TEXTAREA|SELECT)$/.test(element.tagName) || element.isContentEditable); };
17
- const amountKey = (event) => event.metaKey || event.ctrlKey || event.altKey ? null : /^[0-9.]$/.test(event.key) ? event.key : event.key === 'Backspace' ? 'back' : null;
18
- /**
19
- * Send, swap and bridge in one panel: a From card and a To card joined by a flip control, an amount entered in dollars
20
- * or token units, token pickers, settings, and one action that names itself from the chosen pair.
21
- * Presentation only. The host owns tokens, balances, prices, the quote, the wallet and the transaction.
22
- */
23
- export function SwapPanelBlock({ tokens, fromTokens, fromTokensLoading, chains, hotTokenIds, from: fromProp, to: toProp, defaultFrom = null, defaultTo = null, onFromChange, onToChange, amount, onAmountChange, received, fee, fees, quoteLoading, slippage = 0.005, onSlippageChange, denomination, onDenominationChange, wallet, onConnect, onDisconnect, recipient, onRecipientChange, onScanRecipient, receive, receiving, onReceivingChange, onSubmit, submitting = false, onReset, destination, details, note, noteTone = 'muted', title, onBack, controls = true, actionIcon, lockFrom = false, lockTo = false, actionLabel, actionDisabled = false, actionStatus, actionIntent = 'primary', limitToBalance = false, banner, footer, oneWay: oneWayProp = false, denominationSwitch = true, keypad = 'auto', shortcuts = true, captureKeyboard = false, view: viewProp, onViewChange, settings, className, style }) {
24
- const { messages } = useHIG();
25
- const [from, setFrom] = useControllable(fromProp, defaultFrom, onFromChange);
26
- const [to, setTo] = useControllable(toProp, defaultTo, onToChange);
27
- const [defaultMode, setDefaultMode] = useControllable(denomination, 'usd', onDenominationChange);
28
- const [isReceiving, setReceiving] = useControllable(receiving, false, onReceivingChange);
29
- // A mounted `amount` seeds the entry, in the default denomination at the initial From token's price.
30
- const [entry, setEntry] = useState(() => amount === undefined ? '0' : unitsToEntry(Number(amount) || 0, defaultMode, from?.price ?? 0));
31
- const [fromMode, applyFromMode] = useState(defaultMode);
32
- const [toMode, applyToMode] = useState(defaultMode);
33
- const [view, show] = useControllable(viewProp, 'main', onViewChange);
34
- const root = useRef(null);
35
- const previous = useRef('main');
36
- const openPicker = (side) => show(side);
37
- const back = () => show(parentView(view));
38
- // A push slides in from the trailing edge and a pop from the leading edge. Popping to the cards returns focus to the control that pushed.
39
- const direction = view === 'main' || (view === 'settings' && previous.current !== 'main') ? 'pop' : 'push';
40
- useEffect(() => { const from = previous.current; previous.current = view; if (view !== 'main' || from === 'main')
41
- return; root.current?.querySelector(from === 'from' || from === 'to' ? `[data-side='${from}'] .hig-swap-hit` : '.hig-swap-settings-button')?.focus(); }, [view]);
42
- const [touch, setTouch] = useState(false);
43
- const [hint, showHint] = useState(null);
44
- const [copied, setCopied] = useState('');
45
- useEffect(() => {
46
- const coarse = window.matchMedia?.('(pointer: coarse)');
47
- const update = () => setTouch(!!coarse?.matches);
48
- update();
49
- coarse?.addEventListener('change', update);
50
- if (window.matchMedia?.('(hover: hover) and (pointer: fine)').matches)
51
- showHint(/Mac|iPhone|iPad/.test(navigator.platform) ? 'mac' : 'pc');
52
- return () => coarse?.removeEventListener('change', update);
53
- }, []);
54
- const fromPrice = from?.price ?? 0, toPrice = to?.price ?? 0, input = Number(entry) || 0;
55
- const units = fromMode === 'token' ? input : fromPrice > 0 ? input / fromPrice : 0, usd = units * fromPrice, unitsText = trimNumber(units);
56
- const showReceive = isReceiving && !!receive;
57
- // Report the amount in token units; resync the entry when the host sets a different amount.
58
- const reported = useRef(amount ?? '0');
59
- useEffect(() => { if (reported.current !== unitsText) {
60
- reported.current = unitsText;
61
- onAmountChange?.(unitsText);
62
- } }, [unitsText]);
63
- useEffect(() => { if (amount === undefined || Number(amount) === Number(reported.current))
64
- return; reported.current = trimNumber(Number(amount) || 0); setEntry(unitsToEntry(Number(amount) || 0, fromMode, fromPrice)); }, [amount]);
65
- const sameAsset = !!from && !!to && from.id === to.id;
66
- const receivedUnits = sameAsset ? units : received ?? (toPrice > 0 ? usd / toPrice : 0);
67
- const receivedUsd = toPrice > 0 ? receivedUnits * toPrice : sameAsset ? usd : 0;
68
- const action = swapAction(from, to);
69
- const insufficient = !!from && (from.balance ?? 0) > 0 && units > (from.balance ?? 0);
70
- // A destination or a details card stands in for the To token: one way, and ready from the From side alone.
71
- const fixed = !!destination || (!!details && !to);
72
- const oneWay = oneWayProp || fixed;
73
- const eligible = !!from && (!!to || fixed) && !destination?.pending && units > 0 && !insufficient;
74
- const ready = eligible && !actionDisabled;
75
- const actionText = showReceive ? (messages.swapSendFromWallet ?? en.swapSendFromWallet) : !from || (!to && !fixed) ? (messages.swapChooseToken ?? en.swapChooseToken) : destination?.pending ? (messages.swapChooseDestination ?? en.swapChooseDestination) : units <= 0 ? (messages.swapEnterAmount ?? en.swapEnterAmount) : insufficient ? (messages.swapInsufficient ?? en.swapInsufficient)(from.symbol) : actionDisabled && actionStatus ? actionStatus : actionLabel ?? (action === 'swap' && !fixed ? messages.swapActionSwap ?? en.swapActionSwap : action === 'bridge' && !fixed ? messages.swapActionBridge ?? en.swapActionBridge : messages.swapActionSend ?? en.swapActionSend);
76
- const pristine = (lockFrom || !from) && (lockTo || !to) && input === 0;
77
- // Updater form: several keys can land before the next render, and each must build on the last.
78
- const latest = useRef(fromMode);
79
- latest.current = fromMode;
80
- const latestView = useRef(view);
81
- latestView.current = view;
82
- // Read at key time: several keys can land in one render.
83
- const limits = useRef({ decimals: from?.decimals, balance: from?.balance ?? 0, price: fromPrice, cap: limitToBalance });
84
- limits.current = { decimals: from?.decimals, balance: from?.balance ?? 0, price: fromPrice, cap: limitToBalance };
85
- const over = (next) => { const { balance, price, cap } = limits.current; if (!cap || !(balance > 0))
86
- return false; const value = Number(next) || 0; return (latest.current === 'token' ? value : price > 0 ? value / price : 0) > balance; };
87
- const press = (key) => setEntry(current => { const next = applyAmountKey(current, key, latest.current, limits.current.decimals); return key !== 'back' && over(next) ? current : next; });
88
- const paste = (text) => { const clean = text.trim().replace(/,/g, ''); if (clean === '' || !/^[0-9]*\.?[0-9]*$/.test(clean))
89
- return false; const next = sanitizeAmount(clean); setEntry(latest.current === 'usd' ? trimNumber(Number(next) || 0, 2) : next); return true; };
90
- const switchFromMode = (mode) => { if (mode === fromMode)
91
- return; setEntry(mode === 'usd' ? trimNumber(usd, 2) : trimNumber(units)); applyFromMode(mode); };
92
- const changeDenomination = (mode) => { setDefaultMode(mode); switchFromMode(mode); applyToMode(mode); };
93
- // A new default applies to an untouched entry at once; a typed amount keeps its denomination until reset.
94
- useEffect(() => { if (input === 0) {
95
- applyFromMode(defaultMode);
96
- applyToMode(defaultMode);
97
- } }, [defaultMode]);
98
- const reset = () => { setEntry('0'); applyFromMode(defaultMode); applyToMode(defaultMode); if (isReceiving)
99
- setReceiving(false); if (!lockFrom)
100
- setFrom(null); if (!lockTo)
101
- setTo(null); onReset?.(); };
102
- const flip = () => { if (!from || !to)
103
- return; setFrom(to); setTo(from); };
104
- const submit = () => { if (submitting)
105
- return; if (showReceive) {
106
- onConnect?.();
107
- return;
108
- } if (ready)
109
- onSubmit(fixed ? 'send' : action); };
110
- const copyAddress = () => { if (!receive?.onCopy)
111
- return; Promise.resolve().then(receive.onCopy).then(() => { const text = (messages.addressCopied ?? en.addressCopied); setCopied(notify(text, { severity: 'success', id: 'hig-swap-address', dismissName: (messages.dismissNotice ?? en.dismissNotice)(text, (messages.dismiss ?? en.dismiss)) }) ? text : ''); }).catch(() => setCopied('')); };
112
- useEffect(() => {
113
- if (!shortcuts && !captureKeyboard)
114
- return;
115
- const onKeyDown = (event) => {
116
- const key = event.key.toLowerCase();
117
- if (shortcuts && (event.metaKey || event.ctrlKey) && !event.altKey && !event.shiftKey && (key === 'f' || key === 'k')) {
118
- const side = key === 'f' ? 'from' : 'to';
119
- if (side === 'from' ? lockFrom : lockTo || fixed)
120
- return;
121
- event.preventDefault();
122
- show(side);
123
- return;
124
- }
125
- if (!captureKeyboard || event.defaultPrevented || textTarget(event.target) || latestView.current !== 'main')
126
- return;
127
- const pressed = amountKey(event);
128
- if (pressed) {
129
- event.preventDefault();
130
- press(pressed);
131
- }
132
- };
133
- const onPaste = (event) => { if (captureKeyboard && !event.defaultPrevented && !textTarget(event.target) && paste(event.clipboardData?.getData('text') ?? ''))
134
- event.preventDefault(); };
135
- window.addEventListener('keydown', onKeyDown);
136
- document.addEventListener('paste', onPaste);
137
- return () => { window.removeEventListener('keydown', onKeyDown); document.removeEventListener('paste', onPaste); };
138
- }, [shortcuts, captureKeyboard, lockFrom, lockTo, fixed]);
139
- // Keys typed while focus is inside the cards drive the amount; in a pushed view Escape pops it.
140
- const inPanel = (event) => view === 'main' && !textTarget(event.target);
141
- const onKeyDown = (event) => { if (view !== 'main' && event.key === 'Escape') {
142
- event.preventDefault();
143
- event.stopPropagation();
144
- back();
145
- return;
146
- } if (captureKeyboard || !inPanel(event))
147
- return; const pressed = amountKey(event); if (pressed) {
148
- event.preventDefault();
149
- press(pressed);
150
- } };
151
- const onPaste = (event) => { if (!captureKeyboard && inPanel(event) && paste(event.clipboardData.getData('text')))
152
- event.preventDefault(); };
153
- const chainList = useMemo(() => chains ?? chainsOf(tokens), [chains, tokens]);
154
- // The fee keeps its sentence; only a known amount moves. Loading and unknown are plain placeholders.
155
- const feeLine = quoteLoading || fee == null ? (messages.swapFee ?? en.swapFee)(quoteLoading ? '…' : '—') : _jsx(SwapNumber, { template: messages.swapFee ?? en.swapFee, ...usdNumber(fee) });
156
- const fraction = entry.includes('.') ? Math.min(entry.length - entry.indexOf('.') - 1, fromMode === 'usd' ? 2 : 8) : 0;
157
- // An account (a token with a `caption`) reads name over caption beside one disc, and offers Max only.
158
- const account = (side, token, locked) => _jsxs("div", { className: 'hig-swap-selected', "data-account": 'true', children: [_jsx("span", { className: 'hig-swap-stack', "aria-hidden": 'true', children: token.icon ? swapArt(token.icon) : _jsx("span", { className: 'hig-swap-initials', children: token.symbol.slice(0, 3) }) }), _jsxs("span", { className: 'hig-swap-identity', children: [_jsxs("strong", { children: [token.name, !locked && _jsx(SwapIcon, { name: 'expand', size: 16 })] }), _jsx("span", { children: swapFigure(token.caption ?? '') })] }), side === 'from' && (token.balance ?? 0) > 0 && _jsx("span", { className: 'hig-swap-meta', children: _jsx(SwapPill, { onClick: () => setEntry(unitsToEntry(token.balance ?? 0, fromMode, fromPrice)), children: (messages.swapMax ?? en.swapMax) }) })] });
159
- const header = (side, token) => _jsxs("div", { className: 'hig-swap-selected', children: [_jsxs("span", { className: 'hig-swap-stack', "aria-hidden": 'true', children: [wallet?.address && _jsx("span", { className: 'hig-swap-avatar', style: { background: addressGradient(wallet.address) } }), token.chainIcon && swapArt(token.chainIcon), token.icon ? swapArt(token.icon) : _jsx("span", { className: 'hig-swap-initials', children: token.symbol.slice(0, 3) })] }), _jsxs("span", { className: 'hig-swap-identity', children: [wallet?.address && _jsx("span", { children: shortAddress(wallet.address) }), _jsx("span", { children: token.chain }), _jsx("strong", { children: token.name })] }), side === 'from' ? (token.balance ?? 0) > 0 && _jsxs("span", { className: 'hig-swap-meta', children: [_jsxs("span", { className: 'hig-swap-pills', children: [_jsxs(SwapPill, { onClick: () => setEntry(unitsToEntry(testAmount(token), fromMode, fromPrice)), children: [_jsx(SwapIcon, { name: 'flask', size: 14 }), (messages.swapTest ?? en.swapTest)] }), _jsx(SwapPill, { onClick: () => setEntry(unitsToEntry(token.balance ?? 0, fromMode, fromPrice)), children: (messages.swapMax ?? en.swapMax) })] }), _jsx(SwapNumber, { value: token.balance, suffix: ' ' + token.symbol, options: { maximumFractionDigits: 6 } })] })
160
- : _jsxs("span", { className: 'hig-swap-meta', children: [_jsxs(SwapPill, { onClick: () => show(onSlippageChange ? 'slippage' : 'settings'), children: [_jsx(SwapIcon, { name: 'sliders', size: 14 }), _jsx(SwapNumber, { template: messages.swapSlippage ?? en.swapSlippage, ...percentNumber(slippage) })] }), _jsx("span", { children: feeLine })] })] });
161
- const receiveView = (view) => { const content = _jsxs(_Fragment, { children: [view.qr && _jsx("span", { className: 'hig-swap-qr', children: view.qr }), _jsx(VerticalAddress, { address: view.address })] }); return view.onCopy ? _jsxs("button", { type: 'button', className: 'hig-swap-receive', "aria-label": (messages.copyAddress ?? en.copyAddress) + ': ' + view.address, onClick: copyAddress, children: [content, _jsx(PressDecoration, { kind: 'row' })] }) : _jsx("div", { className: 'hig-swap-receive', children: content }); };
162
- const card = (side) => {
163
- const token = side === 'from' ? from : to, label = side === 'from' ? (messages.swapFrom ?? en.swapFrom) : (messages.swapTo ?? en.swapTo), mode = side === 'from' ? fromMode : toMode, locked = side === 'from' ? lockFrom : lockTo;
164
- const cardUnits = side === 'from' ? units : receivedUnits, cardUsd = side === 'from' ? usd : receivedUsd;
165
- const shown = side === 'from' ? input : mode === 'token' ? receivedUnits : receivedUsd;
166
- return _jsxs("div", { className: 'hig-swap-card', "data-side": side, "data-locked": locked || undefined, children: [_jsxs("div", { className: 'hig-swap-slot', children: [!locked && _jsx("button", { type: 'button', className: 'hig-swap-hit', "aria-label": (messages.swapSelectToken ?? en.swapSelectToken)(label), onClick: () => openPicker(side), children: _jsx(PressDecoration, { kind: 'row' }) }), _jsx("div", { className: 'hig-swap-slot-content', children: token ? token.caption !== undefined ? account(side, token, locked) : header(side, token) : _jsxs(_Fragment, { children: [_jsxs("span", { className: 'hig-swap-placeholder', children: [label, "\u2026"] }), shortcuts && hint && !locked && _jsxs("kbd", { className: 'hig-swap-kbd', children: [hint === 'mac' ? '⌘' : messages.swapControlKey ?? en.swapControlKey, " ", side === 'from' ? 'F' : 'K'] })] }) })] }), side === 'from' && showReceive && receive ? receiveView(receive) :
167
- !(side === 'to' && showReceive) && _jsxs("div", { className: 'hig-swap-amount-area', children: [!locked && _jsx("button", { type: 'button', className: 'hig-swap-hit', tabIndex: -1, "aria-hidden": 'true', onClick: () => openPicker(side), children: _jsx(PressDecoration, { kind: 'row' }) }), _jsxs("div", { className: 'hig-swap-amount-content', children: [_jsx("div", { className: 'hig-swap-amount', "data-muted": side === 'to' || undefined, ...(side === 'from' ? { role: 'textbox', tabIndex: 0, 'aria-label': (messages.swapAmount ?? en.swapAmount)(label) } : {}), children: _jsx(AnimatedNumberReadout, { value: shown, label: side === 'to' ? (messages.swapAmount ?? en.swapAmount)(label) : undefined, prefix: mode === 'usd' ? '$' : '', suffix: side === 'from' && entry.endsWith('.') ? '.' : '', options: { minimumFractionDigits: side === 'from' ? fraction : 0, maximumFractionDigits: mode === 'usd' ? 2 : 8, useGrouping: false } }) }), denominationSwitch && _jsxs(SwapPill, { "aria-label": (messages.swapSwitchDenomination ?? en.swapSwitchDenomination), onClick: () => side === 'from' ? switchFromMode(fromMode === 'usd' ? 'token' : 'usd') : applyToMode(toMode === 'usd' ? 'token' : 'usd'), children: [_jsx("span", { "aria-hidden": 'true', className: 'hig-swap-equals', children: "=" }), mode === 'token' ? _jsx(AnimatedNumberReadout, { value: cardUsd, options: { style: 'currency', currency: 'USD' } }) : _jsx(AnimatedNumberReadout, { value: cardUnits, suffix: token ? ` ${token.symbol}` : '', options: { maximumFractionDigits: 8, useGrouping: false } }), _jsx(SwapIcon, { name: 'flip', size: 14 })] })] })] })] });
168
- };
169
- // The fixed bottom card is one compact row for the destination (artwork, where it goes, a trailing detail and fee), label and value rows, or both.
170
- const fixedCard = fixed && _jsxs("div", { className: 'hig-swap-card', "data-side": 'to', "data-compact": 'true', "data-pending": destination?.pending || undefined, children: [destination && _jsxs("div", { className: 'hig-swap-slot', children: [destination.onPress && _jsx("button", { type: 'button', className: 'hig-swap-hit', "aria-label": destination.title, onClick: destination.onPress, children: _jsx(PressDecoration, { kind: 'row' }) }), _jsx("div", { className: 'hig-swap-slot-content', children: _jsxs("div", { className: 'hig-swap-selected', children: [_jsx("span", { className: 'hig-swap-stack', "aria-hidden": 'true', children: destination.icon ? swapArt(destination.icon) : destination.address ? _jsx("span", { className: 'hig-swap-avatar', style: { background: addressGradient(destination.address) } }) : _jsx("span", { className: 'hig-swap-initials', children: destination.title.slice(0, 2) }) }), _jsxs("span", { className: 'hig-swap-identity', children: [_jsx("strong", { children: destination.title }), destination.subtitle && _jsx("span", { children: destination.subtitle }), destination.address && _jsx("span", { children: shortAddress(destination.address) })] }), (destination.detail || fee !== undefined || destination.onPress) && _jsxs("span", { className: 'hig-swap-meta', "data-row": destination.onPress ? 'true' : undefined, children: [_jsxs("span", { children: [destination.detail && _jsx("span", { children: swapFigure(destination.detail) }), fee !== undefined && _jsx("span", { children: feeLine })] }), destination.onPress && _jsx(SwapIcon, { name: 'chevron', size: 16 })] })] }) })] }), details && details.length > 0 && _jsx("dl", { className: 'hig-swap-details', children: details.map(row => _jsxs("div", { children: [_jsx("dt", { children: row.label }), _jsx("dd", { children: typeof row.value === 'number' ? _jsx(SwapNumber, { value: row.value, options: row.options, prefix: row.prefix, suffix: row.suffix, formattedValue: row.formattedValue, animateFormatted: !!row.formattedValue }) : row.value })] }, row.label)) })] });
171
- const fromCard = card('from'), toCard = fixedCard || card('to');
172
- const body = view === 'main' ? _jsxs(_Fragment, { children: [title && _jsxs("div", { className: 'hig-swap-view-header', "data-plain": onBack ? undefined : 'true', children: [onBack && _jsxs("button", { type: 'button', className: 'hig-swap-back', "aria-label": messages.back ?? en.back, onClick: onBack, children: [_jsx(SwapIcon, { name: 'back' }), _jsx(PressDecoration, { kind: 'back' })] }), _jsx("h2", { className: 'hig-swap-view-title', children: title })] }), banner, fromCard, _jsx("div", { className: 'hig-swap-flip', children: oneWay ? _jsx("span", { "aria-hidden": 'true', children: _jsx(SwapIcon, { name: 'down', size: 16 }) }) : _jsxs("button", { type: 'button', "aria-label": (messages.swapFlip ?? en.swapFlip), disabled: !from || !to, onClick: flip, children: [_jsx(SwapIcon, { name: 'flip', size: 16 }), _jsx(PressDecoration, { kind: 'icon-button', disabled: !from || !to })] }) }), toCard, !showReceive && (keypad === 'always' || (keypad === 'auto' && touch)) && _jsx(SwapKeypad, { onKey: press, label: (messages.swapKeypad ?? en.swapKeypad), deleteLabel: (messages.swapDelete ?? en.swapDelete) }), note && _jsx("p", { className: 'hig-swap-note', "data-tone": noteTone, role: 'note', children: note }), _jsxs("div", { className: 'hig-swap-actions', children: [controls && _jsx(IconButton, { className: 'hig-swap-settings-button', intent: 'secondary', label: (messages.swapSettings ?? en.swapSettings), suppressFeedback: true, onClick: () => show('settings'), children: _jsx(SwapIcon, { name: 'menu' }) }), _jsxs(Button, { fullWidth: true, intent: actionIntent, busy: submitting, disabled: !showReceive && !ready, onClick: submit, children: [actionIcon, actionText] }), controls && _jsx(IconButton, { intent: 'secondary', label: (messages.swapReset ?? en.swapReset), disabled: pristine || submitting, onClick: reset, children: _jsx(SwapIcon, { name: 'reset' }) })] }), footer] }) : view === 'from' ? _jsx(SwapPicker, { side: view, onBack: back, tokens: fromTokens ?? tokens, loading: fromTokensLoading, chains: chainList, hotTokenIds: hotTokenIds, selected: from, onSelect: setFrom, wallet: wallet, onConnect: onConnect, onDisconnect: onDisconnect, receiving: isReceiving, onReceivingChange: receive ? setReceiving : undefined })
173
- : view === 'to' ? _jsx(SwapPicker, { side: view, onBack: back, tokens: tokens, chains: chainList, hotTokenIds: hotTokenIds, selected: to, onSelect: setTo, wallet: wallet, recipient: recipient, onRecipientChange: onRecipientChange, onScanRecipient: onScanRecipient })
174
- : _jsx(SwapSettings, { view: view, onViewChange: show, onBack: back, denomination: defaultMode, onDenominationChange: denominationSwitch ? changeDenomination : undefined, slippage: slippage, onSlippageChange: onSlippageChange, fee: fee, fees: fees, quoteLoading: quoteLoading, children: settings });
175
- return _jsxs("section", { ref: root, className: `hig-swap-panel${className ? ` ${className}` : ''}`, style: style, "data-view": view, "data-receiving": showReceive || undefined, onKeyDown: onKeyDown, onPaste: onPaste, children: [_jsx("div", { className: 'hig-swap-view', "data-direction": direction, children: body }, view), _jsx("p", { className: 'hig-sr-only', role: 'status', children: copied })] });
176
- }
177
- /** @deprecated Renamed `SwapPanelBlock`. The old name and the `blocks/swap-panel` and `recipes/swap-panel` import paths keep working until the next major release. */
178
- export const SwapPanel = SwapPanelBlock;