@bloxwap/hig 0.5.1 → 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} +20 -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 +13 -5
- package/native/dist/pickers.js +10 -6
- 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} +28 -9
- package/native/dist/{swap-panel.js → swap-panel-block.js} +24 -14
- package/native/dist/swap-parts.d.ts +14 -3
- package/native/dist/swap-parts.js +16 -1
- package/native/dist/swap-shared.d.ts +18 -6
- package/native/dist/swap-shared.js +3 -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 +11 -8
- 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 +9 -6
- 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/settings.js +5 -7
- package/react/dist/{recipes → blocks}/swap/shared.d.ts +44 -6
- package/react/dist/{recipes → blocks}/swap/shared.js +25 -5
- package/react/dist/{recipes/swap-panel.d.ts → blocks/swap-panel-block.d.ts} +29 -9
- package/react/dist/{recipes/swap-panel.js → blocks/swap-panel-block.js} +22 -14
- 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 +275 -8
- package/tokens/README.md +1 -1
- package/native/dist/recipes.d.ts +0 -45
- 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}/trade-entry.d.ts +0 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type AssetArtwork } from '../asset-balance-row.js';
|
|
3
|
+
export { AssetBalanceRow, type AssetArtwork, type AssetBalanceRowProps } from '../asset-balance-row.js';
|
|
4
|
+
/** One holding of the account. The host supplies every figure; HIG sorts, formats and lays it out. */
|
|
5
|
+
export interface AccountAsset {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
symbol: string;
|
|
9
|
+
icon?: AssetArtwork;
|
|
10
|
+
/** Holding in token units. */
|
|
11
|
+
balance?: number | null;
|
|
12
|
+
/** USD per unit, when the host knows it. */
|
|
13
|
+
price?: number | null;
|
|
14
|
+
/** Dollar value of the holding. Defaults to `balance × price`. */
|
|
15
|
+
value?: number | null;
|
|
16
|
+
}
|
|
17
|
+
export interface AccountBlockProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
|
|
18
|
+
/** Heading. Defaults to the built-in “Account”. */
|
|
19
|
+
title?: string;
|
|
20
|
+
/** Shows Back on the leading edge of the header. */
|
|
21
|
+
onBack?: () => void;
|
|
22
|
+
/** Shows a QR button on the trailing edge of the header, above the deposit action. The host shows the account address, for example with `WalletAddress`. */
|
|
23
|
+
onShowAddress?: () => void;
|
|
24
|
+
/** A control on the trailing edge of the header, usually an `IconButton`. Replaces the QR button. */
|
|
25
|
+
headerAction?: React.ReactNode;
|
|
26
|
+
/** Total in dollars. Defaults to the sum of the asset values; `null` reads as unknown. */
|
|
27
|
+
balance?: number | null;
|
|
28
|
+
assets: readonly AccountAsset[];
|
|
29
|
+
/** Symbol of the asset that is always first. Defaults to `USDC`. */
|
|
30
|
+
pinnedSymbol?: string;
|
|
31
|
+
/** Shows the deposit action beside the total. */
|
|
32
|
+
onDeposit?: () => void;
|
|
33
|
+
/** Text of the deposit action. Defaults to the built-in “Deposit”. */
|
|
34
|
+
depositLabel?: string;
|
|
35
|
+
/** Makes each row a button that reports its asset. */
|
|
36
|
+
onAssetSelect?: (asset: AccountAsset) => void;
|
|
37
|
+
}
|
|
38
|
+
/** Dollar value of a holding: its `value`, or `balance × price` when both are known. */
|
|
39
|
+
export declare const assetValue: (asset: AccountAsset) => number | null;
|
|
40
|
+
/** The account's rows in display order: the pinned asset (a zero placeholder when the account does not hold it), then every other asset by dollar value, largest first, unknown values last and ties by name. */
|
|
41
|
+
export declare function accountRows(assets: readonly AccountAsset[], pinnedSymbol?: string): {
|
|
42
|
+
pinned: AccountAsset;
|
|
43
|
+
rest: AccountAsset[];
|
|
44
|
+
};
|
|
45
|
+
/** An account at a glance: a header, the total with a deposit action, the pinned dollar balance, then every other holding by value. */
|
|
46
|
+
export declare function AccountBlock({ title, onBack, onShowAddress, headerAction, balance, assets, pinnedSymbol, onDeposit, depositLabel, onAssetSelect, className, ...rest }: AccountBlockProps): React.JSX.Element;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
4
|
+
import { useHIG } from '../provider.js';
|
|
5
|
+
import { Button } from '../button.js';
|
|
6
|
+
import { AnimatedNumberReadout } from '../animated-number.js';
|
|
7
|
+
import { AssetBalanceRow } from '../asset-balance-row.js';
|
|
8
|
+
import { ScreenHeader, qrIcon } from './screen-header.js';
|
|
9
|
+
export { AssetBalanceRow } from '../asset-balance-row.js';
|
|
10
|
+
const usdCoin = 'USD Coin', usd = { style: 'currency', currency: 'USD' };
|
|
11
|
+
/** Dollar value of a holding: its `value`, or `balance × price` when both are known. */
|
|
12
|
+
export const assetValue = (asset) => asset.value !== undefined ? asset.value : asset.balance != null && asset.price != null ? asset.balance * asset.price : null;
|
|
13
|
+
/** The account's rows in display order: the pinned asset (a zero placeholder when the account does not hold it), then every other asset by dollar value, largest first, unknown values last and ties by name. */
|
|
14
|
+
export function accountRows(assets, pinnedSymbol = 'USDC') {
|
|
15
|
+
const index = assets.findIndex(asset => asset.symbol.toUpperCase() === pinnedSymbol.toUpperCase());
|
|
16
|
+
const pinned = index >= 0 ? assets[index] : { id: pinnedSymbol, name: pinnedSymbol === 'USDC' ? usdCoin : pinnedSymbol, symbol: pinnedSymbol, balance: 0, value: 0 };
|
|
17
|
+
const rest = assets.filter((_, position) => position !== index).sort((a, b) => { const left = assetValue(a), right = assetValue(b); return left === right ? a.name.localeCompare(b.name) : left === null ? 1 : right === null ? -1 : right - left || a.name.localeCompare(b.name); });
|
|
18
|
+
return { pinned, rest };
|
|
19
|
+
}
|
|
20
|
+
/** An account at a glance: a header, the total with a deposit action, the pinned dollar balance, then every other holding by value. */
|
|
21
|
+
export function AccountBlock({ title, onBack, onShowAddress, headerAction, balance, assets, pinnedSymbol = 'USDC', onDeposit, depositLabel, onAssetSelect, className, ...rest }) {
|
|
22
|
+
const { messages } = useHIG();
|
|
23
|
+
const { pinned, rest: others } = accountRows(assets, pinnedSymbol);
|
|
24
|
+
const total = balance !== undefined ? balance : assets.reduce((sum, asset) => sum + (assetValue(asset) ?? 0), 0);
|
|
25
|
+
const row = (asset, pin) => _jsx("li", { "data-pinned": pin || undefined, children: _jsx(AssetBalanceRow, { name: asset.name, symbol: asset.symbol, icon: asset.icon, value: assetValue(asset), balance: pin ? undefined : asset.balance ?? null, onSelect: onAssetSelect && (() => onAssetSelect(asset)) }) }, asset.id);
|
|
26
|
+
return _jsxs("section", { ...rest, className: `hig-account-block${className ? ` ${className}` : ''}`, children: [_jsx(ScreenHeader, { title: title ?? messages.account ?? en.account, onBack: onBack, action: headerAction ?? (onShowAddress && _jsx("button", { type: 'button', className: 'hig-swap-back hig-account-address', "aria-label": messages.showAddress ?? en.showAddress, onClick: onShowAddress, children: qrIcon })) }), _jsxs("div", { className: 'hig-account-summary', children: [_jsx("div", { className: 'hig-account-balance', children: _jsx(AnimatedNumberReadout, { value: total, label: messages.accountBalance ?? en.accountBalance, options: usd }) }), onDeposit && _jsx(Button, { onClick: onDeposit, children: depositLabel ?? messages.deposit ?? en.deposit })] }), _jsxs("ul", { className: 'hig-account-assets', children: [row(pinned, true), others.map(asset => row(asset, false))] })] });
|
|
27
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/** One language the host offers. */
|
|
3
|
+
export interface LanguageOption {
|
|
4
|
+
/** Stable id the host switches on, usually a BCP 47 tag such as `pt-BR`. */
|
|
5
|
+
code: string;
|
|
6
|
+
/** The language in its own words: `Français`. */
|
|
7
|
+
name: string;
|
|
8
|
+
/** The language in the reader's words, shown under the name: `French`. Omit it where it would repeat the name. */
|
|
9
|
+
description?: string;
|
|
10
|
+
/** Round artwork, usually a flag: an image URL or a host element. Without it the row shows the first letters of the code. */
|
|
11
|
+
flag?: string | React.ReactElement;
|
|
12
|
+
}
|
|
13
|
+
export interface LanguageBlockProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title' | 'onSelect'> {
|
|
14
|
+
/** Heading. Defaults to the built-in “Language”. */
|
|
15
|
+
title?: string;
|
|
16
|
+
/** Shows Back on the leading edge of the header. */
|
|
17
|
+
onBack?: () => void;
|
|
18
|
+
/** A control on the trailing edge of the header, usually an `IconButton` that closes the sheet. */
|
|
19
|
+
headerAction?: React.ReactNode;
|
|
20
|
+
languages: readonly LanguageOption[];
|
|
21
|
+
/** `code` of the language in use. */
|
|
22
|
+
value?: string | null;
|
|
23
|
+
onSelect: (language: LanguageOption) => void;
|
|
24
|
+
/** Set false to leave out the search field, for a short list. Default `true`. */
|
|
25
|
+
search?: boolean;
|
|
26
|
+
/** With a hardware pointer, focus the search field on mount so typing filters at once. */
|
|
27
|
+
autoFocus?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** The languages whose name, description or code contains the query, ignoring case and accents. An empty query keeps every language, in the host's order. */
|
|
30
|
+
export declare function filterLanguages(languages: readonly LanguageOption[], query: string): LanguageOption[];
|
|
31
|
+
/** Choose the app's language: a header, a search field, then each language as a row with its flag, its own name over the reader's name for it, and a check on the one in use. */
|
|
32
|
+
export declare function LanguageBlock({ title, onBack, headerAction, languages, value, onSelect, search, autoFocus, className, ...rest }: LanguageBlockProps): React.JSX.Element;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
4
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
5
|
+
import { useHIG } from '../provider.js';
|
|
6
|
+
import { SearchInput } from '../field.js';
|
|
7
|
+
import { ScreenHeader } from './screen-header.js';
|
|
8
|
+
const fold = (text) => text.normalize('NFD').replace(/[̀-ͯ]/g, '').toLowerCase();
|
|
9
|
+
/** The languages whose name, description or code contains the query, ignoring case and accents. An empty query keeps every language, in the host's order. */
|
|
10
|
+
export function filterLanguages(languages, query) {
|
|
11
|
+
const needle = fold(query.trim());
|
|
12
|
+
return needle === '' ? [...languages] : languages.filter(language => fold(`${language.name} ${language.description ?? ''} ${language.code}`).includes(needle));
|
|
13
|
+
}
|
|
14
|
+
const check = _jsx("svg", { className: 'hig-language-check', "aria-hidden": 'true', focusable: 'false', viewBox: '0 0 20 20', width: '20', height: '20', fill: 'none', stroke: 'currentColor', strokeWidth: '2', strokeLinecap: 'round', strokeLinejoin: 'round', children: _jsx("path", { d: 'm4.5 10.5 3.5 3.5 7.5-8' }) });
|
|
15
|
+
/** Choose the app's language: a header, a search field, then each language as a row with its flag, its own name over the reader's name for it, and a check on the one in use. */
|
|
16
|
+
export function LanguageBlock({ title, onBack, headerAction, languages, value = null, onSelect, search = true, autoFocus, className, ...rest }) {
|
|
17
|
+
const { messages } = useHIG();
|
|
18
|
+
const heading = title ?? messages.language ?? en.language;
|
|
19
|
+
const [query, setQuery] = useState('');
|
|
20
|
+
const [active, setActive] = useState(-1);
|
|
21
|
+
const field = useRef(null), list = useRef(null);
|
|
22
|
+
useEffect(() => { if (autoFocus && window.matchMedia?.('(pointer: fine)').matches)
|
|
23
|
+
field.current?.focus(); }, []);
|
|
24
|
+
const rows = useMemo(() => filterLanguages(languages, query), [languages, query]);
|
|
25
|
+
useEffect(() => { setActive(-1); }, [query]);
|
|
26
|
+
useEffect(() => { if (active >= 0)
|
|
27
|
+
list.current?.querySelector('[data-active="true"]')?.scrollIntoView?.({ block: 'nearest' }); }, [active]);
|
|
28
|
+
// From the search field, the arrow keys move through the matches and Enter chooses one: the only match, or the one the arrows reached.
|
|
29
|
+
const onKeyDown = (event) => {
|
|
30
|
+
if (event.key === 'ArrowDown') {
|
|
31
|
+
event.preventDefault();
|
|
32
|
+
setActive(index => Math.min(index + 1, rows.length - 1));
|
|
33
|
+
}
|
|
34
|
+
else if (event.key === 'ArrowUp') {
|
|
35
|
+
event.preventDefault();
|
|
36
|
+
setActive(index => Math.max(index - 1, 0));
|
|
37
|
+
}
|
|
38
|
+
else if (event.key === 'Enter') {
|
|
39
|
+
const choice = rows[active] ?? (rows.length === 1 ? rows[0] : undefined);
|
|
40
|
+
if (choice) {
|
|
41
|
+
event.preventDefault();
|
|
42
|
+
onSelect(choice);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const label = messages.searchLanguages ?? en.searchLanguages;
|
|
47
|
+
return _jsxs("section", { ...rest, className: `hig-language-block${className ? ` ${className}` : ''}`, children: [_jsx(ScreenHeader, { title: heading, onBack: onBack, action: headerAction }), search && _jsx(SearchInput, { ref: field, "aria-label": label, placeholder: label, value: query, onChange: event => setQuery(event.target.value), onKeyDown: onKeyDown, enterKeyHint: 'search', autoComplete: 'off', autoCapitalize: 'none', autoCorrect: 'off', spellCheck: false }), rows.length === 0 && _jsx("p", { className: 'hig-swap-empty', role: 'status', children: messages.noResults ?? en.noResults }), rows.length > 0 && _jsx("div", { ref: list, className: 'hig-language-list', role: 'radiogroup', "aria-label": heading, children: rows.map((language, index) => {
|
|
48
|
+
const selected = language.code === value;
|
|
49
|
+
return _jsxs("button", { type: 'button', role: 'radio', "aria-checked": selected, lang: language.code, className: 'hig-language-row', "data-active": index === active || undefined, onClick: () => onSelect(language), children: [_jsx("span", { className: 'hig-language-flag', "aria-hidden": 'true', children: typeof language.flag === 'string' ? _jsx("img", { src: language.flag, alt: '' }) : language.flag ?? language.code.slice(0, 2).toUpperCase() }), _jsxs("span", { className: 'hig-language-text', children: [_jsx("strong", { children: language.name }), language.description && _jsx("span", { lang: '', children: language.description })] }), selected && check] }, language.code);
|
|
50
|
+
}) })] });
|
|
51
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { AssetArtwork } from '../asset-balance-row.js';
|
|
3
|
+
/** The words of the block. They are trading terms, so the host supplies them in its own vocabulary and language; HIG ships none. */
|
|
4
|
+
export interface ManagePositionBlockLabels {
|
|
5
|
+
title: string;
|
|
6
|
+
margin: string;
|
|
7
|
+
notional: string;
|
|
8
|
+
liquidation: string;
|
|
9
|
+
/** `99.8% to liquidation`: receives the formatted percent. */
|
|
10
|
+
toLiquidation: (percent: string) => string;
|
|
11
|
+
mark: string;
|
|
12
|
+
entry: string;
|
|
13
|
+
/** Accessible words for the direction arrow. */
|
|
14
|
+
long: string;
|
|
15
|
+
short: string;
|
|
16
|
+
}
|
|
17
|
+
export interface ManagePositionBlockAction {
|
|
18
|
+
id: string;
|
|
19
|
+
label: string;
|
|
20
|
+
onSelect: () => void;
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/** The position being managed, shown as the row under the actions. */
|
|
24
|
+
export interface ManagePositionBlockSummary {
|
|
25
|
+
name: string;
|
|
26
|
+
icon?: AssetArtwork;
|
|
27
|
+
/** 40 reads `40×`. */
|
|
28
|
+
leverage?: number;
|
|
29
|
+
/** Size in asset units. */
|
|
30
|
+
size?: number | null;
|
|
31
|
+
/** Profit and loss in dollars. */
|
|
32
|
+
pnl?: number | null;
|
|
33
|
+
/** Profit and loss as a fraction: -0.0025 reads -0.25%. */
|
|
34
|
+
pnlPercent?: number | null;
|
|
35
|
+
}
|
|
36
|
+
export interface ManagePositionBlockProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
|
|
37
|
+
labels: ManagePositionBlockLabels;
|
|
38
|
+
/** Margin mode, the title of the first card: Demo, Cross, Isolated. Without it the title is the margin label. */
|
|
39
|
+
mode?: string;
|
|
40
|
+
side: 'long' | 'short';
|
|
41
|
+
entry: number;
|
|
42
|
+
mark?: number | null;
|
|
43
|
+
liquidation?: number | null;
|
|
44
|
+
margin: number;
|
|
45
|
+
notional: number;
|
|
46
|
+
/** Format of the three prices, such as another currency. They are drawn compact: no extra zeros. */
|
|
47
|
+
priceOptions?: Intl.NumberFormatOptions;
|
|
48
|
+
actions: readonly ManagePositionBlockAction[];
|
|
49
|
+
position?: ManagePositionBlockSummary;
|
|
50
|
+
onBack?: () => void;
|
|
51
|
+
/** A control on the trailing edge of the header, usually an `IconButton`. */
|
|
52
|
+
headerAction?: React.ReactNode;
|
|
53
|
+
}
|
|
54
|
+
/** Distance left before liquidation. `total` is the span from entry to liquidation, `buffer` what remains of it between the mark and liquidation (the whole span while in profit, nothing once past liquidation), `drawdown` the rest, and `share` the buffer as a fraction. Unknown prices, or a liquidation price on the wrong side of entry, give an empty corridor. */
|
|
55
|
+
export declare function positionCorridor({ side, entry, mark, liquidation }: {
|
|
56
|
+
side: 'long' | 'short';
|
|
57
|
+
entry: number;
|
|
58
|
+
mark?: number | null;
|
|
59
|
+
liquidation?: number | null;
|
|
60
|
+
}): {
|
|
61
|
+
total: number;
|
|
62
|
+
buffer: number;
|
|
63
|
+
drawdown: number;
|
|
64
|
+
share: number | null;
|
|
65
|
+
};
|
|
66
|
+
/** Manage one open position: margin against notional (with the share left before liquidation) as a `BarMark` and the liquidation, mark and entry prices as a `BarPnl`, both drawn without a card because they are read-only, the host's actions as one `ListGroup` of rows, and the position itself underneath. */
|
|
67
|
+
export declare function ManagePositionBlock({ labels, mode, side, entry, mark, liquidation, margin, notional, priceOptions, actions, position, onBack, headerAction, className, ...rest }: ManagePositionBlockProps): React.JSX.Element;
|
|
@@ -0,0 +1,28 @@
|
|
|
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 { BarMark } from '../bar-mark.js';
|
|
7
|
+
import { BarPnl } from '../bar-pnl.js';
|
|
8
|
+
import { ListGroup, ListRow } from '../list-group.js';
|
|
9
|
+
import { ScreenHeader } from './screen-header.js';
|
|
10
|
+
import { SwapNumber } from './swap/shared.js';
|
|
11
|
+
const usd = { style: 'currency', currency: 'USD' }, known = (value) => value != null && Number.isFinite(value);
|
|
12
|
+
/** Distance left before liquidation. `total` is the span from entry to liquidation, `buffer` what remains of it between the mark and liquidation (the whole span while in profit, nothing once past liquidation), `drawdown` the rest, and `share` the buffer as a fraction. Unknown prices, or a liquidation price on the wrong side of entry, give an empty corridor. */
|
|
13
|
+
export function positionCorridor({ side, entry, mark, liquidation }) {
|
|
14
|
+
if (!known(mark) || !known(liquidation))
|
|
15
|
+
return { total: 0, buffer: 0, drawdown: 0, share: null };
|
|
16
|
+
const span = side === 'long' ? entry - liquidation : liquidation - entry;
|
|
17
|
+
if (!(span > 0))
|
|
18
|
+
return { total: 0, buffer: 0, drawdown: 0, share: null };
|
|
19
|
+
const traveled = side === 'long' ? entry - mark : mark - entry, buffer = Math.max(0, Math.min(span, span - traveled));
|
|
20
|
+
return { total: span, buffer, drawdown: span - buffer, share: buffer / span };
|
|
21
|
+
}
|
|
22
|
+
/** Manage one open position: margin against notional (with the share left before liquidation) as a `BarMark` and the liquidation, mark and entry prices as a `BarPnl`, both drawn without a card because they are read-only, the host's actions as one `ListGroup` of rows, and the position itself underneath. */
|
|
23
|
+
export function ManagePositionBlock({ labels, mode, side, entry, mark, liquidation, margin, notional, priceOptions, actions, position, onBack, headerAction, className, ...rest }) {
|
|
24
|
+
const { locale } = useHIG();
|
|
25
|
+
const corridor = positionCorridor({ side, entry, mark, liquidation });
|
|
26
|
+
const pnlTone = !known(position?.pnl) || position.pnl === 0 ? undefined : position.pnl > 0 ? 'up' : 'down';
|
|
27
|
+
return _jsxs("section", { ...rest, className: `hig-manage-position-block${className ? ` ${className}` : ''}`, children: [_jsx(ScreenHeader, { title: labels.title, onBack: onBack, action: headerAction }), _jsxs("div", { className: 'hig-token-bars', children: [_jsx(BarMark, { surface: false, title: mode ?? labels.margin, description: corridor.share === null ? labels.toLiquidation('—') : _jsx(SwapNumber, { template: labels.toLiquidation, value: Number((corridor.share * 100).toFixed(1)), suffix: '%', options: { maximumFractionDigits: 1 } }), elements: [{ id: 'margin', label: labels.margin, value: margin, detail: formatNumber(margin, locale, usd), tone: 'info' }, { id: 'notional', label: labels.notional, value: known(notional) ? Math.max(notional - margin, 0) : 0, detail: known(notional) ? formatNumber(notional, locale, usd) : '—', tone: 'positive' }] }), _jsx(BarPnl, { surface: false, compact: true, side: side, entry: entry, mark: mark, liquidation: liquidation, labels: { liquidation: labels.liquidation, mark: labels.mark, entry: labels.entry }, priceOptions: priceOptions })] }), actions.length > 0 && _jsx(ListGroup, { className: 'hig-manage-actions', children: actions.map(action => _jsx(ListRow, { label: action.label, disabled: action.disabled, onSelect: action.onSelect }, action.id)) }), position && _jsxs("div", { className: 'hig-asset-row hig-position-row', children: [_jsx("span", { className: 'hig-asset-row-icon', "aria-hidden": 'true', children: typeof position.icon === 'string' ? _jsx("img", { src: position.icon, alt: '' }) : position.icon ?? position.name.slice(0, 3) }), _jsxs("span", { className: 'hig-asset-row-identity', children: [_jsx("strong", { children: position.name }), _jsxs("span", { children: [_jsx("span", { className: 'hig-position-side', "data-side": side, "aria-hidden": 'true', children: side === 'long' ? '↑' : '↓' }), _jsx("span", { className: 'hig-sr-only', children: side === 'long' ? labels.long : labels.short }), position.leverage != null && _jsxs("span", { className: 'hig-position-side hig-position-leverage', "data-side": side, children: [" ", formatNumber(position.leverage, locale), "\u00D7"] }), known(position.size) && _jsxs(_Fragment, { children: [" \u00B7 ", _jsx(AnimatedNumberReadout, { value: position.size, options: { maximumFractionDigits: 6 } })] })] })] }), _jsxs("span", { className: 'hig-asset-row-amounts', children: [_jsx("strong", { "data-tone": pnlTone, children: _jsx(AnimatedNumberReadout, { value: position.pnl, options: { ...usd, signDisplay: 'exceptZero', maximumFractionDigits: 4 } }) }), _jsx("span", { children: _jsx(AnimatedNumberReadout, { value: position.pnlPercent, options: { style: 'percent', minimumFractionDigits: 2, maximumFractionDigits: 2, signDisplay: 'exceptZero' } }) })] })] })] });
|
|
28
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/** One kind of notification. Every word is host text. */
|
|
3
|
+
export interface NotificationsItem {
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
checked: boolean;
|
|
8
|
+
onCheckedChange: (checked: boolean) => void;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
/** Why turning it on failed, under the card: Push request timed out. It is announced when it appears. */
|
|
11
|
+
error?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface NotificationsBlockProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
|
|
14
|
+
/** Heading: Notifications. */
|
|
15
|
+
title: string;
|
|
16
|
+
/** One card each, in order. */
|
|
17
|
+
items: readonly NotificationsItem[];
|
|
18
|
+
onBack?: () => void;
|
|
19
|
+
/** A control on the trailing edge of the header, usually an `IconButton`. */
|
|
20
|
+
headerAction?: React.ReactNode;
|
|
21
|
+
}
|
|
22
|
+
/** The notifications the viewer receives: each kind is a card with a switch and a line of explanation, and a failure to turn one on reads under its card. */
|
|
23
|
+
export declare function NotificationsBlock({ title, items, onBack, headerAction, className, ...rest }: NotificationsBlockProps): React.JSX.Element;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { ScreenHeader } from './screen-header.js';
|
|
4
|
+
import { SettingSwitch } from './setting-switch.js';
|
|
5
|
+
/** The notifications the viewer receives: each kind is a card with a switch and a line of explanation, and a failure to turn one on reads under its card. */
|
|
6
|
+
export function NotificationsBlock({ title, items, onBack, headerAction, className, ...rest }) {
|
|
7
|
+
return _jsxs("section", { ...rest, className: `hig-settings-block${className ? ` ${className}` : ''}`, children: [_jsx(ScreenHeader, { title: title, onBack: onBack, action: headerAction }), items.length > 0 && _jsx("div", { className: 'hig-setting-cards', children: items.map(item => _jsxs("div", { className: 'hig-notifications-item', children: [_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.error && _jsx("p", { role: 'alert', className: 'hig-setting-error', children: item.error })] }, item.id)) })] });
|
|
8
|
+
}
|
|
@@ -22,7 +22,7 @@ export interface PickerListProps {
|
|
|
22
22
|
/** With a hardware pointer, focus the search field on mount so typing filters at once. */
|
|
23
23
|
autoFocus?: boolean;
|
|
24
24
|
}
|
|
25
|
-
export interface
|
|
25
|
+
export interface FromPickerBlockProps extends PickerListProps {
|
|
26
26
|
/** The connected wallet. Omit for a list with no wallet row at all. */
|
|
27
27
|
wallet?: SwapWallet;
|
|
28
28
|
/** Shows Connect wallet while no wallet is connected. */
|
|
@@ -39,8 +39,8 @@ export interface FromPickerProps extends PickerListProps {
|
|
|
39
39
|
* the tokens it holds (or a whitelist). With no wallet it offers Connect wallet and a Generate address switch above the list.
|
|
40
40
|
* The host owns the wallet, the token data and the generated address.
|
|
41
41
|
*/
|
|
42
|
-
export declare function
|
|
43
|
-
export interface
|
|
42
|
+
export declare function FromPickerBlock({ wallet, onConnect, onDisconnect, generateAddress, onGenerateAddressChange, className, ...list }: FromPickerBlockProps): React.JSX.Element;
|
|
43
|
+
export interface ToPickerBlockProps extends Partial<PickerListProps> {
|
|
44
44
|
/** The destination address field. Omit `onAddressChange` to hide it. */
|
|
45
45
|
address?: string;
|
|
46
46
|
onAddressChange?: (address: string) => void;
|
|
@@ -54,4 +54,12 @@ export interface ToPickerProps extends Partial<PickerListProps> {
|
|
|
54
54
|
* Where the assets go. On its own it is a destination address field with a scan button. With `tokens` it adds the
|
|
55
55
|
* searchable token list, with the chain filter or, with `chainFilter={false}`, without it.
|
|
56
56
|
*/
|
|
57
|
-
export declare function
|
|
57
|
+
export declare function ToPickerBlock({ address, onAddressChange, addressPlaceholder, onScan, className, tokens, onSelect, ...list }: ToPickerBlockProps): React.JSX.Element;
|
|
58
|
+
/** @deprecated Renamed `FromPickerBlock`. The old name keeps working until the next major release. */
|
|
59
|
+
export declare const FromPicker: typeof FromPickerBlock;
|
|
60
|
+
/** @deprecated Renamed `FromPickerBlockProps`. */
|
|
61
|
+
export type FromPickerProps = FromPickerBlockProps;
|
|
62
|
+
/** @deprecated Renamed `ToPickerBlock`. The old name keeps working until the next major release. */
|
|
63
|
+
export declare const ToPicker: typeof ToPickerBlock;
|
|
64
|
+
/** @deprecated Renamed `ToPickerBlockProps`. */
|
|
65
|
+
export type ToPickerProps = ToPickerBlockProps;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useEffect, useId, useMemo, useRef, useState } from 'react';
|
|
4
|
-
import { formatNumber } from '@bloxwap/hig/contracts';
|
|
5
4
|
import * as en from '@bloxwap/hig/contracts/messages';
|
|
6
5
|
import { useHIG } from '../provider.js';
|
|
7
6
|
import { Button, IconButton } from '../button.js';
|
|
8
7
|
import { Input, SearchInput } from '../field.js';
|
|
9
8
|
import { Filter } from '../selection.js';
|
|
10
|
-
import { SwapIcon, TokenIcon, addressGradient, chainsOf, fuzzyMatch, shortAddress } from './swap/shared.js';
|
|
9
|
+
import { SwapIcon, SwapNumber, TokenIcon, usdNumber, addressGradient, chainsOf, fuzzyMatch, shortAddress } from './swap/shared.js';
|
|
11
10
|
function TokenList({ tokens, chains, chainFilter = true, hotTokenIds, selected = null, onSelect, loading, autoFocus, label }) {
|
|
12
|
-
const { messages
|
|
11
|
+
const { messages } = useHIG();
|
|
13
12
|
const id = useId();
|
|
14
13
|
const [query, setQuery] = useState('');
|
|
15
14
|
const [chainId, setChainId] = useState(null);
|
|
@@ -50,7 +49,7 @@ function TokenList({ tokens, chains, chainFilter = true, hotTokenIds, selected =
|
|
|
50
49
|
const filters = [{ value: '', label: messages.swapAllChains ?? en.swapAllChains }, ...options.map(chain => ({ value: String(chain.chainId), label: chain.name, icon: chain.icon }))];
|
|
51
50
|
const row = (token, index) => {
|
|
52
51
|
const isSelected = selected?.id === token.id;
|
|
53
|
-
return _jsx("div", { role: 'listitem', children: _jsxs("button", { type: 'button', className: 'hig-swap-row', "data-active": index === active, "data-selected": isSelected || undefined, onClick: () => onSelect(token), onPointerMove: () => setActive(index), children: [_jsx(TokenIcon, { token: token }), _jsxs("span", { className: 'hig-swap-row-text', children: [_jsx("strong", { children: token.name }), _jsxs("span", { children: [token.chain, isSelected ? ' · ' + (messages.swapSelected ?? en.swapSelected) : ''] })] }), (token.balance ?? 0) > 0 && _jsxs("span", { className: 'hig-swap-row-balance', children: [_jsx("strong", {
|
|
52
|
+
return _jsx("div", { role: 'listitem', children: _jsxs("button", { type: 'button', className: 'hig-swap-row', "data-active": index === active, "data-selected": isSelected || undefined, onClick: () => onSelect(token), onPointerMove: () => setActive(index), children: [_jsx(TokenIcon, { token: token }), _jsxs("span", { className: 'hig-swap-row-text', children: [_jsx("strong", { children: token.name }), _jsxs("span", { children: [token.chain, isSelected ? ' · ' + (messages.swapSelected ?? en.swapSelected) : ''] })] }), (token.balance ?? 0) > 0 && _jsxs("span", { className: 'hig-swap-row-balance', children: [_jsx("strong", { children: _jsx(SwapNumber, { value: token.balance, options: { maximumFractionDigits: 6 } }) }), (token.price ?? 0) > 0 && _jsx(SwapNumber, { ...usdNumber((token.balance ?? 0) * (token.price ?? 0)) })] })] }) }, token.id);
|
|
54
53
|
};
|
|
55
54
|
return _jsxs(_Fragment, { children: [_jsx(SearchInput, { ref: search, "aria-label": messages.swapSearchTokens ?? en.swapSearchTokens, placeholder: messages.swapSearchTokens ?? en.swapSearchTokens, value: query, onChange: event => setQuery(event.target.value), onKeyDown: onKeyDown, enterKeyHint: 'search', autoComplete: 'off', autoCapitalize: 'none', autoCorrect: 'off', spellCheck: false }), chainFilter && options.length > 1 && _jsx(Filter, { label: messages.swapChains ?? en.swapChains, options: filters, value: chainId === null ? '' : String(chainId), onValueChange: next => setChainId(options.find(chain => String(chain.chainId) === next)?.chainId ?? null) }), _jsxs("div", { ref: list, className: 'hig-swap-list', "aria-busy": loading || undefined, children: [rows.length === 0 && _jsx("p", { className: 'hig-swap-empty', role: 'status', children: loading ? (messages.loading ?? en.loading) + '…' : messages.swapNoTokens ?? en.swapNoTokens }), hotCount > 0 && _jsxs("p", { className: 'hig-swap-section', id: `${id}-hot`, children: [_jsx(SwapIcon, { name: 'flame', size: 14 }), messages.swapHot ?? en.swapHot] }), hotCount > 0 && _jsx("div", { role: 'list', "aria-labelledby": `${id}-hot`, children: rows.slice(0, hotCount).map((token, index) => row(token, index)) }), hotCount > 0 && _jsx("p", { className: 'hig-swap-section', id: `${id}-all`, children: messages.swapAllTokens ?? en.swapAllTokens }), rows.length > hotCount && _jsx("div", { role: 'list', ...(hotCount > 0 ? { 'aria-labelledby': `${id}-all` } : { 'aria-label': label }), children: rows.slice(hotCount).map((token, index) => row(token, index + hotCount)) })] })] });
|
|
56
55
|
}
|
|
@@ -59,7 +58,7 @@ function TokenList({ tokens, chains, chainFilter = true, hotTokenIds, selected =
|
|
|
59
58
|
* the tokens it holds (or a whitelist). With no wallet it offers Connect wallet and a Generate address switch above the list.
|
|
60
59
|
* The host owns the wallet, the token data and the generated address.
|
|
61
60
|
*/
|
|
62
|
-
export function
|
|
61
|
+
export function FromPickerBlock({ wallet, onConnect, onDisconnect, generateAddress = false, onGenerateAddressChange, className, ...list }) {
|
|
63
62
|
const { messages } = useHIG();
|
|
64
63
|
const id = useId();
|
|
65
64
|
const label = messages.swapFrom ?? en.swapFrom;
|
|
@@ -71,8 +70,12 @@ export function FromPicker({ wallet, onConnect, onDisconnect, generateAddress =
|
|
|
71
70
|
* Where the assets go. On its own it is a destination address field with a scan button. With `tokens` it adds the
|
|
72
71
|
* searchable token list, with the chain filter or, with `chainFilter={false}`, without it.
|
|
73
72
|
*/
|
|
74
|
-
export function
|
|
73
|
+
export function ToPickerBlock({ address, onAddressChange, addressPlaceholder, onScan, className, tokens, onSelect, ...list }) {
|
|
75
74
|
const { messages } = useHIG();
|
|
76
75
|
const label = messages.swapTo ?? en.swapTo;
|
|
77
76
|
return _jsxs("div", { className: `hig-picker${className ? ` ${className}` : ''}`, role: 'group', "aria-label": label, children: [onAddressChange && _jsxs("div", { className: 'hig-swap-wallet', children: [_jsx(Input, { "aria-label": messages.swapRecipient ?? en.swapRecipient, placeholder: addressPlaceholder ?? messages.swapRecipient ?? en.swapRecipient, value: address ?? '', onChange: event => onAddressChange(event.target.value), autoComplete: 'off', autoCapitalize: 'none', autoCorrect: 'off', spellCheck: false }), onScan && _jsx(IconButton, { intent: 'secondary', label: messages.swapScan ?? en.swapScan, onClick: onScan, children: _jsx(SwapIcon, { name: 'scan' }) })] }), tokens && onSelect && _jsx(TokenList, { ...list, tokens: tokens, onSelect: onSelect, label: label })] });
|
|
78
77
|
}
|
|
78
|
+
/** @deprecated Renamed `FromPickerBlock`. The old name keeps working until the next major release. */
|
|
79
|
+
export const FromPicker = FromPickerBlock;
|
|
80
|
+
/** @deprecated Renamed `ToPickerBlock`. The old name keeps working until the next major release. */
|
|
81
|
+
export const ToPicker = ToPickerBlock;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/** A number the host supplies as a number so it updates place by place: `{value:0.53,options:{style:'currency',currency:'USD'}}`. `null` reads as unknown. */
|
|
3
|
+
export interface PositionBlockFigure {
|
|
4
|
+
value: number | null;
|
|
5
|
+
options?: Intl.NumberFormatOptions;
|
|
6
|
+
prefix?: string;
|
|
7
|
+
suffix?: string;
|
|
8
|
+
}
|
|
9
|
+
/** One line of the summary: Notional, Fee, Liquidation. `value` is host text (`2% of profit`) or a live figure. `tone` colours the value; the default is the text colour. */
|
|
10
|
+
export interface PositionBlockDetail {
|
|
11
|
+
id?: string;
|
|
12
|
+
label: string;
|
|
13
|
+
value: string | PositionBlockFigure;
|
|
14
|
+
tone?: 'positive' | 'negative' | 'muted';
|
|
15
|
+
}
|
|
16
|
+
/** One setting of the position: Size, Leverage, Stop Loss. With `onSelect` the row opens the host's own view and shows a chevron. */
|
|
17
|
+
export interface PositionBlockRow {
|
|
18
|
+
id: string;
|
|
19
|
+
label: string;
|
|
20
|
+
value?: string;
|
|
21
|
+
onSelect?: () => void;
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/** The paper trading switch. The host supplies its name, because HIG ships no trading terms. */
|
|
25
|
+
export interface PositionBlockFlag {
|
|
26
|
+
label: string;
|
|
27
|
+
checked: boolean;
|
|
28
|
+
onCheckedChange: (checked: boolean) => void;
|
|
29
|
+
disabled?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface PositionBlockProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
|
|
32
|
+
/** Heading: Position. */
|
|
33
|
+
title: string;
|
|
34
|
+
/** The summary under the header, in order. */
|
|
35
|
+
details: readonly PositionBlockDetail[];
|
|
36
|
+
/** One sentence under the summary, such as the minimum margin. */
|
|
37
|
+
note?: string;
|
|
38
|
+
/** Shows the paper trading switch as a row of its own above the settings. */
|
|
39
|
+
paperTrade?: PositionBlockFlag;
|
|
40
|
+
/** The settings, as groups of rows. Each group is one rounded container. */
|
|
41
|
+
groups: readonly (readonly PositionBlockRow[])[];
|
|
42
|
+
/** Shows Close on the trailing edge of the header. */
|
|
43
|
+
onClose?: () => void;
|
|
44
|
+
onBack?: () => void;
|
|
45
|
+
/** A control on the trailing edge of the header in place of Close. */
|
|
46
|
+
headerAction?: React.ReactNode;
|
|
47
|
+
}
|
|
48
|
+
/** The position being opened or edited: a summary of what it costs and where it ends, an optional paper trading switch, and its settings as grouped rows that open the host's own views. */
|
|
49
|
+
export declare function PositionBlock({ title, details, note, paperTrade, groups, onClose, onBack, headerAction, className, ...rest }: PositionBlockProps): React.JSX.Element;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
4
|
+
import { useHIG } from '../provider.js';
|
|
5
|
+
import { Switch } from '../selection.js';
|
|
6
|
+
import { ListGroup, ListRow } from '../list-group.js';
|
|
7
|
+
import { AnimatedNumberReadout } from '../animated-number.js';
|
|
8
|
+
import { ScreenHeader } from './screen-header.js';
|
|
9
|
+
import { SwapIcon } from './swap/shared.js';
|
|
10
|
+
/** The position being opened or edited: a summary of what it costs and where it ends, an optional paper trading switch, and its settings as grouped rows that open the host's own views. */
|
|
11
|
+
export function PositionBlock({ title, details, note, paperTrade, groups, onClose, onBack, headerAction, className, ...rest }) {
|
|
12
|
+
const { messages } = useHIG();
|
|
13
|
+
return _jsxs("section", { ...rest, className: `hig-position-block${className ? ` ${className}` : ''}`, children: [_jsx(ScreenHeader, { title: title, onBack: onBack, action: headerAction ?? (onClose && _jsx("button", { type: 'button', className: 'hig-swap-back', "aria-label": messages.close ?? en.close, onClick: onClose, children: _jsx(SwapIcon, { name: 'close' }) })) }), details.length > 0 && _jsx("dl", { className: 'hig-position-details', children: details.map((detail, index) => _jsxs("div", { "data-tone": detail.tone, children: [_jsx("dt", { children: detail.label }), _jsx("dd", { className: 'hig-number', children: typeof detail.value === 'string' ? detail.value : _jsx(AnimatedNumberReadout, { ...detail.value }) })] }, detail.id ?? index)) }), note && _jsx("p", { className: 'hig-position-note', children: note }), (paperTrade || groups.some(group => group.length > 0)) && _jsxs("div", { className: 'hig-position-groups', children: [paperTrade && _jsx(ListGroup, { className: 'hig-position-flag', children: _jsx(ListRow, { label: paperTrade.label, disabled: paperTrade.disabled, trailing: _jsx(Switch, { label: paperTrade.label, checked: paperTrade.checked, disabled: paperTrade.disabled, onCheckedChange: paperTrade.onCheckedChange }) }) }), groups.map((group, index) => group.length > 0 && _jsx(ListGroup, { children: group.map(row => _jsx(ListRow, { label: row.label, value: row.value, onSelect: row.onSelect, disabled: row.disabled }, row.id)) }, index))] })] });
|
|
14
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { AssetArtwork } from '../asset-balance-row.js';
|
|
3
|
+
/** One row of a profile section. With `onSelect` it opens something and shows a chevron; with `onCheckedChange` it is a switch. */
|
|
4
|
+
export interface ProfileRow {
|
|
5
|
+
id: string;
|
|
6
|
+
label: string;
|
|
7
|
+
/** Artwork before the label, such as an icon. */
|
|
8
|
+
leading?: React.ReactNode;
|
|
9
|
+
/** Short text on the trailing edge, such as a balance or `Off`. */
|
|
10
|
+
value?: React.ReactNode;
|
|
11
|
+
/** Anything richer on the trailing edge: icons or a `Badge`. */
|
|
12
|
+
trailing?: React.ReactNode;
|
|
13
|
+
onSelect?: () => void;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
/** With `onCheckedChange`, the row is a switch: the track trails and the label names it. */
|
|
16
|
+
checked?: boolean;
|
|
17
|
+
onCheckedChange?: (checked: boolean) => void;
|
|
18
|
+
}
|
|
19
|
+
export interface ProfileSection {
|
|
20
|
+
id: string;
|
|
21
|
+
/** Heading above the group, such as Rewards or Settings. */
|
|
22
|
+
title?: string;
|
|
23
|
+
rows: readonly ProfileRow[];
|
|
24
|
+
}
|
|
25
|
+
/** The dot on the avatar: an account mode or state the host names, such as Demo. */
|
|
26
|
+
export interface ProfileStatus {
|
|
27
|
+
/** Read out for the dot. */
|
|
28
|
+
label: string;
|
|
29
|
+
tone?: 'positive' | 'warning' | 'negative' | 'info';
|
|
30
|
+
}
|
|
31
|
+
export interface ProfileBlockProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
|
|
32
|
+
/** The name under the avatar: a display name or a shortened address. */
|
|
33
|
+
name: string;
|
|
34
|
+
/** Colours the avatar when there is no artwork. */
|
|
35
|
+
address?: string;
|
|
36
|
+
/** An image URL or an element the host draws. */
|
|
37
|
+
avatar?: AssetArtwork;
|
|
38
|
+
status?: ProfileStatus;
|
|
39
|
+
/** Shows the edit control after the name. */
|
|
40
|
+
onEditName?: () => void;
|
|
41
|
+
/** Shows the address control on the leading edge of the top bar. */
|
|
42
|
+
onShowAddress?: () => void;
|
|
43
|
+
/** Shows Close on the trailing edge of the top bar. */
|
|
44
|
+
onClose?: () => void;
|
|
45
|
+
sections: readonly ProfileSection[];
|
|
46
|
+
}
|
|
47
|
+
/** A person's profile as one screen: who they are (avatar, status, name), then grouped rows that open their accounts, history, rewards and settings. */
|
|
48
|
+
export declare function ProfileBlock({ name, address, avatar, status, onEditName, onShowAddress, onClose, sections, className, ...rest }: ProfileBlockProps): React.JSX.Element;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
4
|
+
import { useHIG } from '../provider.js';
|
|
5
|
+
import { IconButton } from '../button.js';
|
|
6
|
+
import { Switch } from '../selection.js';
|
|
7
|
+
import { ListGroup, ListRow } from '../list-group.js';
|
|
8
|
+
import { qrIcon } from './screen-header.js';
|
|
9
|
+
import { SwapIcon, addressGradient } from './swap/shared.js';
|
|
10
|
+
const editIcon = _jsx("svg", { "aria-hidden": 'true', focusable: 'false', viewBox: '0 0 20 20', width: '20', height: '20', fill: 'none', stroke: 'currentColor', strokeWidth: '1.6', strokeLinecap: 'round', strokeLinejoin: 'round', children: _jsx("path", { d: 'M12.5 4.5 15.5 7.5 7.5 15.5H4.5V12.5ZM10.5 15.5H16' }) });
|
|
11
|
+
/** A person's profile as one screen: who they are (avatar, status, name), then grouped rows that open their accounts, history, rewards and settings. */
|
|
12
|
+
export function ProfileBlock({ name, address, avatar, status, onEditName, onShowAddress, onClose, sections, className, ...rest }) {
|
|
13
|
+
const { messages } = useHIG();
|
|
14
|
+
return _jsxs("section", { ...rest, className: `hig-profile-block${className ? ` ${className}` : ''}`, children: [_jsxs("div", { className: 'hig-profile-bar', children: [_jsx("span", { children: onShowAddress && _jsx(IconButton, { intent: 'ghost', label: messages.showAddress ?? en.showAddress, onClick: onShowAddress, children: qrIcon }) }), _jsx("span", { children: onClose && _jsx(IconButton, { intent: 'ghost', label: messages.close ?? en.close, onClick: onClose, children: _jsx(SwapIcon, { name: 'close' }) }) })] }), _jsxs("div", { className: 'hig-profile-identity', children: [_jsxs("span", { className: 'hig-profile-avatar', style: avatar == null && address ? { background: addressGradient(address) } : undefined, children: [_jsx("span", { className: 'hig-profile-artwork', "aria-hidden": 'true', children: typeof avatar === 'string' ? _jsx("img", { src: avatar, alt: '' }) : avatar ?? (address ? null : name.slice(0, 2)) }), status && _jsx("span", { className: 'hig-profile-status', "data-tone": status.tone ?? 'warning', children: _jsx("span", { className: 'hig-sr-only', children: status.label }) })] }), _jsxs("div", { className: 'hig-profile-name', children: [_jsx("h2", { children: name }), onEditName && _jsx(IconButton, { intent: 'ghost', label: messages.editName ?? en.editName, onClick: onEditName, children: editIcon })] })] }), sections.filter(section => section.rows.length > 0).map(section => _jsx(ListGroup, { title: section.title, children: section.rows.map(row => _jsx(ListRow, { label: row.label, leading: row.leading, value: row.value, disabled: row.disabled, onSelect: row.onCheckedChange ? undefined : row.onSelect, trailing: row.onCheckedChange ? _jsx(Switch, { label: row.label, checked: !!row.checked, disabled: row.disabled, onCheckedChange: row.onCheckedChange }) : row.trailing }, row.id)) }, section.id))] });
|
|
15
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { AssetArtwork } from '../asset-balance-row.js';
|
|
3
|
+
/** The promotion above the standings: a prize pool filling towards a goal, or a draw with a top prize. Every word is host text. */
|
|
4
|
+
export interface RewardPromo {
|
|
5
|
+
/** The small capitals line: Season 01. */
|
|
6
|
+
eyebrow: string;
|
|
7
|
+
/** A text link with a chevron on the trailing edge of the eyebrow: Rules. */
|
|
8
|
+
rules?: {
|
|
9
|
+
label: string;
|
|
10
|
+
onSelect: () => void;
|
|
11
|
+
};
|
|
12
|
+
/** The headline figure: the pool so far, or the top prize. `null` reads as unknown. */
|
|
13
|
+
amount: number | null;
|
|
14
|
+
/** Format of `amount` and `goal`. Defaults to whole US dollars. */
|
|
15
|
+
amountOptions?: Intl.NumberFormatOptions;
|
|
16
|
+
/** The amount the pool is filling towards. Draws the progress bar under the caption. */
|
|
17
|
+
goal?: number;
|
|
18
|
+
/** The line under the figure. A function receives the formatted goal: `goal => 'of ' + goal + ' prize pool'`. A string is drawn as given: top prize. */
|
|
19
|
+
caption?: string | ((goal: string) => string);
|
|
20
|
+
/** The lead of the explaining sentence, in the text colour: Top 100 traders split the pool. */
|
|
21
|
+
headline?: string;
|
|
22
|
+
/** Continues the sentence after the headline in the muted colour: Funded by builder fees on every trade. */
|
|
23
|
+
description?: string;
|
|
24
|
+
/** A quiet row under a hairline at the foot of the card, with a chevron on its trailing edge: Draws and winners. The host opens its own destination. */
|
|
25
|
+
action?: {
|
|
26
|
+
label: string;
|
|
27
|
+
onSelect: () => void;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** One trader in the standings. */
|
|
31
|
+
export interface RewardEntry {
|
|
32
|
+
id: string;
|
|
33
|
+
rank: number;
|
|
34
|
+
/** A short address, a handle, or the host's word for the viewer. */
|
|
35
|
+
name: string;
|
|
36
|
+
/** An image URL or a host element. Without one the first letters of the name are shown. */
|
|
37
|
+
avatar?: AssetArtwork;
|
|
38
|
+
/** Shows the verified mark after the name. */
|
|
39
|
+
verified?: boolean;
|
|
40
|
+
/** The line under the name: `$1,090,779 vol`. */
|
|
41
|
+
detail?: string;
|
|
42
|
+
/** Points or entries. `null` reads as unknown. */
|
|
43
|
+
score: number | null;
|
|
44
|
+
/** Marks the viewer's own row: the name and score take the action colour. */
|
|
45
|
+
you?: boolean;
|
|
46
|
+
}
|
|
47
|
+
export interface RewardBlockProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
|
|
48
|
+
/** Heading: Leaderboard. */
|
|
49
|
+
title: string;
|
|
50
|
+
promo?: RewardPromo;
|
|
51
|
+
/** A choice between standings, such as Upcoming draw and Top winners. `label` names the control and is not drawn. */
|
|
52
|
+
tabs?: {
|
|
53
|
+
label: string;
|
|
54
|
+
options: readonly {
|
|
55
|
+
value: string;
|
|
56
|
+
label: string;
|
|
57
|
+
}[];
|
|
58
|
+
value: string;
|
|
59
|
+
onValueChange: (value: string) => void;
|
|
60
|
+
};
|
|
61
|
+
/** The viewer's own standing, pinned above the list on a tinted row. */
|
|
62
|
+
you?: RewardEntry;
|
|
63
|
+
/** The column heading over the names: Top 25 by volume. */
|
|
64
|
+
listTitle?: string;
|
|
65
|
+
/** The column heading over the scores: Entries. */
|
|
66
|
+
scoreTitle?: string;
|
|
67
|
+
entries: readonly RewardEntry[];
|
|
68
|
+
/** Format of every score. Defaults to a whole number. */
|
|
69
|
+
scoreOptions?: Intl.NumberFormatOptions;
|
|
70
|
+
/** Accessible name of the verified mark. The mark is decorative without it. */
|
|
71
|
+
verifiedLabel?: string;
|
|
72
|
+
/** A line under the list: Entries are provisional until audited. */
|
|
73
|
+
footnote?: string;
|
|
74
|
+
onBack?: () => void;
|
|
75
|
+
/** A control on the trailing edge of the header, usually an `IconButton` that shares. */
|
|
76
|
+
headerAction?: React.ReactNode;
|
|
77
|
+
}
|
|
78
|
+
/** The share of the goal reached, from 0 to 1. Unknown amounts and goals that are not above zero give `null`. */
|
|
79
|
+
export declare function rewardProgress(amount: number | null | undefined, goal: number | null | undefined): number | null;
|
|
80
|
+
/** A competition as a screen: an optional promotion (a prize pool filling towards its goal, or a draw with its top prize), an optional choice of standings, the viewer's own standing pinned on a tinted row, and the ranked list. */
|
|
81
|
+
export declare function RewardBlock({ title, promo, tabs, you, listTitle, scoreTitle, entries, scoreOptions, verifiedLabel, footnote, onBack, headerAction, className, ...rest }: RewardBlockProps): React.JSX.Element;
|