@bloxwap/hig 0.6.0 → 0.8.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 (286) 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 +45 -2
  31. package/contracts/dist/index.js +145 -4
  32. package/contracts/dist/invariants.d.ts +17 -0
  33. package/contracts/dist/invariants.js +24 -0
  34. package/contracts/dist/messages.d.ts +62 -2
  35. package/contracts/dist/messages.js +22 -2
  36. package/contracts/dist/number-flow.d.ts +90 -0
  37. package/contracts/dist/number-flow.js +150 -0
  38. package/contracts/dist/qr.d.ts +151 -0
  39. package/contracts/dist/qr.js +581 -0
  40. package/contracts/dist/toast.d.ts +168 -0
  41. package/contracts/dist/toast.js +171 -0
  42. package/feedback/README.md +1 -1
  43. package/feedback/dist/contract.js +1 -1
  44. package/feedback/dist/react.js +2 -4
  45. package/native/README.md +6 -1
  46. package/native/dist/account-block.d.ts +62 -7
  47. package/native/dist/account-block.js +54 -11
  48. package/native/dist/animated-number-model.d.ts +47 -1
  49. package/native/dist/animated-number-model.js +248 -21
  50. package/native/dist/animated-number.d.ts +41 -1
  51. package/native/dist/animated-number.js +165 -17
  52. package/native/dist/announce.d.ts +2 -0
  53. package/native/dist/announce.js +10 -0
  54. package/native/dist/asset-balance-row.d.ts +19 -1
  55. package/native/dist/asset-balance-row.js +24 -8
  56. package/native/dist/assets-block.d.ts +115 -0
  57. package/native/dist/assets-block.js +87 -0
  58. package/native/dist/async-result.d.ts +2 -0
  59. package/native/dist/async-result.js +11 -0
  60. package/native/dist/avatar-frame.d.ts +29 -0
  61. package/native/dist/avatar-frame.js +56 -0
  62. package/native/dist/avatar.d.ts +21 -0
  63. package/native/dist/avatar.js +31 -0
  64. package/native/dist/bar-mark.d.ts +16 -2
  65. package/native/dist/bar-mark.js +23 -7
  66. package/native/dist/bar-pnl.js +7 -5
  67. package/native/dist/blocks.d.ts +13 -14
  68. package/native/dist/blocks.js +10 -6
  69. package/native/dist/brand.js +2 -1
  70. package/native/dist/button.d.ts +7 -2
  71. package/native/dist/button.js +16 -4
  72. package/native/dist/checkbox.js +2 -1
  73. package/native/dist/confetti.d.ts +33 -0
  74. package/native/dist/confetti.js +143 -0
  75. package/native/dist/confirm-block.d.ts +98 -0
  76. package/native/dist/confirm-block.js +48 -0
  77. package/native/dist/data.d.ts +1 -1
  78. package/native/dist/data.js +8 -4
  79. package/native/dist/explainer-block.d.ts +91 -0
  80. package/native/dist/explainer-block.js +34 -0
  81. package/native/dist/field.d.ts +19 -5
  82. package/native/dist/field.js +56 -9
  83. package/native/dist/figure.d.ts +23 -0
  84. package/native/dist/figure.js +10 -0
  85. package/native/dist/gesture-sheet-model.d.ts +50 -0
  86. package/native/dist/gesture-sheet-model.js +105 -0
  87. package/native/dist/gesture-sheet-next.d.ts +82 -0
  88. package/native/dist/gesture-sheet-next.js +315 -0
  89. package/native/dist/gesture-sheet.d.ts +5 -1
  90. package/native/dist/gesture-sheet.js +13 -6
  91. package/native/dist/icons.d.ts +9 -6
  92. package/native/dist/icons.js +25 -24
  93. package/native/dist/language-block.d.ts +14 -1
  94. package/native/dist/language-block.js +11 -4
  95. package/native/dist/list-group.d.ts +44 -8
  96. package/native/dist/list-group.js +84 -13
  97. package/native/dist/manage-position-block.d.ts +35 -2
  98. package/native/dist/manage-position-block.js +41 -11
  99. package/native/dist/market-row.d.ts +46 -0
  100. package/native/dist/market-row.js +41 -0
  101. package/native/dist/navigation.js +5 -3
  102. package/native/dist/notifications-block.d.ts +30 -2
  103. package/native/dist/notifications-block.js +16 -8
  104. package/native/dist/number-format.d.ts +6 -0
  105. package/native/dist/number-format.js +9 -0
  106. package/native/dist/pickers.d.ts +32 -2
  107. package/native/dist/pickers.js +17 -9
  108. package/native/dist/position-block.d.ts +66 -10
  109. package/native/dist/position-block.js +45 -11
  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 +38 -5
  115. package/native/dist/profile-block.js +31 -6
  116. package/native/dist/provider.d.ts +14 -5
  117. package/native/dist/provider.js +32 -6
  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 +23 -5
  121. package/native/dist/radio-group.js +40 -12
  122. package/native/dist/recipes.d.ts +6 -0
  123. package/native/dist/recipes.js +6 -0
  124. package/native/dist/reward-block.d.ts +55 -13
  125. package/native/dist/reward-block.js +37 -14
  126. package/native/dist/screen-header.d.ts +59 -0
  127. package/native/dist/screen-header.js +37 -0
  128. package/native/dist/select.js +4 -2
  129. package/native/dist/selection.d.ts +3 -2
  130. package/native/dist/selection.js +1 -0
  131. package/native/dist/setting-header.d.ts +2 -8
  132. package/native/dist/setting-header.js +2 -11
  133. package/native/dist/setting-switch.d.ts +15 -2
  134. package/native/dist/setting-switch.js +11 -4
  135. package/native/dist/signals-block.d.ts +26 -2
  136. package/native/dist/signals-block.js +14 -4
  137. package/native/dist/slider.js +5 -1
  138. package/native/dist/sound-haptics-block.d.ts +29 -2
  139. package/native/dist/sound-haptics-block.js +19 -8
  140. package/native/dist/status.d.ts +47 -14
  141. package/native/dist/status.js +39 -22
  142. package/native/dist/sticky-header.d.ts +28 -0
  143. package/native/dist/sticky-header.js +29 -0
  144. package/native/dist/surface.d.ts +3 -1
  145. package/native/dist/surface.js +2 -1
  146. package/native/dist/swap-amount-card.d.ts +57 -0
  147. package/native/dist/swap-amount-card.js +31 -0
  148. package/native/dist/swap-panel-block.d.ts +11 -4
  149. package/native/dist/swap-panel-block.js +67 -38
  150. package/native/dist/swap-parts.d.ts +5 -10
  151. package/native/dist/swap-parts.js +22 -24
  152. package/native/dist/swap-shared.d.ts +8 -2
  153. package/native/dist/swap-shared.js +10 -6
  154. package/native/dist/swap-views.js +6 -4
  155. package/native/dist/switch-row.d.ts +3 -2
  156. package/native/dist/switch-row.js +5 -3
  157. package/native/dist/switch.d.ts +4 -2
  158. package/native/dist/switch.js +3 -3
  159. package/native/dist/target-block.d.ts +40 -7
  160. package/native/dist/target-block.js +31 -11
  161. package/native/dist/toast.d.ts +47 -0
  162. package/native/dist/toast.js +386 -0
  163. package/native/dist/token-action-block.d.ts +26 -9
  164. package/native/dist/token-action-block.js +21 -8
  165. package/native/dist/trade-history-detail-block.d.ts +26 -1
  166. package/native/dist/trade-history-detail-block.js +17 -9
  167. package/native/dist/trade-history-list-block.d.ts +71 -5
  168. package/native/dist/trade-history-list-block.js +55 -17
  169. package/native/dist/wallet-address-core.d.ts +25 -0
  170. package/native/dist/wallet-address-core.js +34 -0
  171. package/native/dist/wallet-address.d.ts +6 -10
  172. package/native/dist/wallet-address.js +16 -20
  173. package/native-fonts/README.md +1 -1
  174. package/og-fonts/README.md +1 -1
  175. package/package.json +131 -2
  176. package/react/README.md +3 -1
  177. package/react/dist/animated-number-flow.d.ts +72 -0
  178. package/react/dist/animated-number-flow.js +316 -0
  179. package/react/dist/animated-number-model.d.ts +24 -0
  180. package/react/dist/animated-number-model.js +106 -3
  181. package/react/dist/animated-number.d.ts +49 -1
  182. package/react/dist/animated-number.js +146 -11
  183. package/react/dist/asset-balance-row.d.ts +19 -1
  184. package/react/dist/asset-balance-row.js +17 -3
  185. package/react/dist/async-result.d.ts +2 -0
  186. package/react/dist/async-result.js +11 -0
  187. package/react/dist/avatar.d.ts +25 -0
  188. package/react/dist/avatar.js +50 -0
  189. package/react/dist/bar-mark.d.ts +5 -2
  190. package/react/dist/bar-mark.js +5 -3
  191. package/react/dist/blocks/account-block.d.ts +57 -7
  192. package/react/dist/blocks/account-block.js +51 -11
  193. package/react/dist/blocks/assets-block.d.ts +106 -0
  194. package/react/dist/blocks/assets-block.js +135 -0
  195. package/react/dist/blocks/confirm-block.d.ts +91 -0
  196. package/react/dist/blocks/confirm-block.js +31 -0
  197. package/react/dist/blocks/explainer-block.d.ts +80 -0
  198. package/react/dist/blocks/explainer-block.js +20 -0
  199. package/react/dist/blocks/install-command.js +3 -1
  200. package/react/dist/blocks/language-block.d.ts +9 -1
  201. package/react/dist/blocks/language-block.js +8 -6
  202. package/react/dist/blocks/manage-position-block.d.ts +30 -2
  203. package/react/dist/blocks/manage-position-block.js +23 -4
  204. package/react/dist/blocks/market-row.d.ts +20 -9
  205. package/react/dist/blocks/market-row.js +17 -4
  206. package/react/dist/blocks/notifications-block.d.ts +27 -2
  207. package/react/dist/blocks/notifications-block.js +11 -2
  208. package/react/dist/blocks/pickers.d.ts +30 -1
  209. package/react/dist/blocks/pickers.js +32 -10
  210. package/react/dist/blocks/position-block.d.ts +34 -11
  211. package/react/dist/blocks/position-block.js +16 -5
  212. package/react/dist/blocks/preset-picker-block.d.ts +85 -0
  213. package/react/dist/blocks/preset-picker-block.js +19 -0
  214. package/react/dist/blocks/profile-block.d.ts +33 -6
  215. package/react/dist/blocks/profile-block.js +31 -6
  216. package/react/dist/blocks/reward-block.d.ts +65 -21
  217. package/react/dist/blocks/reward-block.js +24 -11
  218. package/react/dist/blocks/screen-header.d.ts +34 -2
  219. package/react/dist/blocks/screen-header.js +17 -6
  220. package/react/dist/blocks/setting-switch.d.ts +14 -1
  221. package/react/dist/blocks/setting-switch.js +11 -4
  222. package/react/dist/blocks/signals-block.d.ts +23 -2
  223. package/react/dist/blocks/signals-block.js +6 -5
  224. package/react/dist/blocks/sound-haptics-block.d.ts +27 -3
  225. package/react/dist/blocks/sound-haptics-block.js +11 -7
  226. package/react/dist/blocks/sticky-header.d.ts +19 -0
  227. package/react/dist/blocks/sticky-header.js +103 -0
  228. package/react/dist/blocks/swap/amount-card.js +2 -1
  229. package/react/dist/blocks/swap/settings.js +4 -3
  230. package/react/dist/blocks/swap/shared.d.ts +29 -23
  231. package/react/dist/blocks/swap/shared.js +36 -32
  232. package/react/dist/blocks/swap-panel-block.d.ts +12 -3
  233. package/react/dist/blocks/swap-panel-block.js +72 -37
  234. package/react/dist/blocks/target-block.d.ts +35 -7
  235. package/react/dist/blocks/target-block.js +26 -12
  236. package/react/dist/blocks/token-action-block.d.ts +21 -8
  237. package/react/dist/blocks/token-action-block.js +9 -6
  238. package/react/dist/blocks/trade-history-detail-block.d.ts +23 -1
  239. package/react/dist/blocks/trade-history-detail-block.js +5 -4
  240. package/react/dist/blocks/trade-history-list-block.d.ts +31 -5
  241. package/react/dist/blocks/trade-history-list-block.js +20 -10
  242. package/react/dist/blocks.d.ts +12 -8
  243. package/react/dist/blocks.js +6 -2
  244. package/react/dist/brand.js +2 -1
  245. package/react/dist/button.d.ts +9 -3
  246. package/react/dist/button.js +12 -5
  247. package/react/dist/confetti.d.ts +27 -0
  248. package/react/dist/confetti.js +240 -0
  249. package/react/dist/data.js +11 -4
  250. package/react/dist/field.d.ts +20 -5
  251. package/react/dist/field.js +30 -8
  252. package/react/dist/figure.d.ts +23 -0
  253. package/react/dist/figure.js +12 -0
  254. package/react/dist/gesture-sheet.d.ts +15 -1
  255. package/react/dist/gesture-sheet.js +53 -8
  256. package/react/dist/list-group.d.ts +41 -8
  257. package/react/dist/list-group.js +49 -13
  258. package/react/dist/navigation.js +11 -3
  259. package/react/dist/overlay.d.ts +28 -3
  260. package/react/dist/overlay.js +29 -3
  261. package/react/dist/preset-group.d.ts +30 -0
  262. package/react/dist/preset-group.js +13 -0
  263. package/react/dist/provider.d.ts +42 -5
  264. package/react/dist/provider.js +84 -10
  265. package/react/dist/qr-code.d.ts +32 -0
  266. package/react/dist/qr-code.js +28 -0
  267. package/react/dist/select.js +10 -3
  268. package/react/dist/selection.d.ts +18 -4
  269. package/react/dist/selection.js +20 -10
  270. package/react/dist/slider.js +5 -1
  271. package/react/dist/status.d.ts +14 -10
  272. package/react/dist/status.js +17 -9
  273. package/react/dist/styles.css +380 -150
  274. package/react/dist/surface.d.ts +5 -1
  275. package/react/dist/surface.js +1 -1
  276. package/react/dist/toast.d.ts +19 -12
  277. package/react/dist/toast.js +29 -7
  278. package/react/dist/wallet-address-core.d.ts +27 -0
  279. package/react/dist/wallet-address-core.js +29 -0
  280. package/react/dist/wallet-address.d.ts +6 -12
  281. package/react/dist/wallet-address.js +5 -16
  282. package/tokens/README.md +2 -2
  283. package/tokens/dist/index.d.ts +16 -0
  284. package/tokens/dist/index.js +16 -0
  285. package/tokens/dist/manifest.json +8 -0
  286. package/tokens/dist/tokens.css +6 -0
@@ -31,6 +31,8 @@ export interface SwapDetail {
31
31
  options?: Intl.NumberFormatOptions;
32
32
  prefix?: string;
33
33
  suffix?: string;
34
+ /** With a number `value`: host-formatted text drawn and read in place of Intl's, still moving place by place. */
35
+ formattedValue?: string;
34
36
  }
35
37
  /** The receive view: the host's address and its rendered QR code. HIG ships no QR encoder. */
36
38
  export interface SwapReceive {
@@ -83,7 +85,10 @@ export interface SwapPanelBlockProps {
83
85
  onReceivingChange?: (receiving: boolean) => void;
84
86
  /** The host validates, quotes and executes. HIG never submits a transaction. */
85
87
  onSubmit: (action: SwapAction) => void;
88
+ /** The host's submit is in flight: the action shows a spinner and ignores presses, the keypad, typed keys, Max and Test leave the amount as it is, and the action keeps its ready name (or `submittingLabel`, or a held action's `actionStatus`) even when the host has cleared the amount meanwhile, never “Enter an amount” or the balance check. */
86
89
  submitting?: boolean;
90
+ /** What the action says while `submitting`, in place of its ready name: Burning…. Host text. */
91
+ submittingLabel?: string;
87
92
  /** Called after the panel clears its entry and both tokens (through `onFromChange(null)` / `onToChange(null)`), so the host can drop its quote. */
88
93
  onReset?: () => void;
89
94
  /** `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. */
@@ -95,9 +100,11 @@ export interface SwapPanelBlockProps {
95
100
  /** A line under the cards: a limit, a delay, a warning. `noteTone` tints it. */
96
101
  note?: React.ReactNode;
97
102
  noteTone?: 'muted' | 'warning' | 'negative';
98
- /** Heading above the cards, for a panel that is its own screen or sheet (“Withdraw from Papertrade”). `onBack` adds a Back control beside it. */
103
+ /** Heading above the cards, for a panel that is its own screen or sheet (“Withdraw from Papertrade”), drawn as the shared `ScreenHeader` (the title centred in a 44px row) like every other block. `onBack` adds Back on its leading edge. */
99
104
  title?: string;
100
105
  onBack?: () => void;
106
+ /** With `title`: `id` of the heading, so a host dialog or sheet can name itself with `aria-labelledby`. */
107
+ headingId?: string;
101
108
  /** `false` leaves the action button on its own, full width: no settings and no reset button. */
102
109
  controls?: boolean;
103
110
  /** Decoration before the action text. */
@@ -109,7 +116,7 @@ export interface SwapPanelBlockProps {
109
116
  actionLabel?: string;
110
117
  /** Holds the action for a reason only the host knows: below a minimum, no quote yet, a closed market. The panel's own checks (a token, an amount, the balance) still apply first. */
111
118
  actionDisabled?: boolean;
112
- /** What the held action says, for example “Below minimum”. Without it the action keeps its ready name. */
119
+ /** What the held action says, for example “Below minimum” or, while `submitting`, “Signing…” (a `submittingLabel` wins over it). Without it the action keeps its ready name. */
113
120
  actionStatus?: string;
114
121
  /** `destructive` for an action that cannot be undone, such as a burn. */
115
122
  actionIntent?: 'primary' | 'destructive';
@@ -127,6 +134,8 @@ export interface SwapPanelBlockProps {
127
134
  shortcuts?: boolean;
128
135
  /** Digits typed anywhere on the page (outside a text field) drive the amount, not only inside the panel. */
129
136
  captureKeyboard?: boolean;
137
+ /** Disable global shortcuts and amount capture while a retained screen is inactive. */
138
+ active?: boolean;
130
139
  /** 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. */
131
140
  view?: SwapView;
132
141
  onViewChange?: (view: SwapView) => void;
@@ -140,7 +149,7 @@ export interface SwapPanelBlockProps {
140
149
  * or token units, token pickers, settings, and one action that names itself from the chosen pair.
141
150
  * Presentation only. The host owns tokens, balances, prices, the quote, the wallet and the transaction.
142
151
  */
143
- export declare function SwapPanelBlock({ 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, actionDisabled, actionStatus, actionIntent, limitToBalance, banner, footer, oneWay: oneWayProp, denominationSwitch, keypad, shortcuts, captureKeyboard, view: viewProp, onViewChange, settings, className, style }: SwapPanelBlockProps): React.JSX.Element;
152
+ export declare function SwapPanelBlock({ 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, submittingLabel, onReset, destination, details, note, noteTone, title, onBack, headingId, controls, actionIcon, lockFrom, lockTo, actionLabel, actionDisabled, actionStatus, actionIntent, limitToBalance, banner, footer, oneWay: oneWayProp, denominationSwitch, keypad, shortcuts, captureKeyboard, active, view: viewProp, onViewChange, settings, className, style }: SwapPanelBlockProps): React.JSX.Element;
144
153
  /** @deprecated Renamed `SwapPanelBlock`. The old name and the `blocks/swap-panel` and `recipes/swap-panel` import paths keep working until the next major release. */
145
154
  export declare const SwapPanel: typeof SwapPanelBlock;
146
155
  /** @deprecated Renamed `SwapPanelBlockProps`. */
@@ -1,18 +1,28 @@
1
1
  "use client";
2
2
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { decimal, decimalDivide, decimalCompare, localizeDecimal } from '@bloxwap/hig/contracts';
4
+ import { useAsyncResult } from '../async-result.js';
3
5
  import { useEffect, useMemo, useRef, useState } from 'react';
4
6
  import * as en from '@bloxwap/hig/contracts/messages';
5
- import { useControllable, useHIG } from '../provider.js';
7
+ import { PressDecoration, useControllable, useHIG, useNumberLocale } from '../provider.js';
6
8
  import { Button, IconButton } from '../button.js';
7
9
  import { AnimatedNumberReadout } from '../animated-number.js';
8
10
  import { notify } from '../notify.js';
9
11
  import { VerticalAddress } from '../data.js';
10
12
  import { SwapPicker } from './swap/picker.js';
13
+ import { ScreenHeader } from './screen-header.js';
11
14
  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';
15
+ import { SwapIcon, SwapKeypad, SwapNumber, SwapPill, percentNumber, swapArt, swapFigure, usdNumber, addressGradient, applyAmountKey, chainsOf, parentView, sanitizeAmount, shortAddress, swapAction, testAmount, unitsToEntry } from './swap/shared.js';
13
16
  export { swapAction } from './swap/shared.js';
14
17
  export { SwapAmountCard } from './swap/amount-card.js';
15
18
  export { SwapPill, SwapKeypad, SwapNumber } from './swap/shared.js';
19
+ const visiblePanel = (node) => { for (let el = node; el; el = el.parentElement) {
20
+ const style = getComputedStyle(el);
21
+ if (style.display === 'none' || style.visibility === 'hidden')
22
+ return false;
23
+ } return true; };
24
+ const keyboardPanels = new Set();
25
+ const ownsKeyboard = (node) => { const visible = [...keyboardPanels].filter(el => el.isConnected && !el.closest('[hidden],[inert],[aria-hidden=true]') && visiblePanel(el)); return !!node && (visible.find(el => el.contains(document.activeElement)) ?? visible.at(-1)) === node; };
16
26
  const textTarget = (target) => { const element = target; return !!element && (/^(INPUT|TEXTAREA|SELECT)$/.test(element.tagName) || element.isContentEditable); };
17
27
  const amountKey = (event) => event.metaKey || event.ctrlKey || event.altKey ? null : /^[0-9.]$/.test(event.key) ? event.key : event.key === 'Backspace' ? 'back' : null;
18
28
  /**
@@ -20,14 +30,16 @@ const amountKey = (event) => event.metaKey || event.ctrlKey || event.altKey ? nu
20
30
  * or token units, token pickers, settings, and one action that names itself from the chosen pair.
21
31
  * Presentation only. The host owns tokens, balances, prices, the quote, the wallet and the transaction.
22
32
  */
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 }) {
33
+ 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, submittingLabel, onReset, destination, details, note, noteTone = 'muted', title, onBack, headingId, 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, active = true, view: viewProp, onViewChange, settings, className, style }) {
24
34
  const { messages } = useHIG();
35
+ const locale = useNumberLocale();
25
36
  const [from, setFrom] = useControllable(fromProp, defaultFrom, onFromChange);
26
37
  const [to, setTo] = useControllable(toProp, defaultTo, onToChange);
38
+ const boundedUnits = (raw) => { const canonical = decimal(raw, from?.decimals ?? 100); return limitToBalance && from?.balance != null && Number.isFinite(from.balance) && from.balance >= 0 && decimalCompare(canonical, from.balance) > 0 ? decimal(from.balance, from?.decimals ?? 100) : canonical; };
27
39
  const [defaultMode, setDefaultMode] = useControllable(denomination, 'usd', onDenominationChange);
28
40
  const [isReceiving, setReceiving] = useControllable(receiving, false, onReceivingChange);
29
41
  // 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));
42
+ const [entry, setEntry] = useState(() => amount === undefined ? '0' : unitsToEntry(boundedUnits(amount), defaultMode, from?.price ?? 0));
31
43
  const [fromMode, applyFromMode] = useState(defaultMode);
32
44
  const [toMode, applyToMode] = useState(defaultMode);
33
45
  const [view, show] = useControllable(viewProp, 'main', onViewChange);
@@ -52,7 +64,9 @@ export function SwapPanelBlock({ tokens, fromTokens, fromTokensLoading, chains,
52
64
  return () => coarse?.removeEventListener('change', update);
53
65
  }, []);
54
66
  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);
67
+ const exact = useRef(amount === undefined ? null : { entry, mode: fromMode, units: boundedUnits(amount), asset: from?.id });
68
+ const unitsText = exact.current && exact.current.entry === entry && exact.current.mode === fromMode && exact.current.asset === from?.id ? exact.current.units : fromMode === 'token' ? decimal(entry, from?.decimals ?? 100) : decimalDivide(entry, fromPrice, from?.decimals ?? 18);
69
+ const units = Number(unitsText), usd = units * fromPrice;
56
70
  const showReceive = isReceiving && !!receive;
57
71
  // Report the amount in token units; resync the entry when the host sets a different amount.
58
72
  const reported = useRef(amount ?? '0');
@@ -60,19 +74,22 @@ export function SwapPanelBlock({ tokens, fromTokens, fromTokensLoading, chains,
60
74
  reported.current = unitsText;
61
75
  onAmountChange?.(unitsText);
62
76
  } }, [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;
77
+ useEffect(() => { if (amount === undefined || boundedUnits(amount) === reported.current)
78
+ return; const canonical = boundedUnits(amount), next = unitsToEntry(canonical, fromMode, fromPrice); reported.current = canonical; if (decimal(amount) !== canonical)
79
+ onAmountChange?.(canonical); exact.current = { entry: next, mode: fromMode, units: canonical, asset: from?.id }; setEntry(next); }, [amount]);
80
+ const sameAsset = !!from && !!to && swapAction(from, to) === 'send';
66
81
  const receivedUnits = sameAsset ? units : received ?? (toPrice > 0 ? usd / toPrice : 0);
67
82
  const receivedUsd = toPrice > 0 ? receivedUnits * toPrice : sameAsset ? usd : 0;
68
83
  const action = swapAction(from, to);
69
- const insufficient = !!from && (from.balance ?? 0) > 0 && units > (from.balance ?? 0);
84
+ const insufficient = !!from && from.balance != null && (!Number.isFinite(from.balance) || from.balance < 0 || decimalCompare(unitsText, from.balance) > 0);
70
85
  // A destination or a details card stands in for the To token: one way, and ready from the From side alone.
71
86
  const fixed = !!destination || (!!details && !to);
72
87
  const oneWay = oneWayProp || fixed;
73
- const eligible = !!from && (!!to || fixed) && !destination?.pending && units > 0 && !insufficient;
88
+ const eligible = !!from && (!!to || fixed) && !destination?.pending && Number.isFinite(units) && units > 0 && !insufficient;
74
89
  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);
90
+ const readyText = actionLabel ?? (action === 'swap' && !fixed ? messages.swapActionSwap ?? en.swapActionSwap : action === 'bridge' && !fixed ? messages.swapActionBridge ?? en.swapActionBridge : messages.swapActionSend ?? en.swapActionSend);
91
+ // While the host's submit is in flight the amount may already be cleared: the action keeps its name rather than asking for an amount.
92
+ const actionText = showReceive ? (messages.swapSendFromWallet ?? en.swapSendFromWallet) : !from || (!to && !fixed) ? (messages.swapChooseToken ?? en.swapChooseToken) : destination?.pending ? (messages.swapChooseDestination ?? en.swapChooseDestination) : submitting ? submittingLabel ?? (actionDisabled && actionStatus ? actionStatus : readyText) : units <= 0 ? (messages.swapEnterAmount ?? en.swapEnterAmount) : insufficient ? (messages.swapInsufficient ?? en.swapInsufficient)(from.symbol) : actionDisabled && actionStatus ? actionStatus : readyText;
76
93
  const pristine = (lockFrom || !from) && (lockTo || !to) && input === 0;
77
94
  // Updater form: several keys can land before the next render, and each must build on the last.
78
95
  const latest = useRef(fromMode);
@@ -80,26 +97,34 @@ export function SwapPanelBlock({ tokens, fromTokens, fromTokensLoading, chains,
80
97
  const latestView = useRef(view);
81
98
  latestView.current = view;
82
99
  // 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; });
100
+ const limits = useRef({ decimals: from?.decimals, balance: from?.balance, price: fromPrice, cap: limitToBalance });
101
+ limits.current = { decimals: from?.decimals, balance: from?.balance, price: fromPrice, cap: limitToBalance };
102
+ const over = (next) => { const { balance, price, cap } = limits.current; if (!cap || balance == null)
103
+ return false; if (!Number.isFinite(balance) || balance < 0)
104
+ return true; const value = latest.current === 'token' ? next : decimalDivide(next, price, limits.current.decimals ?? 18); return decimalCompare(value, balance) > 0; };
105
+ // While the host's submit is in flight the keypad, typed keys, a paste, Max and Test leave the amount as it is.
106
+ const typed = next => { if (!submitting)
107
+ setEntry(current => { const value = typeof next === 'function' ? next(current) : next; if (value === current || value.length > 1000)
108
+ return current; const normalized = decimal(value, latest.current === 'usd' ? 2 : limits.current.decimals ?? 100); if (over(normalized))
109
+ return current; exact.current = null; const [whole, fraction] = value.split('.'); const places = latest.current === 'usd' ? 2 : limits.current.decimals ?? 100; return fraction === undefined ? whole : places > 0 ? whole + '.' + fraction.slice(0, places) : whole; }); };
110
+ const press = (key) => typed(current => { const next = applyAmountKey(current, key, latest.current, limits.current.decimals); return key !== 'back' && over(next) ? current : next; });
88
111
  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); };
112
+ return false; const next = sanitizeAmount(clean); typed(next); return true; };
113
+ const switchFromMode = (mode) => { if (submitting || mode === fromMode)
114
+ return; const next = unitsToEntry(unitsText, mode, fromPrice); exact.current = { entry: next, mode, units: unitsText, asset: from?.id }; setEntry(next); applyFromMode(mode); };
115
+ const changeDenomination = (mode) => { if (submitting)
116
+ return; setDefaultMode(mode); switchFromMode(mode); applyToMode(mode); };
93
117
  // A new default applies to an untouched entry at once; a typed amount keeps its denomination until reset.
94
118
  useEffect(() => { if (input === 0) {
95
119
  applyFromMode(defaultMode);
96
120
  applyToMode(defaultMode);
97
121
  } }, [defaultMode]);
98
- const reset = () => { setEntry('0'); applyFromMode(defaultMode); applyToMode(defaultMode); if (isReceiving)
122
+ const reset = () => { if (submitting)
123
+ return; exact.current = null; setEntry('0'); applyFromMode(defaultMode); applyToMode(defaultMode); if (isReceiving)
99
124
  setReceiving(false); if (!lockFrom)
100
125
  setFrom(null); if (!lockTo)
101
126
  setTo(null); onReset?.(); };
102
- const flip = () => { if (!from || !to)
127
+ const flip = () => { if (submitting || !from || !to)
103
128
  return; setFrom(to); setTo(from); };
104
129
  const submit = () => { if (submitting)
105
130
  return; if (showReceive) {
@@ -107,12 +132,19 @@ export function SwapPanelBlock({ tokens, fromTokens, fromTokensLoading, chains,
107
132
  return;
108
133
  } if (ready)
109
134
  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('')); };
135
+ const beginCopy = useAsyncResult(receive?.address);
136
+ const copyAddress = () => { const current = beginCopy(); if (!receive?.onCopy)
137
+ return; Promise.resolve().then(receive.onCopy).then(() => { if (!current())
138
+ return; 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(() => { if (current())
139
+ setCopied(''); }); };
140
+ useEffect(() => { const node = root.current; if (!active || (!shortcuts && !captureKeyboard) || !node)
141
+ return; keyboardPanels.add(node); return () => { keyboardPanels.delete(node); }; }, [active, shortcuts, captureKeyboard]);
112
142
  useEffect(() => {
113
- if (!shortcuts && !captureKeyboard)
143
+ if (!active || (!shortcuts && !captureKeyboard))
114
144
  return;
115
145
  const onKeyDown = (event) => {
146
+ if (submitting || event.defaultPrevented || !ownsKeyboard(root.current))
147
+ return;
116
148
  const key = event.key.toLowerCase();
117
149
  if (shortcuts && (event.metaKey || event.ctrlKey) && !event.altKey && !event.shiftKey && (key === 'f' || key === 'k')) {
118
150
  const side = key === 'f' ? 'from' : 'to';
@@ -130,12 +162,12 @@ export function SwapPanelBlock({ tokens, fromTokens, fromTokensLoading, chains,
130
162
  press(pressed);
131
163
  }
132
164
  };
133
- const onPaste = (event) => { if (captureKeyboard && !event.defaultPrevented && !textTarget(event.target) && paste(event.clipboardData?.getData('text') ?? ''))
165
+ const onPaste = (event) => { if (!submitting && ownsKeyboard(root.current) && captureKeyboard && !event.defaultPrevented && !textTarget(event.target) && paste(event.clipboardData?.getData('text') ?? ''))
134
166
  event.preventDefault(); };
135
167
  window.addEventListener('keydown', onKeyDown);
136
168
  document.addEventListener('paste', onPaste);
137
169
  return () => { window.removeEventListener('keydown', onKeyDown); document.removeEventListener('paste', onPaste); };
138
- }, [shortcuts, captureKeyboard, lockFrom, lockTo, fixed]);
170
+ });
139
171
  // Keys typed while focus is inside the cards drive the amount; in a pushed view Escape pops it.
140
172
  const inPanel = (event) => view === 'main' && !textTarget(event.target);
141
173
  const onKeyDown = (event) => { if (view !== 'main' && event.key === 'Escape') {
@@ -155,24 +187,27 @@ export function SwapPanelBlock({ tokens, fromTokens, fromTokensLoading, chains,
155
187
  const feeLine = quoteLoading || fee == null ? (messages.swapFee ?? en.swapFee)(quoteLoading ? '…' : '—') : _jsx(SwapNumber, { template: messages.swapFee ?? en.swapFee, ...usdNumber(fee) });
156
188
  const fraction = entry.includes('.') ? Math.min(entry.length - entry.indexOf('.') - 1, fromMode === 'usd' ? 2 : 8) : 0;
157
189
  // 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 ? _jsx("button", { type: 'button', className: 'hig-swap-receive', "aria-label": (messages.copyAddress ?? en.copyAddress) + ': ' + view.address, onClick: copyAddress, children: content }) : _jsx("div", { className: 'hig-swap-receive', children: content }); };
190
+ 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, { disabled: submitting, onClick: () => typed(unitsToEntry(token.balance ?? 0, fromMode, fromPrice)), children: (messages.swapMax ?? en.swapMax) }) })] });
191
+ 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, { disabled: submitting, onClick: () => typed(unitsToEntry(testAmount(token), fromMode, fromPrice)), children: [_jsx(SwapIcon, { name: 'flask', size: 14 }), (messages.swapTest ?? en.swapTest)] }), _jsx(SwapPill, { disabled: submitting, onClick: () => typed(unitsToEntry(token.balance ?? 0, fromMode, fromPrice)), children: (messages.swapMax ?? en.swapMax) })] }), _jsx(SwapNumber, { value: token.balance, suffix: ' ' + token.symbol, options: { maximumFractionDigits: 6 } })] })
192
+ : _jsxs("span", { className: 'hig-swap-meta', children: [_jsxs(SwapPill, { disabled: submitting, 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 })] })] });
193
+ 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
194
  const card = (side) => {
163
195
  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
196
  const cardUnits = side === 'from' ? units : receivedUnits, cardUsd = side === 'from' ? usd : receivedUsd;
165
197
  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) }), _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) }), _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 })] })] })] })] });
198
+ 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', disabled: submitting, 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) :
199
+ !(side === 'to' && showReceive) && _jsxs("div", { className: 'hig-swap-amount-area', children: [!locked && _jsx("button", { type: 'button', disabled: submitting, 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, formattedValue: side === 'from' && mode === 'token' ? localizeDecimal(entry, locale) : undefined, label: side === 'to' ? (messages.swapAmount ?? en.swapAmount)(label) : undefined, prefix: mode === 'usd' ? '$' : '', suffix: side === 'from' && mode === 'usd' && entry.endsWith('.') ? '.' : '', options: { minimumFractionDigits: side === 'from' ? fraction : 0, maximumFractionDigits: mode === 'usd' ? 2 : 8, useGrouping: false } }) }), denominationSwitch && _jsxs(SwapPill, { disabled: submitting, "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
200
  };
169
201
  // 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 }), _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 }) : row.value })] }, row.label)) })] });
202
+ 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', disabled: submitting, 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
203
  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 && _jsx("button", { type: 'button', className: 'hig-swap-back', "aria-label": messages.back ?? en.back, onClick: onBack, children: _jsx(SwapIcon, { name: '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 }) }) : _jsx("button", { type: 'button', "aria-label": (messages.swapFlip ?? en.swapFlip), disabled: !from || !to, onClick: flip, children: _jsx(SwapIcon, { name: 'flip', size: 16 }) }) }), 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 })
204
+ const body = view === 'main' ? _jsxs(_Fragment, { children: [title && _jsx(ScreenHeader, { title: title, onBack: onBack, headingId: headingId }), 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: submitting || !from || !to, onClick: flip, children: [_jsx(SwapIcon, { name: 'flip', size: 16 }), _jsx(PressDecoration, { kind: 'icon-button', disabled: submitting || !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, { disabled: submitting, 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: submitting ? undefined : onConnect, onDisconnect: submitting ? undefined : onDisconnect, receiving: isReceiving, onReceivingChange: receive ? setReceiving : undefined })
205
+ : 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: submitting ? undefined : onScanRecipient })
174
206
  : _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 })] });
207
+ return _jsxs("section", { ref: root, className: `hig-swap-panel${className ? ` ${className}` : ''}`, style: style, onClickCapture: event => { if (submitting) {
208
+ event.preventDefault();
209
+ event.stopPropagation();
210
+ } }, "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
211
  }
177
212
  /** @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
213
  export const SwapPanel = SwapPanelBlock;
@@ -23,6 +23,8 @@ export interface TargetBlockLabels {
23
23
  custom: string;
24
24
  /** Accessible name of the info button that shows `note`: How this order fills. Without it the note is always shown. */
25
25
  info?: string;
26
+ /** Accessible name of the quick choices' group, not drawn: Quick targets. Defaults to `title`. */
27
+ presets?: string;
26
28
  }
27
29
  export interface TargetBlockProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
28
30
  kind: TargetKind;
@@ -37,16 +39,18 @@ export interface TargetBlockProps extends Omit<React.HTMLAttributes<HTMLElement>
37
39
  /** Price the order triggers at. Defaults to `value` when the unit is `price`; otherwise unknown until the host supplies it. */
38
40
  trigger?: number | null;
39
41
  unit: TargetUnit;
40
- /** Units offered, in order. Defaults to all three; one unit hides the control. */
41
- units?: readonly TargetUnit[];
42
+ /** Units offered, in order. Defaults to all three; one unit hides the control. `{unit, disabled}` shows a unit that cannot be chosen now, dimmed. */
43
+ units?: readonly (TargetUnit | TargetUnitOption)[];
42
44
  onUnitChange?: (unit: TargetUnit) => void;
43
45
  /** The target in the current unit: signed dollars (2, -0.5), a price, or a signed fraction (0.05 reads +5%). `null` reads as unknown and disables the confirming action. */
44
46
  value: number | null;
45
47
  onValueChange?: (value: number) => void;
46
- /** Quick choices in the current unit. The one equal to `value` is shown selected. */
47
- presets?: readonly number[];
48
+ /** Quick choices in the current unit. The one equal to `value` is shown selected. `{value, disabled}` shows a choice that cannot be taken now, dimmed. */
49
+ presets?: readonly (number | TargetPreset)[];
48
50
  /** Shows the Custom row; the host opens its own entry. */
49
51
  onCustom?: () => void;
52
+ /** The value the host's own entry set, in the current unit. The Custom row then shows it on its trailing edge and reads as selected, and no quick choice does. Has no effect without `onCustom`; null keeps the row a toggle that reads as not selected. */
53
+ customValue?: number | null;
50
54
  /** Format of prices. Defaults to US dollars. */
51
55
  priceOptions?: Intl.NumberFormatOptions;
52
56
  /** Set true to draw the prices inside a card: a surface fill, padding and radius. By default the title row, bar and readouts sit directly on the screen. */
@@ -58,10 +62,34 @@ export interface TargetBlockProps extends Omit<React.HTMLAttributes<HTMLElement>
58
62
  /** Shows Cancel beside the confirming action. */
59
63
  onCancel?: () => void;
60
64
  onBack?: () => void;
61
- /** A control on the trailing edge of the header, usually an `IconButton`. It takes the place of the info button, and the note is then always shown. */
65
+ /** A control on the trailing edge of the header, usually an `IconButton`. It takes the place of the info button, and the note is then always shown, unless `headerActionBesideInfo` is set. */
62
66
  headerAction?: React.ReactNode;
67
+ /** Set true to keep the info button when `headerAction` is given: the info button comes first and `headerAction` sits on the trailing edge. */
68
+ headerActionBesideInfo?: boolean;
69
+ /** `id` of the heading, so a dialog or sheet can name itself with `aria-labelledby`. */
70
+ headingId?: string;
71
+ /** Pins the header to the top of the nearest scrolling container, transparent at rest and filled with `--hig-sticky-header-background` once content scrolls under it. */
72
+ stickyHeader?: boolean;
63
73
  }
64
- /** Number format of a target in a unit. Dollars and percents carry their sign; `short` drops the cents of a whole dollar amount, for a preset. */
74
+ /** A quick choice that can be shown dimmed. */
75
+ export interface TargetPreset {
76
+ value: number;
77
+ disabled?: boolean;
78
+ }
79
+ /** A unit that can be shown dimmed. */
80
+ export interface TargetUnitOption {
81
+ unit: TargetUnit;
82
+ disabled?: boolean;
83
+ }
84
+ /** The quick choices as `{value, disabled}`, whichever form the host gave. */
85
+ export declare function targetPresets(presets: readonly (number | TargetPreset)[]): TargetPreset[];
86
+ /** The units as `{unit, disabled}`, whichever form the host gave. */
87
+ export declare function targetUnits(units: readonly (TargetUnit | TargetUnitOption)[]): TargetUnitOption[];
88
+ /**
89
+ * Number format of a target in a unit. Dollars and percents carry their sign. `short` is a preset's value: a whole dollar amount
90
+ * or a whole price drops its fraction digits (`+$10`, `$63,000`), whatever fraction digits `priceOptions` fix, so a preset reads
91
+ * the same on web and native; a price formatted by significant digits keeps `priceOptions`.
92
+ */
65
93
  export declare function targetFormat(unit: TargetUnit, priceOptions?: Intl.NumberFormatOptions, short?: number): Intl.NumberFormatOptions;
66
94
  /**
67
95
  * Where each known price sits on the bar, as a fraction of its width from the low-price edge, the prices in price order, and
@@ -78,4 +106,4 @@ export declare function targetLayout({ entry, trigger }: {
78
106
  to: number;
79
107
  };
80
108
  /** Set a take profit or a stop loss on one position: the target as the headline figure, a price card whose bar shows how far the price is from the trigger, the unit, the host's quick choices, and the confirming action. */
81
- export declare function TargetBlock({ kind, labels, position, orderType, note, entry, trigger, unit, units, onUnitChange, value, onValueChange, presets, onCustom, priceOptions, surface, onSubmit, submitDisabled, busy, onCancel, onBack, headerAction, className, ...rest }: TargetBlockProps): React.JSX.Element;
109
+ export declare function TargetBlock({ kind, labels, position, orderType, note, entry, trigger, unit, units, onUnitChange, value, onValueChange, presets, onCustom, customValue, priceOptions, surface, onSubmit, submitDisabled, busy, onCancel, onBack, headerAction, headerActionBesideInfo, headingId, stickyHeader, className, ...rest }: TargetBlockProps): React.JSX.Element;
@@ -3,21 +3,31 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useEffect, useId, useRef, useState } from 'react';
4
4
  import { formatNumber } from '@bloxwap/hig/contracts';
5
5
  import * as en from '@bloxwap/hig/contracts/messages';
6
- import { useHIG } from '../provider.js';
6
+ import { PressDecoration, usePresentNumber, useHIG, useNumberLocale } from '../provider.js';
7
7
  import { Button } from '../button.js';
8
8
  import { SegmentedControl } from '../selection.js';
9
+ import { PresetGroup } from '../preset-group.js';
9
10
  import { AnimatedNumberReadout } from '../animated-number.js';
10
11
  import { ScreenHeader } from './screen-header.js';
11
12
  import { SwapIcon } from './swap/shared.js';
13
+ /** The quick choices as `{value, disabled}`, whichever form the host gave. */
14
+ export function targetPresets(presets) { return presets.map(preset => typeof preset === 'number' ? { value: preset } : preset); }
15
+ /** The units as `{unit, disabled}`, whichever form the host gave. */
16
+ export function targetUnits(units) { return units.map(unit => typeof unit === 'string' ? { unit } : unit); }
12
17
  const usd = { style: 'currency', currency: 'USD' }, allUnits = ['dollar', 'price', 'percent'];
13
18
  const known = (value) => value != null && Number.isFinite(value);
14
- /** Number format of a target in a unit. Dollars and percents carry their sign; `short` drops the cents of a whole dollar amount, for a preset. */
19
+ /**
20
+ * Number format of a target in a unit. Dollars and percents carry their sign. `short` is a preset's value: a whole dollar amount
21
+ * or a whole price drops its fraction digits (`+$10`, `$63,000`), whatever fraction digits `priceOptions` fix, so a preset reads
22
+ * the same on web and native; a price formatted by significant digits keeps `priceOptions`.
23
+ */
15
24
  export function targetFormat(unit, priceOptions = usd, short) {
25
+ const whole = short !== undefined && Number.isInteger(short);
16
26
  if (unit === 'price')
17
- return priceOptions;
27
+ return whole && priceOptions.minimumSignificantDigits === undefined && priceOptions.maximumSignificantDigits === undefined ? { ...priceOptions, minimumFractionDigits: 0, maximumFractionDigits: 0 } : priceOptions;
18
28
  if (unit === 'percent')
19
29
  return { style: 'percent', maximumFractionDigits: 2, signDisplay: 'exceptZero' };
20
- return { ...usd, signDisplay: 'exceptZero', ...(short !== undefined && Number.isInteger(short) ? { maximumFractionDigits: 0 } : null) };
30
+ return { ...usd, signDisplay: 'exceptZero', ...(whole ? { maximumFractionDigits: 0 } : null) };
21
31
  }
22
32
  /**
23
33
  * Where each known price sits on the bar, as a fraction of its width from the low-price edge, the prices in price order, and
@@ -43,8 +53,10 @@ export function targetLayout({ entry, trigger }) {
43
53
  return start === undefined || end === undefined ? { positions, order, from: 0.5, to: 0.5 } : { positions, order, from: Math.min(start, end), to: Math.max(start, end) };
44
54
  }
45
55
  /** Set a take profit or a stop loss on one position: the target as the headline figure, a price card whose bar shows how far the price is from the trigger, the unit, the host's quick choices, and the confirming action. */
46
- export function TargetBlock({ kind, labels, position, orderType, note, entry, trigger, unit, units = allUnits, onUnitChange, value, onValueChange, presets = [], onCustom, priceOptions = usd, surface = false, onSubmit, submitDisabled, busy, onCancel, onBack, headerAction, className, ...rest }) {
47
- const { messages, locale } = useHIG();
56
+ export function TargetBlock({ kind, labels, position, orderType, note, entry, trigger, unit, units = allUnits, onUnitChange, value, onValueChange, presets = [], onCustom, customValue, priceOptions = usd, surface = false, onSubmit, submitDisabled, busy, onCancel, onBack, headerAction, headerActionBesideInfo, headingId, stickyHeader, className, ...rest }) {
57
+ const { messages } = useHIG();
58
+ const locale = useNumberLocale();
59
+ const present = usePresentNumber();
48
60
  const id = useId(), noteId = useId();
49
61
  const [open, setOpen] = useState(false);
50
62
  const anchor = useRef(null);
@@ -52,14 +64,16 @@ export function TargetBlock({ kind, labels, position, orderType, note, entry, tr
52
64
  useEffect(() => { if (!open)
53
65
  return; const outside = (event) => { if (!anchor.current?.contains(event.target))
54
66
  setOpen(false); }; document.addEventListener('pointerdown', outside); return () => document.removeEventListener('pointerdown', outside); }, [open]);
55
- const info = note && labels.info && !headerAction ? labels.info : undefined;
67
+ const info = note && labels.info && (!headerAction || headerActionBesideInfo) ? labels.info : undefined;
68
+ const custom = onCustom && known(customValue) ? customValue : null;
69
+ const infoButton = info && _jsxs("span", { ref: anchor, className: 'hig-target-info', onKeyDown: event => { if (event.key === 'Escape' && open) {
70
+ event.stopPropagation();
71
+ setOpen(false);
72
+ } }, onBlur: event => { if (!event.currentTarget.contains(event.relatedTarget))
73
+ setOpen(false); }, children: [_jsxs("button", { type: 'button', className: 'hig-swap-back', "aria-label": info, "aria-expanded": open, "aria-controls": open ? noteId : undefined, onClick: () => setOpen(!open), children: [_jsx(SwapIcon, { name: 'info' }), _jsx(PressDecoration, { kind: 'back' })] }), open && _jsx("span", { id: noteId, role: 'status', className: 'hig-popover hig-target-popover', children: note })] });
56
74
  const target = trigger !== undefined ? trigger : unit === 'price' ? value : null;
57
75
  const { positions, order, from, to } = targetLayout({ entry, trigger: target });
58
76
  const prices = { entry, trigger: target };
59
77
  const intent = kind === 'stop-loss' ? 'destructive' : 'primary';
60
- return _jsxs("section", { ...rest, className: `hig-target-block${className ? ` ${className}` : ''}`, "data-kind": kind, children: [_jsx(ScreenHeader, { title: labels.title, onBack: onBack, action: info ? _jsxs("span", { ref: anchor, className: 'hig-target-info', onKeyDown: event => { if (event.key === 'Escape' && open) {
61
- event.stopPropagation();
62
- setOpen(false);
63
- } }, onBlur: event => { if (!event.currentTarget.contains(event.relatedTarget))
64
- setOpen(false); }, children: [_jsx("button", { type: 'button', className: 'hig-swap-back', "aria-label": info, "aria-expanded": open, "aria-controls": open ? noteId : undefined, onClick: () => setOpen(!open), children: _jsx(SwapIcon, { name: 'info' }) }), open && _jsx("span", { id: noteId, role: 'status', className: 'hig-popover hig-target-popover', children: note })] }) : headerAction }), _jsx("p", { className: 'hig-target-amount', children: _jsx(AnimatedNumberReadout, { value: value, options: targetFormat(unit, priceOptions) }) }), note && !info && _jsx("p", { className: 'hig-target-note', children: note }), _jsxs("section", { className: surface ? 'hig-surface hig-target-prices' : 'hig-target-prices', "data-surface": surface ? undefined : 'false', "aria-labelledby": position ? id : undefined, children: [(position || orderType) && _jsxs("div", { className: 'hig-bar-mark-header', children: [position && _jsx("strong", { id: id, className: 'hig-bar-mark-title', children: position }), orderType && _jsx("span", { className: 'hig-bar-mark-description', children: orderType })] }), _jsxs("div", { className: 'hig-target-bar', "aria-hidden": 'true', children: [_jsx("span", { className: 'hig-target-rest', style: { flexGrow: from } }), to > from && _jsx("span", { className: 'hig-target-move', "data-lead": (positions.trigger ?? 0) < (positions.entry ?? 0) ? 'trigger' : 'start', style: { flexGrow: to - from } }), _jsx("span", { className: 'hig-target-rest', style: { flexGrow: 1 - to } })] }), _jsx("dl", { className: 'hig-bar-pnl-readouts', children: order.map(price => _jsxs("div", { "data-price": price, children: [_jsx("dt", { children: labels[price] }), _jsx("dd", { children: _jsx(AnimatedNumberReadout, { value: prices[price], options: priceOptions }) })] }, price)) })] }), units.length > 1 && _jsx(SegmentedControl, { label: labels.unit, options: units.map(option => ({ value: option, label: labels.units[option] })), value: unit, onValueChange: next => onUnitChange?.(next) }), onCustom && _jsxs("button", { type: 'button', className: 'hig-swap-setting', onClick: onCustom, children: [_jsx("span", { children: labels.custom }), _jsx(SwapIcon, { name: 'chevron', size: 16 })] }), presets.length > 0 && _jsx("div", { className: 'hig-target-presets', children: presets.map(preset => _jsx(Button, { fullWidth: true, intent: preset === value ? intent : 'secondary', "aria-pressed": preset === value, onClick: () => onValueChange?.(preset), children: formatNumber(preset, locale, targetFormat(unit, priceOptions, preset)) }, preset)) }), _jsxs("div", { className: 'hig-target-actions', children: [onCancel && _jsx(Button, { fullWidth: true, intent: 'secondary', onClick: onCancel, children: labels.cancel ?? messages.cancel ?? en.cancel }), _jsx(Button, { fullWidth: true, intent: intent, disabled: submitDisabled ?? value === null, busy: busy, onClick: onSubmit, children: labels.submit })] })] });
78
+ return _jsxs("section", { ...rest, className: `hig-target-block${className ? ` ${className}` : ''}`, "data-kind": kind, children: [_jsx(ScreenHeader, { title: labels.title, onBack: onBack, headingId: headingId, stickyHeader: stickyHeader, action: info ? headerAction ? _jsxs("span", { className: 'hig-target-header-actions', children: [infoButton, headerAction] }) : infoButton : headerAction }), _jsx("p", { className: 'hig-target-amount', children: _jsx(AnimatedNumberReadout, { value: value, options: targetFormat(unit, priceOptions) }) }), note && !info && _jsx("p", { className: 'hig-target-note', children: note }), _jsxs("section", { className: surface ? 'hig-surface hig-target-prices' : 'hig-target-prices', "data-surface": surface ? undefined : 'false', "aria-labelledby": position ? id : undefined, children: [(position || orderType) && _jsxs("div", { className: 'hig-bar-mark-header', children: [position && _jsx("strong", { id: id, className: 'hig-bar-mark-title', children: position }), orderType && _jsx("span", { className: 'hig-bar-mark-description', children: orderType })] }), _jsxs("div", { className: 'hig-target-bar', "aria-hidden": 'true', children: [_jsx("span", { className: 'hig-target-rest', style: { flexGrow: from } }), to > from && _jsx("span", { className: 'hig-target-move', "data-lead": (positions.trigger ?? 0) < (positions.entry ?? 0) ? 'trigger' : 'start', style: { flexGrow: to - from } }), _jsx("span", { className: 'hig-target-rest', style: { flexGrow: 1 - to } })] }), _jsx("dl", { className: 'hig-bar-pnl-readouts', children: order.map(price => _jsxs("div", { "data-price": price, children: [_jsx("dt", { children: labels[price] }), _jsx("dd", { children: _jsx(AnimatedNumberReadout, { value: prices[price], options: priceOptions }) })] }, price)) })] }), units.length > 1 && _jsx(SegmentedControl, { label: labels.unit, options: targetUnits(units).map(option => ({ value: option.unit, label: labels.units[option.unit], disabled: option.disabled })), value: unit, onValueChange: next => onUnitChange?.(next) }), onCustom && (custom === null ? _jsxs("button", { type: 'button', className: 'hig-swap-setting', "aria-pressed": customValue !== undefined ? false : undefined, onClick: onCustom, children: [_jsx("span", { children: labels.custom }), _jsx(SwapIcon, { name: 'chevron', size: 16 }), _jsx(PressDecoration, { kind: 'row' })] }) : _jsxs("button", { type: 'button', className: 'hig-swap-setting', "aria-pressed": 'true', onClick: onCustom, children: [_jsx("span", { children: labels.custom }), _jsxs("span", { className: 'hig-swap-setting-value', children: [formatNumber(custom, locale, present(targetFormat(unit, priceOptions))), _jsx(SwapIcon, { name: 'chevron', size: 16 })] }), _jsx(PressDecoration, { kind: 'row' })] })), presets.length > 0 && _jsx(PresetGroup, { className: 'hig-target-presets', label: labels.presets ?? labels.title, selectedIntent: intent, options: targetPresets(presets).map(({ value: preset, disabled }) => ({ value: preset, disabled, label: formatNumber(preset, locale, present(targetFormat(unit, priceOptions, preset))) })), value: custom === null ? value : null, onValueChange: next => onValueChange?.(next) }), _jsxs("div", { className: 'hig-target-actions', children: [onCancel && _jsx(Button, { fullWidth: true, intent: 'secondary', onClick: onCancel, children: labels.cancel ?? messages.cancel ?? en.cancel }), _jsx(Button, { fullWidth: true, intent: intent, disabled: !!submitDisabled || !known(value) || (unit === 'price' && value <= 0), busy: busy, onClick: onSubmit, children: labels.submit })] })] });
65
79
  }
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import type { HIGMessages } from '@bloxwap/hig/contracts/messages';
3
3
  import { type BarMarkElement } from '../bar-mark.js';
4
- export type { BarMarkElement, BarMarkTone } from '../bar-mark.js';
4
+ export type { BarMarkElement, BarMarkFigure, BarMarkTone } from '../bar-mark.js';
5
5
  /** Actions with a built-in, translated label. */
6
6
  export type TokenActionId = 'send' | 'receive' | 'stake' | 'unstake';
7
7
  export interface TokenAction {
@@ -16,22 +16,35 @@ export interface TokenAction {
16
16
  export interface TokenActionBlockProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
17
17
  /** Heading, usually the ticker: HYPE. */
18
18
  symbol: string;
19
- /** Title of the assets bar: Hyperliquid. */
20
- name: string;
19
+ /** Title of the assets bar: Hyperliquid. Needed only with `assets`; the symbol stands in without it. */
20
+ name?: string;
21
21
  /** Total holding in dollars, on the trailing edge of the assets bar. Defaults to the sum of the asset values; `null` reads as unknown. */
22
22
  value?: number | null;
23
- /** Where the token is held: Staked, Core, Paper. */
24
- assets: readonly BarMarkElement[];
25
- /** The chains the token sits on. */
26
- chains: readonly BarMarkElement[];
23
+ /** The holding in token units, for a token with no dollar value: with `value` left out or `null` it is drawn in place of the dollar total. */
24
+ units?: number | null;
25
+ /** Host text after the units, such as ` BLOX`. */
26
+ unitsSuffix?: string;
27
+ /** Format of the units. Defaults to at most six fraction digits. */
28
+ unitsOptions?: Intl.NumberFormatOptions;
29
+ /** Where the token is held: Staked, Core, Paper. Leave it out to draw no assets bar. */
30
+ assets?: readonly BarMarkElement[];
31
+ /** The chains the token sits on. Leave it out to draw no chains bar. */
32
+ chains?: readonly BarMarkElement[];
27
33
  /** Title of the chains bar. Defaults to the built-in “Chains”. */
28
34
  chainsTitle?: string;
29
35
  actions: readonly TokenAction[];
30
36
  onBack?: () => void;
31
37
  /** A control on the trailing edge of the header, usually an `IconButton`. */
32
38
  headerAction?: React.ReactNode;
39
+ /** Pins the header to the top of the nearest scroller: transparent at rest, filled once content scrolls under it, and still when it starts to stick. See Pinned headers. */
40
+ stickyHeader?: boolean;
41
+ /** `id` of the header's heading, so a host dialog or sheet can name itself with `aria-labelledby`. */
42
+ headingId?: string;
43
+ /** A line under the actions, for example why some are missing. `noteTone` tints it as in `SwapPanelBlock`. */
44
+ note?: React.ReactNode;
45
+ noteTone?: 'muted' | 'warning' | 'negative';
33
46
  }
34
47
  /** The text of an action: its `label`, the built-in label for a known id, or the id itself. */
35
48
  export declare const tokenActionLabel: (action: TokenAction, messages?: Partial<HIGMessages>) => string;
36
49
  /** One token and what can be done with it: where it is held, which chains it sits on, and the actions as equal full-width buttons. */
37
- export declare function TokenActionBlock({ symbol, name, value, assets, chains, chainsTitle, actions, onBack, headerAction, className, ...rest }: TokenActionBlockProps): React.JSX.Element;
50
+ export declare function TokenActionBlock({ symbol, name, value, units, unitsSuffix, unitsOptions, assets, chains, chainsTitle, actions, onBack, headerAction, note, noteTone, stickyHeader, headingId, className, ...rest }: TokenActionBlockProps): React.JSX.Element;
@@ -2,17 +2,20 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { formatNumber } from '@bloxwap/hig/contracts';
4
4
  import * as en from '@bloxwap/hig/contracts/messages';
5
- import { useHIG } from '../provider.js';
5
+ import { useHIG, useNumberLocale } from '../provider.js';
6
6
  import { Button } from '../button.js';
7
7
  import { AnimatedNumberReadout } from '../animated-number.js';
8
8
  import { BarMark } from '../bar-mark.js';
9
9
  import { ScreenHeader } from './screen-header.js';
10
- const usd = { style: 'currency', currency: 'USD' }, held = (value) => Number.isFinite(value) && value > 0;
10
+ const usd = { style: 'currency', currency: 'USD' }, unitsFormat = { maximumFractionDigits: 6 }, held = (value) => Number.isFinite(value) && value > 0;
11
11
  /** The text of an action: its `label`, the built-in label for a known id, or the id itself. */
12
12
  export const tokenActionLabel = (action, messages = {}) => action.label ?? (action.id === 'send' ? messages.swapActionSend ?? en.swapActionSend : action.id === 'receive' ? messages.receive ?? en.receive : action.id === 'stake' ? messages.stake ?? en.stake : action.id === 'unstake' ? messages.unstake ?? en.unstake : action.id);
13
13
  /** One token and what can be done with it: where it is held, which chains it sits on, and the actions as equal full-width buttons. */
14
- export function TokenActionBlock({ symbol, name, value, assets, chains, chainsTitle, actions, onBack, headerAction, className, ...rest }) {
15
- const { messages, locale } = useHIG();
16
- const total = value !== undefined ? value : assets.reduce((sum, asset) => sum + (held(asset.value) ? asset.value : 0), 0);
17
- return _jsxs("section", { ...rest, className: `hig-token-card${className ? ` ${className}` : ''}`, children: [_jsx(ScreenHeader, { title: symbol, onBack: onBack, action: headerAction }), _jsxs("div", { className: 'hig-token-bars', children: [_jsx(BarMark, { surface: false, title: name, description: _jsx(AnimatedNumberReadout, { value: total, options: usd }), elements: assets }), _jsx(BarMark, { surface: false, title: chainsTitle ?? messages.swapChains ?? en.swapChains, description: formatNumber(chains.filter(chain => held(chain.value)).length, locale), elements: chains })] }), actions.length > 0 && _jsx("div", { className: 'hig-token-actions', children: actions.map(action => _jsx(Button, { fullWidth: true, intent: action.intent ?? 'secondary', disabled: action.disabled, onClick: action.onSelect, children: tokenActionLabel(action, messages) }, action.id)) })] });
14
+ export function TokenActionBlock({ symbol, name, value, units, unitsSuffix, unitsOptions = unitsFormat, assets, chains, chainsTitle, actions, onBack, headerAction, note, noteTone = 'muted', stickyHeader, headingId, className, ...rest }) {
15
+ const { messages } = useHIG();
16
+ const locale = useNumberLocale();
17
+ const total = value !== undefined ? value : (assets ?? []).reduce((sum, asset) => sum + (held(asset.value) ? asset.value : 0), 0);
18
+ // With no dollar value the units are the headline, as an AccountBlock row headlines them.
19
+ const headline = units !== undefined && value == null ? _jsx(AnimatedNumberReadout, { value: units, options: unitsOptions, suffix: unitsSuffix }, 'units') : _jsx(AnimatedNumberReadout, { value: total, options: usd }, 'value');
20
+ return _jsxs("section", { ...rest, className: `hig-token-card${className ? ` ${className}` : ''}`, children: [_jsx(ScreenHeader, { title: symbol, onBack: onBack, action: headerAction, headingId: headingId, stickyHeader: stickyHeader }), (assets || chains) && _jsxs("div", { className: 'hig-token-bars', children: [assets && _jsx(BarMark, { surface: false, title: name ?? symbol, description: headline, elements: assets }), chains && _jsx(BarMark, { surface: false, title: chainsTitle ?? messages.swapChains ?? en.swapChains, description: formatNumber(chains.filter(chain => held(chain.value)).length, locale), elements: chains })] }), actions.length > 0 && _jsx("div", { className: 'hig-token-actions', children: actions.map(action => _jsx(Button, { fullWidth: true, intent: action.intent ?? 'secondary', disabled: action.disabled, onClick: action.onSelect, children: tokenActionLabel(action, messages) }, action.id)) }), note != null && note !== false && _jsx("p", { className: 'hig-swap-note hig-token-note', "data-tone": noteTone, role: 'note', children: note })] });
18
21
  }