@bloxwap/hig 0.5.2 → 0.6.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/messages.d.ts +31 -4
- package/contracts/dist/messages.js +11 -2
- package/feedback/README.md +1 -1
- package/native/README.md +1 -1
- package/native/dist/account-block.d.ts +46 -0
- package/native/dist/account-block.js +28 -0
- package/native/dist/asset-balance-row.d.ts +20 -0
- package/native/dist/asset-balance-row.js +21 -0
- package/native/dist/bar-mark.d.ts +45 -0
- package/native/dist/bar-mark.js +34 -0
- package/native/dist/bar-pnl.d.ts +50 -0
- package/native/dist/bar-pnl.js +59 -0
- package/native/dist/blocks.d.ts +44 -0
- package/native/dist/{recipes.js → blocks.js} +19 -9
- package/native/dist/field.d.ts +0 -1
- package/native/dist/field.js +0 -1
- package/native/dist/icons.d.ts +8 -0
- package/native/dist/icons.js +4 -0
- package/native/dist/language-block.d.ts +31 -0
- package/native/dist/language-block.js +30 -0
- package/native/dist/list-group.d.ts +26 -0
- package/native/dist/list-group.js +27 -0
- package/native/dist/manage-position-block.d.ts +69 -0
- package/native/dist/manage-position-block.js +57 -0
- package/native/dist/notifications-block.d.ts +25 -0
- package/native/dist/notifications-block.js +14 -0
- package/native/dist/pickers.d.ts +12 -4
- package/native/dist/pickers.js +6 -2
- package/native/dist/position-block.d.ts +51 -0
- package/native/dist/position-block.js +21 -0
- package/native/dist/profile-block.d.ts +42 -0
- package/native/dist/profile-block.js +28 -0
- package/native/dist/reward-block.d.ts +83 -0
- package/native/dist/reward-block.js +35 -0
- package/native/dist/setting-header.d.ts +8 -0
- package/native/dist/setting-header.js +11 -0
- package/native/dist/setting-switch.d.ts +18 -0
- package/native/dist/setting-switch.js +17 -0
- package/native/dist/signals-block.d.ts +37 -0
- package/native/dist/signals-block.js +16 -0
- package/native/dist/sound-haptics-block.d.ts +39 -0
- package/native/dist/sound-haptics-block.js +21 -0
- package/native/dist/{swap-panel.d.ts → swap-panel-block.d.ts} +6 -2
- package/native/dist/{swap-panel.js → swap-panel-block.js} +4 -2
- 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 +4 -4
- package/native/dist/target-block.d.ts +83 -0
- package/native/dist/target-block.js +61 -0
- package/native/dist/token-action-block.d.ts +39 -0
- package/native/dist/token-action-block.js +20 -0
- package/native/dist/trade-history-detail-block.d.ts +59 -0
- package/native/dist/trade-history-detail-block.js +38 -0
- package/native/dist/trade-history-list-block.d.ts +44 -0
- package/native/dist/trade-history-list-block.js +29 -0
- package/native-fonts/README.md +1 -1
- package/og-fonts/README.md +1 -1
- package/package.json +246 -41
- package/react/README.md +1 -1
- package/react/dist/asset-balance-row.d.ts +19 -0
- package/react/dist/asset-balance-row.js +10 -0
- package/react/dist/bar-mark.d.ts +35 -0
- package/react/dist/bar-mark.js +21 -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 +46 -0
- package/react/dist/blocks/account-block.js +27 -0
- package/react/dist/blocks/language-block.d.ts +32 -0
- package/react/dist/blocks/language-block.js +51 -0
- package/react/dist/blocks/manage-position-block.d.ts +67 -0
- package/react/dist/blocks/manage-position-block.js +28 -0
- package/react/dist/blocks/notifications-block.d.ts +23 -0
- package/react/dist/blocks/notifications-block.js +8 -0
- package/react/dist/{recipes → blocks}/pickers.d.ts +12 -4
- package/react/dist/{recipes → blocks}/pickers.js +6 -2
- package/react/dist/blocks/position-block.d.ts +49 -0
- package/react/dist/blocks/position-block.js +14 -0
- package/react/dist/blocks/profile-block.d.ts +48 -0
- package/react/dist/blocks/profile-block.js +15 -0
- package/react/dist/blocks/reward-block.d.ts +81 -0
- package/react/dist/blocks/reward-block.js +24 -0
- package/react/dist/blocks/screen-header.d.ts +9 -0
- package/react/dist/blocks/screen-header.js +12 -0
- package/react/dist/blocks/setting-switch.d.ts +10 -0
- package/react/dist/blocks/setting-switch.js +8 -0
- package/react/dist/blocks/signals-block.d.ts +35 -0
- package/react/dist/blocks/signals-block.js +15 -0
- package/react/dist/blocks/sound-haptics-block.d.ts +37 -0
- package/react/dist/blocks/sound-haptics-block.js +18 -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/shared.d.ts +1 -0
- package/react/dist/{recipes → blocks}/swap/shared.js +1 -0
- package/react/dist/{recipes/swap-panel.d.ts → blocks/swap-panel-block.d.ts} +6 -2
- package/react/dist/{recipes/swap-panel.js → blocks/swap-panel-block.js} +3 -1
- 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 +81 -0
- package/react/dist/blocks/target-block.js +65 -0
- package/react/dist/blocks/token-action-block.d.ts +37 -0
- package/react/dist/blocks/token-action-block.js +18 -0
- package/react/dist/{recipes → blocks}/trade-entry.js +2 -2
- package/react/dist/blocks/trade-history-detail-block.d.ts +58 -0
- package/react/dist/blocks/trade-history-detail-block.js +16 -0
- package/react/dist/blocks/trade-history-list-block.d.ts +43 -0
- package/react/dist/blocks/trade-history-list-block.js +21 -0
- package/react/dist/blocks.d.ts +20 -0
- package/react/dist/blocks.js +21 -0
- package/react/dist/field.d.ts +0 -2
- package/react/dist/field.js +0 -2
- package/react/dist/list-group.d.ts +26 -0
- package/react/dist/list-group.js +20 -0
- package/react/dist/styles.css +270 -5
- package/tokens/README.md +1 -1
- package/native/dist/recipes.d.ts +0 -46
- 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.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}/market-row.d.ts +0 -0
- /package/react/dist/{recipes → blocks}/market-row.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/amount-card.js +0 -0
- /package/react/dist/{recipes → blocks}/swap/settings.d.ts +0 -0
- /package/react/dist/{recipes → blocks}/swap/settings.js +0 -0
- /package/react/dist/{recipes → blocks}/trade-entry.d.ts +0 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useId } from 'react';
|
|
4
|
+
import { ScreenHeader } from './screen-header.js';
|
|
5
|
+
import { SettingSwitch } from './setting-switch.js';
|
|
6
|
+
import { SwapPill } from './swap/shared.js';
|
|
7
|
+
const verifiedMark = _jsxs("svg", { "aria-hidden": 'true', focusable: 'false', viewBox: '0 0 20 20', width: '16', height: '16', fill: 'none', stroke: 'currentColor', strokeWidth: '1.8', strokeLinecap: 'round', strokeLinejoin: 'round', children: [_jsx("circle", { cx: '10', cy: '10', r: '7.5' }), _jsx("path", { d: 'm6.75 10.25 2.25 2.25 4.25-4.75' })] });
|
|
8
|
+
function Group({ group, verifiedLabel }) {
|
|
9
|
+
const id = useId();
|
|
10
|
+
return _jsxs("section", { className: 'hig-signals-group', "aria-labelledby": id, children: [_jsxs("div", { className: 'hig-signals-group-header', children: [_jsxs("h3", { id: id, children: [group.title, group.verified && _jsx("span", { className: 'hig-reward-verified', role: verifiedLabel ? 'img' : undefined, "aria-label": verifiedLabel, children: verifiedMark })] }), group.help && _jsx(SwapPill, { onClick: group.help.onSelect, children: group.help.label })] }), group.items.length > 0 && _jsx("div", { className: 'hig-setting-list', children: group.items.map(item => _jsx("div", { className: 'hig-setting-card', children: _jsx(SettingSwitch, { label: item.label, description: item.description, checked: item.checked, disabled: item.disabled, onCheckedChange: item.onCheckedChange }) }, item.id)) })] });
|
|
11
|
+
}
|
|
12
|
+
/** The signals the viewer receives, in groups: each group has a heading with an optional verified mark and a small help pill, and its signals as switches with a line of explanation, sharing one rounded container. */
|
|
13
|
+
export function SignalsBlock({ title, groups, verifiedLabel, onBack, headerAction, className, ...rest }) {
|
|
14
|
+
return _jsxs("section", { ...rest, className: `hig-settings-block${className ? ` ${className}` : ''}`, children: [_jsx(ScreenHeader, { title: title, onBack: onBack, action: headerAction }), groups.map(group => _jsx(Group, { group: group, verifiedLabel: verifiedLabel }, group.id))] });
|
|
15
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/** A volume as a few fixed steps. `value` and `options` are fractions: 0.25 reads 25%. */
|
|
3
|
+
export interface SoundVolume {
|
|
4
|
+
/** Names the steps and is drawn above them: Volume. */
|
|
5
|
+
label: string;
|
|
6
|
+
/** Defaults to 25%, 50%, 75% and 100%. */
|
|
7
|
+
options?: readonly number[];
|
|
8
|
+
value: number;
|
|
9
|
+
onValueChange: (value: number) => void;
|
|
10
|
+
}
|
|
11
|
+
/** One feedback channel: sound effects, the microphone, haptics, the flash. Every word is host text. */
|
|
12
|
+
export interface SoundSection {
|
|
13
|
+
id: string;
|
|
14
|
+
label: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
checked: boolean;
|
|
17
|
+
onCheckedChange: (checked: boolean) => void;
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
/** The device in use, under the switch: iPhone Microphone. */
|
|
20
|
+
source?: string;
|
|
21
|
+
/** A live input level from 0 to 1, drawn as a meter. `null` draws an empty meter. */
|
|
22
|
+
level?: number | null;
|
|
23
|
+
volume?: SoundVolume;
|
|
24
|
+
}
|
|
25
|
+
export interface SoundHapticsBlockProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
|
|
26
|
+
/** Heading: Sound & Haptics. */
|
|
27
|
+
title: string;
|
|
28
|
+
/** One card each, in order. A section's source, meter and volume show only while it is on. */
|
|
29
|
+
sections: readonly SoundSection[];
|
|
30
|
+
onBack?: () => void;
|
|
31
|
+
/** A control on the trailing edge of the header, usually an `IconButton`. */
|
|
32
|
+
headerAction?: React.ReactNode;
|
|
33
|
+
}
|
|
34
|
+
/** The share of the meter filled, from 0 to 1. Unknown and out-of-range levels are clamped. */
|
|
35
|
+
export declare const soundLevel: (level: number | null | undefined) => number;
|
|
36
|
+
/** The settings for what the app plays and feels like: each channel is a card with a switch, and a channel that is on can show the device it uses, a live input meter and its volume as fixed steps. */
|
|
37
|
+
export declare function SoundHapticsBlock({ title, sections, onBack, headerAction, className, ...rest }: SoundHapticsBlockProps): React.JSX.Element;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { formatNumber } from '@bloxwap/hig/contracts';
|
|
4
|
+
import { useHIG } from '../provider.js';
|
|
5
|
+
import { Button } from '../button.js';
|
|
6
|
+
import { ScreenHeader } from './screen-header.js';
|
|
7
|
+
import { SettingSwitch } from './setting-switch.js';
|
|
8
|
+
const steps = [0.25, 0.5, 0.75, 1], percent = { style: 'percent', maximumFractionDigits: 0 };
|
|
9
|
+
/** The share of the meter filled, from 0 to 1. Unknown and out-of-range levels are clamped. */
|
|
10
|
+
export const soundLevel = (level) => level == null || !Number.isFinite(level) ? 0 : Math.min(1, Math.max(0, level));
|
|
11
|
+
/** The settings for what the app plays and feels like: each channel is a card with a switch, and a channel that is on can show the device it uses, a live input meter and its volume as fixed steps. */
|
|
12
|
+
export function SoundHapticsBlock({ title, sections, onBack, headerAction, className, ...rest }) {
|
|
13
|
+
const { locale } = useHIG();
|
|
14
|
+
return _jsxs("section", { ...rest, className: `hig-settings-block${className ? ` ${className}` : ''}`, children: [_jsx(ScreenHeader, { title: title, onBack: onBack, action: headerAction }), sections.length > 0 && _jsx("div", { className: 'hig-setting-cards', children: sections.map(section => {
|
|
15
|
+
const { source, level, volume } = section, open = section.checked && (!!source || level !== undefined || !!volume);
|
|
16
|
+
return _jsxs("div", { className: 'hig-setting-card', children: [_jsx(SettingSwitch, { label: section.label, description: section.description, checked: section.checked, disabled: section.disabled, onCheckedChange: section.onCheckedChange }), open && _jsxs("div", { className: 'hig-setting-body', children: [source && _jsx("span", { className: 'hig-setting-caption', children: source }), level !== undefined && _jsx("div", { className: 'hig-setting-meter', "aria-hidden": 'true', children: _jsx("span", { style: { width: `${soundLevel(level) * 100}%` } }) }), volume && _jsxs("div", { className: 'hig-setting-volume', role: 'group', "aria-label": volume.label, children: [_jsx("span", { className: 'hig-setting-caption', "aria-hidden": 'true', children: volume.label }), _jsx("div", { className: 'hig-setting-steps', children: (volume.options ?? steps).map(option => _jsx(Button, { fullWidth: true, intent: option === volume.value ? 'primary' : 'secondary', "aria-pressed": option === volume.value, disabled: section.disabled, onClick: () => volume.onValueChange(option), children: formatNumber(option, locale, percent) }, option)) })] })] })] }, section.id);
|
|
17
|
+
}) })] });
|
|
18
|
+
}
|
|
@@ -22,5 +22,5 @@ export interface SwapPickerProps {
|
|
|
22
22
|
onRecipientChange?: (address: string) => void;
|
|
23
23
|
onScanRecipient?: () => void;
|
|
24
24
|
}
|
|
25
|
-
/** The panel's pushed picker view: a header with Back above the From or To picker
|
|
25
|
+
/** The panel's pushed picker view: a header with Back above the From or To picker block. */
|
|
26
26
|
export declare function SwapPicker({ side, onBack, selected, onSelect, wallet, onConnect, onDisconnect, receiving, onReceivingChange, recipient, onRecipientChange, onScanRecipient, ...list }: SwapPickerProps): React.JSX.Element;
|
|
@@ -3,9 +3,9 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { useEffect, useRef } from 'react';
|
|
4
4
|
import * as en from '@bloxwap/hig/contracts/messages';
|
|
5
5
|
import { useHIG } from '../../provider.js';
|
|
6
|
-
import {
|
|
6
|
+
import { FromPickerBlock, ToPickerBlock } from '../pickers.js';
|
|
7
7
|
import { SwapViewHeader, shortAddress } from './shared.js';
|
|
8
|
-
/** The panel's pushed picker view: a header with Back above the From or To picker
|
|
8
|
+
/** The panel's pushed picker view: a header with Back above the From or To picker block. */
|
|
9
9
|
export function SwapPicker({ side, onBack, selected, onSelect, wallet, onConnect, onDisconnect, receiving, onReceivingChange, recipient, onRecipientChange, onScanRecipient, ...list }) {
|
|
10
10
|
const { messages } = useHIG();
|
|
11
11
|
const title = side === 'from' ? messages.swapFrom ?? en.swapFrom : messages.swapTo ?? en.swapTo;
|
|
@@ -15,6 +15,6 @@ export function SwapPicker({ side, onBack, selected, onSelect, wallet, onConnect
|
|
|
15
15
|
heading.current?.focus(); }, []);
|
|
16
16
|
const choose = (token) => { onSelect(token); onBack(); };
|
|
17
17
|
return _jsxs("div", { className: 'hig-swap-picker', children: [_jsx(SwapViewHeader, { title: title, titleRef: heading, backLabel: messages.back ?? en.back, onBack: onBack }), side === 'from'
|
|
18
|
-
? _jsx(
|
|
19
|
-
: _jsx(
|
|
18
|
+
? _jsx(FromPickerBlock, { ...list, autoFocus: true, selected: selected, onSelect: choose, wallet: wallet ?? { connected: false }, onConnect: onConnect, onDisconnect: onDisconnect, generateAddress: !!receiving, onGenerateAddressChange: onReceivingChange })
|
|
19
|
+
: _jsx(ToPickerBlock, { ...list, autoFocus: true, selected: selected, onSelect: choose, address: recipient, onAddressChange: onRecipientChange, addressPlaceholder: wallet?.address ? shortAddress(wallet.address) : undefined, onScan: onScanRecipient })] });
|
|
20
20
|
}
|
|
@@ -97,6 +97,7 @@ const paths = {
|
|
|
97
97
|
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
98
|
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
99
|
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' }),
|
|
100
|
+
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
101
|
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
102
|
};
|
|
102
103
|
/** Outline symbol on a 20 unit grid; decorative, so the control that holds it carries the name. */
|
|
@@ -38,7 +38,7 @@ export interface SwapReceive {
|
|
|
38
38
|
qr?: React.ReactNode; /** Host clipboard adapter. When set, the whole view copies the address. */
|
|
39
39
|
onCopy?: () => Promise<void> | void;
|
|
40
40
|
}
|
|
41
|
-
export interface
|
|
41
|
+
export interface SwapPanelBlockProps {
|
|
42
42
|
/** Catalog for the To side, and for the From side unless `fromTokens` is given. */
|
|
43
43
|
tokens: readonly SwapToken[];
|
|
44
44
|
/** Assets offered on the From side, typically the connected wallet's holdings. */
|
|
@@ -140,4 +140,8 @@ export interface SwapPanelProps {
|
|
|
140
140
|
* or token units, token pickers, settings, and one action that names itself from the chosen pair.
|
|
141
141
|
* Presentation only. The host owns tokens, balances, prices, the quote, the wallet and the transaction.
|
|
142
142
|
*/
|
|
143
|
-
export declare function
|
|
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;
|
|
144
|
+
/** @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
|
+
export declare const SwapPanel: typeof SwapPanelBlock;
|
|
146
|
+
/** @deprecated Renamed `SwapPanelBlockProps`. */
|
|
147
|
+
export type SwapPanelProps = SwapPanelBlockProps;
|
|
@@ -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);
|
|
@@ -174,3 +174,5 @@ export function SwapPanel({ tokens, fromTokens, fromTokensLoading, chains, hotTo
|
|
|
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,81 @@
|
|
|
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. */
|
|
41
|
+
units?: readonly TargetUnit[];
|
|
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. */
|
|
47
|
+
presets?: readonly number[];
|
|
48
|
+
/** Shows the Custom row; the host opens its own entry. */
|
|
49
|
+
onCustom?: () => void;
|
|
50
|
+
/** Format of prices. Defaults to US dollars. */
|
|
51
|
+
priceOptions?: Intl.NumberFormatOptions;
|
|
52
|
+
/** 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. */
|
|
53
|
+
surface?: boolean;
|
|
54
|
+
onSubmit: () => void;
|
|
55
|
+
/** Defaults to disabled while `value` is unknown. */
|
|
56
|
+
submitDisabled?: boolean;
|
|
57
|
+
busy?: boolean;
|
|
58
|
+
/** Shows Cancel beside the confirming action. */
|
|
59
|
+
onCancel?: () => void;
|
|
60
|
+
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. */
|
|
62
|
+
headerAction?: React.ReactNode;
|
|
63
|
+
}
|
|
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. */
|
|
65
|
+
export declare function targetFormat(unit: TargetUnit, priceOptions?: Intl.NumberFormatOptions, short?: number): Intl.NumberFormatOptions;
|
|
66
|
+
/**
|
|
67
|
+
* 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
|
|
68
|
+
* the stretch (`from` to `to`) between them: the whole bar, from entry to the trigger.
|
|
69
|
+
* Without a trigger there is no stretch.
|
|
70
|
+
*/
|
|
71
|
+
export declare function targetLayout({ entry, trigger }: {
|
|
72
|
+
entry: number;
|
|
73
|
+
trigger?: number | null;
|
|
74
|
+
}): {
|
|
75
|
+
positions: Partial<Record<TargetPrice, number>>;
|
|
76
|
+
order: TargetPrice[];
|
|
77
|
+
from: number;
|
|
78
|
+
to: number;
|
|
79
|
+
};
|
|
80
|
+
/** 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;
|
|
@@ -0,0 +1,65 @@
|
|
|
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 { useHIG } 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
|
+
const usd = { style: 'currency', currency: 'USD' }, allUnits = ['dollar', 'price', 'percent'];
|
|
13
|
+
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. */
|
|
15
|
+
export function targetFormat(unit, priceOptions = usd, short) {
|
|
16
|
+
if (unit === 'price')
|
|
17
|
+
return priceOptions;
|
|
18
|
+
if (unit === 'percent')
|
|
19
|
+
return { style: 'percent', maximumFractionDigits: 2, signDisplay: 'exceptZero' };
|
|
20
|
+
return { ...usd, signDisplay: 'exceptZero', ...(short !== undefined && Number.isInteger(short) ? { maximumFractionDigits: 0 } : null) };
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 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
|
|
24
|
+
* the stretch (`from` to `to`) between them: the whole bar, from entry to the trigger.
|
|
25
|
+
* Without a trigger there is no stretch.
|
|
26
|
+
*/
|
|
27
|
+
export function targetLayout({ entry, trigger }) {
|
|
28
|
+
const values = {};
|
|
29
|
+
if (known(entry))
|
|
30
|
+
values.entry = entry;
|
|
31
|
+
if (known(trigger))
|
|
32
|
+
values.trigger = trigger;
|
|
33
|
+
const kinds = Object.keys(values), prices = kinds.map(kind => values[kind]);
|
|
34
|
+
if (!kinds.length)
|
|
35
|
+
return { positions: {}, order: [], from: 0.5, to: 0.5 };
|
|
36
|
+
const low = Math.min(...prices), span = Math.max(...prices) - low;
|
|
37
|
+
const positions = {};
|
|
38
|
+
for (const kind of kinds)
|
|
39
|
+
positions[kind] = span > 0 ? (values[kind] - low) / span : 0.5;
|
|
40
|
+
const rank = { entry: 0, trigger: 1 };
|
|
41
|
+
const order = [...kinds].sort((a, b) => values[a] - values[b] || rank[a] - rank[b]);
|
|
42
|
+
const start = positions.entry, end = positions.trigger;
|
|
43
|
+
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
|
+
}
|
|
45
|
+
/** 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();
|
|
48
|
+
const id = useId(), noteId = useId();
|
|
49
|
+
const [open, setOpen] = useState(false);
|
|
50
|
+
const anchor = useRef(null);
|
|
51
|
+
// The popover closes on a press outside it, on Escape, and when focus leaves it.
|
|
52
|
+
useEffect(() => { if (!open)
|
|
53
|
+
return; const outside = (event) => { if (!anchor.current?.contains(event.target))
|
|
54
|
+
setOpen(false); }; document.addEventListener('pointerdown', outside); return () => document.removeEventListener('pointerdown', outside); }, [open]);
|
|
55
|
+
const info = note && labels.info && !headerAction ? labels.info : undefined;
|
|
56
|
+
const target = trigger !== undefined ? trigger : unit === 'price' ? value : null;
|
|
57
|
+
const { positions, order, from, to } = targetLayout({ entry, trigger: target });
|
|
58
|
+
const prices = { entry, trigger: target };
|
|
59
|
+
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 })] })] });
|
|
65
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
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, 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. */
|
|
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
|
+
/** Where the token is held: Staked, Core, Paper. */
|
|
24
|
+
assets: readonly BarMarkElement[];
|
|
25
|
+
/** The chains the token sits on. */
|
|
26
|
+
chains: readonly BarMarkElement[];
|
|
27
|
+
/** Title of the chains bar. Defaults to the built-in “Chains”. */
|
|
28
|
+
chainsTitle?: string;
|
|
29
|
+
actions: readonly TokenAction[];
|
|
30
|
+
onBack?: () => void;
|
|
31
|
+
/** A control on the trailing edge of the header, usually an `IconButton`. */
|
|
32
|
+
headerAction?: React.ReactNode;
|
|
33
|
+
}
|
|
34
|
+
/** The text of an action: its `label`, the built-in label for a known id, or the id itself. */
|
|
35
|
+
export declare const tokenActionLabel: (action: TokenAction, messages?: Partial<HIGMessages>) => string;
|
|
36
|
+
/** 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;
|
|
@@ -0,0 +1,18 @@
|
|
|
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 } 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' }, 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, 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)) })] });
|
|
18
|
+
}
|
|
@@ -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,58 @@
|
|
|
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
|
+
}
|
|
24
|
+
export interface TradeHistoryAction {
|
|
25
|
+
id: string;
|
|
26
|
+
label: string;
|
|
27
|
+
onSelect: () => void;
|
|
28
|
+
intent?: 'primary' | 'secondary';
|
|
29
|
+
disabled?: boolean;
|
|
30
|
+
busy?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface TradeHistoryDetailBlockProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
|
|
33
|
+
labels: TradeHistoryDetailLabels;
|
|
34
|
+
/** Asset name: Amazon. */
|
|
35
|
+
name: string;
|
|
36
|
+
icon?: AssetArtwork;
|
|
37
|
+
side: 'long' | 'short';
|
|
38
|
+
/** 20 reads `20×`. */
|
|
39
|
+
leverage?: number;
|
|
40
|
+
/** Net profit and loss in dollars. `null` reads as unknown. */
|
|
41
|
+
pnl: number | null;
|
|
42
|
+
/** Return on margin as a fraction: 0.0284 reads +2.84%. */
|
|
43
|
+
pnlPercent?: number | null;
|
|
44
|
+
/** 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. */
|
|
45
|
+
entry?: number;
|
|
46
|
+
exit?: number;
|
|
47
|
+
/** Format of the two prices. Defaults to US dollars. */
|
|
48
|
+
priceOptions?: Intl.NumberFormatOptions;
|
|
49
|
+
/** 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. */
|
|
50
|
+
details: readonly TradeHistoryDetail[];
|
|
51
|
+
/** Actions in one row under the details, such as Save image and Share. */
|
|
52
|
+
actions?: readonly TradeHistoryAction[];
|
|
53
|
+
onBack?: () => void;
|
|
54
|
+
/** A control on the trailing edge of the header, usually an `IconButton`. */
|
|
55
|
+
headerAction?: React.ReactNode;
|
|
56
|
+
}
|
|
57
|
+
/** 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. */
|
|
58
|
+
export declare function TradeHistoryDetailBlock({ labels, name, icon, side, leverage, pnl, pnlPercent, entry, exit, priceOptions, details, actions, onBack, headerAction, className, ...rest }: TradeHistoryDetailBlockProps): React.JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
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 { useHIG } 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, side, leverage, pnl, pnlPercent, entry, exit, priceOptions, details, actions = [], onBack, headerAction, className, ...rest }) {
|
|
13
|
+
const { locale } = useHIG();
|
|
14
|
+
const tone = pnl == null || pnl === 0 ? undefined : pnl > 0 ? 'up' : 'down';
|
|
15
|
+
return _jsxs("section", { ...rest, className: `hig-trade-detail${className ? ` ${className}` : ''}`, children: [_jsx(ScreenHeader, { title: labels.title, onBack: onBack, action: headerAction }), _jsxs("div", { className: 'hig-trade-summary', children: [_jsxs("div", { className: 'hig-trade-result', "data-tone": tone, 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 ?? 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"] })] })] }), _jsxs("strong", { className: 'hig-trade-figure', children: [_jsxs("span", { className: 'hig-trade-caption hig-sr-only', children: [labels.netPnl, " "] }), _jsx(AnimatedNumberReadout, { value: pnl, options: pnlFormat })] }), pnlPercent !== undefined && _jsx("span", { className: 'hig-trade-return', children: pnlPercent === null ? labels.onMargin('—') : _jsx(SwapNumber, { template: labels.onMargin, value: pnlPercent, options: percentFormat }) })] }), 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 }) : row.value })] }, row.label)) })] }), 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)) })] });
|
|
16
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
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 TradeHistoryListLabels {
|
|
5
|
+
/** Heading of the screen: History. */
|
|
6
|
+
title: string;
|
|
7
|
+
long: string;
|
|
8
|
+
short: string;
|
|
9
|
+
/** Shown in place of the rows when there are no trades. */
|
|
10
|
+
empty: string;
|
|
11
|
+
}
|
|
12
|
+
/** One closed trade. */
|
|
13
|
+
export interface TradeHistoryItem {
|
|
14
|
+
id: string;
|
|
15
|
+
/** Asset name: Amazon. */
|
|
16
|
+
name: string;
|
|
17
|
+
/** Round artwork: an image URL or a host element. Without it the row shows the first letters of the name. */
|
|
18
|
+
icon?: AssetArtwork;
|
|
19
|
+
side: 'long' | 'short';
|
|
20
|
+
/** 20 reads `20×`. */
|
|
21
|
+
leverage?: number;
|
|
22
|
+
/** Net profit and loss in dollars. `null` reads as unknown. */
|
|
23
|
+
pnl: number | null;
|
|
24
|
+
/** Host-formatted age or time of the close, shown under the result: `2d`. */
|
|
25
|
+
time?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface TradeHistoryListBlockProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title' | 'onSelect'> {
|
|
28
|
+
labels: TradeHistoryListLabels;
|
|
29
|
+
/** Closed trades, in the order shown. The host sorts and pages them. */
|
|
30
|
+
trades: readonly TradeHistoryItem[];
|
|
31
|
+
/** Makes each row a button that reports its trade, usually to open its detail, and shows the disclosure chevron. */
|
|
32
|
+
onSelect?: (trade: TradeHistoryItem) => void;
|
|
33
|
+
/** Shows Back on the leading edge of the header. */
|
|
34
|
+
onBack?: () => void;
|
|
35
|
+
/** A control on the trailing edge of the header, usually an `IconButton`. */
|
|
36
|
+
headerAction?: React.ReactNode;
|
|
37
|
+
/** Format of the result. Defaults to signed US dollars at four significant digits: `+$1.412`, `+$17.90`, `-$0.6878`. */
|
|
38
|
+
pnlOptions?: Intl.NumberFormatOptions;
|
|
39
|
+
}
|
|
40
|
+
/** How a row reads its side: `Short 20×`, or `Short` without leverage. */
|
|
41
|
+
export declare const tradeHistorySide: (trade: Pick<TradeHistoryItem, 'side' | 'leverage'>, labels: Pick<TradeHistoryListLabels, 'long' | 'short'>, locale?: string) => string;
|
|
42
|
+
/** A history of closed trades as one screen: a header, then one row per trade with the asset, its side and leverage in the direction colour, and the net result in the result colour over its age. */
|
|
43
|
+
export declare function TradeHistoryListBlock({ labels, trades, onSelect, onBack, headerAction, pnlOptions, className, ...rest }: TradeHistoryListBlockProps): React.JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
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 { useHIG } from '../provider.js';
|
|
5
|
+
import { AnimatedNumberReadout } from '../animated-number.js';
|
|
6
|
+
import { ScreenHeader } from './screen-header.js';
|
|
7
|
+
const pnlFormat = { style: 'currency', currency: 'USD', signDisplay: 'exceptZero', minimumSignificantDigits: 4, maximumSignificantDigits: 4 };
|
|
8
|
+
/** How a row reads its side: `Short 20×`, or `Short` without leverage. */
|
|
9
|
+
export const tradeHistorySide = (trade, labels, locale) => `${trade.side === 'long' ? labels.long : labels.short}${trade.leverage != null ? ` ${formatNumber(trade.leverage, locale)}×` : ''}`;
|
|
10
|
+
const arrow = (side) => _jsx("svg", { "aria-hidden": 'true', focusable: 'false', viewBox: '0 0 16 16', width: '16', height: '16', fill: 'none', stroke: 'currentColor', strokeWidth: '1.8', strokeLinecap: 'round', strokeLinejoin: 'round', children: side === 'long' ? _jsx("path", { d: 'M8 13V3.5M4 7.5l4-4 4 4' }) : _jsx("path", { d: 'M8 3v9.5M4 8.5l4 4 4-4' }) });
|
|
11
|
+
const chevron = _jsx("svg", { className: 'hig-trade-row-chevron', "aria-hidden": 'true', focusable: 'false', viewBox: '0 0 20 20', width: '20', height: '20', fill: 'none', stroke: 'currentColor', strokeWidth: '1.8', strokeLinecap: 'round', strokeLinejoin: 'round', children: _jsx("path", { d: 'm7.5 4.5 5.5 5.5-5.5 5.5' }) });
|
|
12
|
+
/** A history of closed trades as one screen: a header, then one row per trade with the asset, its side and leverage in the direction colour, and the net result in the result colour over its age. */
|
|
13
|
+
export function TradeHistoryListBlock({ labels, trades, onSelect, onBack, headerAction, pnlOptions = pnlFormat, className, ...rest }) {
|
|
14
|
+
const { locale } = useHIG();
|
|
15
|
+
const row = (trade) => {
|
|
16
|
+
const side = tradeHistorySide(trade, labels, locale), tone = trade.pnl == null || trade.pnl === 0 ? undefined : trade.pnl > 0 ? 'up' : 'down';
|
|
17
|
+
const content = _jsxs(_Fragment, { children: [_jsx("span", { className: 'hig-asset-row-icon', "aria-hidden": 'true', children: typeof trade.icon === 'string' ? _jsx("img", { src: trade.icon, alt: '' }) : trade.icon ?? trade.name.slice(0, 3) }), _jsxs("span", { className: 'hig-trade-row-identity', children: [_jsx("strong", { children: trade.name }), _jsxs("span", { className: 'hig-trade-row-side', "data-side": trade.side, children: [arrow(trade.side), _jsxs("span", { className: 'hig-sr-only', children: [trade.side === 'long' ? labels.long : labels.short, " "] }), trade.leverage != null && `${formatNumber(trade.leverage, locale)}×`] })] }), _jsxs("span", { className: 'hig-trade-row-result', children: [_jsx("strong", { className: 'hig-trade-pnl', "data-tone": tone, children: _jsx(AnimatedNumberReadout, { value: trade.pnl, options: pnlOptions }) }), trade.time && _jsx("span", { children: trade.time })] }), onSelect && chevron] });
|
|
18
|
+
return _jsx("li", { children: onSelect ? _jsx("button", { type: 'button', className: 'hig-trade-row', "aria-label": [trade.name, side, formatNumber(trade.pnl, locale, pnlOptions), trade.time].filter(Boolean).join(', '), onClick: () => onSelect(trade), children: content }) : _jsx("div", { className: 'hig-trade-row', children: content }) }, trade.id);
|
|
19
|
+
};
|
|
20
|
+
return _jsxs("section", { ...rest, className: `hig-trade-history-list${className ? ` ${className}` : ''}`, children: [_jsx(ScreenHeader, { title: labels.title, onBack: onBack, action: headerAction }), trades.length === 0 ? _jsx("p", { className: 'hig-swap-empty', role: 'status', children: labels.empty }) : _jsx("ul", { className: 'hig-trade-rows', "aria-label": labels.title, children: trades.map(row) })] });
|
|
21
|
+
}
|