@bloxwap/hig 0.5.2 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/chart/README.md +1 -1
- package/contracts/README.md +1 -1
- package/contracts/dist/index.d.ts +16 -0
- package/contracts/dist/index.js +22 -0
- package/contracts/dist/messages.d.ts +37 -4
- package/contracts/dist/messages.js +13 -2
- package/feedback/README.md +1 -1
- package/native/README.md +1 -1
- package/native/dist/account-block.d.ts +92 -0
- package/native/dist/account-block.js +61 -0
- package/native/dist/animated-number-model.d.ts +7 -1
- package/native/dist/animated-number-model.js +50 -1
- package/native/dist/animated-number.d.ts +3 -1
- package/native/dist/animated-number.js +8 -5
- package/native/dist/asset-balance-row.d.ts +36 -0
- package/native/dist/asset-balance-row.js +26 -0
- package/native/dist/bar-mark.d.ts +57 -0
- package/native/dist/bar-mark.js +48 -0
- package/native/dist/bar-pnl.d.ts +50 -0
- package/native/dist/bar-pnl.js +60 -0
- package/native/dist/blocks.d.ts +38 -0
- package/native/dist/blocks.js +42 -0
- package/native/dist/button.js +3 -1
- package/native/dist/data.d.ts +1 -1
- package/native/dist/data.js +6 -4
- package/native/dist/field.d.ts +14 -5
- package/native/dist/field.js +33 -8
- package/native/dist/figure.d.ts +23 -0
- package/native/dist/figure.js +10 -0
- package/native/dist/icons.d.ts +8 -0
- package/native/dist/icons.js +4 -0
- package/native/dist/language-block.d.ts +35 -0
- package/native/dist/language-block.js +30 -0
- package/native/dist/list-group.d.ts +60 -0
- package/native/dist/list-group.js +85 -0
- package/native/dist/manage-position-block.d.ts +95 -0
- package/native/dist/manage-position-block.js +82 -0
- package/native/dist/market-row.d.ts +46 -0
- package/native/dist/market-row.js +30 -0
- package/native/dist/notifications-block.d.ts +53 -0
- package/native/dist/notifications-block.js +22 -0
- package/native/dist/pickers.d.ts +35 -5
- package/native/dist/pickers.js +21 -9
- package/native/dist/position-block.d.ts +107 -0
- package/native/dist/position-block.js +55 -0
- package/native/dist/profile-block.d.ts +66 -0
- package/native/dist/profile-block.js +48 -0
- package/native/dist/provider.d.ts +9 -3
- package/native/dist/provider.js +7 -3
- package/native/dist/radio-group.d.ts +9 -3
- package/native/dist/radio-group.js +4 -5
- package/native/dist/recipes.d.ts +6 -46
- package/native/dist/recipes.js +6 -33
- package/native/dist/reward-block.d.ts +122 -0
- package/native/dist/reward-block.js +53 -0
- package/native/dist/screen-header.d.ts +49 -0
- package/native/dist/screen-header.js +29 -0
- package/native/dist/selection.d.ts +2 -2
- package/native/dist/setting-header.d.ts +2 -0
- package/native/dist/setting-header.js +2 -0
- package/native/dist/setting-switch.d.ts +31 -0
- package/native/dist/setting-switch.js +20 -0
- package/native/dist/signals-block.d.ts +61 -0
- package/native/dist/signals-block.js +26 -0
- package/native/dist/sound-haptics-block.d.ts +66 -0
- package/native/dist/sound-haptics-block.js +32 -0
- package/native/dist/status.d.ts +6 -5
- package/native/dist/status.js +5 -5
- package/native/dist/sticky-header.d.ts +28 -0
- package/native/dist/sticky-header.js +21 -0
- package/native/dist/surface.d.ts +3 -1
- package/native/dist/surface.js +2 -1
- package/native/dist/{swap-panel.d.ts → swap-panel-block.d.ts} +8 -3
- package/native/dist/{swap-panel.js → swap-panel-block.js} +13 -8
- package/native/dist/swap-parts.d.ts +5 -3
- package/native/dist/swap-parts.js +2 -2
- package/native/dist/swap-shared.d.ts +6 -0
- package/native/dist/swap-sheet.d.ts +4 -4
- package/native/dist/swap-sheet.js +4 -4
- package/native/dist/swap-views.d.ts +1 -1
- package/native/dist/swap-views.js +9 -7
- package/native/dist/switch-row.d.ts +3 -2
- package/native/dist/switch-row.js +5 -3
- package/native/dist/switch.d.ts +4 -2
- package/native/dist/switch.js +3 -3
- package/native/dist/target-block.d.ts +110 -0
- package/native/dist/target-block.js +74 -0
- package/native/dist/token-action-block.d.ts +47 -0
- package/native/dist/token-action-block.js +28 -0
- package/native/dist/trade-history-detail-block.d.ts +84 -0
- package/native/dist/trade-history-detail-block.js +46 -0
- package/native/dist/trade-history-list-block.d.ts +110 -0
- package/native/dist/trade-history-list-block.js +64 -0
- package/native/dist/wallet-address-core.d.ts +25 -0
- package/native/dist/wallet-address-core.js +31 -0
- package/native/dist/wallet-address.d.ts +6 -10
- package/native/dist/wallet-address.js +16 -20
- package/native-fonts/README.md +1 -1
- package/og-fonts/README.md +1 -1
- package/package.json +266 -41
- package/react/README.md +1 -1
- package/react/dist/animated-number-model.d.ts +6 -0
- package/react/dist/animated-number-model.js +33 -0
- package/react/dist/animated-number.d.ts +5 -1
- package/react/dist/animated-number.js +12 -8
- package/react/dist/asset-balance-row.d.ts +35 -0
- package/react/dist/asset-balance-row.js +18 -0
- package/react/dist/bar-mark.d.ts +38 -0
- package/react/dist/bar-mark.js +23 -0
- package/react/dist/bar-pnl.d.ts +49 -0
- package/react/dist/bar-pnl.js +45 -0
- package/react/dist/blocks/account-block.d.ts +92 -0
- package/react/dist/blocks/account-block.js +62 -0
- package/react/dist/blocks/language-block.d.ts +36 -0
- package/react/dist/blocks/language-block.js +52 -0
- package/react/dist/blocks/manage-position-block.d.ts +93 -0
- package/react/dist/blocks/manage-position-block.js +47 -0
- package/react/dist/blocks/market-row.d.ts +36 -0
- package/react/dist/blocks/market-row.js +16 -0
- package/react/dist/blocks/notifications-block.d.ts +46 -0
- package/react/dist/blocks/notifications-block.js +17 -0
- package/react/dist/{recipes → blocks}/pickers.d.ts +32 -4
- package/react/dist/{recipes → blocks}/pickers.js +35 -11
- package/react/dist/blocks/position-block.d.ts +72 -0
- package/react/dist/blocks/position-block.js +25 -0
- package/react/dist/blocks/profile-block.d.ts +71 -0
- package/react/dist/blocks/profile-block.js +41 -0
- package/react/dist/blocks/reward-block.d.ts +120 -0
- package/react/dist/blocks/reward-block.js +34 -0
- package/react/dist/blocks/screen-header.d.ts +33 -0
- package/react/dist/blocks/screen-header.js +20 -0
- package/react/dist/blocks/setting-switch.d.ts +23 -0
- package/react/dist/blocks/setting-switch.js +12 -0
- package/react/dist/blocks/signals-block.d.ts +54 -0
- package/react/dist/blocks/signals-block.js +15 -0
- package/react/dist/blocks/sound-haptics-block.d.ts +59 -0
- package/react/dist/blocks/sound-haptics-block.js +22 -0
- package/react/dist/blocks/sticky-header.d.ts +9 -0
- package/react/dist/blocks/sticky-header.js +43 -0
- package/react/dist/blocks/swap/amount-card.js +8 -0
- package/react/dist/{recipes → blocks}/swap/picker.d.ts +1 -1
- package/react/dist/{recipes → blocks}/swap/picker.js +4 -4
- package/react/dist/{recipes → blocks}/swap/settings.js +2 -2
- package/react/dist/{recipes → blocks}/swap/shared.d.ts +8 -1
- package/react/dist/{recipes → blocks}/swap/shared.js +7 -4
- package/react/dist/{recipes/swap-panel.d.ts → blocks/swap-panel-block.d.ts} +8 -2
- package/react/dist/{recipes/swap-panel.js → blocks/swap-panel-block.js} +9 -7
- package/react/dist/{recipes → blocks}/swap-sheet.d.ts +4 -4
- package/react/dist/{recipes → blocks}/swap-sheet.js +4 -4
- package/react/dist/blocks/target-block.d.ts +103 -0
- package/react/dist/blocks/target-block.js +73 -0
- package/react/dist/blocks/token-action-block.d.ts +46 -0
- package/react/dist/blocks/token-action-block.js +21 -0
- package/react/dist/{recipes → blocks}/trade-entry.js +2 -2
- package/react/dist/blocks/trade-history-detail-block.d.ts +78 -0
- package/react/dist/blocks/trade-history-detail-block.js +17 -0
- package/react/dist/blocks/trade-history-list-block.d.ts +67 -0
- package/react/dist/blocks/trade-history-list-block.js +28 -0
- package/react/dist/blocks.d.ts +20 -0
- package/react/dist/blocks.js +21 -0
- package/react/dist/button.js +6 -4
- package/react/dist/data.js +3 -3
- package/react/dist/field.d.ts +14 -6
- package/react/dist/field.js +19 -8
- package/react/dist/figure.d.ts +23 -0
- package/react/dist/figure.js +12 -0
- package/react/dist/list-group.d.ts +59 -0
- package/react/dist/list-group.js +52 -0
- package/react/dist/provider.d.ts +40 -3
- package/react/dist/provider.js +63 -6
- package/react/dist/selection.d.ts +8 -2
- package/react/dist/selection.js +11 -6
- package/react/dist/styles.css +425 -5
- package/react/dist/surface.d.ts +5 -1
- package/react/dist/surface.js +1 -1
- package/react/dist/wallet-address-core.d.ts +23 -0
- package/react/dist/wallet-address-core.js +24 -0
- package/react/dist/wallet-address.d.ts +6 -12
- package/react/dist/wallet-address.js +5 -16
- package/tokens/README.md +1 -1
- package/react/dist/recipes/activity-list.d.ts +0 -8
- package/react/dist/recipes/activity-list.js +0 -6
- package/react/dist/recipes/balance-card.d.ts +0 -6
- package/react/dist/recipes/balance-card.js +0 -5
- package/react/dist/recipes/code-window.d.ts +0 -4
- package/react/dist/recipes/code-window.js +0 -4
- package/react/dist/recipes/market-row.d.ts +0 -25
- package/react/dist/recipes/market-row.js +0 -8
- package/react/dist/recipes/swap/amount-card.js +0 -7
- package/react/dist/recipes.d.ts +0 -10
- package/react/dist/recipes.js +0 -11
- /package/react/dist/{recipes → blocks}/install-command.d.ts +0 -0
- /package/react/dist/{recipes → blocks}/install-command.js +0 -0
- /package/react/dist/{recipes → blocks}/marketing-hero.d.ts +0 -0
- /package/react/dist/{recipes → blocks}/marketing-hero.js +0 -0
- /package/react/dist/{recipes → blocks}/swap/amount-card.d.ts +0 -0
- /package/react/dist/{recipes → blocks}/swap/settings.d.ts +0 -0
- /package/react/dist/{recipes → blocks}/trade-entry.d.ts +0 -0
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { AnimatedNumberReadout } from '../../animated-number.js';
|
|
4
|
+
import { PressDecoration } from '../../provider.js';
|
|
5
|
+
import { figureProps } from '../../figure.js';
|
|
4
6
|
/** Artwork in a disc: the URL as an image, the host's element inside a clipped wrapper. */
|
|
5
7
|
export const swapArt = (icon, className, lazy) => typeof icon === 'string' ? _jsx("img", { className: className, src: icon, alt: '', loading: lazy ? 'lazy' : undefined }) : _jsx("span", { className: `hig-swap-art${className ? ` ${className}` : ''}`, "aria-hidden": 'true', children: icon });
|
|
6
8
|
export function swapAction(from, to) {
|
|
@@ -59,7 +61,7 @@ export function SwapNumber({ template, ...number }) {
|
|
|
59
61
|
return _jsxs("span", { children: [before, _jsx(AnimatedNumberReadout, { ...number }), after] });
|
|
60
62
|
}
|
|
61
63
|
/** Host text that is either a fixed string or a live figure. */
|
|
62
|
-
export const swapFigure = (text) => typeof text === 'string' ? text : _jsx(SwapNumber, {
|
|
64
|
+
export const swapFigure = (text) => typeof text === 'string' ? text : _jsx(SwapNumber, { ...figureProps(text) });
|
|
63
65
|
/** `SwapNumber` props for a dollar amount and for a slippage fraction (0.005 reads `0.5%`). */
|
|
64
66
|
export const usdNumber = (value) => ({ value, options: { style: 'currency', currency: 'USD' } });
|
|
65
67
|
export const percentNumber = (fraction) => ({ value: Number((fraction * 100).toFixed(4)), suffix: '%', options: { maximumFractionDigits: 4, useGrouping: false } });
|
|
@@ -97,6 +99,7 @@ const paths = {
|
|
|
97
99
|
flame: _jsx("path", { d: 'M10 17a5 5 0 0 0 5-5c0-3-2.5-4.5-3-8-2 1-3.5 3-3.5 5.5C7.5 8.5 7 7.5 7 7c-1.5 1.5-2 3-2 5a5 5 0 0 0 5 5Z' }),
|
|
98
100
|
logout: _jsx("path", { d: 'M8 4H5.5A1.5 1.5 0 0 0 4 5.5v9A1.5 1.5 0 0 0 5.5 16H8M12.5 6.5 16 10l-3.5 3.5M16 10H8' }),
|
|
99
101
|
wallet: _jsx("path", { d: 'M3.5 6.5A1.5 1.5 0 0 1 5 5h9.5A1.5 1.5 0 0 1 16 6.5v.75M3.5 6.5v7A1.5 1.5 0 0 0 5 15h10.5a1 1 0 0 0 1-1V8.25a1 1 0 0 0-1-1H5a1.5 1.5 0 0 1-1.5-.75M13.25 11.25v.01' }),
|
|
102
|
+
info: _jsx("path", { d: 'M10 17a7 7 0 1 0 0-14 7 7 0 0 0 0 14ZM10 9.5v4M10 6.5v.01' }),
|
|
100
103
|
lock: _jsx("path", { d: 'M5.5 9h9a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1h-9a1 1 0 0 1-1-1v-5a1 1 0 0 1 1-1ZM7 9V6.5a3 3 0 0 1 6 0V9' }),
|
|
101
104
|
};
|
|
102
105
|
/** Outline symbol on a 20 unit grid; decorative, so the control that holds it carries the name. */
|
|
@@ -107,11 +110,11 @@ export function TokenIcon({ token, size = 44 }) {
|
|
|
107
110
|
return _jsxs("span", { className: 'hig-swap-token-icon', style: { width: size, height: size }, children: [token.icon ? swapArt(token.icon, undefined, true) : _jsx("span", { "aria-hidden": 'true', children: token.symbol.slice(0, 3) }), token.chainIcon && swapArt(token.chainIcon, chainBadge, true)] });
|
|
108
111
|
}
|
|
109
112
|
/** Small capsule action that sits on a card: Max, Test, the slippage setting and the denomination switch. */
|
|
110
|
-
export function SwapPill({ children, ...props }) { return
|
|
113
|
+
export function SwapPill({ children, ...props }) { return _jsxs("button", { type: 'button', ...props, className: 'hig-swap-pill', children: [children, _jsx(PressDecoration, { kind: 'button', disabled: !!props.disabled })] }); }
|
|
111
114
|
const keys = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '0', 'back'];
|
|
112
115
|
/** Numeric keypad. Emits `0`–`9`, `.` or `back`. */
|
|
113
116
|
export function SwapKeypad({ onKey, label, deleteLabel }) {
|
|
114
|
-
return _jsx("div", { className: 'hig-swap-keypad', role: 'group', "aria-label": label, children: keys.map(key =>
|
|
117
|
+
return _jsx("div", { className: 'hig-swap-keypad', role: 'group', "aria-label": label, children: keys.map(key => _jsxs("button", { type: 'button', className: 'hig-swap-key', "aria-label": key === 'back' ? deleteLabel : undefined, onClick: () => onKey(key), children: [key === 'back' ? _jsx(SwapIcon, { name: 'delete', size: 24 }) : key, _jsx(PressDecoration, { kind: 'button' })] }, key)) });
|
|
115
118
|
}
|
|
116
119
|
/** Chains present in a token list, in first-seen order. */
|
|
117
120
|
export function chainsOf(tokens) { const seen = new Map(); for (const token of tokens)
|
|
@@ -121,5 +124,5 @@ export function chainsOf(tokens) { const seen = new Map(); for (const token of t
|
|
|
121
124
|
export const parentView = (view) => view === 'slippage' || view === 'fees' ? 'settings' : 'main';
|
|
122
125
|
/** Header of a pushed view: Back on the leading edge, then the title, which takes focus when the view arrives. */
|
|
123
126
|
export function SwapViewHeader({ title, titleRef, backLabel, onBack }) {
|
|
124
|
-
return _jsxs("div", { className: 'hig-swap-view-header', children: [
|
|
127
|
+
return _jsxs("div", { className: 'hig-swap-view-header', children: [_jsxs("button", { type: 'button', className: 'hig-swap-back', "aria-label": backLabel, onClick: onBack, children: [_jsx(SwapIcon, { name: 'back' }), _jsx(PressDecoration, { kind: 'back' })] }), _jsx("h2", { ref: titleRef, tabIndex: -1, className: 'hig-swap-view-title', children: title })] });
|
|
125
128
|
}
|
|
@@ -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 {
|
|
@@ -38,7 +40,7 @@ export interface SwapReceive {
|
|
|
38
40
|
qr?: React.ReactNode; /** Host clipboard adapter. When set, the whole view copies the address. */
|
|
39
41
|
onCopy?: () => Promise<void> | void;
|
|
40
42
|
}
|
|
41
|
-
export interface
|
|
43
|
+
export interface SwapPanelBlockProps {
|
|
42
44
|
/** Catalog for the To side, and for the From side unless `fromTokens` is given. */
|
|
43
45
|
tokens: readonly SwapToken[];
|
|
44
46
|
/** Assets offered on the From side, typically the connected wallet's holdings. */
|
|
@@ -140,4 +142,8 @@ export interface SwapPanelProps {
|
|
|
140
142
|
* or token units, token pickers, settings, and one action that names itself from the chosen pair.
|
|
141
143
|
* Presentation only. The host owns tokens, balances, prices, the quote, the wallet and the transaction.
|
|
142
144
|
*/
|
|
143
|
-
export declare function
|
|
145
|
+
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;
|
|
146
|
+
/** @deprecated Renamed `SwapPanelBlock`. The old name and the `blocks/swap-panel` and `recipes/swap-panel` import paths keep working until the next major release. */
|
|
147
|
+
export declare const SwapPanel: typeof SwapPanelBlock;
|
|
148
|
+
/** @deprecated Renamed `SwapPanelBlockProps`. */
|
|
149
|
+
export type SwapPanelProps = SwapPanelBlockProps;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
4
4
|
import * as en from '@bloxwap/hig/contracts/messages';
|
|
5
|
-
import { useControllable, useHIG } from '../provider.js';
|
|
5
|
+
import { PressDecoration, useControllable, useHIG } from '../provider.js';
|
|
6
6
|
import { Button, IconButton } from '../button.js';
|
|
7
7
|
import { AnimatedNumberReadout } from '../animated-number.js';
|
|
8
8
|
import { notify } from '../notify.js';
|
|
@@ -20,7 +20,7 @@ const amountKey = (event) => event.metaKey || event.ctrlKey || event.altKey ? nu
|
|
|
20
20
|
* or token units, token pickers, settings, and one action that names itself from the chosen pair.
|
|
21
21
|
* Presentation only. The host owns tokens, balances, prices, the quote, the wallet and the transaction.
|
|
22
22
|
*/
|
|
23
|
-
export function
|
|
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
24
|
const { messages } = useHIG();
|
|
25
25
|
const [from, setFrom] = useControllable(fromProp, defaultFrom, onFromChange);
|
|
26
26
|
const [to, setTo] = useControllable(toProp, defaultTo, onToChange);
|
|
@@ -158,19 +158,21 @@ export function SwapPanel({ tokens, fromTokens, fromTokensLoading, chains, hotTo
|
|
|
158
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
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
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 ?
|
|
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
162
|
const card = (side) => {
|
|
163
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
164
|
const cardUnits = side === 'from' ? units : receivedUnits, cardUsd = side === 'from' ? usd : receivedUsd;
|
|
165
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) }), _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 })] })] })] })] });
|
|
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
168
|
};
|
|
169
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 }), _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)) })] });
|
|
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
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 &&
|
|
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
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
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
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
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;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { type
|
|
3
|
-
export interface SwapSheetProps extends
|
|
2
|
+
import { type SwapPanelBlockProps } from './swap-panel-block.js';
|
|
3
|
+
export interface SwapSheetProps extends SwapPanelBlockProps {
|
|
4
4
|
open: boolean;
|
|
5
5
|
onOpenChange: (open: boolean) => void;
|
|
6
6
|
/** Accessible name of the sheet; not drawn. */
|
|
@@ -9,8 +9,8 @@ export interface SwapSheetProps extends SwapPanelProps {
|
|
|
9
9
|
trigger?: React.ReactNode;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* SwapPanelBlock presented in a gesture sheet (Vaul). Token pickers and settings push inside the same sheet, which resizes to
|
|
13
13
|
* each view. Escape and Back pop a pushed view first; from the cards, Escape, the scrim and a downward drag close the sheet.
|
|
14
|
-
* Lives in its own entry so the
|
|
14
|
+
* Lives in its own entry so the blocks aggregate stays free of the optional Vaul peer.
|
|
15
15
|
*/
|
|
16
16
|
export declare function SwapSheet({ open, onOpenChange, title, trigger, view: viewProp, onViewChange, ...panel }: SwapSheetProps): React.JSX.Element;
|
|
@@ -3,12 +3,12 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
3
3
|
import { useEffect } from 'react';
|
|
4
4
|
import { useControllable } from '../provider.js';
|
|
5
5
|
import { GestureSheet } from '../gesture-sheet.js';
|
|
6
|
-
import {
|
|
6
|
+
import { SwapPanelBlock } from './swap-panel-block.js';
|
|
7
7
|
import { parentView } from './swap/shared.js';
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* SwapPanelBlock presented in a gesture sheet (Vaul). Token pickers and settings push inside the same sheet, which resizes to
|
|
10
10
|
* each view. Escape and Back pop a pushed view first; from the cards, Escape, the scrim and a downward drag close the sheet.
|
|
11
|
-
* Lives in its own entry so the
|
|
11
|
+
* Lives in its own entry so the blocks aggregate stays free of the optional Vaul peer.
|
|
12
12
|
*/
|
|
13
13
|
export function SwapSheet({ open, onOpenChange, title, trigger, view: viewProp, onViewChange, ...panel }) {
|
|
14
14
|
const [view, show] = useControllable(viewProp, 'main', onViewChange);
|
|
@@ -18,5 +18,5 @@ export function SwapSheet({ open, onOpenChange, title, trigger, view: viewProp,
|
|
|
18
18
|
return _jsx(GestureSheet, { open: open, onOpenChange: onOpenChange, title: title, titleHidden: true, trigger: trigger, closeButton: null, contentMode: 'custom', enableDynamicSizing: true, contentProps: { className: 'hig-swap-sheet', onEscapeKeyDown: event => { if (view !== 'main') {
|
|
19
19
|
event.preventDefault();
|
|
20
20
|
show(parentView(view));
|
|
21
|
-
} } }, children: _jsx(
|
|
21
|
+
} } }, children: _jsx(SwapPanelBlock, { ...panel, view: view, onViewChange: show }) });
|
|
22
22
|
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/** What the target does: close in profit, or cap the loss. */
|
|
3
|
+
export type TargetKind = 'take-profit' | 'stop-loss';
|
|
4
|
+
/** How the target is expressed: profit or loss in dollars, a price, or a share of the position. */
|
|
5
|
+
export type TargetUnit = 'dollar' | 'price' | 'percent';
|
|
6
|
+
/** The three prices on the bar. */
|
|
7
|
+
export type TargetPrice = 'entry' | 'trigger';
|
|
8
|
+
/** The words of the block. They are trading terms, so the host supplies them in its own vocabulary and language; only Cancel has a built-in default. */
|
|
9
|
+
export interface TargetBlockLabels {
|
|
10
|
+
/** Heading: Take Profit, Stop Loss. */
|
|
11
|
+
title: string;
|
|
12
|
+
/** The confirming action: Set Take Profit. */
|
|
13
|
+
submit: string;
|
|
14
|
+
/** Defaults to the built-in Cancel. */
|
|
15
|
+
cancel?: string;
|
|
16
|
+
entry: string;
|
|
17
|
+
/** The price the order triggers at: If triggered. */
|
|
18
|
+
trigger: string;
|
|
19
|
+
/** Accessible name of the unit control; not drawn. */
|
|
20
|
+
unit: string;
|
|
21
|
+
units: Record<TargetUnit, string>;
|
|
22
|
+
/** The row that opens the host's own entry: Custom. */
|
|
23
|
+
custom: string;
|
|
24
|
+
/** Accessible name of the info button that shows `note`: How this order fills. Without it the note is always shown. */
|
|
25
|
+
info?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface TargetBlockProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
|
|
28
|
+
kind: TargetKind;
|
|
29
|
+
labels: TargetBlockLabels;
|
|
30
|
+
/** Title of the price card, the position the target belongs to: `BTC · Long 40×`. */
|
|
31
|
+
position?: string;
|
|
32
|
+
/** Trailing text of the price card, the order the target places: Take-limit, Stop-market. */
|
|
33
|
+
orderType?: string;
|
|
34
|
+
/** One sentence about how the order fills. With `labels.info` it opens in a popover from an info button on the trailing edge of the header; otherwise it is always shown under the headline figure. */
|
|
35
|
+
note?: string;
|
|
36
|
+
entry: number;
|
|
37
|
+
/** Price the order triggers at. Defaults to `value` when the unit is `price`; otherwise unknown until the host supplies it. */
|
|
38
|
+
trigger?: number | null;
|
|
39
|
+
unit: TargetUnit;
|
|
40
|
+
/** Units offered, in order. Defaults to all three; one unit hides the control. `{unit, disabled}` shows a unit that cannot be chosen now, dimmed. */
|
|
41
|
+
units?: readonly (TargetUnit | TargetUnitOption)[];
|
|
42
|
+
onUnitChange?: (unit: TargetUnit) => void;
|
|
43
|
+
/** 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
|
+
value: number | null;
|
|
45
|
+
onValueChange?: (value: number) => void;
|
|
46
|
+
/** 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. */
|
|
47
|
+
presets?: readonly (number | TargetPreset)[];
|
|
48
|
+
/** Shows the Custom row; the host opens its own entry. */
|
|
49
|
+
onCustom?: () => void;
|
|
50
|
+
/** 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. */
|
|
51
|
+
customValue?: number | null;
|
|
52
|
+
/** Format of prices. Defaults to US dollars. */
|
|
53
|
+
priceOptions?: Intl.NumberFormatOptions;
|
|
54
|
+
/** 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. */
|
|
55
|
+
surface?: boolean;
|
|
56
|
+
onSubmit: () => void;
|
|
57
|
+
/** Defaults to disabled while `value` is unknown. */
|
|
58
|
+
submitDisabled?: boolean;
|
|
59
|
+
busy?: boolean;
|
|
60
|
+
/** Shows Cancel beside the confirming action. */
|
|
61
|
+
onCancel?: () => void;
|
|
62
|
+
onBack?: () => void;
|
|
63
|
+
/** 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. */
|
|
64
|
+
headerAction?: React.ReactNode;
|
|
65
|
+
/** Set true to keep the info button when `headerAction` is given: the info button comes first and `headerAction` sits on the trailing edge. */
|
|
66
|
+
headerActionBesideInfo?: boolean;
|
|
67
|
+
/** `id` of the heading, so a dialog or sheet can name itself with `aria-labelledby`. */
|
|
68
|
+
headingId?: string;
|
|
69
|
+
/** 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. */
|
|
70
|
+
stickyHeader?: boolean;
|
|
71
|
+
}
|
|
72
|
+
/** A quick choice that can be shown dimmed. */
|
|
73
|
+
export interface TargetPreset {
|
|
74
|
+
value: number;
|
|
75
|
+
disabled?: boolean;
|
|
76
|
+
}
|
|
77
|
+
/** A unit that can be shown dimmed. */
|
|
78
|
+
export interface TargetUnitOption {
|
|
79
|
+
unit: TargetUnit;
|
|
80
|
+
disabled?: boolean;
|
|
81
|
+
}
|
|
82
|
+
/** The quick choices as `{value, disabled}`, whichever form the host gave. */
|
|
83
|
+
export declare function targetPresets(presets: readonly (number | TargetPreset)[]): TargetPreset[];
|
|
84
|
+
/** The units as `{unit, disabled}`, whichever form the host gave. */
|
|
85
|
+
export declare function targetUnits(units: readonly (TargetUnit | TargetUnitOption)[]): TargetUnitOption[];
|
|
86
|
+
/** 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. */
|
|
87
|
+
export declare function targetFormat(unit: TargetUnit, priceOptions?: Intl.NumberFormatOptions, short?: number): Intl.NumberFormatOptions;
|
|
88
|
+
/**
|
|
89
|
+
* 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
|
|
90
|
+
* the stretch (`from` to `to`) between them: the whole bar, from entry to the trigger.
|
|
91
|
+
* Without a trigger there is no stretch.
|
|
92
|
+
*/
|
|
93
|
+
export declare function targetLayout({ entry, trigger }: {
|
|
94
|
+
entry: number;
|
|
95
|
+
trigger?: number | null;
|
|
96
|
+
}): {
|
|
97
|
+
positions: Partial<Record<TargetPrice, number>>;
|
|
98
|
+
order: TargetPrice[];
|
|
99
|
+
from: number;
|
|
100
|
+
to: number;
|
|
101
|
+
};
|
|
102
|
+
/** 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. */
|
|
103
|
+
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;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useId, useRef, useState } from 'react';
|
|
4
|
+
import { formatNumber } from '@bloxwap/hig/contracts';
|
|
5
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
6
|
+
import { PressDecoration, usePresentNumber, useHIG, useNumberLocale } from '../provider.js';
|
|
7
|
+
import { Button } from '../button.js';
|
|
8
|
+
import { SegmentedControl } from '../selection.js';
|
|
9
|
+
import { AnimatedNumberReadout } from '../animated-number.js';
|
|
10
|
+
import { ScreenHeader } from './screen-header.js';
|
|
11
|
+
import { SwapIcon } from './swap/shared.js';
|
|
12
|
+
/** The quick choices as `{value, disabled}`, whichever form the host gave. */
|
|
13
|
+
export function targetPresets(presets) { return presets.map(preset => typeof preset === 'number' ? { value: preset } : preset); }
|
|
14
|
+
/** The units as `{unit, disabled}`, whichever form the host gave. */
|
|
15
|
+
export function targetUnits(units) { return units.map(unit => typeof unit === 'string' ? { unit } : unit); }
|
|
16
|
+
const usd = { style: 'currency', currency: 'USD' }, allUnits = ['dollar', 'price', 'percent'];
|
|
17
|
+
const known = (value) => value != null && Number.isFinite(value);
|
|
18
|
+
/** 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
|
+
export function targetFormat(unit, priceOptions = usd, short) {
|
|
20
|
+
if (unit === 'price')
|
|
21
|
+
return priceOptions;
|
|
22
|
+
if (unit === 'percent')
|
|
23
|
+
return { style: 'percent', maximumFractionDigits: 2, signDisplay: 'exceptZero' };
|
|
24
|
+
return { ...usd, signDisplay: 'exceptZero', ...(short !== undefined && Number.isInteger(short) ? { maximumFractionDigits: 0 } : null) };
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 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
|
|
28
|
+
* the stretch (`from` to `to`) between them: the whole bar, from entry to the trigger.
|
|
29
|
+
* Without a trigger there is no stretch.
|
|
30
|
+
*/
|
|
31
|
+
export function targetLayout({ entry, trigger }) {
|
|
32
|
+
const values = {};
|
|
33
|
+
if (known(entry))
|
|
34
|
+
values.entry = entry;
|
|
35
|
+
if (known(trigger))
|
|
36
|
+
values.trigger = trigger;
|
|
37
|
+
const kinds = Object.keys(values), prices = kinds.map(kind => values[kind]);
|
|
38
|
+
if (!kinds.length)
|
|
39
|
+
return { positions: {}, order: [], from: 0.5, to: 0.5 };
|
|
40
|
+
const low = Math.min(...prices), span = Math.max(...prices) - low;
|
|
41
|
+
const positions = {};
|
|
42
|
+
for (const kind of kinds)
|
|
43
|
+
positions[kind] = span > 0 ? (values[kind] - low) / span : 0.5;
|
|
44
|
+
const rank = { entry: 0, trigger: 1 };
|
|
45
|
+
const order = [...kinds].sort((a, b) => values[a] - values[b] || rank[a] - rank[b]);
|
|
46
|
+
const start = positions.entry, end = positions.trigger;
|
|
47
|
+
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) };
|
|
48
|
+
}
|
|
49
|
+
/** 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. */
|
|
50
|
+
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 }) {
|
|
51
|
+
const { messages } = useHIG();
|
|
52
|
+
const locale = useNumberLocale();
|
|
53
|
+
const present = usePresentNumber();
|
|
54
|
+
const id = useId(), noteId = useId();
|
|
55
|
+
const [open, setOpen] = useState(false);
|
|
56
|
+
const anchor = useRef(null);
|
|
57
|
+
// The popover closes on a press outside it, on Escape, and when focus leaves it.
|
|
58
|
+
useEffect(() => { if (!open)
|
|
59
|
+
return; const outside = (event) => { if (!anchor.current?.contains(event.target))
|
|
60
|
+
setOpen(false); }; document.addEventListener('pointerdown', outside); return () => document.removeEventListener('pointerdown', outside); }, [open]);
|
|
61
|
+
const info = note && labels.info && (!headerAction || headerActionBesideInfo) ? labels.info : undefined;
|
|
62
|
+
const custom = onCustom && known(customValue) ? customValue : null;
|
|
63
|
+
const infoButton = info && _jsxs("span", { ref: anchor, className: 'hig-target-info', onKeyDown: event => { if (event.key === 'Escape' && open) {
|
|
64
|
+
event.stopPropagation();
|
|
65
|
+
setOpen(false);
|
|
66
|
+
} }, onBlur: event => { if (!event.currentTarget.contains(event.relatedTarget))
|
|
67
|
+
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 })] });
|
|
68
|
+
const target = trigger !== undefined ? trigger : unit === 'price' ? value : null;
|
|
69
|
+
const { positions, order, from, to } = targetLayout({ entry, trigger: target });
|
|
70
|
+
const prices = { entry, trigger: target };
|
|
71
|
+
const intent = kind === 'stop-loss' ? 'destructive' : 'primary';
|
|
72
|
+
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("div", { className: 'hig-target-presets', children: targetPresets(presets).map(({ value: preset, disabled }) => { const selected = custom === null && preset === value; return _jsx(Button, { fullWidth: true, intent: selected ? intent : 'secondary', "aria-pressed": selected, disabled: disabled, onClick: () => onValueChange?.(preset), children: formatNumber(preset, locale, present(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 })] })] });
|
|
73
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { HIGMessages } from '@bloxwap/hig/contracts/messages';
|
|
3
|
+
import { type BarMarkElement } from '../bar-mark.js';
|
|
4
|
+
export type { BarMarkElement, BarMarkFigure, BarMarkTone } from '../bar-mark.js';
|
|
5
|
+
/** Actions with a built-in, translated label. */
|
|
6
|
+
export type TokenActionId = 'send' | 'receive' | 'stake' | 'unstake';
|
|
7
|
+
export interface TokenAction {
|
|
8
|
+
/** `send`, `receive`, `stake` and `unstake` take a built-in label; any other id needs `label`. */
|
|
9
|
+
id: TokenActionId | (string & {});
|
|
10
|
+
label?: string;
|
|
11
|
+
onSelect: () => void;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
/** Defaults to `secondary`: the card offers equal choices, so no action is the primary one unless the host says so. */
|
|
14
|
+
intent?: 'primary' | 'secondary' | 'destructive';
|
|
15
|
+
}
|
|
16
|
+
export interface TokenActionBlockProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
|
|
17
|
+
/** Heading, usually the ticker: HYPE. */
|
|
18
|
+
symbol: string;
|
|
19
|
+
/** Title of the assets bar: Hyperliquid. Needed only with `assets`; the symbol stands in without it. */
|
|
20
|
+
name?: string;
|
|
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
|
+
value?: number | null;
|
|
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[];
|
|
33
|
+
/** Title of the chains bar. Defaults to the built-in “Chains”. */
|
|
34
|
+
chainsTitle?: string;
|
|
35
|
+
actions: readonly TokenAction[];
|
|
36
|
+
onBack?: () => void;
|
|
37
|
+
/** A control on the trailing edge of the header, usually an `IconButton`. */
|
|
38
|
+
headerAction?: React.ReactNode;
|
|
39
|
+
/** A line under the actions, for example why some are missing. `noteTone` tints it as in `SwapPanelBlock`. */
|
|
40
|
+
note?: React.ReactNode;
|
|
41
|
+
noteTone?: 'muted' | 'warning' | 'negative';
|
|
42
|
+
}
|
|
43
|
+
/** The text of an action: its `label`, the built-in label for a known id, or the id itself. */
|
|
44
|
+
export declare const tokenActionLabel: (action: TokenAction, messages?: Partial<HIGMessages>) => string;
|
|
45
|
+
/** 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. */
|
|
46
|
+
export declare function TokenActionBlock({ symbol, name, value, units, unitsSuffix, unitsOptions, assets, chains, chainsTitle, actions, onBack, headerAction, note, noteTone, className, ...rest }: TokenActionBlockProps): React.JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { formatNumber } from '@bloxwap/hig/contracts';
|
|
4
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
5
|
+
import { useHIG, useNumberLocale } from '../provider.js';
|
|
6
|
+
import { Button } from '../button.js';
|
|
7
|
+
import { AnimatedNumberReadout } from '../animated-number.js';
|
|
8
|
+
import { BarMark } from '../bar-mark.js';
|
|
9
|
+
import { ScreenHeader } from './screen-header.js';
|
|
10
|
+
const usd = { style: 'currency', currency: 'USD' }, unitsFormat = { maximumFractionDigits: 6 }, held = (value) => Number.isFinite(value) && value > 0;
|
|
11
|
+
/** The text of an action: its `label`, the built-in label for a known id, or the id itself. */
|
|
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
|
+
/** 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, units, unitsSuffix, unitsOptions = unitsFormat, assets, chains, chainsTitle, actions, onBack, headerAction, note, noteTone = 'muted', 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 }), (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 })] });
|
|
21
|
+
}
|
|
@@ -5,8 +5,8 @@ import * as en from '@bloxwap/hig/contracts/messages';
|
|
|
5
5
|
import { useHIG } from '../provider.js';
|
|
6
6
|
import { Button } from '../button.js';
|
|
7
7
|
import { Surface, Stack, Heading } from '../surface.js';
|
|
8
|
-
import { Field,
|
|
8
|
+
import { Field, Input } from '../field.js';
|
|
9
9
|
import { Dialog } from '../dialog.js';
|
|
10
10
|
import { Alert } from '../status.js';
|
|
11
11
|
/** Host validates and submits. Opening review never submits a transaction. */
|
|
12
|
-
export function TradeEntry({ asset, amount, onAmountChange, onConfirm, busy, error, available }) { const { messages } = useHIG(); const [review, setReview] = useState(false); return _jsx(Surface, { children: _jsxs(Stack, { children: [_jsx(Heading, { children: (messages.reviewAssetOrder ?? en.reviewAssetOrder)(asset) }), _jsx(Field, { label: (messages.amountInAsset ?? en.amountInAsset)(asset), description: (messages.availableAmount ?? en.availableAmount)(available), error: error, children: _jsx(
|
|
12
|
+
export function TradeEntry({ asset, amount, onAmountChange, onConfirm, busy, error, available }) { const { messages } = useHIG(); const [review, setReview] = useState(false); return _jsx(Surface, { children: _jsxs(Stack, { children: [_jsx(Heading, { children: (messages.reviewAssetOrder ?? en.reviewAssetOrder)(asset) }), _jsx(Field, { label: (messages.amountInAsset ?? en.amountInAsset)(asset), description: (messages.availableAmount ?? en.availableAmount)(available), error: error, children: _jsx(Input, { type: 'text', inputMode: 'decimal', value: amount, onChange: e => onAmountChange(e.target.value), readOnly: busy }) }), _jsx(Button, { fullWidth: true, className: 'hig-form-action', disabled: !amount || !!error, busy: busy, onClick: () => setReview(true), children: messages.reviewOrder ?? en.reviewOrder }), _jsxs(Dialog, { open: review, onOpenChange: setReview, title: messages.confirmOrder ?? en.confirmOrder, description: (messages.confirmOrderDescription ?? en.confirmOrderDescription)(amount, asset), children: [_jsx(Button, { busy: busy, disabled: !!error, onClick: onConfirm, children: messages.confirmOrder ?? en.confirmOrder }), error && _jsx(Alert, { title: messages.orderUnavailable ?? en.orderUnavailable, severity: 'error', children: _jsx("p", { children: error }) })] })] }) }); }
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { AssetArtwork } from '../asset-balance-row.js';
|
|
3
|
+
/** The words of the card. They are trading terms, so the host supplies them; HIG ships none. */
|
|
4
|
+
export interface TradeHistoryDetailLabels {
|
|
5
|
+
title: string;
|
|
6
|
+
/** Names the figure for assistive technology: Net PnL. It is not drawn; the signed figure and the line under it carry the meaning on screen. */
|
|
7
|
+
netPnl: string;
|
|
8
|
+
/** Names of the two prices under the bar. Needed with `entry` and `exit`. */
|
|
9
|
+
entry?: string;
|
|
10
|
+
exit?: string;
|
|
11
|
+
/** `+2.84% on margin`: receives the formatted percent. */
|
|
12
|
+
onMargin: (percent: string) => string;
|
|
13
|
+
long: string;
|
|
14
|
+
short: string;
|
|
15
|
+
}
|
|
16
|
+
/** One label and value row. A number is formatted with `options` between `prefix` and `suffix`; a string is drawn as given, for example a duration the host has already formatted. */
|
|
17
|
+
export interface TradeHistoryDetail {
|
|
18
|
+
label: string;
|
|
19
|
+
value: string | number;
|
|
20
|
+
options?: Intl.NumberFormatOptions;
|
|
21
|
+
prefix?: string;
|
|
22
|
+
suffix?: string;
|
|
23
|
+
/** With a number `value`: host-formatted text drawn and read in place of Intl's, still moving place by place. */
|
|
24
|
+
formattedValue?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface TradeHistoryAction {
|
|
27
|
+
id: string;
|
|
28
|
+
label: string;
|
|
29
|
+
onSelect: () => void;
|
|
30
|
+
intent?: 'primary' | 'secondary';
|
|
31
|
+
disabled?: boolean;
|
|
32
|
+
busy?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export interface TradeHistoryDetailBlockProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
|
|
35
|
+
labels: TradeHistoryDetailLabels;
|
|
36
|
+
/** Asset name: Amazon. */
|
|
37
|
+
name: string;
|
|
38
|
+
icon?: AssetArtwork;
|
|
39
|
+
/** Short ticker for the fallback disc when there is no `icon`: BTC. Without it the disc shows the first letters of the name. */
|
|
40
|
+
symbol?: string;
|
|
41
|
+
side: 'long' | 'short';
|
|
42
|
+
/** 20 reads `20×`. */
|
|
43
|
+
leverage?: number;
|
|
44
|
+
/** A short muted qualifier after the leverage, read with it: current. */
|
|
45
|
+
leverageNote?: string;
|
|
46
|
+
/** Net profit and loss in dollars. `null` reads as unknown. */
|
|
47
|
+
pnl: number | null;
|
|
48
|
+
/** Format of the headline result. Defaults to signed US dollars with up to four decimals. The provider's `numberFormat` is merged under it. */
|
|
49
|
+
pnlOptions?: Intl.NumberFormatOptions;
|
|
50
|
+
/** Return on margin as a fraction: 0.0284 reads +2.84%. */
|
|
51
|
+
pnlPercent?: number | null;
|
|
52
|
+
/** Format of the return on margin. Defaults to a signed percent with two decimals. */
|
|
53
|
+
percentOptions?: Intl.NumberFormatOptions;
|
|
54
|
+
/** Entry and exit prices. With both, one bar runs from entry to exit in the result colour, with the two prices under it, in place of two rows. */
|
|
55
|
+
entry?: number;
|
|
56
|
+
exit?: number;
|
|
57
|
+
/** Format of the two prices. Defaults to US dollars. */
|
|
58
|
+
priceOptions?: Intl.NumberFormatOptions;
|
|
59
|
+
/** The trade's other figures in the order shown: size, notional, time held, fees, funding. They are drawn as a grid of small labels over values. */
|
|
60
|
+
details: readonly TradeHistoryDetail[];
|
|
61
|
+
/** One muted sentence under the details, such as that part of the record is missing. */
|
|
62
|
+
note?: string;
|
|
63
|
+
/** Short host text in a badge beside the title: Demo. */
|
|
64
|
+
badge?: string;
|
|
65
|
+
/** Actions in one row under the details, such as Save image and Share. */
|
|
66
|
+
actions?: readonly TradeHistoryAction[];
|
|
67
|
+
onBack?: () => void;
|
|
68
|
+
/** A control on the trailing edge of the header, usually an `IconButton`. */
|
|
69
|
+
headerAction?: React.ReactNode;
|
|
70
|
+
/** Ref to the summary (the asset line, the headline figure and the return), for a host that captures it as an image. */
|
|
71
|
+
summaryRef?: React.Ref<HTMLDivElement>;
|
|
72
|
+
/** Fills the summary, so an image captured from `summaryRef` is not transparent: `true` for the background role, or a CSS colour such as `var(--hig-overlay)` in a sheet. */
|
|
73
|
+
summaryBackground?: boolean | string;
|
|
74
|
+
/** 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. */
|
|
75
|
+
stickyHeader?: boolean;
|
|
76
|
+
}
|
|
77
|
+
/** The full record of one closed trade, drawn on the screen without cards because none of it is pressable: the asset with its side and leverage on one line, the net result as the headline figure, a bar from the entry price to the exit price, the other figures as a compact grid, and the host's actions. */
|
|
78
|
+
export declare function TradeHistoryDetailBlock({ labels, name, icon, symbol, side, leverage, leverageNote, pnl, pnlOptions, pnlPercent, percentOptions, entry, exit, priceOptions, details, note, badge, actions, onBack, headerAction, summaryRef, summaryBackground, stickyHeader, className, ...rest }: TradeHistoryDetailBlockProps): React.JSX.Element;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { formatNumber } from '@bloxwap/hig/contracts';
|
|
4
|
+
import { useNumberLocale } from '../provider.js';
|
|
5
|
+
import { Button } from '../button.js';
|
|
6
|
+
import { AnimatedNumberReadout } from '../animated-number.js';
|
|
7
|
+
import { BarPnl } from '../bar-pnl.js';
|
|
8
|
+
import { ScreenHeader } from './screen-header.js';
|
|
9
|
+
import { SwapNumber } from './swap/shared.js';
|
|
10
|
+
const pnlFormat = { style: 'currency', currency: 'USD', signDisplay: 'exceptZero', maximumFractionDigits: 4 }, percentFormat = { style: 'percent', minimumFractionDigits: 2, maximumFractionDigits: 2, signDisplay: 'exceptZero' };
|
|
11
|
+
/** The full record of one closed trade, drawn on the screen without cards because none of it is pressable: the asset with its side and leverage on one line, the net result as the headline figure, a bar from the entry price to the exit price, the other figures as a compact grid, and the host's actions. */
|
|
12
|
+
export function TradeHistoryDetailBlock({ labels, name, icon, symbol, side, leverage, leverageNote, pnl, pnlOptions = pnlFormat, pnlPercent, percentOptions = percentFormat, entry, exit, priceOptions, details, note, badge, actions = [], onBack, headerAction, summaryRef, summaryBackground, stickyHeader, className, ...rest }) {
|
|
13
|
+
const locale = useNumberLocale();
|
|
14
|
+
const tone = pnl == null || pnl === 0 ? undefined : pnl > 0 ? 'up' : 'down';
|
|
15
|
+
const fill = summaryBackground === true ? 'var(--hig-background)' : typeof summaryBackground === 'string' && summaryBackground ? summaryBackground : undefined;
|
|
16
|
+
return _jsxs("section", { ...rest, className: `hig-trade-detail${className ? ` ${className}` : ''}`, children: [_jsx(ScreenHeader, { title: labels.title, onBack: onBack, action: headerAction, badge: badge, stickyHeader: stickyHeader }), _jsxs("div", { className: 'hig-trade-summary', children: [_jsxs("div", { ref: summaryRef, className: 'hig-trade-result', "data-tone": tone, style: fill ? { background: fill } : undefined, children: [_jsxs("div", { className: 'hig-trade-identity', children: [_jsx("span", { className: 'hig-trade-avatar', "aria-hidden": 'true', children: typeof icon === 'string' ? _jsx("img", { src: icon, alt: '' }) : icon ?? symbol ?? name.slice(0, 3) }), _jsx("strong", { children: name }), _jsxs("span", { children: [_jsxs("span", { className: 'hig-position-side hig-trade-side', "data-side": side, children: [_jsxs("span", { "aria-hidden": 'true', children: [side === 'long' ? '↑' : '↓', " "] }), side === 'long' ? labels.long : labels.short] }), leverage != null && _jsxs(_Fragment, { children: [" ", formatNumber(leverage, locale), "\u00D7"] }), leverageNote && _jsxs(_Fragment, { children: [" ", _jsx("span", { className: 'hig-trade-leverage-note', children: leverageNote })] })] })] }), _jsxs("strong", { className: 'hig-trade-figure', children: [_jsxs("span", { className: 'hig-trade-caption hig-sr-only', children: [labels.netPnl, " "] }), _jsx(AnimatedNumberReadout, { value: pnl, options: pnlOptions })] }), pnlPercent !== undefined && _jsx("span", { className: 'hig-trade-return', children: pnlPercent === null ? labels.onMargin('—') : _jsx(SwapNumber, { template: labels.onMargin, value: pnlPercent, options: percentOptions }) })] }), entry != null && exit != null && _jsx(BarPnl, { className: 'hig-trade-bar', surface: false, fit: true, side: side, entry: entry, mark: exit, labels: { entry: labels.entry ?? '', mark: labels.exit ?? '', liquidation: '' }, priceOptions: priceOptions }), details.length > 0 && _jsx("dl", { className: 'hig-trade-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)) }), note && _jsx("p", { className: 'hig-trade-note', children: note })] }), actions.length > 0 && _jsx("div", { className: 'hig-trade-actions', children: actions.map(action => _jsx(Button, { fullWidth: true, intent: action.intent ?? 'secondary', disabled: action.disabled, busy: action.busy, onClick: action.onSelect, children: action.label }, action.id)) })] });
|
|
17
|
+
}
|