@bloxwap/hig 0.5.2 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/chart/README.md +1 -1
- package/contracts/README.md +1 -1
- package/contracts/dist/index.d.ts +16 -0
- package/contracts/dist/index.js +22 -0
- package/contracts/dist/messages.d.ts +37 -4
- package/contracts/dist/messages.js +13 -2
- package/feedback/README.md +1 -1
- package/native/README.md +1 -1
- package/native/dist/account-block.d.ts +92 -0
- package/native/dist/account-block.js +61 -0
- package/native/dist/animated-number-model.d.ts +7 -1
- package/native/dist/animated-number-model.js +50 -1
- package/native/dist/animated-number.d.ts +3 -1
- package/native/dist/animated-number.js +8 -5
- package/native/dist/asset-balance-row.d.ts +36 -0
- package/native/dist/asset-balance-row.js +26 -0
- package/native/dist/bar-mark.d.ts +57 -0
- package/native/dist/bar-mark.js +48 -0
- package/native/dist/bar-pnl.d.ts +50 -0
- package/native/dist/bar-pnl.js +60 -0
- package/native/dist/blocks.d.ts +38 -0
- package/native/dist/blocks.js +42 -0
- package/native/dist/button.js +3 -1
- package/native/dist/data.d.ts +1 -1
- package/native/dist/data.js +6 -4
- package/native/dist/field.d.ts +14 -5
- package/native/dist/field.js +33 -8
- package/native/dist/figure.d.ts +23 -0
- package/native/dist/figure.js +10 -0
- package/native/dist/icons.d.ts +8 -0
- package/native/dist/icons.js +4 -0
- package/native/dist/language-block.d.ts +35 -0
- package/native/dist/language-block.js +30 -0
- package/native/dist/list-group.d.ts +60 -0
- package/native/dist/list-group.js +85 -0
- package/native/dist/manage-position-block.d.ts +95 -0
- package/native/dist/manage-position-block.js +82 -0
- package/native/dist/market-row.d.ts +46 -0
- package/native/dist/market-row.js +30 -0
- package/native/dist/notifications-block.d.ts +53 -0
- package/native/dist/notifications-block.js +22 -0
- package/native/dist/pickers.d.ts +35 -5
- package/native/dist/pickers.js +21 -9
- package/native/dist/position-block.d.ts +107 -0
- package/native/dist/position-block.js +55 -0
- package/native/dist/profile-block.d.ts +66 -0
- package/native/dist/profile-block.js +48 -0
- package/native/dist/provider.d.ts +9 -3
- package/native/dist/provider.js +7 -3
- package/native/dist/radio-group.d.ts +9 -3
- package/native/dist/radio-group.js +4 -5
- package/native/dist/recipes.d.ts +6 -46
- package/native/dist/recipes.js +6 -33
- package/native/dist/reward-block.d.ts +122 -0
- package/native/dist/reward-block.js +53 -0
- package/native/dist/screen-header.d.ts +49 -0
- package/native/dist/screen-header.js +29 -0
- package/native/dist/selection.d.ts +2 -2
- package/native/dist/setting-header.d.ts +2 -0
- package/native/dist/setting-header.js +2 -0
- package/native/dist/setting-switch.d.ts +31 -0
- package/native/dist/setting-switch.js +20 -0
- package/native/dist/signals-block.d.ts +61 -0
- package/native/dist/signals-block.js +26 -0
- package/native/dist/sound-haptics-block.d.ts +66 -0
- package/native/dist/sound-haptics-block.js +32 -0
- package/native/dist/status.d.ts +6 -5
- package/native/dist/status.js +5 -5
- package/native/dist/sticky-header.d.ts +28 -0
- package/native/dist/sticky-header.js +21 -0
- package/native/dist/surface.d.ts +3 -1
- package/native/dist/surface.js +2 -1
- package/native/dist/{swap-panel.d.ts → swap-panel-block.d.ts} +8 -3
- package/native/dist/{swap-panel.js → swap-panel-block.js} +13 -8
- package/native/dist/swap-parts.d.ts +5 -3
- package/native/dist/swap-parts.js +2 -2
- package/native/dist/swap-shared.d.ts +6 -0
- package/native/dist/swap-sheet.d.ts +4 -4
- package/native/dist/swap-sheet.js +4 -4
- package/native/dist/swap-views.d.ts +1 -1
- package/native/dist/swap-views.js +9 -7
- package/native/dist/switch-row.d.ts +3 -2
- package/native/dist/switch-row.js +5 -3
- package/native/dist/switch.d.ts +4 -2
- package/native/dist/switch.js +3 -3
- package/native/dist/target-block.d.ts +110 -0
- package/native/dist/target-block.js +74 -0
- package/native/dist/token-action-block.d.ts +47 -0
- package/native/dist/token-action-block.js +28 -0
- package/native/dist/trade-history-detail-block.d.ts +84 -0
- package/native/dist/trade-history-detail-block.js +46 -0
- package/native/dist/trade-history-list-block.d.ts +110 -0
- package/native/dist/trade-history-list-block.js +64 -0
- package/native/dist/wallet-address-core.d.ts +25 -0
- package/native/dist/wallet-address-core.js +31 -0
- package/native/dist/wallet-address.d.ts +6 -10
- package/native/dist/wallet-address.js +16 -20
- package/native-fonts/README.md +1 -1
- package/og-fonts/README.md +1 -1
- package/package.json +266 -41
- package/react/README.md +1 -1
- package/react/dist/animated-number-model.d.ts +6 -0
- package/react/dist/animated-number-model.js +33 -0
- package/react/dist/animated-number.d.ts +5 -1
- package/react/dist/animated-number.js +12 -8
- package/react/dist/asset-balance-row.d.ts +35 -0
- package/react/dist/asset-balance-row.js +18 -0
- package/react/dist/bar-mark.d.ts +38 -0
- package/react/dist/bar-mark.js +23 -0
- package/react/dist/bar-pnl.d.ts +49 -0
- package/react/dist/bar-pnl.js +45 -0
- package/react/dist/blocks/account-block.d.ts +92 -0
- package/react/dist/blocks/account-block.js +62 -0
- package/react/dist/blocks/language-block.d.ts +36 -0
- package/react/dist/blocks/language-block.js +52 -0
- package/react/dist/blocks/manage-position-block.d.ts +93 -0
- package/react/dist/blocks/manage-position-block.js +47 -0
- package/react/dist/blocks/market-row.d.ts +36 -0
- package/react/dist/blocks/market-row.js +16 -0
- package/react/dist/blocks/notifications-block.d.ts +46 -0
- package/react/dist/blocks/notifications-block.js +17 -0
- package/react/dist/{recipes → blocks}/pickers.d.ts +32 -4
- package/react/dist/{recipes → blocks}/pickers.js +35 -11
- package/react/dist/blocks/position-block.d.ts +72 -0
- package/react/dist/blocks/position-block.js +25 -0
- package/react/dist/blocks/profile-block.d.ts +71 -0
- package/react/dist/blocks/profile-block.js +41 -0
- package/react/dist/blocks/reward-block.d.ts +120 -0
- package/react/dist/blocks/reward-block.js +34 -0
- package/react/dist/blocks/screen-header.d.ts +33 -0
- package/react/dist/blocks/screen-header.js +20 -0
- package/react/dist/blocks/setting-switch.d.ts +23 -0
- package/react/dist/blocks/setting-switch.js +12 -0
- package/react/dist/blocks/signals-block.d.ts +54 -0
- package/react/dist/blocks/signals-block.js +15 -0
- package/react/dist/blocks/sound-haptics-block.d.ts +59 -0
- package/react/dist/blocks/sound-haptics-block.js +22 -0
- package/react/dist/blocks/sticky-header.d.ts +9 -0
- package/react/dist/blocks/sticky-header.js +43 -0
- package/react/dist/blocks/swap/amount-card.js +8 -0
- package/react/dist/{recipes → blocks}/swap/picker.d.ts +1 -1
- package/react/dist/{recipes → blocks}/swap/picker.js +4 -4
- package/react/dist/{recipes → blocks}/swap/settings.js +2 -2
- package/react/dist/{recipes → blocks}/swap/shared.d.ts +8 -1
- package/react/dist/{recipes → blocks}/swap/shared.js +7 -4
- package/react/dist/{recipes/swap-panel.d.ts → blocks/swap-panel-block.d.ts} +8 -2
- package/react/dist/{recipes/swap-panel.js → blocks/swap-panel-block.js} +9 -7
- package/react/dist/{recipes → blocks}/swap-sheet.d.ts +4 -4
- package/react/dist/{recipes → blocks}/swap-sheet.js +4 -4
- package/react/dist/blocks/target-block.d.ts +103 -0
- package/react/dist/blocks/target-block.js +73 -0
- package/react/dist/blocks/token-action-block.d.ts +46 -0
- package/react/dist/blocks/token-action-block.js +21 -0
- package/react/dist/{recipes → blocks}/trade-entry.js +2 -2
- package/react/dist/blocks/trade-history-detail-block.d.ts +78 -0
- package/react/dist/blocks/trade-history-detail-block.js +17 -0
- package/react/dist/blocks/trade-history-list-block.d.ts +67 -0
- package/react/dist/blocks/trade-history-list-block.js +28 -0
- package/react/dist/blocks.d.ts +20 -0
- package/react/dist/blocks.js +21 -0
- package/react/dist/button.js +6 -4
- package/react/dist/data.js +3 -3
- package/react/dist/field.d.ts +14 -6
- package/react/dist/field.js +19 -8
- package/react/dist/figure.d.ts +23 -0
- package/react/dist/figure.js +12 -0
- package/react/dist/list-group.d.ts +59 -0
- package/react/dist/list-group.js +52 -0
- package/react/dist/provider.d.ts +40 -3
- package/react/dist/provider.js +63 -6
- package/react/dist/selection.d.ts +8 -2
- package/react/dist/selection.js +11 -6
- package/react/dist/styles.css +425 -5
- package/react/dist/surface.d.ts +5 -1
- package/react/dist/surface.js +1 -1
- package/react/dist/wallet-address-core.d.ts +23 -0
- package/react/dist/wallet-address-core.js +24 -0
- package/react/dist/wallet-address.d.ts +6 -12
- package/react/dist/wallet-address.js +5 -16
- package/tokens/README.md +1 -1
- package/react/dist/recipes/activity-list.d.ts +0 -8
- package/react/dist/recipes/activity-list.js +0 -6
- package/react/dist/recipes/balance-card.d.ts +0 -6
- package/react/dist/recipes/balance-card.js +0 -5
- package/react/dist/recipes/code-window.d.ts +0 -4
- package/react/dist/recipes/code-window.js +0 -4
- package/react/dist/recipes/market-row.d.ts +0 -25
- package/react/dist/recipes/market-row.js +0 -8
- package/react/dist/recipes/swap/amount-card.js +0 -7
- package/react/dist/recipes.d.ts +0 -10
- package/react/dist/recipes.js +0 -11
- /package/react/dist/{recipes → blocks}/install-command.d.ts +0 -0
- /package/react/dist/{recipes → blocks}/install-command.js +0 -0
- /package/react/dist/{recipes → blocks}/marketing-hero.d.ts +0 -0
- /package/react/dist/{recipes → blocks}/marketing-hero.js +0 -0
- /package/react/dist/{recipes → blocks}/swap/amount-card.d.ts +0 -0
- /package/react/dist/{recipes → blocks}/swap/settings.d.ts +0 -0
- /package/react/dist/{recipes → blocks}/trade-entry.d.ts +0 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useId, useState } from 'react';
|
|
4
|
+
import { formatNumber } from '@bloxwap/hig/contracts';
|
|
5
|
+
import { PressDecoration, usePresentNumber, useNumberLocale } from '../provider.js';
|
|
6
|
+
import { figureProps } from '../figure.js';
|
|
7
|
+
import { Badge } from '../status.js';
|
|
8
|
+
import { AnimatedNumberReadout } from '../animated-number.js';
|
|
9
|
+
import { BarMark } from '../bar-mark.js';
|
|
10
|
+
import { BarPnl } from '../bar-pnl.js';
|
|
11
|
+
import { ListGroup, ListRow } from '../list-group.js';
|
|
12
|
+
import { ScreenHeader } from './screen-header.js';
|
|
13
|
+
import { SwapNumber } from './swap/shared.js';
|
|
14
|
+
const usd = { style: 'currency', currency: 'USD' }, known = (value) => value != null && Number.isFinite(value);
|
|
15
|
+
/** 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. */
|
|
16
|
+
export function positionCorridor({ side, entry, mark, liquidation }) {
|
|
17
|
+
if (!known(mark) || !known(liquidation))
|
|
18
|
+
return { total: 0, buffer: 0, drawdown: 0, share: null };
|
|
19
|
+
const span = side === 'long' ? entry - liquidation : liquidation - entry;
|
|
20
|
+
if (!(span > 0))
|
|
21
|
+
return { total: 0, buffer: 0, drawdown: 0, share: null };
|
|
22
|
+
const traveled = side === 'long' ? entry - mark : mark - entry, buffer = Math.max(0, Math.min(span, span - traveled));
|
|
23
|
+
return { total: span, buffer, drawdown: span - buffer, share: buffer / span };
|
|
24
|
+
}
|
|
25
|
+
/** The position's disc: its artwork, or after a failure the host's fallback or the initials. A failure is kept until the artwork changes. */
|
|
26
|
+
function PositionArt({ position }) {
|
|
27
|
+
const { icon, iconFallback, symbol, name } = position, key = typeof icon === 'string' ? icon : `${symbol ?? ''}|${name}`;
|
|
28
|
+
const [broken, setBroken] = useState(null), failed = broken === key, fail = () => setBroken(key);
|
|
29
|
+
const initials = symbol ?? name.slice(0, 3);
|
|
30
|
+
const art = failed || icon == null ? (failed && iconFallback != null ? iconFallback : initials) : typeof icon === 'string' ? _jsx("img", { src: icon, alt: '', onError: fail }) : typeof icon === 'function' ? icon(fail) : icon;
|
|
31
|
+
return _jsx("span", { className: 'hig-asset-row-icon', "aria-hidden": 'true', children: art });
|
|
32
|
+
}
|
|
33
|
+
/** 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. */
|
|
34
|
+
export function ManagePositionBlock({ labels, mode, side, entry, mark, liquidation, margin, notional, priceOptions, actions, position, pnlOptions, onBack, headerAction, headingId, className, ...rest }) {
|
|
35
|
+
const locale = useNumberLocale();
|
|
36
|
+
const present = usePresentNumber();
|
|
37
|
+
const corridor = positionCorridor({ side, entry, mark, liquidation });
|
|
38
|
+
const pnlTone = !known(position?.pnl) || position.pnl === 0 ? undefined : position.pnl > 0 ? 'up' : 'down';
|
|
39
|
+
const pnlFormat = { ...usd, signDisplay: 'exceptZero', maximumFractionDigits: 4, ...pnlOptions };
|
|
40
|
+
const content = (position, ids) => _jsxs(_Fragment, { children: [_jsx(PositionArt, { position: position }), _jsxs("span", { id: ids?.identity, className: 'hig-asset-row-identity', children: [position.badge ? _jsxs("span", { className: 'hig-position-name', children: [_jsx("strong", { children: position.name }), _jsx(Badge, { className: 'hig-position-badge', children: position.badge })] }) : _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", { id: ids?.amounts, className: 'hig-asset-row-amounts', children: [_jsx("strong", { "data-tone": pnlTone, children: _jsx(AnimatedNumberReadout, { value: position.pnl, options: pnlFormat }) }), _jsx("span", { children: _jsx(AnimatedNumberReadout, { value: position.pnlPercent, options: { style: 'percent', minimumFractionDigits: 2, maximumFractionDigits: 2, signDisplay: 'exceptZero' } }) })] })] });
|
|
41
|
+
return _jsxs("section", { ...rest, className: `hig-manage-position-block${className ? ` ${className}` : ''}`, children: [_jsx(ScreenHeader, { title: labels.title, onBack: onBack, action: headerAction, headingId: headingId }), _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, present(usd)), tone: 'info' }, { id: 'notional', label: labels.notional, value: known(notional) ? Math.max(notional - margin, 0) : 0, detail: known(notional) ? formatNumber(notional, locale, present(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, value: action.value == null ? undefined : _jsx("span", { className: 'hig-manage-action-value', "data-tone": action.tone, children: typeof action.value === 'string' ? action.value : _jsx(AnimatedNumberReadout, { ...figureProps(action.value) }) }) }, action.id)) }), position && (position.onSelect ? _jsx(PositionButton, { position: position, content: content }) : _jsx("div", { className: 'hig-asset-row hig-position-row', children: content(position) })), position?.caption && !position.onSelect && _jsx("p", { className: 'hig-position-caption', children: position.caption })] });
|
|
42
|
+
}
|
|
43
|
+
/** The position row as a button: named by the host's label followed by what it shows, so the figures are part of the name, and described by the caption. Without a label it is named by what it shows alone. Its own component, so the ids it needs exist only when it is drawn. */
|
|
44
|
+
function PositionButton({ position, content }) {
|
|
45
|
+
const name = useId(), identity = useId(), amounts = useId(), about = useId();
|
|
46
|
+
return _jsxs(_Fragment, { children: [_jsxs("button", { type: 'button', className: 'hig-asset-row hig-position-row', "aria-labelledby": position.label ? `${name} ${identity} ${amounts}` : undefined, "aria-describedby": position.caption ? about : undefined, onClick: position.onSelect, children: [position.label && _jsxs("span", { id: name, className: 'hig-sr-only', children: [position.label, ","] }), content(position, { identity, amounts }), _jsx(PressDecoration, { kind: 'row' })] }), position.caption && _jsx("p", { id: about, className: 'hig-position-caption', children: position.caption })] });
|
|
47
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface MarketRowContent extends Omit<React.HTMLAttributes<HTMLDivElement>, 'children' | 'onSelect'> {
|
|
3
|
+
symbol: string;
|
|
4
|
+
name: string;
|
|
5
|
+
/** Leave out to draw no price column (no dash); `null` reads as unknown. */
|
|
6
|
+
price?: number | null;
|
|
7
|
+
/** Leave out to draw no change column (no dash); `null` reads as unknown. */
|
|
8
|
+
change?: number | null;
|
|
9
|
+
/** Intl display options, including a decimal style when the host omits a currency symbol. */ priceOptions?: Intl.NumberFormatOptions;
|
|
10
|
+
/** Percent-point display precision/sign; forwarded to Percent. */ changeOptions?: Intl.NumberFormatOptions;
|
|
11
|
+
/** Optional host-rendered market icon, favourite indicator/control and formatted volume. */ icon?: React.ReactNode;
|
|
12
|
+
favorite?: React.ReactNode;
|
|
13
|
+
volume?: React.ReactNode;
|
|
14
|
+
/** A muted second line under the name, such as the maximum leverage. In action mode it is part of the button's name. */
|
|
15
|
+
detail?: React.ReactNode;
|
|
16
|
+
/** Host content on the trailing edge, after the figures, such as a held position's result. Not interactive inside an action row's layout unless it has its own name. */
|
|
17
|
+
trailing?: React.ReactNode;
|
|
18
|
+
/** The market in use: a check on the trailing edge and `aria-current` on the row's control (the row itself in presentation mode). */
|
|
19
|
+
selected?: boolean;
|
|
20
|
+
/** Dims the row; in action mode the name button is disabled. */
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
/** The row under a host's keyboard cursor, highlighted with the well fill. */
|
|
23
|
+
active?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export type MarketRowProps = MarketRowContent & ({
|
|
26
|
+
mode?: 'action';
|
|
27
|
+
onSelect: () => void;
|
|
28
|
+
identity?: never;
|
|
29
|
+
} | {
|
|
30
|
+
mode: 'presentation';
|
|
31
|
+
onSelect?: never; /** Host market identity, such as symbol/name with its existing compact layout. */
|
|
32
|
+
identity?: React.ReactNode;
|
|
33
|
+
});
|
|
34
|
+
/** A market as one row: its name (a button, or the host's identity in presentation mode), price and change. Other attributes, pointer handlers and the ref reach the row's root. */
|
|
35
|
+
export declare const MarketRow: React.ForwardRefExoticComponent<MarketRowProps & React.RefAttributes<HTMLDivElement>>;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef } from 'react';
|
|
4
|
+
import { Button } from '../button.js';
|
|
5
|
+
import { Usd, Percent } from '../data.js';
|
|
6
|
+
const check = _jsx("svg", { className: 'hig-market-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' }) });
|
|
7
|
+
/** A market as one row: its name (a button, or the host's identity in presentation mode), price and change. Other attributes, pointer handlers and the ref reach the row's root. */
|
|
8
|
+
export const MarketRow = forwardRef(function MarketRow({ symbol, name, price, change, onSelect, priceOptions, changeOptions, mode = 'action', identity, icon, favorite, volume, detail, trailing, selected, disabled, active, className, style, ...rest }, ref) {
|
|
9
|
+
const title = detail === undefined ? _jsxs(_Fragment, { children: [name, " (", symbol, ")"] }) : _jsxs("span", { className: 'hig-market-text', children: [_jsxs("span", { children: [name, " (", symbol, ")"] }), _jsx("span", { className: 'hig-market-detail', children: detail })] });
|
|
10
|
+
const current = selected ? 'true' : undefined;
|
|
11
|
+
const content = _jsxs(_Fragment, { children: [favorite !== undefined && _jsx("span", { className: 'hig-market-favorite', children: favorite }), icon !== undefined && _jsx("span", { className: 'hig-market-icon', children: icon }), mode === 'presentation' ? _jsx("span", { className: 'hig-market-name', children: identity === undefined ? title : identity }) : _jsx(Button, { intent: 'ghost', onClick: onSelect, disabled: disabled, "aria-current": current, children: title })] });
|
|
12
|
+
const hasTrailing = trailing !== undefined && trailing !== null && trailing !== false;
|
|
13
|
+
// The default three or four columns keep their grid; any other set of cells flows into as many columns as it has.
|
|
14
|
+
const flow = price === undefined || change === undefined || hasTrailing || !!selected || undefined;
|
|
15
|
+
return _jsxs("div", { ref: ref, ...rest, className: `hig-row hig-market-row${className ? ` ${className}` : ''}`, style: style, "data-mode": mode, "data-has-volume": volume !== undefined || undefined, "data-flow": flow, "data-selected": selected || undefined, "data-active": active || undefined, "data-disabled": disabled || undefined, "aria-current": mode === 'presentation' ? current : undefined, "aria-disabled": mode === 'presentation' && disabled ? true : undefined, children: [_jsx("div", { className: 'hig-market-identity', children: content }), price !== undefined && _jsx("span", { className: 'hig-market-price', children: _jsx(Usd, { value: price, options: priceOptions }) }), change !== undefined && _jsx("span", { className: 'hig-market-change', children: _jsx(Percent, { value: change, options: changeOptions }) }), volume !== undefined && _jsx("span", { className: 'hig-market-volume', children: volume }), hasTrailing && _jsx("span", { className: 'hig-market-trailing', children: trailing }), selected && check] });
|
|
16
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type SettingAction } from './setting-switch.js';
|
|
3
|
+
/** One kind of notification. Every word is host text. */
|
|
4
|
+
export interface NotificationsItem {
|
|
5
|
+
id: string;
|
|
6
|
+
label: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
checked: boolean;
|
|
9
|
+
onCheckedChange: (checked: boolean) => void;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
/** Always on and not changeable: shown on at full strength and read as unavailable. */
|
|
12
|
+
locked?: boolean;
|
|
13
|
+
/** Host content after the label, such as a badge. It is part of the switch's name. */
|
|
14
|
+
labelAccessory?: React.ReactNode;
|
|
15
|
+
/** Host words for the `labelAccessory`, read after the label and a pause in place of its content: `Push, New`. */
|
|
16
|
+
labelAccessoryLabel?: string;
|
|
17
|
+
/** A neutral line under the card, announced when it changes, for progress or a hint: Registering this device. */
|
|
18
|
+
hint?: string;
|
|
19
|
+
/** Why turning it on failed, under the card: Push request timed out. It is announced when it appears. */
|
|
20
|
+
error?: string;
|
|
21
|
+
/** A secondary action under the card, such as Open Settings after the permission was refused. `feedback: false` keeps the provider's press feedback off it. */
|
|
22
|
+
action?: SettingAction;
|
|
23
|
+
}
|
|
24
|
+
/** Notifications under one optional heading: Alert types. */
|
|
25
|
+
export interface NotificationsGroup {
|
|
26
|
+
id: string;
|
|
27
|
+
title?: string;
|
|
28
|
+
items: readonly NotificationsItem[];
|
|
29
|
+
}
|
|
30
|
+
export interface NotificationsBlockProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
|
|
31
|
+
/** Heading: Notifications. */
|
|
32
|
+
title: string;
|
|
33
|
+
/** A muted line under the header that explains the screen. */
|
|
34
|
+
description?: string;
|
|
35
|
+
/** One card each, in order. */
|
|
36
|
+
items?: readonly NotificationsItem[];
|
|
37
|
+
/** More cards under the items, in groups with an optional heading, 24 units apart. */
|
|
38
|
+
groups?: readonly NotificationsGroup[];
|
|
39
|
+
onBack?: () => void;
|
|
40
|
+
/** A control on the trailing edge of the header, usually an `IconButton`. */
|
|
41
|
+
headerAction?: React.ReactNode;
|
|
42
|
+
/** Pins the header to the top of the nearest scrolling container, transparent at rest and filled with `--hig-sticky-header-background` once content scrolls under it. */
|
|
43
|
+
stickyHeader?: boolean;
|
|
44
|
+
}
|
|
45
|
+
/** 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. */
|
|
46
|
+
export declare function NotificationsBlock({ title, description, items, groups, onBack, headerAction, stickyHeader, className, ...rest }: NotificationsBlockProps): React.JSX.Element;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useId } from 'react';
|
|
4
|
+
import { Button } from '../button.js';
|
|
5
|
+
import { ScreenHeader } from './screen-header.js';
|
|
6
|
+
import { SettingSwitch } from './setting-switch.js';
|
|
7
|
+
function Item({ item }) {
|
|
8
|
+
return _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, locked: item.locked, labelAccessory: item.labelAccessory, labelAccessoryLabel: item.labelAccessoryLabel, onCheckedChange: item.onCheckedChange }) }), item.hint && _jsx("p", { role: 'status', className: 'hig-setting-hint', children: item.hint }), item.error && _jsx("p", { role: 'alert', className: 'hig-setting-error', children: item.error }), item.action && _jsx(Button, { className: 'hig-notifications-action', intent: 'secondary', fullWidth: true, disabled: item.action.disabled, suppressFeedback: item.action.feedback === false, onClick: item.action.onSelect, children: item.action.label })] });
|
|
9
|
+
}
|
|
10
|
+
function Group({ group }) {
|
|
11
|
+
const id = useId();
|
|
12
|
+
return _jsxs("section", { className: 'hig-notifications-group', "aria-labelledby": group.title ? id : undefined, children: [group.title && _jsx("div", { className: 'hig-signals-group-header', children: _jsx("h3", { id: id, children: group.title }) }), group.items.length > 0 && _jsx("div", { className: 'hig-setting-cards', children: group.items.map(item => _jsx(Item, { item: item }, item.id)) })] });
|
|
13
|
+
}
|
|
14
|
+
/** 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. */
|
|
15
|
+
export function NotificationsBlock({ title, description, items = [], groups, onBack, headerAction, stickyHeader, className, ...rest }) {
|
|
16
|
+
return _jsxs("section", { ...rest, className: `hig-settings-block${className ? ` ${className}` : ''}`, children: [_jsx(ScreenHeader, { title: title, onBack: onBack, action: headerAction, stickyHeader: stickyHeader }), description && _jsx("p", { className: 'hig-settings-description', children: description }), items.length > 0 && _jsx("div", { className: 'hig-setting-cards', children: items.map(item => _jsx(Item, { item: item }, item.id)) }), groups?.map(group => _jsx(Group, { group: group }, group.id))] });
|
|
17
|
+
}
|
|
@@ -21,8 +21,22 @@ export interface PickerListProps {
|
|
|
21
21
|
loading?: boolean;
|
|
22
22
|
/** With a hardware pointer, focus the search field on mount so typing filters at once. */
|
|
23
23
|
autoFocus?: boolean;
|
|
24
|
+
/** `false` leaves out the search field, for a short list. Defaults to `true`. */
|
|
25
|
+
search?: boolean;
|
|
26
|
+
/** Shows a token's balance when it is zero, where by default only a balance above zero is drawn. */
|
|
27
|
+
zeroBalances?: boolean;
|
|
28
|
+
/** A visible label over the search field, which then names it in place of the built-in hidden label. */
|
|
29
|
+
searchLabel?: string;
|
|
30
|
+
/** A ref to the search input, for example to focus it or register it with a host sheet. */
|
|
31
|
+
searchRef?: React.Ref<HTMLInputElement>;
|
|
32
|
+
/** Attributes for the search input, such as `name`, `autoComplete`, `data-1p-ignore` or `onFocus`/`onBlur`. The value and its change handler stay HIG's; a host `onKeyDown` runs before the list's arrow keys. */
|
|
33
|
+
searchInputProps?: PickerInputProps;
|
|
24
34
|
}
|
|
25
|
-
|
|
35
|
+
/** Host attributes for a picker's input: anything an `<input>` takes, including `data-*`, except the value and its change handler. */
|
|
36
|
+
export type PickerInputProps = Omit<React.InputHTMLAttributes<HTMLInputElement>, 'value' | 'defaultValue' | 'onChange' | 'type' | 'children'> & {
|
|
37
|
+
[attribute: `data-${string}`]: string | number | boolean | undefined;
|
|
38
|
+
};
|
|
39
|
+
export interface FromPickerBlockProps extends PickerListProps {
|
|
26
40
|
/** The connected wallet. Omit for a list with no wallet row at all. */
|
|
27
41
|
wallet?: SwapWallet;
|
|
28
42
|
/** Shows Connect wallet while no wallet is connected. */
|
|
@@ -39,8 +53,8 @@ export interface FromPickerProps extends PickerListProps {
|
|
|
39
53
|
* the tokens it holds (or a whitelist). With no wallet it offers Connect wallet and a Generate address switch above the list.
|
|
40
54
|
* The host owns the wallet, the token data and the generated address.
|
|
41
55
|
*/
|
|
42
|
-
export declare function
|
|
43
|
-
export interface
|
|
56
|
+
export declare function FromPickerBlock({ wallet, onConnect, onDisconnect, generateAddress, onGenerateAddressChange, className, ...list }: FromPickerBlockProps): React.JSX.Element;
|
|
57
|
+
export interface ToPickerBlockProps extends Partial<PickerListProps> {
|
|
44
58
|
/** The destination address field. Omit `onAddressChange` to hide it. */
|
|
45
59
|
address?: string;
|
|
46
60
|
onAddressChange?: (address: string) => void;
|
|
@@ -48,10 +62,24 @@ export interface ToPickerProps extends Partial<PickerListProps> {
|
|
|
48
62
|
addressPlaceholder?: string;
|
|
49
63
|
/** Shows the scan button. HIG ships no scanner: the host opens its own and writes the result to `address`. */
|
|
50
64
|
onScan?: () => void;
|
|
65
|
+
/** A visible label over the address field, which then names it in place of the built-in hidden “Recipient”. */
|
|
66
|
+
addressLabel?: string;
|
|
67
|
+
/** A ref to the address input, for example to focus it or register it with a host sheet. */
|
|
68
|
+
addressRef?: React.Ref<HTMLInputElement>;
|
|
69
|
+
/** Attributes for the address input, such as `name='recipient'`, `data-1p-ignore`, `data-lpignore`, a mono `className` or `onFocus`/`onBlur`. The value and its change handler stay HIG's. */
|
|
70
|
+
addressInputProps?: PickerInputProps;
|
|
51
71
|
className?: string;
|
|
52
72
|
}
|
|
53
73
|
/**
|
|
54
74
|
* Where the assets go. On its own it is a destination address field with a scan button. With `tokens` it adds the
|
|
55
75
|
* searchable token list, with the chain filter or, with `chainFilter={false}`, without it.
|
|
56
76
|
*/
|
|
57
|
-
export declare function
|
|
77
|
+
export declare function ToPickerBlock({ address, onAddressChange, addressPlaceholder, onScan, addressLabel, addressRef, addressInputProps, className, tokens, onSelect, ...list }: ToPickerBlockProps): React.JSX.Element;
|
|
78
|
+
/** @deprecated Renamed `FromPickerBlock`. The old name keeps working until the next major release. */
|
|
79
|
+
export declare const FromPicker: typeof FromPickerBlock;
|
|
80
|
+
/** @deprecated Renamed `FromPickerBlockProps`. */
|
|
81
|
+
export type FromPickerProps = FromPickerBlockProps;
|
|
82
|
+
/** @deprecated Renamed `ToPickerBlock`. The old name keeps working until the next major release. */
|
|
83
|
+
export declare const ToPicker: typeof ToPickerBlock;
|
|
84
|
+
/** @deprecated Renamed `ToPickerBlockProps`. */
|
|
85
|
+
export type ToPickerProps = ToPickerBlockProps;
|
|
@@ -1,20 +1,34 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useEffect, useId, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react';
|
|
4
4
|
import * as en from '@bloxwap/hig/contracts/messages';
|
|
5
|
-
import { useHIG } from '../provider.js';
|
|
5
|
+
import { PressDecoration, useHIG } from '../provider.js';
|
|
6
6
|
import { Button, IconButton } from '../button.js';
|
|
7
|
-
import { Input, SearchInput } from '../field.js';
|
|
7
|
+
import { Field, Input, SearchInput } from '../field.js';
|
|
8
8
|
import { Filter } from '../selection.js';
|
|
9
9
|
import { SwapIcon, SwapNumber, TokenIcon, usdNumber, addressGradient, chainsOf, fuzzyMatch, shortAddress } from './swap/shared.js';
|
|
10
|
-
|
|
10
|
+
/** A row shows a known balance above zero, or a zero one when the host asks for it. */
|
|
11
|
+
const showBalance = (token, zero) => token.balance != null && Number.isFinite(token.balance) && (token.balance > 0 || (!!zero && token.balance === 0));
|
|
12
|
+
/** One callback ref that sets each given ref. */
|
|
13
|
+
function useMergedRef(...refs) {
|
|
14
|
+
const latest = useRef(refs);
|
|
15
|
+
latest.current = refs;
|
|
16
|
+
return useCallback((node) => { for (const ref of latest.current) {
|
|
17
|
+
if (typeof ref === 'function')
|
|
18
|
+
ref(node);
|
|
19
|
+
else if (ref)
|
|
20
|
+
ref.current = node;
|
|
21
|
+
} }, []);
|
|
22
|
+
}
|
|
23
|
+
function TokenList({ tokens, chains, chainFilter = true, hotTokenIds, selected = null, onSelect, loading, autoFocus, search: searchable = true, zeroBalances, searchLabel, searchRef, searchInputProps, label }) {
|
|
11
24
|
const { messages } = useHIG();
|
|
12
25
|
const id = useId();
|
|
13
26
|
const [query, setQuery] = useState('');
|
|
14
27
|
const [chainId, setChainId] = useState(null);
|
|
15
|
-
const [active, setActive] = useState(0);
|
|
28
|
+
const [active, setActive] = useState(searchable ? 0 : -1);
|
|
16
29
|
const list = useRef(null);
|
|
17
30
|
const search = useRef(null);
|
|
31
|
+
const searchInput = useMergedRef(search, searchRef);
|
|
18
32
|
useEffect(() => { if (autoFocus && window.matchMedia?.('(pointer: fine)').matches)
|
|
19
33
|
search.current?.focus(); }, []);
|
|
20
34
|
const options = useMemo(() => chains ?? chainsOf(tokens), [chains, tokens]);
|
|
@@ -29,7 +43,8 @@ function TokenList({ tokens, chains, chainFilter = true, hotTokenIds, selected =
|
|
|
29
43
|
return { rows: filtered, hotCount: 0 };
|
|
30
44
|
return { rows: [...hot, ...filtered.filter(token => !hot.includes(token))], hotCount: hot.length };
|
|
31
45
|
}, [tokens, hotTokenIds, query, chainId]);
|
|
32
|
-
|
|
46
|
+
// Without a search field there is no arrow-key cursor, so no row is highlighted until the pointer moves over one.
|
|
47
|
+
useEffect(() => { setActive(searchable ? 0 : -1); }, [query, chainId, searchable]);
|
|
33
48
|
useEffect(() => { list.current?.querySelector('[data-active="true"]')?.scrollIntoView?.({ block: 'nearest' }); }, [active]);
|
|
34
49
|
const onKeyDown = (event) => {
|
|
35
50
|
if (event.key === 'ArrowDown') {
|
|
@@ -49,16 +64,19 @@ function TokenList({ tokens, chains, chainFilter = true, hotTokenIds, selected =
|
|
|
49
64
|
const filters = [{ value: '', label: messages.swapAllChains ?? en.swapAllChains }, ...options.map(chain => ({ value: String(chain.chainId), label: chain.name, icon: chain.icon }))];
|
|
50
65
|
const row = (token, index) => {
|
|
51
66
|
const isSelected = selected?.id === token.id;
|
|
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
|
|
67
|
+
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.detail ?? token.chain, isSelected ? ' · ' + (messages.swapSelected ?? en.swapSelected) : ''] })] }), showBalance(token, zeroBalances) && _jsxs("span", { className: 'hig-swap-row-balance', children: [_jsx("strong", { children: _jsx(SwapNumber, { value: token.balance, options: { maximumFractionDigits: 6 }, suffix: token.unitsSuffix }) }), (token.price ?? 0) > 0 && _jsx(SwapNumber, { ...usdNumber((token.balance ?? 0) * (token.price ?? 0)) })] }), _jsx(PressDecoration, { kind: 'row' })] }) }, token.id);
|
|
53
68
|
};
|
|
54
|
-
|
|
69
|
+
const searchName = messages.swapSearchTokens ?? en.swapSearchTokens;
|
|
70
|
+
const field = _jsx(SearchInput, { ref: searchInput, "aria-label": searchLabel ? undefined : searchName, placeholder: searchName, enterKeyHint: 'search', autoComplete: 'off', autoCapitalize: 'none', autoCorrect: 'off', spellCheck: false, ...searchInputProps, value: query, onChange: event => setQuery(event.target.value), onKeyDown: event => { searchInputProps?.onKeyDown?.(event); if (!event.defaultPrevented)
|
|
71
|
+
onKeyDown(event); } });
|
|
72
|
+
return _jsxs(_Fragment, { children: [searchable && (searchLabel ? _jsx(Field, { label: searchLabel, children: field }) : field), 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)) })] })] });
|
|
55
73
|
}
|
|
56
74
|
/**
|
|
57
75
|
* Where the assets come from. A connected wallet shows its address, with a disconnect button the host can leave out, above
|
|
58
76
|
* the tokens it holds (or a whitelist). With no wallet it offers Connect wallet and a Generate address switch above the list.
|
|
59
77
|
* The host owns the wallet, the token data and the generated address.
|
|
60
78
|
*/
|
|
61
|
-
export function
|
|
79
|
+
export function FromPickerBlock({ wallet, onConnect, onDisconnect, generateAddress = false, onGenerateAddressChange, className, ...list }) {
|
|
62
80
|
const { messages } = useHIG();
|
|
63
81
|
const id = useId();
|
|
64
82
|
const label = messages.swapFrom ?? en.swapFrom;
|
|
@@ -70,8 +88,14 @@ export function FromPicker({ wallet, onConnect, onDisconnect, generateAddress =
|
|
|
70
88
|
* Where the assets go. On its own it is a destination address field with a scan button. With `tokens` it adds the
|
|
71
89
|
* searchable token list, with the chain filter or, with `chainFilter={false}`, without it.
|
|
72
90
|
*/
|
|
73
|
-
export function
|
|
91
|
+
export function ToPickerBlock({ address, onAddressChange, addressPlaceholder, onScan, addressLabel, addressRef, addressInputProps, className, tokens, onSelect, ...list }) {
|
|
74
92
|
const { messages } = useHIG();
|
|
75
93
|
const label = messages.swapTo ?? en.swapTo;
|
|
76
|
-
|
|
94
|
+
const recipient = messages.swapRecipient ?? en.swapRecipient;
|
|
95
|
+
const row = onAddressChange && _jsxs("div", { className: 'hig-swap-wallet', children: [_jsx(Input, { ref: addressRef, "aria-label": addressLabel ? undefined : recipient, placeholder: addressPlaceholder ?? recipient, autoComplete: 'off', autoCapitalize: 'none', autoCorrect: 'off', spellCheck: false, ...addressInputProps, value: address ?? '', onChange: event => onAddressChange(event.target.value) }), onScan && _jsx(IconButton, { intent: 'secondary', label: messages.swapScan ?? en.swapScan, onClick: onScan, children: _jsx(SwapIcon, { name: 'scan' }) })] });
|
|
96
|
+
return _jsxs("div", { className: `hig-picker${className ? ` ${className}` : ''}`, role: 'group', "aria-label": label, children: [row && (addressLabel ? _jsx(Field, { label: addressLabel, children: row }) : row), tokens && onSelect && _jsx(TokenList, { ...list, tokens: tokens, onSelect: onSelect, label: label })] });
|
|
77
97
|
}
|
|
98
|
+
/** @deprecated Renamed `FromPickerBlock`. The old name keeps working until the next major release. */
|
|
99
|
+
export const FromPicker = FromPickerBlock;
|
|
100
|
+
/** @deprecated Renamed `ToPickerBlock`. The old name keeps working until the next major release. */
|
|
101
|
+
export const ToPicker = ToPickerBlock;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type Figure } from '../figure.js';
|
|
3
|
+
import { type ScreenHeaderControlProps } from './screen-header.js';
|
|
4
|
+
/** A number the host supplies as a number so it updates place by place: `{value:0.53,options:{style:'currency',currency:'USD'}}`, or Leverage as `{value:40,suffix:'×'}`. `null` reads as unknown. `formattedValue` is the host's own text for it, still moving place by place. */
|
|
5
|
+
export type PositionBlockFigure = Figure;
|
|
6
|
+
/** 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. */
|
|
7
|
+
export interface PositionBlockDetail {
|
|
8
|
+
id?: string;
|
|
9
|
+
label: string;
|
|
10
|
+
value: string | PositionBlockFigure;
|
|
11
|
+
tone?: 'positive' | 'negative' | 'muted';
|
|
12
|
+
/** Draws the value struck through, for a charge that does not apply, and reads this host text after it: Waived. */
|
|
13
|
+
struck?: string;
|
|
14
|
+
/** Host content right after the label, such as a badge that explains the line. It may be interactive. */
|
|
15
|
+
labelAccessory?: React.ReactNode;
|
|
16
|
+
}
|
|
17
|
+
/** One setting of the position: Size, Leverage, Stop Loss. With `onSelect` the row opens the host's own view and shows a chevron; with `onCheckedChange` the row is a switch. */
|
|
18
|
+
export interface PositionBlockRow {
|
|
19
|
+
id: string;
|
|
20
|
+
label: string;
|
|
21
|
+
/** Host text on the trailing edge, or a live figure that updates place by place. */
|
|
22
|
+
value?: string | PositionBlockFigure;
|
|
23
|
+
onSelect?: () => void;
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
/** With `onCheckedChange`, the row is a switch named by its label, and the whole row toggles it. */
|
|
26
|
+
checked?: boolean;
|
|
27
|
+
onCheckedChange?: (checked: boolean) => void;
|
|
28
|
+
}
|
|
29
|
+
/** An action on the paper trading row's card, under the switch, such as collecting what the paper position earned. */
|
|
30
|
+
export interface PositionBlockFlagAction {
|
|
31
|
+
label: string;
|
|
32
|
+
onSelect: () => void;
|
|
33
|
+
intent?: 'primary' | 'secondary' | 'destructive';
|
|
34
|
+
busy?: boolean;
|
|
35
|
+
disabled?: boolean;
|
|
36
|
+
}
|
|
37
|
+
/** The paper trading switch. The host supplies its name, because HIG ships no trading terms. */
|
|
38
|
+
export interface PositionBlockFlag {
|
|
39
|
+
label: string;
|
|
40
|
+
checked: boolean;
|
|
41
|
+
onCheckedChange: (checked: boolean) => void;
|
|
42
|
+
disabled?: boolean;
|
|
43
|
+
/** A button on the row's card, under the switch. */
|
|
44
|
+
action?: PositionBlockFlagAction;
|
|
45
|
+
}
|
|
46
|
+
export interface PositionBlockProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
|
|
47
|
+
/** Heading: Position. */
|
|
48
|
+
title: string;
|
|
49
|
+
/** The summary under the header, in order. */
|
|
50
|
+
details: readonly PositionBlockDetail[];
|
|
51
|
+
/** One sentence under the summary, such as the minimum margin. */
|
|
52
|
+
note?: string;
|
|
53
|
+
/** Shows the paper trading switch as a row of its own above the settings. The whole row toggles it. */
|
|
54
|
+
paperTrade?: PositionBlockFlag;
|
|
55
|
+
/** The settings, as groups of rows. Each group is one rounded container. */
|
|
56
|
+
groups: readonly (readonly PositionBlockRow[])[];
|
|
57
|
+
/** Shows Close on the trailing edge of the header. */
|
|
58
|
+
onClose?: () => void;
|
|
59
|
+
onBack?: () => void;
|
|
60
|
+
/** A control on the trailing edge of the header in place of Close. */
|
|
61
|
+
headerAction?: React.ReactNode;
|
|
62
|
+
/** `id` of the heading, so a dialog or sheet can name itself with `aria-labelledby`. */
|
|
63
|
+
headingId?: string;
|
|
64
|
+
/** Set true to pin the header to the top of the nearest scrolling container while the rest scrolls under it. It is transparent at rest and fills with `--hig-sticky-header-background` once content scrolls under it. */
|
|
65
|
+
stickyHeader?: boolean;
|
|
66
|
+
/** Attributes for the header's Back `<button>`. */
|
|
67
|
+
backProps?: ScreenHeaderControlProps;
|
|
68
|
+
/** Attributes for the header's Close `<button>`. */
|
|
69
|
+
closeProps?: ScreenHeaderControlProps;
|
|
70
|
+
}
|
|
71
|
+
/** 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. */
|
|
72
|
+
export declare function PositionBlock({ title, details, note, paperTrade, groups, onClose, onBack, headerAction, headingId, stickyHeader, backProps, closeProps, className, ...rest }: PositionBlockProps): React.JSX.Element;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, 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 { Switch } from '../selection.js';
|
|
7
|
+
import { ListGroup, ListRow } from '../list-group.js';
|
|
8
|
+
import { AnimatedNumberReadout } from '../animated-number.js';
|
|
9
|
+
import { figureProps } from '../figure.js';
|
|
10
|
+
import { HeaderClose, ScreenHeader } from './screen-header.js';
|
|
11
|
+
const figure = (value) => typeof value === 'string' ? value : _jsx(AnimatedNumberReadout, { ...figureProps(value) });
|
|
12
|
+
/** A press anywhere on a switch row that is not on a control toggles the row's switch, through the switch itself so its change and feedback run once. */
|
|
13
|
+
function toggleRow(event) {
|
|
14
|
+
if (event.target.closest('a,button,input,label,select,textarea'))
|
|
15
|
+
return;
|
|
16
|
+
const input = event.currentTarget.querySelector('input[role="switch"]');
|
|
17
|
+
if (input && !input.disabled)
|
|
18
|
+
input.click();
|
|
19
|
+
}
|
|
20
|
+
/** 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. */
|
|
21
|
+
export function PositionBlock({ title, details, note, paperTrade, groups, onClose, onBack, headerAction, headingId, stickyHeader, backProps, closeProps, className, ...rest }) {
|
|
22
|
+
const { messages } = useHIG();
|
|
23
|
+
const flag = paperTrade && _jsx(ListRow, { label: paperTrade.label, disabled: paperTrade.disabled, onClick: toggleRow, trailing: _jsx(Switch, { label: paperTrade.label, checked: paperTrade.checked, disabled: paperTrade.disabled, onCheckedChange: paperTrade.onCheckedChange }) });
|
|
24
|
+
return _jsxs("section", { ...rest, className: `hig-position-block${className ? ` ${className}` : ''}`, children: [_jsx(ScreenHeader, { title: title, onBack: onBack, backProps: backProps, headingId: headingId, stickyHeader: stickyHeader, action: headerAction ?? (onClose && _jsx(HeaderClose, { onClose: onClose, label: messages.close ?? en.close, closeProps: closeProps })) }), details.length > 0 && _jsx("dl", { className: 'hig-position-details', children: details.map((detail, index) => _jsxs("div", { "data-tone": detail.tone, children: [_jsxs("dt", { children: [detail.label, detail.labelAccessory != null && _jsx("span", { className: 'hig-position-label-accessory', children: detail.labelAccessory })] }), _jsx("dd", { className: 'hig-number', children: detail.struck ? _jsxs(_Fragment, { children: [_jsx("span", { className: 'hig-position-struck', children: figure(detail.value) }), _jsxs("span", { className: 'hig-sr-only', children: [" ", detail.struck] })] }) : figure(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: paperTrade.action ? _jsxs("div", { className: 'hig-position-flag-card', children: [flag, _jsx("div", { className: 'hig-position-flag-action', children: _jsx(Button, { fullWidth: true, intent: paperTrade.action.intent ?? 'primary', busy: paperTrade.action.busy, disabled: paperTrade.action.disabled, onClick: paperTrade.action.onSelect, children: paperTrade.action.label }) })] }) : flag }), groups.map((group, index) => group.length > 0 && _jsx(ListGroup, { children: group.map(row => row.onCheckedChange ? _jsx(ListRow, { label: row.label, value: row.value == null ? undefined : figure(row.value), disabled: row.disabled, onClick: toggleRow, trailing: _jsx(Switch, { label: row.label, checked: !!row.checked, disabled: row.disabled, onCheckedChange: row.onCheckedChange }) }, row.id) : _jsx(ListRow, { label: row.label, value: row.value == null || typeof row.value === 'string' ? row.value : figure(row.value), onSelect: row.onSelect, disabled: row.disabled }, row.id)) }, index))] })] });
|
|
25
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type Figure } from '../figure.js';
|
|
3
|
+
import type { AssetArtwork } from '../asset-balance-row.js';
|
|
4
|
+
/** A row value that can change while the profile is shown, such as a balance: formatted with `options` between `prefix` and `suffix`, and updated place by place. `null` reads as unknown. */
|
|
5
|
+
export type ProfileFigure = Figure;
|
|
6
|
+
/** One row of a profile section. With `onSelect` it opens something and shows a chevron; with `onCheckedChange` it is a switch. */
|
|
7
|
+
export interface ProfileRow {
|
|
8
|
+
id: string;
|
|
9
|
+
label: string;
|
|
10
|
+
/** Artwork before the label, such as an icon. */
|
|
11
|
+
leading?: React.ReactNode;
|
|
12
|
+
/** Short text on the trailing edge, such as a balance or `Off`, or a live figure that updates place by place. */
|
|
13
|
+
value?: React.ReactNode | ProfileFigure;
|
|
14
|
+
/** Colours the value. Without it the value keeps the row's muted value style. */
|
|
15
|
+
tone?: 'positive' | 'warning' | 'negative' | 'muted';
|
|
16
|
+
/** Anything richer on the trailing edge: icons or a `Badge`. */
|
|
17
|
+
trailing?: React.ReactNode;
|
|
18
|
+
onSelect?: () => void;
|
|
19
|
+
disabled?: boolean;
|
|
20
|
+
/** With `onCheckedChange`, the row is a switch: the track trails, the label names it, and a press anywhere on the row toggles it. */
|
|
21
|
+
checked?: boolean;
|
|
22
|
+
onCheckedChange?: (checked: boolean) => void;
|
|
23
|
+
}
|
|
24
|
+
export interface ProfileSection {
|
|
25
|
+
id: string;
|
|
26
|
+
/** Heading above the group, such as Rewards or Settings. */
|
|
27
|
+
title?: string;
|
|
28
|
+
rows: readonly ProfileRow[];
|
|
29
|
+
}
|
|
30
|
+
/** The dot on the avatar: an account mode or state the host names, such as Demo. */
|
|
31
|
+
export interface ProfileStatus {
|
|
32
|
+
/** Read out for the dot. */
|
|
33
|
+
label: string;
|
|
34
|
+
tone?: 'positive' | 'warning' | 'negative' | 'info';
|
|
35
|
+
}
|
|
36
|
+
/** The primary action under the name, such as Log in for a signed-out viewer. The host writes the label. */
|
|
37
|
+
export interface ProfileAction {
|
|
38
|
+
label: string;
|
|
39
|
+
onSelect: () => void;
|
|
40
|
+
disabled?: boolean;
|
|
41
|
+
/** Defaults to `primary`. */
|
|
42
|
+
intent?: 'primary' | 'secondary';
|
|
43
|
+
}
|
|
44
|
+
export interface ProfileBlockProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
|
|
45
|
+
/** The name under the avatar: a display name or a shortened address. It may be left out when `action` is set, for a signed-out viewer. */
|
|
46
|
+
name?: string;
|
|
47
|
+
/** Host content beside the name, such as a badge. It stays in the accessibility tree, so give an interactive badge its own name. */
|
|
48
|
+
nameAccessory?: React.ReactNode;
|
|
49
|
+
/** Colours the avatar when there is no artwork. */
|
|
50
|
+
address?: string;
|
|
51
|
+
/** An image URL or an element the host draws. */
|
|
52
|
+
avatar?: AssetArtwork;
|
|
53
|
+
/** Makes the avatar a button, for example to choose a picture. `avatarLabel` names it. */
|
|
54
|
+
onAvatarPress?: () => void;
|
|
55
|
+
/** The accessible name of the avatar button, such as Change profile picture. Defaults to `name`, then the built-in “Change profile picture”. */
|
|
56
|
+
avatarLabel?: string;
|
|
57
|
+
status?: ProfileStatus;
|
|
58
|
+
/** Shows the edit control after the name. */
|
|
59
|
+
onEditName?: () => void;
|
|
60
|
+
/** Shows the address control on the leading edge of the top bar. */
|
|
61
|
+
onShowAddress?: () => void;
|
|
62
|
+
/** Shows Close on the trailing edge of the top bar. */
|
|
63
|
+
onClose?: () => void;
|
|
64
|
+
/** A full-width button under the name, such as Log in. */
|
|
65
|
+
action?: ProfileAction;
|
|
66
|
+
sections: readonly ProfileSection[];
|
|
67
|
+
/** Host content under the sections, such as legal links. */
|
|
68
|
+
footer?: React.ReactNode;
|
|
69
|
+
}
|
|
70
|
+
/** A person's profile as one screen: who they are (avatar, status, name), then grouped rows that open their accounts, history, rewards and settings. */
|
|
71
|
+
export declare function ProfileBlock({ name, nameAccessory, address, avatar, onAvatarPress, avatarLabel, status, onEditName, onShowAddress, onClose, action, sections, footer, className, ...rest }: ProfileBlockProps): React.JSX.Element;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import React, { useRef } from 'react';
|
|
4
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
5
|
+
import { PressDecoration, useControllable, useHIG } from '../provider.js';
|
|
6
|
+
import { Button, IconButton } from '../button.js';
|
|
7
|
+
import { ListGroup, ListRow } from '../list-group.js';
|
|
8
|
+
import { AnimatedNumberReadout } from '../animated-number.js';
|
|
9
|
+
import { figureProps } from '../figure.js';
|
|
10
|
+
import { qrIcon } from './screen-header.js';
|
|
11
|
+
import { SwapIcon, addressGradient } from './swap/shared.js';
|
|
12
|
+
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' }) });
|
|
13
|
+
/** True for a `ProfileFigure`: a plain object with a `value`, not an element, array or other node. */
|
|
14
|
+
const isProfileFigure = (value) => value != null && typeof value === 'object' && !React.isValidElement(value) && !Array.isArray(value) && !(Symbol.iterator in value) && 'value' in value;
|
|
15
|
+
function rowValue(row) {
|
|
16
|
+
const { value, tone } = row;
|
|
17
|
+
if (value == null)
|
|
18
|
+
return value;
|
|
19
|
+
if (isProfileFigure(value))
|
|
20
|
+
return _jsx("span", { className: 'hig-profile-value', "data-tone": tone, children: _jsx(AnimatedNumberReadout, { ...figureProps(value) }) });
|
|
21
|
+
return tone ? _jsx("span", { className: 'hig-profile-value', "data-tone": tone, children: value }) : value;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A switch row whose whole row is the target. The markup is a static `ListRow` with a `Switch` in `trailing`, so the row
|
|
25
|
+
* draws exactly as before; a press anywhere outside the switch toggles it, the switch input stays the one named control
|
|
26
|
+
* for keyboard and assistive technology, and the host's press decoration covers the whole row instead of the track.
|
|
27
|
+
*/
|
|
28
|
+
function ProfileSwitchRow({ row }) {
|
|
29
|
+
const [checked, set] = useControllable(!!row.checked, false, row.onCheckedChange);
|
|
30
|
+
const input = useRef(null);
|
|
31
|
+
const toggle = (event) => { if (row.disabled || event.target.closest('.hig-switch'))
|
|
32
|
+
return; input.current?.click(); };
|
|
33
|
+
const value = rowValue(row);
|
|
34
|
+
return _jsxs("div", { className: 'hig-list-row', "aria-disabled": row.disabled || undefined, onClick: toggle, children: [row.leading != null && _jsx("span", { className: 'hig-list-row-leading', "aria-hidden": 'true', children: row.leading }), _jsx("span", { className: 'hig-list-row-label', children: row.label }), value != null && _jsx("span", { className: 'hig-list-row-value', children: value }), _jsx("span", { className: 'hig-list-row-trailing', children: _jsxs("label", { className: 'hig-choice hig-switch', children: [_jsx("input", { ref: input, role: 'switch', type: 'checkbox', checked: !!checked, disabled: row.disabled, onChange: event => set(event.target.checked) }), _jsx("span", { children: row.label })] }) }), _jsx(PressDecoration, { kind: 'switch', disabled: !!row.disabled, input: input })] });
|
|
35
|
+
}
|
|
36
|
+
/** A person's profile as one screen: who they are (avatar, status, name), then grouped rows that open their accounts, history, rewards and settings. */
|
|
37
|
+
export function ProfileBlock({ name, nameAccessory, address, avatar, onAvatarPress, avatarLabel, status, onEditName, onShowAddress, onClose, action, sections, footer, className, ...rest }) {
|
|
38
|
+
const { messages } = useHIG();
|
|
39
|
+
const artwork = typeof avatar === 'string' ? _jsx("img", { src: avatar, alt: '' }) : avatar ?? (address ? null : name?.slice(0, 2));
|
|
40
|
+
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: [onAvatarPress ? _jsxs("button", { type: 'button', className: 'hig-profile-artwork', "aria-label": avatarLabel ?? name ?? messages.changeProfilePicture ?? en.changeProfilePicture, onClick: onAvatarPress, children: [artwork, _jsx(PressDecoration, { kind: 'icon-button' })] }) : _jsx("span", { className: 'hig-profile-artwork', "aria-hidden": 'true', children: artwork }), status && _jsx("span", { className: 'hig-profile-status', "data-tone": status.tone ?? 'warning', children: _jsx("span", { className: 'hig-sr-only', children: status.label }) })] }), name != null && _jsxs("div", { className: 'hig-profile-name', children: [_jsx("h2", { children: name }), nameAccessory != null && _jsx("span", { className: 'hig-profile-name-accessory', children: nameAccessory }), onEditName && _jsx(IconButton, { intent: 'ghost', label: messages.editName ?? en.editName, onClick: onEditName, children: editIcon })] }), action && _jsx(Button, { className: 'hig-profile-action', fullWidth: true, intent: action.intent ?? 'primary', disabled: action.disabled, onClick: action.onSelect, children: action.label })] }), sections.filter(section => section.rows.length > 0).map(section => _jsx(ListGroup, { title: section.title, children: section.rows.map(row => row.onCheckedChange ? _jsx(ProfileSwitchRow, { row: row }, row.id) : _jsx(ListRow, { label: row.label, leading: row.leading, value: rowValue(row), disabled: row.disabled, onSelect: row.onSelect, trailing: row.trailing }, row.id)) }, section.id)), footer != null && _jsx("div", { className: 'hig-profile-footer', children: footer })] });
|
|
41
|
+
}
|