@bloxwap/hig 0.6.0 → 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/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 +6 -0
- package/contracts/dist/messages.js +3 -1
- package/feedback/README.md +1 -1
- package/native/README.md +1 -1
- package/native/dist/account-block.d.ts +53 -7
- package/native/dist/account-block.js +42 -9
- 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 +17 -1
- package/native/dist/asset-balance-row.js +13 -8
- package/native/dist/bar-mark.d.ts +14 -2
- package/native/dist/bar-mark.js +19 -5
- package/native/dist/bar-pnl.js +5 -4
- package/native/dist/blocks.d.ts +8 -14
- package/native/dist/blocks.js +5 -6
- 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 -4
- package/native/dist/field.js +33 -7
- package/native/dist/figure.d.ts +23 -0
- package/native/dist/figure.js +10 -0
- package/native/dist/language-block.d.ts +5 -1
- package/native/dist/language-block.js +3 -3
- package/native/dist/list-group.d.ts +42 -8
- package/native/dist/list-group.js +71 -13
- package/native/dist/manage-position-block.d.ts +28 -2
- package/native/dist/manage-position-block.js +36 -11
- package/native/dist/market-row.d.ts +46 -0
- package/native/dist/market-row.js +30 -0
- package/native/dist/notifications-block.d.ts +30 -2
- package/native/dist/notifications-block.js +16 -8
- package/native/dist/pickers.d.ts +24 -2
- package/native/dist/pickers.js +16 -8
- package/native/dist/position-block.d.ts +66 -10
- package/native/dist/position-block.js +45 -11
- package/native/dist/profile-block.d.ts +29 -5
- package/native/dist/profile-block.js +25 -5
- 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 -0
- package/native/dist/recipes.js +6 -0
- package/native/dist/reward-block.d.ts +45 -6
- package/native/dist/reward-block.js +30 -12
- 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 -8
- package/native/dist/setting-header.js +2 -11
- package/native/dist/setting-switch.d.ts +14 -1
- package/native/dist/setting-switch.js +5 -2
- package/native/dist/signals-block.d.ts +26 -2
- package/native/dist/signals-block.js +14 -4
- package/native/dist/sound-haptics-block.d.ts +29 -2
- package/native/dist/sound-haptics-block.js +18 -7
- 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-block.d.ts +2 -1
- package/native/dist/swap-panel-block.js +9 -6
- 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-views.js +5 -3
- 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 +33 -6
- package/native/dist/target-block.js +19 -6
- package/native/dist/token-action-block.d.ts +17 -9
- package/native/dist/token-action-block.js +14 -6
- package/native/dist/trade-history-detail-block.d.ts +26 -1
- package/native/dist/trade-history-detail-block.js +17 -9
- package/native/dist/trade-history-list-block.d.ts +71 -5
- package/native/dist/trade-history-list-block.js +50 -15
- 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 +21 -1
- 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 +17 -1
- package/react/dist/asset-balance-row.js +11 -3
- package/react/dist/bar-mark.d.ts +5 -2
- package/react/dist/bar-mark.js +5 -3
- package/react/dist/blocks/account-block.d.ts +53 -7
- package/react/dist/blocks/account-block.js +45 -10
- package/react/dist/blocks/language-block.d.ts +5 -1
- package/react/dist/blocks/language-block.js +6 -5
- package/react/dist/blocks/manage-position-block.d.ts +28 -2
- package/react/dist/blocks/manage-position-block.js +23 -4
- package/react/dist/blocks/market-row.d.ts +20 -9
- package/react/dist/blocks/market-row.js +12 -4
- package/react/dist/blocks/notifications-block.d.ts +25 -2
- package/react/dist/blocks/notifications-block.js +11 -2
- package/react/dist/blocks/pickers.d.ts +21 -1
- package/react/dist/blocks/pickers.js +30 -10
- package/react/dist/blocks/position-block.d.ts +34 -11
- package/react/dist/blocks/position-block.js +16 -5
- package/react/dist/blocks/profile-block.d.ts +29 -6
- package/react/dist/blocks/profile-block.js +31 -5
- package/react/dist/blocks/reward-block.d.ts +53 -14
- package/react/dist/blocks/reward-block.js +20 -10
- package/react/dist/blocks/screen-header.d.ts +26 -2
- package/react/dist/blocks/screen-header.js +13 -5
- package/react/dist/blocks/setting-switch.d.ts +14 -1
- package/react/dist/blocks/setting-switch.js +8 -4
- package/react/dist/blocks/signals-block.d.ts +21 -2
- package/react/dist/blocks/signals-block.js +5 -5
- package/react/dist/blocks/sound-haptics-block.d.ts +25 -3
- package/react/dist/blocks/sound-haptics-block.js +11 -7
- 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 +2 -1
- package/react/dist/blocks/swap/settings.js +2 -2
- package/react/dist/blocks/swap/shared.d.ts +7 -1
- package/react/dist/blocks/swap/shared.js +6 -4
- package/react/dist/blocks/swap-panel-block.d.ts +2 -0
- package/react/dist/blocks/swap-panel-block.js +6 -6
- package/react/dist/blocks/target-block.d.ts +28 -6
- package/react/dist/blocks/target-block.js +17 -9
- package/react/dist/blocks/token-action-block.d.ts +17 -8
- package/react/dist/blocks/token-action-block.js +9 -6
- package/react/dist/blocks/trade-history-detail-block.d.ts +21 -1
- package/react/dist/blocks/trade-history-detail-block.js +5 -4
- package/react/dist/blocks/trade-history-list-block.d.ts +29 -5
- package/react/dist/blocks/trade-history-list-block.js +15 -8
- package/react/dist/blocks.d.ts +8 -8
- package/react/dist/blocks.js +2 -2
- package/react/dist/button.js +6 -4
- package/react/dist/data.js +3 -3
- package/react/dist/field.d.ts +14 -4
- package/react/dist/field.js +19 -6
- package/react/dist/figure.d.ts +23 -0
- package/react/dist/figure.js +12 -0
- package/react/dist/list-group.d.ts +41 -8
- package/react/dist/list-group.js +44 -12
- 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 +164 -9
- 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
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
4
|
-
import { createAnimatedNumberModel, createAnimatedNumberTransitions } from './animated-number-model.js';
|
|
5
|
-
import { useHIG } from './provider.js';
|
|
4
|
+
import { createAnimatedNumberModel, createAnimatedNumberTransitions, createFormattedAnimatedNumberModel } from './animated-number-model.js';
|
|
5
|
+
import { useHIG, useNumberLocale } from './provider.js';
|
|
6
6
|
import { tokens as higTokens } from '@bloxwap/hig/tokens';
|
|
7
7
|
import * as en from '@bloxwap/hig/contracts/messages';
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
import { presentNumberFormat } from '@bloxwap/hig/contracts';
|
|
9
|
+
export function AnimatedNumberReadout({ duration = 180, trend, options: requested, formattedValue, animateFormatted = false, ...rest }) {
|
|
10
|
+
const locale = useNumberLocale();
|
|
11
|
+
const { direction, reducedMotion, messages, numberFormat } = useHIG();
|
|
12
|
+
const props = { ...rest, options: presentNumberFormat(requested, numberFormat) };
|
|
10
13
|
const element = useRef(null);
|
|
11
14
|
const previous = useRef(null);
|
|
12
15
|
const generation = useRef(0);
|
|
13
16
|
const active = useRef([]);
|
|
14
|
-
const
|
|
17
|
+
const known = props.value != null && Number.isFinite(props.value), own = known && !!formattedValue;
|
|
18
|
+
const signature = JSON.stringify([locale, direction, props.options ?? {}, own, own && animateFormatted]);
|
|
15
19
|
const frame = useMemo(() => {
|
|
16
|
-
const model = createAnimatedNumberModel(props.value, locale, props.options), prior = previous.current, changed = !!prior && prior.signature === signature && !Object.is(prior.value, props.value);
|
|
20
|
+
const model = own ? createFormattedAnimatedNumberModel(formattedValue, locale, animateFormatted) : createAnimatedNumberModel(props.value, locale, props.options), prior = previous.current, changed = !!prior && prior.signature === signature && !Object.is(prior.value, props.value);
|
|
17
21
|
let movement = 0;
|
|
18
22
|
if (changed && prior && model.animatable && prior.model.animatable && Number.isFinite(prior.value) && Number.isFinite(props.value)) {
|
|
19
23
|
const requested = typeof trend === 'function' ? trend(prior.value, props.value) : trend ?? Math.sign(props.value - prior.value);
|
|
20
24
|
movement = requested === -1 || requested === 1 ? requested : 0;
|
|
21
25
|
}
|
|
22
26
|
return { model, changed, movement, tokens: createAnimatedNumberTransitions(changed ? prior?.model ?? null : null, model) };
|
|
23
|
-
}, [props.value, signature]);
|
|
27
|
+
}, [props.value, signature, formattedValue]);
|
|
24
28
|
const [settled, setSettled] = useState(null);
|
|
25
|
-
const
|
|
29
|
+
const reading = known ? `${props.prefix ?? ''}${frame.model.reading}${props.suffix ?? ''}` : frame.model.reading, staleText = messages.stale ?? en.stale, accessible = `${props.label ? `${props.label}: ` : ''}${reading}${props.stale ? ` ${staleText}` : ''}`;
|
|
26
30
|
useEffect(() => {
|
|
27
31
|
const id = ++generation.current;
|
|
28
32
|
const cancel = () => { const running = active.current; active.current = []; for (const animation of running) {
|
|
@@ -12,8 +12,24 @@ export interface AssetBalanceRowProps extends Omit<React.HTMLAttributes<HTMLElem
|
|
|
12
12
|
balance?: number | null;
|
|
13
13
|
/** Format of the units line. Defaults to at most six fraction digits. */
|
|
14
14
|
balanceOptions?: Intl.NumberFormatOptions;
|
|
15
|
+
/** Host text after the units figure, such as ` HYPE`. Drawn only when the units are known. */
|
|
16
|
+
unitsSuffix?: string;
|
|
17
|
+
/** `units` puts the units on the headline line in place of the value and draws no second line, for a holding with no dollar value. Defaults to `value`. */
|
|
18
|
+
headline?: 'value' | 'units';
|
|
19
|
+
/** `false` draws no figures at all, for a row that is just an item to pick, such as a method or a chain. Defaults to `true`. */
|
|
20
|
+
amounts?: boolean;
|
|
21
|
+
/** Short muted host text under the figures, such as the ledger a holding sits in. Read after them. */
|
|
22
|
+
tag?: string;
|
|
23
|
+
/** Host content on the trailing edge, after the figures. Inside a pressable row it must not be interactive. It is read in place, last. */
|
|
24
|
+
trailing?: React.ReactNode;
|
|
25
|
+
/** What assistive technology reads for `trailing`, in place of its content, for an icon or a figure whose text is not what should be heard. */
|
|
26
|
+
trailingLabel?: string;
|
|
27
|
+
/** Marks the row in use: a check on the trailing edge, and `aria-current` for assistive technology. */
|
|
28
|
+
selected?: boolean;
|
|
29
|
+
/** Dims the row and ignores presses. */
|
|
30
|
+
disabled?: boolean;
|
|
15
31
|
/** Makes the whole row a button. */
|
|
16
32
|
onSelect?: () => void;
|
|
17
33
|
}
|
|
18
34
|
/** One holding in a list: round artwork, the asset's name over its symbol, and its dollar value over its units. Both numbers update place by place. */
|
|
19
|
-
export declare function AssetBalanceRow({ name, symbol, icon, value, balance, balanceOptions, onSelect, className, ...rest }: AssetBalanceRowProps): React.JSX.Element;
|
|
35
|
+
export declare function AssetBalanceRow({ name, symbol, icon, value, balance, balanceOptions, unitsSuffix, headline, amounts, tag, trailing, trailingLabel, selected, disabled, onSelect, className, ...rest }: AssetBalanceRowProps): React.JSX.Element;
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { AnimatedNumberReadout } from './animated-number.js';
|
|
4
|
+
import { PressDecoration } from './provider.js';
|
|
4
5
|
const usd = { style: 'currency', currency: 'USD' }, units = { maximumFractionDigits: 6 };
|
|
6
|
+
const check = _jsx("svg", { className: 'hig-asset-row-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' }) });
|
|
5
7
|
/** One holding in a list: round artwork, the asset's name over its symbol, and its dollar value over its units. Both numbers update place by place. */
|
|
6
|
-
export function AssetBalanceRow({ name, symbol, icon, value, balance, balanceOptions = units, onSelect, className, ...rest }) {
|
|
7
|
-
const
|
|
8
|
+
export function AssetBalanceRow({ name, symbol, icon, value, balance, balanceOptions = units, unitsSuffix, headline = 'value', amounts = true, tag, trailing, trailingLabel, selected, disabled, onSelect, className, ...rest }) {
|
|
9
|
+
const unitsFirst = headline === 'units';
|
|
10
|
+
const figures = amounts && _jsxs(_Fragment, { children: [_jsx("strong", { children: unitsFirst ? _jsx(AnimatedNumberReadout, { value: balance, options: balanceOptions, suffix: unitsSuffix }) : _jsx(AnimatedNumberReadout, { value: value, options: usd }) }), !unitsFirst && balance !== undefined && _jsx("span", { children: _jsx(AnimatedNumberReadout, { value: balance, options: balanceOptions, suffix: unitsSuffix }) })] });
|
|
11
|
+
const content = _jsxs(_Fragment, { children: [_jsx("span", { className: 'hig-asset-row-icon', "aria-hidden": 'true', children: typeof icon === 'string' ? _jsx("img", { src: icon, alt: '' }) : icon ?? symbol.slice(0, 3) }), _jsxs("span", { className: 'hig-asset-row-identity', children: [_jsx("strong", { children: name }), _jsx("span", { children: symbol })] }), (amounts || tag) && _jsxs("span", { className: 'hig-asset-row-amounts', children: [figures, tag && _jsx("small", { className: 'hig-asset-row-tag', children: tag })] }), trailing != null && trailing !== false && _jsx("span", { className: 'hig-asset-row-trailing', "aria-hidden": trailingLabel !== undefined || undefined, children: trailing }), trailingLabel !== undefined && trailing != null && trailing !== false && _jsx("span", { className: 'hig-sr-only hig-asset-row-trailing-label', children: trailingLabel }), selected && check] });
|
|
8
12
|
const classes = `hig-asset-row${className ? ` ${className}` : ''}`;
|
|
9
|
-
|
|
13
|
+
const state = { 'aria-current': selected ? 'true' : undefined, 'data-selected': selected || undefined };
|
|
14
|
+
return onSelect
|
|
15
|
+
? _jsxs("button", { type: 'button', ...rest, ...state, className: classes, disabled: disabled, onClick: onSelect, children: [content, _jsx(PressDecoration, { kind: 'row', disabled: disabled })] })
|
|
16
|
+
// A static row is a generic div, where aria-disabled is not read; disabled, it becomes a group, which carries the state.
|
|
17
|
+
: _jsx("div", { role: disabled ? 'group' : undefined, ...rest, ...state, "aria-disabled": disabled || undefined, className: classes, children: content });
|
|
10
18
|
}
|
package/react/dist/bar-mark.d.ts
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { type Figure } from './figure.js';
|
|
2
3
|
/** Colour roles a segment can take. They follow the token palette (and a host's market colours) like any other role. */
|
|
3
4
|
export type BarMarkTone = 'positive' | 'info' | 'warning' | 'negative' | 'muted' | 'faint';
|
|
4
5
|
/** The order segments take tones in when they name neither a `tone` nor a `color`. */
|
|
5
6
|
export declare const barMarkTones: readonly BarMarkTone[];
|
|
6
|
-
/**
|
|
7
|
+
/** A legend amount that can change while the bar is shown: formatted with `options` between `prefix` and `suffix`, and updated place by place. `null` reads as unknown. */
|
|
8
|
+
export type BarMarkFigure = Figure;
|
|
9
|
+
/** One part of the bar. `value` is in the host's own unit; only its share of the whole is drawn. `detail` is shown after the label: host-formatted text, such as `12.4 GB`, or a live figure. `color` is a host hex for a category outside the tone roles. */
|
|
7
10
|
export interface BarMarkElement {
|
|
8
11
|
id?: string;
|
|
9
12
|
label: string;
|
|
10
13
|
value: number;
|
|
11
14
|
tone?: BarMarkTone;
|
|
12
15
|
color?: string;
|
|
13
|
-
detail?: string;
|
|
16
|
+
detail?: string | BarMarkFigure;
|
|
14
17
|
}
|
|
15
18
|
export interface BarMarkProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
|
|
16
19
|
title: string;
|
package/react/dist/bar-mark.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useId } from 'react';
|
|
4
4
|
import { formatNumber } from '@bloxwap/hig/contracts';
|
|
5
|
-
import {
|
|
5
|
+
import { useNumberLocale } from './provider.js';
|
|
6
|
+
import { AnimatedNumberReadout } from './animated-number.js';
|
|
7
|
+
import { figureProps } from './figure.js';
|
|
6
8
|
/** The order segments take tones in when they name neither a `tone` nor a `color`. */
|
|
7
9
|
export const barMarkTones = ['positive', 'info', 'warning', 'negative', 'muted', 'faint'];
|
|
8
10
|
const amount = (value) => Number.isFinite(value) && value > 0 ? value : 0;
|
|
@@ -13,9 +15,9 @@ export function barMarkShares(elements, total) {
|
|
|
13
15
|
}
|
|
14
16
|
/** A one-dimensional stacked bar: a titled card whose single bar is divided among its elements, with a legend naming each part. */
|
|
15
17
|
export function BarMark({ title, description, elements, total, legend = true, size = 'default', surface = true, className, ...rest }) {
|
|
16
|
-
const
|
|
18
|
+
const locale = useNumberLocale();
|
|
17
19
|
const id = useId();
|
|
18
20
|
const { shares, rest: remainder } = barMarkShares(elements, total);
|
|
19
21
|
const paint = (element, index) => element.color ? { style: { '--hig-bar-mark-color': element.color } } : { 'data-tone': element.tone ?? barMarkTones[index % barMarkTones.length] };
|
|
20
|
-
return _jsxs("section", { ...rest, className: `${surface ? 'hig-surface ' : ''}hig-bar-mark${className ? ` ${className}` : ''}`, "data-surface": surface ? undefined : 'false', "data-size": size === 'small' ? size : undefined, "aria-labelledby": id, children: [_jsxs("div", { className: 'hig-bar-mark-header', children: [_jsx("strong", { id: id, className: 'hig-bar-mark-title', children: title }), description != null && _jsx("span", { className: 'hig-bar-mark-description', children: description })] }), _jsxs("div", { className: 'hig-bar-mark-bar', "aria-hidden": 'true', children: [elements.map((element, index) => shares[index] > 0 && _jsx("span", { className: 'hig-bar-mark-segment', ...paint(element, index), style: { ...paint(element, index).style, flexGrow: shares[index] } }, element.id ?? index)), remainder > 0 && _jsx("span", { className: 'hig-bar-mark-rest', style: { flexGrow: remainder } })] }), _jsx("ul", { className: legend ? 'hig-bar-mark-legend' : 'hig-sr-only', children: elements.map((element, index) => _jsxs("li", { children: [_jsx("span", { className: 'hig-bar-mark-dot', "aria-hidden": 'true', ...paint(element, index) }), _jsx("span", { children: element.label }), element.detail && _jsx("span", { className: 'hig-bar-mark-detail', children: element.detail }), _jsx("span", { className: 'hig-sr-only', children: formatNumber(shares[index], locale, { style: 'percent', maximumFractionDigits: 1 }) })] }, element.id ?? index)) })] });
|
|
22
|
+
return _jsxs("section", { ...rest, className: `${surface ? 'hig-surface ' : ''}hig-bar-mark${className ? ` ${className}` : ''}`, "data-surface": surface ? undefined : 'false', "data-size": size === 'small' ? size : undefined, "aria-labelledby": id, children: [_jsxs("div", { className: 'hig-bar-mark-header', children: [_jsx("strong", { id: id, className: 'hig-bar-mark-title', children: title }), description != null && _jsx("span", { className: 'hig-bar-mark-description', children: description })] }), _jsxs("div", { className: 'hig-bar-mark-bar', "aria-hidden": 'true', children: [elements.map((element, index) => shares[index] > 0 && _jsx("span", { className: 'hig-bar-mark-segment', ...paint(element, index), style: { ...paint(element, index).style, flexGrow: shares[index] } }, element.id ?? index)), remainder > 0 && _jsx("span", { className: 'hig-bar-mark-rest', style: { flexGrow: remainder } })] }), _jsx("ul", { className: legend ? 'hig-bar-mark-legend' : 'hig-sr-only', children: elements.map((element, index) => _jsxs("li", { children: [_jsx("span", { className: 'hig-bar-mark-dot', "aria-hidden": 'true', ...paint(element, index) }), _jsx("span", { children: element.label }), element.detail && _jsx("span", { className: 'hig-bar-mark-detail', children: typeof element.detail === 'string' ? element.detail : _jsx(AnimatedNumberReadout, { ...figureProps(element.detail) }) }), _jsx("span", { className: 'hig-sr-only', children: formatNumber(shares[index], locale, { style: 'percent', maximumFractionDigits: 1 }) })] }, element.id ?? index)) })] });
|
|
21
23
|
}
|
|
@@ -13,6 +13,38 @@ export interface AccountAsset {
|
|
|
13
13
|
price?: number | null;
|
|
14
14
|
/** Dollar value of the holding. Defaults to `balance × price`. */
|
|
15
15
|
value?: number | null;
|
|
16
|
+
/** Set false to draw no units line, for a holding whose units are the same figure as its value. */
|
|
17
|
+
units?: boolean;
|
|
18
|
+
/** Set false to draw this row plain even when the block has `onAssetSelect`. */
|
|
19
|
+
selectable?: boolean;
|
|
20
|
+
/** Format of the units figure. Defaults to at most six fraction digits. */
|
|
21
|
+
unitsOptions?: Intl.NumberFormatOptions;
|
|
22
|
+
/** Host text after the units figure, such as ` PAPER`. */
|
|
23
|
+
unitsSuffix?: string;
|
|
24
|
+
/** Short muted host text under the figures, such as the ledger the holding sits in (Perp, Spot, Staked). */
|
|
25
|
+
tag?: string;
|
|
26
|
+
/** When the value is unknown but the balance is known: `units` (the default) headlines the units; `dash` shows the unknown dash over the units, for a value that is still loading. */
|
|
27
|
+
unknownValue?: 'units' | 'dash';
|
|
28
|
+
}
|
|
29
|
+
/** Row order after the pinned asset: `value` (largest first, the default) or `given` (the order the host passed). */
|
|
30
|
+
export type AccountOrder = 'value' | 'given';
|
|
31
|
+
/** How `accountRows` picks and orders: `order` after the pinned asset, and `pinnedId`, an asset id pinned in place of the symbol match. */
|
|
32
|
+
export interface AccountRowsOptions {
|
|
33
|
+
order?: AccountOrder;
|
|
34
|
+
pinnedId?: string;
|
|
35
|
+
}
|
|
36
|
+
/** A titled group of holdings with its own total, such as one ledger of the account. */
|
|
37
|
+
export interface AccountSection {
|
|
38
|
+
id: string;
|
|
39
|
+
/** Heading over the group. */
|
|
40
|
+
title: string;
|
|
41
|
+
/** The group's total in dollars, on the trailing edge of its heading. Defaults to the sum of its asset values; `null` reads as unknown. */
|
|
42
|
+
total?: number | null;
|
|
43
|
+
assets: readonly AccountAsset[];
|
|
44
|
+
/** Row order in this group; defaults to the block's `order`. */
|
|
45
|
+
order?: AccountOrder;
|
|
46
|
+
/** Id of the asset that leads this group; defaults to the block's `pinnedId`, then the `pinnedSymbol` match. */
|
|
47
|
+
pinnedId?: string;
|
|
16
48
|
}
|
|
17
49
|
export interface AccountBlockProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
|
|
18
50
|
/** Heading. Defaults to the built-in “Account”. */
|
|
@@ -23,24 +55,38 @@ export interface AccountBlockProps extends Omit<React.HTMLAttributes<HTMLElement
|
|
|
23
55
|
onShowAddress?: () => void;
|
|
24
56
|
/** A control on the trailing edge of the header, usually an `IconButton`. Replaces the QR button. */
|
|
25
57
|
headerAction?: React.ReactNode;
|
|
26
|
-
/** Total in dollars. Defaults to the sum of the asset values; `null` reads as unknown. */
|
|
58
|
+
/** Total in dollars. Defaults to the sum of the asset values (with `sections`, the sum of the totals of the sections that are drawn, which is unknown when any of those totals is); `null` reads as unknown. */
|
|
27
59
|
balance?: number | null;
|
|
28
|
-
|
|
60
|
+
/** Every holding as one list: the pinned asset, then the rest by value. Ignored when `sections` is set. */
|
|
61
|
+
assets?: readonly AccountAsset[];
|
|
62
|
+
/** Titled groups, each with its own total, drawn in the order given in place of the flat `assets` list. */
|
|
63
|
+
sections?: readonly AccountSection[];
|
|
29
64
|
/** Symbol of the asset that is always first. Defaults to `USDC`. */
|
|
30
65
|
pinnedSymbol?: string;
|
|
66
|
+
/** Id of the asset that is always first, in place of the `pinnedSymbol` match, for a holding whose symbol is not unique. */
|
|
67
|
+
pinnedId?: string;
|
|
68
|
+
/** Order of the rows after the pinned one: `value` (largest first, the default) or `given` (the order passed). */
|
|
69
|
+
order?: AccountOrder;
|
|
31
70
|
/** Shows the deposit action beside the total. */
|
|
32
71
|
onDeposit?: () => void;
|
|
33
72
|
/** Text of the deposit action. Defaults to the built-in “Deposit”. */
|
|
34
73
|
depositLabel?: string;
|
|
35
|
-
/** Makes each row a button that reports its asset. */
|
|
36
|
-
onAssetSelect?: (asset: AccountAsset) => void;
|
|
74
|
+
/** Makes each row a button that reports its asset, and with `sections` the section it is in. */
|
|
75
|
+
onAssetSelect?: (asset: AccountAsset, section?: AccountSection) => void;
|
|
37
76
|
}
|
|
38
77
|
/** Dollar value of a holding: its `value`, or `balance × price` when both are known. */
|
|
39
78
|
export declare const assetValue: (asset: AccountAsset) => number | null;
|
|
40
|
-
/** The account's rows in display order: the pinned asset (
|
|
41
|
-
export declare function accountRows(assets: readonly AccountAsset[], pinnedSymbol?: string): {
|
|
79
|
+
/** The account's rows in display order: the pinned asset (the one with `options.pinnedId`, else the first with `pinnedSymbol`, else a zero placeholder), then every other asset by dollar value, largest first, unknown values last and ties by name, or with `options.order` `given` in the order passed. */
|
|
80
|
+
export declare function accountRows(assets: readonly AccountAsset[], pinnedSymbol?: string, options?: AccountRowsOptions): {
|
|
42
81
|
pinned: AccountAsset;
|
|
43
82
|
rest: AccountAsset[];
|
|
44
83
|
};
|
|
84
|
+
/** A section's total: its own `total`, or the sum of its asset values. */
|
|
85
|
+
export declare const accountSectionTotal: (section: AccountSection) => number | null;
|
|
86
|
+
/** A section's rows in display order: the pinned asset first when the section holds it (no placeholder), then the rest by dollar value as in `accountRows`. */
|
|
87
|
+
export declare function accountSectionRows(assets: readonly AccountAsset[], pinnedSymbol?: string, options?: AccountRowsOptions): {
|
|
88
|
+
pinned: AccountAsset | null;
|
|
89
|
+
rest: AccountAsset[];
|
|
90
|
+
};
|
|
45
91
|
/** 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;
|
|
92
|
+
export declare function AccountBlock({ title, onBack, onShowAddress, headerAction, balance, assets, sections, pinnedSymbol, pinnedId, order, onDeposit, depositLabel, onAssetSelect, className, ...rest }: AccountBlockProps): React.JSX.Element;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useId } from 'react';
|
|
3
4
|
import * as en from '@bloxwap/hig/contracts/messages';
|
|
4
|
-
import { useHIG } from '../provider.js';
|
|
5
|
+
import { PressDecoration, useHIG } from '../provider.js';
|
|
5
6
|
import { Button } from '../button.js';
|
|
6
7
|
import { AnimatedNumberReadout } from '../animated-number.js';
|
|
7
8
|
import { AssetBalanceRow } from '../asset-balance-row.js';
|
|
@@ -10,18 +11,52 @@ export { AssetBalanceRow } from '../asset-balance-row.js';
|
|
|
10
11
|
const usdCoin = 'USD Coin', usd = { style: 'currency', currency: 'USD' };
|
|
11
12
|
/** Dollar value of a holding: its `value`, or `balance × price` when both are known. */
|
|
12
13
|
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 (
|
|
14
|
-
export function accountRows(assets, pinnedSymbol = 'USDC') {
|
|
15
|
-
const
|
|
14
|
+
/** The account's rows in display order: the pinned asset (the one with `options.pinnedId`, else the first with `pinnedSymbol`, else a zero placeholder), then every other asset by dollar value, largest first, unknown values last and ties by name, or with `options.order` `given` in the order passed. */
|
|
15
|
+
export function accountRows(assets, pinnedSymbol = 'USDC', options = {}) {
|
|
16
|
+
const byId = options.pinnedId === undefined ? -1 : assets.findIndex(asset => asset.id === options.pinnedId);
|
|
17
|
+
const index = byId >= 0 ? byId : assets.findIndex(asset => asset.symbol.toUpperCase() === pinnedSymbol.toUpperCase());
|
|
16
18
|
const pinned = index >= 0 ? assets[index] : { id: pinnedSymbol, name: pinnedSymbol === 'USDC' ? usdCoin : pinnedSymbol, symbol: pinnedSymbol, balance: 0, value: 0 };
|
|
17
|
-
const
|
|
19
|
+
const others = assets.filter((_, position) => position !== index);
|
|
20
|
+
const rest = options.order === 'given' ? others : others.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
21
|
return { pinned, rest };
|
|
19
22
|
}
|
|
23
|
+
const sum = (assets) => assets.reduce((total, asset) => total + (assetValue(asset) ?? 0), 0);
|
|
24
|
+
/** A section's total: its own `total`, or the sum of its asset values. */
|
|
25
|
+
export const accountSectionTotal = (section) => section.total !== undefined ? section.total : sum(section.assets);
|
|
26
|
+
/** The block total for `sections`: the sum of the section totals, or unknown (`null`) when any of them is unknown. Pass only the sections that are drawn. */
|
|
27
|
+
const accountSectionsTotal = (sections) => { let all = 0; for (const section of sections) {
|
|
28
|
+
const total = accountSectionTotal(section);
|
|
29
|
+
if (total === null)
|
|
30
|
+
return null;
|
|
31
|
+
all += total;
|
|
32
|
+
} return all; };
|
|
33
|
+
/** A section's rows in display order: the pinned asset first when the section holds it (no placeholder), then the rest by dollar value as in `accountRows`. */
|
|
34
|
+
export function accountSectionRows(assets, pinnedSymbol = 'USDC', options = {}) {
|
|
35
|
+
const { pinned, rest } = accountRows(assets, pinnedSymbol, options);
|
|
36
|
+
return { pinned: assets.includes(pinned) ? pinned : null, rest };
|
|
37
|
+
}
|
|
20
38
|
/** 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 }) {
|
|
39
|
+
export function AccountBlock({ title, onBack, onShowAddress, headerAction, balance, assets = [], sections, pinnedSymbol = 'USDC', pinnedId, order, onDeposit, depositLabel, onAssetSelect, className, ...rest }) {
|
|
22
40
|
const { messages } = useHIG();
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
|
|
41
|
+
const id = useId();
|
|
42
|
+
const shown = sections?.filter(section => section.assets.length > 0);
|
|
43
|
+
const total = balance !== undefined ? balance : shown ? accountSectionsTotal(shown) : sum(assets);
|
|
44
|
+
const row = (asset, pin, pinId, section) => {
|
|
45
|
+
// A row pinned by symbol is the dollar balance, so its units would repeat its value; a row pinned by id keeps its own units setting.
|
|
46
|
+
const value = assetValue(asset), units = (!pin || asset.id === pinId) && asset.units !== false;
|
|
47
|
+
const select = onAssetSelect && asset.selectable !== false ? (section ? () => onAssetSelect(asset, section) : () => onAssetSelect(asset)) : undefined;
|
|
48
|
+
return _jsx("li", { "data-pinned": pin || undefined, children: _jsx(AssetBalanceRow, { name: asset.name, symbol: asset.symbol, icon: asset.icon, value: value, balance: units ? asset.balance ?? null : undefined, balanceOptions: asset.unitsOptions, unitsSuffix: asset.unitsSuffix, tag: asset.tag, headline: units && value === null && asset.balance != null && asset.unknownValue !== 'dash' ? 'units' : undefined, onSelect: select }) }, asset.id);
|
|
49
|
+
};
|
|
50
|
+
let list;
|
|
51
|
+
if (shown)
|
|
52
|
+
list = _jsx("div", { className: 'hig-account-sections', children: shown.map((section, index) => {
|
|
53
|
+
const pinId = section.pinnedId ?? pinnedId;
|
|
54
|
+
const { pinned, rest: others } = accountSectionRows(section.assets, pinnedSymbol, { order: section.order ?? order, pinnedId: pinId }), heading = `${id}-section-${index}`;
|
|
55
|
+
return _jsxs("section", { className: 'hig-account-section', "aria-labelledby": heading, children: [_jsxs("div", { className: 'hig-account-section-header', children: [_jsx("h3", { id: heading, children: section.title }), _jsx("span", { className: 'hig-account-section-total', children: _jsx(AnimatedNumberReadout, { value: accountSectionTotal(section), options: usd }) })] }), _jsxs("ul", { className: 'hig-account-assets', children: [pinned && row(pinned, true, pinId, section), others.map(asset => row(asset, false, pinId, section))] })] }, section.id);
|
|
56
|
+
}) });
|
|
57
|
+
else {
|
|
58
|
+
const { pinned, rest: others } = accountRows(assets, pinnedSymbol, { order, pinnedId });
|
|
59
|
+
list = _jsxs("ul", { className: 'hig-account-assets', children: [row(pinned, true, pinnedId), others.map(asset => row(asset, false, pinnedId))] });
|
|
60
|
+
}
|
|
61
|
+
return _jsxs("section", { ...rest, className: `hig-account-block${className ? ` ${className}` : ''}`, children: [_jsx(ScreenHeader, { title: title ?? messages.account ?? en.account, onBack: onBack, action: headerAction ?? (onShowAddress && _jsxs("button", { type: 'button', className: 'hig-swap-back hig-account-address', "aria-label": messages.showAddress ?? en.showAddress, onClick: onShowAddress, children: [qrIcon, _jsx(PressDecoration, { kind: 'back' })] })) }), _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 })] }), list] });
|
|
27
62
|
}
|
|
@@ -21,6 +21,10 @@ export interface LanguageBlockProps extends Omit<React.HTMLAttributes<HTMLElemen
|
|
|
21
21
|
/** `code` of the language in use. */
|
|
22
22
|
value?: string | null;
|
|
23
23
|
onSelect: (language: LanguageOption) => void;
|
|
24
|
+
/** Dims the rows and ignores presses, for example while a change is being applied. */
|
|
25
|
+
disabled?: boolean;
|
|
26
|
+
/** A muted line under the header that explains the screen: Choose the language used throughout the app. */
|
|
27
|
+
description?: string;
|
|
24
28
|
/** Set false to leave out the search field, for a short list. Default `true`. */
|
|
25
29
|
search?: boolean;
|
|
26
30
|
/** With a hardware pointer, focus the search field on mount so typing filters at once. */
|
|
@@ -29,4 +33,4 @@ export interface LanguageBlockProps extends Omit<React.HTMLAttributes<HTMLElemen
|
|
|
29
33
|
/** 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
34
|
export declare function filterLanguages(languages: readonly LanguageOption[], query: string): LanguageOption[];
|
|
31
35
|
/** 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;
|
|
36
|
+
export declare function LanguageBlock({ title, onBack, headerAction, languages, value, onSelect, search, autoFocus, disabled, description, className, ...rest }: LanguageBlockProps): React.JSX.Element;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
4
4
|
import * as en from '@bloxwap/hig/contracts/messages';
|
|
5
|
-
import { useHIG } from '../provider.js';
|
|
5
|
+
import { PressDecoration, useHIG } from '../provider.js';
|
|
6
6
|
import { SearchInput } from '../field.js';
|
|
7
7
|
import { ScreenHeader } from './screen-header.js';
|
|
8
8
|
const fold = (text) => text.normalize('NFD').replace(/[̀-ͯ]/g, '').toLowerCase();
|
|
@@ -13,7 +13,7 @@ export function filterLanguages(languages, query) {
|
|
|
13
13
|
}
|
|
14
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
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 }) {
|
|
16
|
+
export function LanguageBlock({ title, onBack, headerAction, languages, value = null, onSelect, search = true, autoFocus, disabled, description, className, ...rest }) {
|
|
17
17
|
const { messages } = useHIG();
|
|
18
18
|
const heading = title ?? messages.language ?? en.language;
|
|
19
19
|
const [query, setQuery] = useState('');
|
|
@@ -39,13 +39,14 @@ export function LanguageBlock({ title, onBack, headerAction, languages, value =
|
|
|
39
39
|
const choice = rows[active] ?? (rows.length === 1 ? rows[0] : undefined);
|
|
40
40
|
if (choice) {
|
|
41
41
|
event.preventDefault();
|
|
42
|
-
|
|
42
|
+
if (!disabled)
|
|
43
|
+
onSelect(choice);
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
};
|
|
46
47
|
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
|
+
return _jsxs("section", { ...rest, className: `hig-language-block${className ? ` ${className}` : ''}`, children: [_jsx(ScreenHeader, { title: heading, onBack: onBack, action: headerAction }), description && _jsx("p", { className: 'hig-settings-description', children: description }), 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, "aria-disabled": disabled || undefined, children: rows.map((language, index) => {
|
|
48
49
|
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
|
+
return _jsxs("button", { type: 'button', role: 'radio', "aria-checked": selected, lang: language.code, className: 'hig-language-row', "data-active": index === active || undefined, disabled: disabled, 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, _jsx(PressDecoration, { kind: 'row', disabled: !!disabled })] }, language.code);
|
|
50
51
|
}) })] });
|
|
51
52
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { type Figure } from '../figure.js';
|
|
2
3
|
import type { AssetArtwork } from '../asset-balance-row.js';
|
|
3
4
|
/** The words of the block. They are trading terms, so the host supplies them in its own vocabulary and language; HIG ships none. */
|
|
4
5
|
export interface ManagePositionBlockLabels {
|
|
@@ -14,16 +15,37 @@ export interface ManagePositionBlockLabels {
|
|
|
14
15
|
long: string;
|
|
15
16
|
short: string;
|
|
16
17
|
}
|
|
18
|
+
/** A number the host supplies as a number so it updates place by place: `{value:66000,options:{style:'currency',currency:'USD'}}`. `null` reads as unknown. */
|
|
19
|
+
export type ManagePositionBlockFigure = Figure;
|
|
20
|
+
/** The position's artwork: an image URL, a host element, or a function that draws a host element and receives `failed`, to call when that element cannot draw (an SVG that did not load); the row then shows `iconFallback` or the initials. */
|
|
21
|
+
export type ManagePositionIcon = AssetArtwork | ((failed: () => void) => React.ReactNode);
|
|
17
22
|
export interface ManagePositionBlockAction {
|
|
18
23
|
id: string;
|
|
19
24
|
label: string;
|
|
20
25
|
onSelect: () => void;
|
|
21
26
|
disabled?: boolean;
|
|
27
|
+
/** Trailing value of the row, before the chevron: host text or a live figure, such as the price a resting trigger is set at. */
|
|
28
|
+
value?: string | ManagePositionBlockFigure;
|
|
29
|
+
/** Colours `value`. The default is the muted value colour. */
|
|
30
|
+
tone?: 'positive' | 'negative' | 'muted';
|
|
22
31
|
}
|
|
23
32
|
/** The position being managed, shown as the row under the actions. */
|
|
24
33
|
export interface ManagePositionBlockSummary {
|
|
25
34
|
name: string;
|
|
26
|
-
|
|
35
|
+
/** An image URL, a host element, or a function that draws one and reports its failure. An image or element that fails shows `iconFallback`, else the initials. */
|
|
36
|
+
icon?: ManagePositionIcon;
|
|
37
|
+
/** A host element drawn in place of an `icon` that failed to draw. Without it the row shows the initials. */
|
|
38
|
+
iconFallback?: React.ReactNode;
|
|
39
|
+
/** Short ticker for the initials when there is no artwork: BTC. Without it the first letters of the name are shown. */
|
|
40
|
+
symbol?: string;
|
|
41
|
+
/** Host text after the name, drawn as a small `Badge`, such as a venue. */
|
|
42
|
+
badge?: string;
|
|
43
|
+
/** One line under the row, such as that the profit and loss is stale or estimated. */
|
|
44
|
+
caption?: string;
|
|
45
|
+
/** Makes the whole row a button, for example one that opens the market. Needs `label`. */
|
|
46
|
+
onSelect?: () => void;
|
|
47
|
+
/** Accessible name of the row when it is a button, read before what the row shows: View Bitcoin. The caption is its description. */
|
|
48
|
+
label?: string;
|
|
27
49
|
/** 40 reads `40×`. */
|
|
28
50
|
leverage?: number;
|
|
29
51
|
/** Size in asset units. */
|
|
@@ -47,9 +69,13 @@ export interface ManagePositionBlockProps extends Omit<React.HTMLAttributes<HTML
|
|
|
47
69
|
priceOptions?: Intl.NumberFormatOptions;
|
|
48
70
|
actions: readonly ManagePositionBlockAction[];
|
|
49
71
|
position?: ManagePositionBlockSummary;
|
|
72
|
+
/** Format of the position's profit and loss, merged over the default: signed US dollars with up to four decimals. */
|
|
73
|
+
pnlOptions?: Intl.NumberFormatOptions;
|
|
50
74
|
onBack?: () => void;
|
|
51
75
|
/** A control on the trailing edge of the header, usually an `IconButton`. */
|
|
52
76
|
headerAction?: React.ReactNode;
|
|
77
|
+
/** `id` of the heading, so a dialog or sheet can name itself with `aria-labelledby`. */
|
|
78
|
+
headingId?: string;
|
|
53
79
|
}
|
|
54
80
|
/** 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
81
|
export declare function positionCorridor({ side, entry, mark, liquidation }: {
|
|
@@ -64,4 +90,4 @@ export declare function positionCorridor({ side, entry, mark, liquidation }: {
|
|
|
64
90
|
share: number | null;
|
|
65
91
|
};
|
|
66
92
|
/** 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;
|
|
93
|
+
export declare function ManagePositionBlock({ labels, mode, side, entry, mark, liquidation, margin, notional, priceOptions, actions, position, pnlOptions, onBack, headerAction, headingId, className, ...rest }: ManagePositionBlockProps): React.JSX.Element;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useId, useState } from 'react';
|
|
3
4
|
import { formatNumber } from '@bloxwap/hig/contracts';
|
|
4
|
-
import {
|
|
5
|
+
import { PressDecoration, usePresentNumber, useNumberLocale } from '../provider.js';
|
|
6
|
+
import { figureProps } from '../figure.js';
|
|
7
|
+
import { Badge } from '../status.js';
|
|
5
8
|
import { AnimatedNumberReadout } from '../animated-number.js';
|
|
6
9
|
import { BarMark } from '../bar-mark.js';
|
|
7
10
|
import { BarPnl } from '../bar-pnl.js';
|
|
@@ -19,10 +22,26 @@ export function positionCorridor({ side, entry, mark, liquidation }) {
|
|
|
19
22
|
const traveled = side === 'long' ? entry - mark : mark - entry, buffer = Math.max(0, Math.min(span, span - traveled));
|
|
20
23
|
return { total: span, buffer, drawdown: span - buffer, share: buffer / span };
|
|
21
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
|
+
}
|
|
22
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. */
|
|
23
|
-
export function ManagePositionBlock({ labels, mode, side, entry, mark, liquidation, margin, notional, priceOptions, actions, position, onBack, headerAction, className, ...rest }) {
|
|
24
|
-
const
|
|
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();
|
|
25
37
|
const corridor = positionCorridor({ side, entry, mark, liquidation });
|
|
26
38
|
const pnlTone = !known(position?.pnl) || position.pnl === 0 ? undefined : position.pnl > 0 ? 'up' : 'down';
|
|
27
|
-
|
|
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 })] });
|
|
28
47
|
}
|
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
interface MarketRowContent {
|
|
2
|
+
interface MarketRowContent extends Omit<React.HTMLAttributes<HTMLDivElement>, 'children' | 'onSelect'> {
|
|
3
3
|
symbol: string;
|
|
4
4
|
name: string;
|
|
5
|
-
price
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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;
|
|
10
12
|
favorite?: React.ReactNode;
|
|
11
13
|
volume?: React.ReactNode;
|
|
12
|
-
|
|
13
|
-
|
|
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;
|
|
14
24
|
}
|
|
15
25
|
export type MarketRowProps = MarketRowContent & ({
|
|
16
26
|
mode?: 'action';
|
|
@@ -21,5 +31,6 @@ export type MarketRowProps = MarketRowContent & ({
|
|
|
21
31
|
onSelect?: never; /** Host market identity, such as symbol/name with its existing compact layout. */
|
|
22
32
|
identity?: React.ReactNode;
|
|
23
33
|
});
|
|
24
|
-
|
|
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>>;
|
|
25
36
|
export {};
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef } from 'react';
|
|
3
4
|
import { Button } from '../button.js';
|
|
4
5
|
import { Usd, Percent } from '../data.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
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
|
+
});
|