@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,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
|
export type { AssetArtwork } from './asset-balance-row.js';
|
|
4
5
|
/** Every trading word of the block. HIG's built-in strings hold no trading terms, so the host supplies them, translated. */
|
|
@@ -15,15 +16,36 @@ export interface ManagePositionBlockLabels {
|
|
|
15
16
|
long: string;
|
|
16
17
|
short: string;
|
|
17
18
|
}
|
|
19
|
+
/** 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. */
|
|
20
|
+
export type ManagePositionBlockFigure = Figure;
|
|
21
|
+
/** 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. */
|
|
22
|
+
export type ManagePositionIcon = AssetArtwork | ((failed: () => void) => React.ReactNode);
|
|
18
23
|
export interface ManagePositionBlockAction {
|
|
19
24
|
id: string;
|
|
20
25
|
label: string;
|
|
21
26
|
onSelect: () => void;
|
|
22
27
|
disabled?: boolean;
|
|
28
|
+
/** Trailing value of the row, before the chevron: host text or a live figure, such as the price a resting trigger is set at. */
|
|
29
|
+
value?: string | ManagePositionBlockFigure;
|
|
30
|
+
/** Colours `value`. The default is the muted value colour. */
|
|
31
|
+
tone?: 'positive' | 'negative' | 'muted';
|
|
23
32
|
}
|
|
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 the figures, which stay in the label: View Bitcoin. The caption is its hint. */
|
|
48
|
+
label?: string;
|
|
27
49
|
/** 40 reads `40×`. */
|
|
28
50
|
leverage?: number;
|
|
29
51
|
/** Size in asset units. */
|
|
@@ -47,10 +69,14 @@ export interface ManagePositionBlockProps {
|
|
|
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
|
/** Shows Back on the leading edge of the header. */
|
|
51
75
|
onBack?: () => void;
|
|
52
76
|
/** A control on the trailing edge of the header, usually an IconButton. */
|
|
53
77
|
headerAction?: React.ReactNode;
|
|
78
|
+
/** Sets `nativeID` on the title, so a sheet around the pane can name itself with `accessibilityLabelledBy` (Android). */
|
|
79
|
+
headingId?: string;
|
|
54
80
|
testID?: string;
|
|
55
81
|
}
|
|
56
82
|
/** Distance left before liquidation. `total` is the span from entry to liquidation, `buffer` how much of it remains between mark and liquidation (the whole span while in profit), `drawdown` the rest, and `share` the buffer as a fraction of the span. Unknown mark or liquidation, or a liquidation on the wrong side of entry, gives zeros and a `null` share. */
|
|
@@ -66,4 +92,4 @@ export declare function positionCorridor({ side, entry, mark, liquidation }: {
|
|
|
66
92
|
share: number | null;
|
|
67
93
|
};
|
|
68
94
|
/** One open position as a screen: margin and notional under the share left before liquidation, then the liquidation, mark and entry prices as a `BarPnl`, what can be done, and the position itself. Both bars are drawn without a card, because nothing in them can be pressed. */
|
|
69
|
-
export declare function ManagePositionBlock({ labels, mode, side, entry, mark, liquidation, margin, notional, priceOptions, actions, position, onBack, headerAction, testID }: ManagePositionBlockProps): React.JSX.Element;
|
|
95
|
+
export declare function ManagePositionBlock({ labels, mode, side, entry, mark, liquidation, margin, notional, priceOptions, actions, position, pnlOptions, onBack, headerAction, headingId, testID }: ManagePositionBlockProps): React.JSX.Element;
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { Image, Pressable, View } from 'react-native';
|
|
4
|
+
import { useColors, useFills, useHIG, useMessages, useNumberLocale, usePresentNumber } from './provider.js';
|
|
4
5
|
import { Text } from './surface.js';
|
|
5
6
|
import { IconButton } from './button.js';
|
|
6
7
|
import { ChevronIcon } from './icons.js';
|
|
7
8
|
import { AnimatedNumberReadout } from './animated-number.js';
|
|
9
|
+
import { figureProps, figureReading } from './figure.js';
|
|
8
10
|
import { formatNumberReadout } from './animated-number-model.js';
|
|
9
11
|
import { BarMark } from './bar-mark.js';
|
|
10
12
|
import { BarPnl } from './bar-pnl.js';
|
|
11
13
|
import { ListGroup, ListRow } from './list-group.js';
|
|
12
14
|
const usd = { style: 'currency', currency: 'USD' };
|
|
13
|
-
const
|
|
15
|
+
const pnlUsdDefault = { style: 'currency', currency: 'USD', signDisplay: 'exceptZero', maximumFractionDigits: 4 };
|
|
14
16
|
const pnlShare = { style: 'percent', minimumFractionDigits: 2, maximumFractionDigits: 2, signDisplay: 'exceptZero' };
|
|
15
17
|
const units = { maximumFractionDigits: 6 };
|
|
16
18
|
const tenth = { maximumFractionDigits: 1 };
|
|
@@ -36,9 +38,12 @@ function Sentence({ template, text, value, options, suffix, testID }) {
|
|
|
36
38
|
return _jsxs(View, { accessible: true, accessibilityLabel: reading, testID: testID, style: { direction, flexDirection: 'row', alignItems: 'center', flexShrink: 1 }, children: [parts[0] ? _jsx(Text, { accessible: false, style: words, children: parts[0] }) : null, _jsx(AnimatedNumberReadout, { value: value, options: options, suffix: suffix, tone: 'muted', style: type }), parts[1] ? _jsx(Text, { accessible: false, style: words, children: parts[1] }) : null] });
|
|
37
39
|
}
|
|
38
40
|
/** One open position as a screen: margin and notional under the share left before liquidation, then the liquidation, mark and entry prices as a `BarPnl`, what can be done, and the position itself. Both bars are drawn without a card, because nothing in them can be pressed. */
|
|
39
|
-
export function ManagePositionBlock({ labels, mode, side, entry, mark, liquidation, margin, notional, priceOptions, actions, position, onBack, headerAction, testID }) {
|
|
40
|
-
const colors = useColors(), fills = useFills(), t = useMessages(), { direction, locale
|
|
41
|
-
|
|
41
|
+
export function ManagePositionBlock({ labels, mode, side, entry, mark, liquidation, margin, notional, priceOptions, actions, position, pnlOptions, onBack, headerAction, headingId, testID }) {
|
|
42
|
+
const colors = useColors(), fills = useFills(), t = useMessages(), { direction } = useHIG(), locale = useNumberLocale(), present = usePresentNumber();
|
|
43
|
+
// The artwork that failed to draw (its URL, or the position for a host element); it then shows the fallback or the initials until the artwork changes.
|
|
44
|
+
const [broken, setBroken] = useState(null);
|
|
45
|
+
const pnlUsd = pnlOptions ? { ...pnlUsdDefault, ...pnlOptions } : pnlUsdDefault;
|
|
46
|
+
const read = (value, options) => known(value) ? formatNumberReadout(value, locale, present(options)).text : unknown;
|
|
42
47
|
const corridor = positionCorridor({ side, entry, mark, liquidation }), long = side === 'long';
|
|
43
48
|
const marginBar = [{ id: 'margin', label: labels.margin, value: margin, detail: read(margin, usd), tone: 'info' }, { id: 'notional', label: labels.notional, value: known(notional) ? Math.max(notional - margin, 0) : 0, detail: read(notional, usd), tone: 'positive' }];
|
|
44
49
|
const left = corridor.share === null ? null : corridor.share * 100;
|
|
@@ -46,12 +51,32 @@ export function ManagePositionBlock({ labels, mode, side, entry, mark, liquidati
|
|
|
46
51
|
const row = () => {
|
|
47
52
|
if (!position)
|
|
48
53
|
return null;
|
|
49
|
-
const { name, icon, leverage, size, pnl, pnlPercent } = position;
|
|
50
|
-
const
|
|
54
|
+
const { name, icon, iconFallback, symbol, leverage, size, pnl, pnlPercent, badge, caption, onSelect } = position;
|
|
55
|
+
const initials = _jsx(Text, { accessible: false, maxFontSizeMultiplier: 1, style: { fontSize: 12, lineHeight: 16, fontWeight: '600', color: colors.muted }, children: symbol ?? name.slice(0, 3) });
|
|
56
|
+
const key = typeof icon === 'string' ? icon : `${symbol ?? ''}|${name}`, failed = broken === key, fail = () => setBroken(key);
|
|
57
|
+
const art = failed ? _jsx(View, { testID: 'manage-position-initials', style: shape, children: iconFallback ?? initials })
|
|
58
|
+
: typeof icon === 'string' ? _jsx(Image, { accessible: false, accessibilityIgnoresInvertColors: true, source: { uri: icon }, onError: fail, style: shape })
|
|
59
|
+
: _jsx(View, { style: shape, children: typeof icon === 'function' ? icon(fail) : icon ?? initials });
|
|
51
60
|
const gearing = known(leverage) ? formatNumberReadout(leverage, locale, units).text + times : null, held = size !== undefined ? read(size, units) : null;
|
|
52
61
|
const label = [name, long ? labels.long : labels.short, gearing, held, pnl !== undefined ? read(pnl, pnlUsd) : null, pnlPercent !== undefined ? read(pnlPercent, pnlShare) : null].filter(Boolean).join(', ');
|
|
53
62
|
const meta = { fontSize: 14, lineHeight: 20 };
|
|
54
|
-
|
|
63
|
+
const title = _jsx(Text, { numberOfLines: 1, style: { fontSize: 16, lineHeight: 24, fontWeight: '600', color: colors.text, ...(badge ? { flexShrink: 1 } : null) }, children: name });
|
|
64
|
+
const surface = (pressed) => ({ flexDirection: 'row', alignItems: 'center', gap: 12, minHeight: 56, paddingVertical: 8, paddingStart: 8, paddingEnd: 16, borderRadius: 28, backgroundColor: pressed ? fills.raised : fills.well, marginTop: 16 });
|
|
65
|
+
const parts = _jsxs(_Fragment, { children: [_jsx(View, { ...hidden, children: art }), _jsxs(View, { ...hidden, style: { flex: 1, flexShrink: 1, minWidth: 0 }, children: [badge ? _jsxs(View, { style: { direction, flexDirection: 'row', alignItems: 'center', gap: 8, minWidth: 0 }, children: [title, _jsx(View, { testID: 'manage-position-badge', style: { flexShrink: 0, borderRadius: 9999, paddingHorizontal: 8, backgroundColor: fills.raised }, children: _jsx(Text, { numberOfLines: 1, style: { fontSize: 12, lineHeight: 18, fontWeight: '500', color: colors.muted }, children: badge }) })] }) : title, _jsxs(View, { style: { direction, flexDirection: 'row', alignItems: 'center', gap: 4 }, children: [_jsx(Text, { testID: 'manage-position-side', style: { ...meta, fontWeight: '600', color: long ? colors.up : colors.down }, children: long ? up : down }), gearing ? _jsx(Text, { testID: 'manage-position-leverage', style: { ...meta, fontWeight: '600', color: long ? colors.up : colors.down }, children: gearing }) : null, gearing && held ? _jsx(Text, { style: { ...meta, color: colors.muted }, children: dot.trim() }) : null, size !== undefined ? _jsx(AnimatedNumberReadout, { value: size, options: units, tone: 'muted', testID: 'manage-position-size', style: meta }) : null] })] }), _jsxs(View, { ...hidden, style: { alignItems: 'flex-end', justifyContent: 'center' }, children: [pnl !== undefined ? _jsx(AnimatedNumberReadout, { value: pnl, options: pnlUsd, tone: known(pnl) && pnl > 0 ? 'up' : known(pnl) && pnl < 0 ? 'down' : 'text', testID: 'manage-position-pnl', style: { fontSize: 16, lineHeight: 24, fontWeight: '600' } }) : null, pnlPercent !== undefined ? _jsx(AnimatedNumberReadout, { value: pnlPercent, options: pnlShare, tone: 'muted', testID: 'manage-position-pnl-percent', style: meta }) : null] })] });
|
|
66
|
+
const note = caption ? _jsx(Text, { testID: 'manage-position-caption', style: { marginTop: 8, paddingHorizontal: 16, color: colors.muted, fontSize: 13, lineHeight: 20 }, children: caption }) : null;
|
|
67
|
+
if (onSelect) {
|
|
68
|
+
// A pressable row is named by the host's label and then what it shows, so the figures are read even with hints off; the caption is its hint.
|
|
69
|
+
return _jsxs(_Fragment, { children: [_jsx(Pressable, { testID: 'manage-position-row', accessibilityRole: 'button', accessibilityLabel: position.label ? `${position.label}, ${label}` : label, accessibilityHint: caption, onPress: onSelect, style: ({ pressed }) => surface(pressed), children: parts }), note] });
|
|
70
|
+
}
|
|
71
|
+
return _jsxs(_Fragment, { children: [_jsx(View, { testID: 'manage-position-row', accessible: true, accessibilityLabel: label, style: surface(false), children: parts }), note] });
|
|
55
72
|
};
|
|
56
|
-
|
|
73
|
+
const actionValue = (action) => {
|
|
74
|
+
const figure = action.value;
|
|
75
|
+
if (figure == null)
|
|
76
|
+
return {};
|
|
77
|
+
if (typeof figure === 'string')
|
|
78
|
+
return { value: figure, valueTone: action.tone };
|
|
79
|
+
return { value: _jsx(AnimatedNumberReadout, { ...figureProps(figure), tone: action.tone ?? 'muted', testID: `manage-action-${action.id}-value`, style: { fontSize: 16, lineHeight: 24 } }), valueLabel: figureReading(figure, locale, present(figure.options)) };
|
|
80
|
+
};
|
|
81
|
+
return _jsxs(View, { testID: testID, style: { padding: 16 }, children: [_jsxs(View, { testID: 'manage-header', style: { flexDirection: 'row', alignItems: 'center', minHeight: 44 }, children: [_jsx(View, { style: { minWidth: 44, alignItems: 'flex-start' }, children: onBack ? _jsx(IconButton, { intent: 'ghost', label: t.back, suppressFeedback: true, testID: 'manage-back', onPress: onBack, children: _jsx(View, { style: { transform: [{ rotate: direction === 'rtl' ? '-90deg' : '90deg' }] }, children: _jsx(ChevronIcon, { color: colors.text }) }) }) : null }), _jsx(Text, { testID: 'manage-title', nativeID: headingId, accessibilityRole: 'header', numberOfLines: 1, style: { flex: 1, textAlign: 'center', fontSize: 17, lineHeight: 24, fontWeight: '600', color: colors.text }, children: labels.title }), _jsx(View, { style: { minWidth: 44, alignItems: 'flex-end' }, children: headerAction })] }), _jsxs(View, { style: { gap: 20, marginTop: 16, paddingHorizontal: 4 }, children: [_jsx(BarMark, { testID: 'manage-margin', surface: false, title: mode ?? labels.margin, elements: marginBar, description: _jsx(Sentence, { testID: 'manage-to-liquidation', template: labels.toLiquidation, text: left === null ? unknown : formatNumberReadout(left, locale, tenth).text + percent, value: left, options: tenth, suffix: percent }) }), _jsx(BarPnl, { testID: 'manage-liquidation', 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(View, { testID: 'manage-actions', style: { marginTop: 16 }, children: _jsx(ListGroup, { children: actions.map(action => _jsx(ListRow, { testID: `manage-action-${action.id}`, label: action.label, disabled: action.disabled, onSelect: action.onSelect, ...actionValue(action) }, action.id)) }) }) : null, row()] });
|
|
57
82
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { View, type GestureResponderEvent, type StyleProp, type ViewStyle } from 'react-native';
|
|
3
|
+
interface MarketRowContent {
|
|
4
|
+
symbol: string;
|
|
5
|
+
name: string;
|
|
6
|
+
/** Leave out to draw no price (no dash); `null` reads as unknown. */
|
|
7
|
+
price?: number | null;
|
|
8
|
+
/** Leave out to draw no change (no dash); `null` reads as unknown. */
|
|
9
|
+
change?: number | null;
|
|
10
|
+
/** Intl display options for the price, including a decimal style when the host omits a currency symbol. */
|
|
11
|
+
priceOptions?: Intl.NumberFormatOptions;
|
|
12
|
+
/** Percent-point display precision and sign, forwarded to `Percent`. */
|
|
13
|
+
changeOptions?: Intl.NumberFormatOptions;
|
|
14
|
+
/** Host artwork before the name, such as the market icon. Decorative. */
|
|
15
|
+
icon?: React.ReactNode;
|
|
16
|
+
/** Host favourite indicator or control before the icon. */
|
|
17
|
+
favorite?: React.ReactNode;
|
|
18
|
+
/** Host-formatted volume after the change. */
|
|
19
|
+
volume?: React.ReactNode;
|
|
20
|
+
/** A muted second line under the name, such as the maximum leverage. Text, or host nodes (text nodes are drawn muted; an element is drawn as given). In action mode its text is read with the name. */
|
|
21
|
+
detail?: React.ReactNode;
|
|
22
|
+
/** Host content on the trailing edge, after the figures, such as a held position's result. */
|
|
23
|
+
trailing?: React.ReactNode;
|
|
24
|
+
/** The market in use: a check on the trailing edge and `accessibilityState.selected` on the name button (the row in presentation mode). */
|
|
25
|
+
selected?: boolean;
|
|
26
|
+
/** Dims the row; in action mode the name button is disabled. */
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
/** Highlights the row with the well fill, as for a host's keyboard cursor. */
|
|
29
|
+
active?: boolean;
|
|
30
|
+
/** Action mode: called when a press starts on the name button, before it is accepted, for example to prefetch the market. */
|
|
31
|
+
onPressIn?: (event: GestureResponderEvent) => void;
|
|
32
|
+
testID?: string;
|
|
33
|
+
style?: StyleProp<ViewStyle>;
|
|
34
|
+
}
|
|
35
|
+
export type MarketRowProps = MarketRowContent & ({
|
|
36
|
+
mode?: 'action';
|
|
37
|
+
onSelect: () => void;
|
|
38
|
+
identity?: never;
|
|
39
|
+
} | {
|
|
40
|
+
mode: 'presentation';
|
|
41
|
+
onSelect?: never; /** Host market identity in place of `name (symbol)`. */
|
|
42
|
+
identity?: React.ReactNode;
|
|
43
|
+
});
|
|
44
|
+
/** A market as one row: its name (a button, or the host's identity in presentation mode), price and change. The ref reaches the row's root view. */
|
|
45
|
+
export declare const MarketRow: React.ForwardRefExoticComponent<MarketRowProps & React.RefAttributes<React.ComponentRef<typeof View>>>;
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import { View } from 'react-native';
|
|
4
|
+
import { useColors, useFills } from './provider.js';
|
|
5
|
+
import { Button } from './button.js';
|
|
6
|
+
import { Text } from './surface.js';
|
|
7
|
+
import { Row, Usd, Percent } from './data.js';
|
|
8
|
+
import { plainText } from './text-content.js';
|
|
9
|
+
const hidden = { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants' };
|
|
10
|
+
/** A market as one row: its name (a button, or the host's identity in presentation mode), price and change. The ref reaches the row's root view. */
|
|
11
|
+
export const MarketRow = /* @__PURE__ */ forwardRef(function MarketRow({ symbol, name, price, change, priceOptions, changeOptions, mode = 'action', onSelect, identity, icon, favorite, volume, detail, trailing, selected, disabled, active, onPressIn, testID, style }, ref) {
|
|
12
|
+
const colors = useColors(), fills = useFills();
|
|
13
|
+
const label = `${name} (${symbol})`;
|
|
14
|
+
const lines = detail === undefined ? null : _jsxs(View, { style: { alignItems: 'flex-start' }, children: [_jsx(Text, { style: { fontSize: 16, lineHeight: 24, fontWeight: '600', color: disabled ? colors.muted : colors.text }, children: label }), typeof detail === 'string' || typeof detail === 'number' ? _jsx(Text, { style: { fontSize: 14, lineHeight: 20, color: colors.muted }, children: detail }) : detail] });
|
|
15
|
+
const detailText = detail === undefined ? '' : plainText(detail);
|
|
16
|
+
const title = mode === 'presentation'
|
|
17
|
+
? _jsx(View, { style: disabled ? { opacity: 0.5, flexShrink: 1 } : { flexShrink: 1 }, children: identity ?? lines ?? _jsx(Text, { children: label }) })
|
|
18
|
+
: lines ? _jsx(Button, { intent: 'ghost', contentMode: 'custom', accessibilityLabel: detailText ? `${label}, ${detailText}` : label, accessibilityState: selected ? { selected: true } : undefined, disabled: disabled, onPress: onSelect, onPressIn: onPressIn, testID: testID ? `${testID}-select` : undefined, style: { alignItems: 'flex-start' }, children: lines })
|
|
19
|
+
: _jsx(Button, { intent: 'ghost', accessibilityState: selected ? { selected: true } : undefined, disabled: disabled, onPress: onSelect, onPressIn: onPressIn, testID: testID ? `${testID}-select` : undefined, children: label });
|
|
20
|
+
const leading = favorite !== undefined || icon !== undefined;
|
|
21
|
+
const identityCell = leading ? _jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: 8, flexShrink: 1, minWidth: 0 }, children: [favorite !== undefined ? favorite : null, icon !== undefined ? _jsx(View, { ...hidden, children: icon }) : null, title] }) : title;
|
|
22
|
+
const dim = disabled ? { opacity: 0.5 } : undefined;
|
|
23
|
+
const cells = _jsxs(_Fragment, { children: [identityCell, price !== undefined ? _jsx(View, { style: dim, children: _jsx(Usd, { value: price, options: priceOptions }) }) : null, change !== undefined ? _jsx(View, { style: dim, children: _jsx(Percent, { value: change, options: changeOptions }) }) : null, volume !== undefined ? _jsx(View, { style: dim, children: volume }) : null, trailing != null && trailing !== false ? _jsx(View, { testID: testID ? `${testID}-trailing` : undefined, style: [{ flexDirection: 'row', alignItems: 'center', gap: 8 }, dim], children: trailing }) : null, selected ? _jsx(View, { ...hidden, testID: testID ? `${testID}-check` : undefined, style: { width: 20, height: 20, alignItems: 'center', justifyContent: 'center' }, children: _jsx(View, { style: { width: 6, height: 12, borderRightWidth: 2, borderBottomWidth: 2, borderColor: colors.text, transform: [{ translateY: -1 }, { rotate: '45deg' }] } }) }) : null] });
|
|
24
|
+
const plain = !ref && !leading && detail === undefined && price !== undefined && change !== undefined && volume === undefined && trailing == null && !selected && !disabled && !active && !onPressIn && mode === 'action' && !testID && !style;
|
|
25
|
+
// Without host options the row is exactly the 0.6.0 one: the name button, the price and the change in a wrapping Row.
|
|
26
|
+
if (plain)
|
|
27
|
+
return _jsxs(Row, { children: [_jsxs(Button, { intent: 'ghost', onPress: onSelect, children: [name, " (", symbol, ")"] }), _jsx(Usd, { value: price, options: priceOptions }), _jsx(Percent, { value: change, options: changeOptions })] });
|
|
28
|
+
const state = mode === 'presentation' && (selected || disabled) ? { ...(selected ? { selected: true } : {}), ...(disabled ? { disabled: true } : {}) } : undefined;
|
|
29
|
+
return _jsx(View, { ref: ref, testID: testID, accessibilityState: state, style: [{ flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', flexWrap: 'wrap', gap: 12, paddingVertical: 12 }, active ? { backgroundColor: fills.well, borderRadius: 14 } : null, style], children: cells });
|
|
30
|
+
});
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { type ScrollViewProps } from 'react-native';
|
|
3
|
+
import { type SettingAction } from './setting-switch.js';
|
|
2
4
|
/** One kind of notification. Every word is host text. */
|
|
3
5
|
export interface NotificationsItem {
|
|
4
6
|
id: string;
|
|
@@ -7,19 +9,45 @@ export interface NotificationsItem {
|
|
|
7
9
|
checked: boolean;
|
|
8
10
|
onCheckedChange: (checked: boolean) => void;
|
|
9
11
|
disabled?: boolean;
|
|
12
|
+
/** Always on and not changeable: shown on at full strength and read as unavailable. */
|
|
13
|
+
locked?: boolean;
|
|
14
|
+
/** Host content after the label, such as a badge. It is drawn only; the switch is read by `label`. */
|
|
15
|
+
labelAccessory?: React.ReactNode;
|
|
16
|
+
/** Host words for the `labelAccessory`, read after the label and a pause: `Push, New`. */
|
|
17
|
+
labelAccessoryLabel?: string;
|
|
18
|
+
/** A neutral line under the card, announced when it changes, for progress or a hint: Registering this device. */
|
|
19
|
+
hint?: string;
|
|
10
20
|
/** Why turning it on failed, under the card: Push request timed out. It is announced when it appears. */
|
|
11
21
|
error?: string;
|
|
22
|
+
/** 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. */
|
|
23
|
+
action?: SettingAction;
|
|
24
|
+
}
|
|
25
|
+
/** Notifications under one optional heading: Alert types. */
|
|
26
|
+
export interface NotificationsGroup {
|
|
27
|
+
id: string;
|
|
28
|
+
title?: string;
|
|
29
|
+
items: readonly NotificationsItem[];
|
|
12
30
|
}
|
|
13
31
|
export interface NotificationsBlockProps {
|
|
14
32
|
/** Heading: Notifications. */
|
|
15
33
|
title: string;
|
|
34
|
+
/** A muted line under the header that explains the screen. */
|
|
35
|
+
description?: string;
|
|
16
36
|
/** One card each, in order. */
|
|
17
|
-
items
|
|
37
|
+
items?: readonly NotificationsItem[];
|
|
38
|
+
/** More cards under the items, in groups with an optional heading, 24dp apart. */
|
|
39
|
+
groups?: readonly NotificationsGroup[];
|
|
18
40
|
/** Shows Back on the leading edge of the header. */
|
|
19
41
|
onBack?: () => void;
|
|
20
42
|
/** A control on the trailing edge of the header, usually an IconButton. */
|
|
21
43
|
headerAction?: React.ReactNode;
|
|
44
|
+
/** Keeps the header pinned while the cards scroll: the block becomes its own scroll view with the header as its sticky first child, transparent at rest and filled once content scrolls under it. Place it in a bounded container. */
|
|
45
|
+
stickyHeader?: boolean;
|
|
46
|
+
/** Fill behind the pinned header once content scrolls under it. Defaults to the background role; in a sheet pass the sheet's fill. */
|
|
47
|
+
stickyHeaderBackground?: string;
|
|
48
|
+
/** The scroll view used with `stickyHeader`, such as a sheet library's own. */
|
|
49
|
+
scrollComponent?: React.ComponentType<ScrollViewProps>;
|
|
22
50
|
testID?: string;
|
|
23
51
|
}
|
|
24
52
|
/** The notifications the viewer receives, as a screen: each kind is a card with a switch and a line of explanation, and a failure to turn one on reads under its card. */
|
|
25
|
-
export declare function NotificationsBlock({ title, items, onBack, headerAction, testID }: NotificationsBlockProps): React.JSX.Element;
|
|
53
|
+
export declare function NotificationsBlock({ title, description, items, groups, onBack, headerAction, stickyHeader, stickyHeaderBackground, scrollComponent, testID }: NotificationsBlockProps): React.JSX.Element;
|
|
@@ -1,14 +1,22 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { View } from 'react-native';
|
|
3
|
-
import { useColors } from './provider.js';
|
|
3
|
+
import { useColors, useHIG } from './provider.js';
|
|
4
4
|
import { Text } from './surface.js';
|
|
5
|
+
import { Button } from './button.js';
|
|
5
6
|
import { SettingCard, SettingHeader, SettingSwitch } from './setting-switch.js';
|
|
7
|
+
import { StickyHeaderLayout } from './sticky-header.js';
|
|
6
8
|
/** The notifications the viewer receives, as a screen: each kind is a card with a switch and a line of explanation, and a failure to turn one on reads under its card. */
|
|
7
|
-
export function NotificationsBlock({ title, items, onBack, headerAction, testID }) {
|
|
8
|
-
const colors = useColors();
|
|
9
|
-
const
|
|
9
|
+
export function NotificationsBlock({ title, description, items = [], groups, onBack, headerAction, stickyHeader, stickyHeaderBackground, scrollComponent, testID }) {
|
|
10
|
+
const colors = useColors(), { direction } = useHIG();
|
|
11
|
+
const note = { paddingHorizontal: 20, fontSize: 14, lineHeight: 21 };
|
|
12
|
+
const card = (item) => {
|
|
10
13
|
const id = `notifications-${item.id}`;
|
|
11
|
-
return _jsxs(View, { style: { gap: 8 }, children: [_jsx(SettingCard, { testID: id, children: _jsx(SettingSwitch, { testID: `${id}-switch`, label: item.label, description: item.description, checked: item.checked, disabled: item.disabled, onCheckedChange: item.onCheckedChange }) }), item.error ? _jsx(Text, { testID: `${id}-error`, accessibilityRole: 'alert', accessibilityLiveRegion: 'polite', style: { paddingHorizontal: 20, fontSize: 14, lineHeight: 21, color: colors.negative }, children: item.error }) : null] }, item.id);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
+
return _jsxs(View, { style: { gap: 8 }, children: [_jsx(SettingCard, { testID: id, children: _jsx(SettingSwitch, { testID: `${id}-switch`, 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(Text, { testID: `${id}-hint`, accessibilityLiveRegion: 'polite', style: { ...note, color: colors.muted }, children: item.hint }) : null, item.error ? _jsx(Text, { testID: `${id}-error`, accessibilityRole: 'alert', accessibilityLiveRegion: 'polite', style: { paddingHorizontal: 20, fontSize: 14, lineHeight: 21, color: colors.negative }, children: item.error }) : null, item.action ? _jsx(View, { style: { marginTop: 8 }, children: _jsx(Button, { testID: `${id}-action`, intent: 'secondary', fullWidth: true, disabled: item.action.disabled, suppressFeedback: item.action.feedback === false, onPress: item.action.onSelect, children: item.action.label }) }) : null] }, item.id);
|
|
15
|
+
};
|
|
16
|
+
const cards = items.map(card);
|
|
17
|
+
const header = _jsx(SettingHeader, { testID: 'notifications', title: title, onBack: onBack, action: headerAction });
|
|
18
|
+
const body = _jsxs(_Fragment, { children: [description ? _jsx(Text, { testID: 'notifications-description', style: { fontSize: 14, lineHeight: 21, color: colors.muted, marginTop: 16, paddingHorizontal: 4 }, children: description }) : null, items.length > 0 ? _jsx(View, { testID: 'notifications-items', style: { gap: 8, marginTop: 16 }, children: cards }) : null, groups?.map(group => _jsxs(View, { testID: `notifications-group-${group.id}`, style: { gap: 8, marginTop: 24 }, children: [group.title ? _jsx(View, { style: { direction, flexDirection: 'row', alignItems: 'center', minHeight: 44, paddingStart: 4 }, children: _jsx(Text, { testID: `notifications-group-${group.id}-title`, accessibilityRole: 'header', numberOfLines: 1, style: { flexShrink: 1, fontSize: 16, lineHeight: 24, fontWeight: '500', color: colors.muted }, children: group.title }) }) : null, group.items.map(card)] }, group.id))] });
|
|
19
|
+
if (stickyHeader)
|
|
20
|
+
return _jsx(StickyHeaderLayout, { testID: testID, headerTestID: 'notifications-sticky-header', header: header, background: stickyHeaderBackground, scrollComponent: scrollComponent, children: body });
|
|
21
|
+
return _jsxs(View, { testID: testID, style: { padding: 16 }, children: [header, body] });
|
|
14
22
|
}
|
package/native/dist/pickers.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { type StyleProp, type ViewStyle } from 'react-native';
|
|
2
|
+
import { type FlatListProps, type StyleProp, type TextInput, type TextInputProps, type ViewStyle } from 'react-native';
|
|
3
3
|
import { type SwapChain, type SwapToken, type SwapWallet } from './swap-shared.js';
|
|
4
4
|
export type { SwapChain, SwapFigure, SwapToken, SwapWallet } from './swap-shared.js';
|
|
5
|
+
/** The list component (and height animation) a sheet hands to the pickers it holds; `listComponent` on a picker block does the same for one block. */
|
|
6
|
+
export { SwapHostContext } from './swap-parts.js';
|
|
5
7
|
/** The searchable token list both pickers share. */
|
|
6
8
|
export interface PickerListProps {
|
|
7
9
|
/** Tokens offered: a wallet's holdings, a whitelist, or a whole catalog. */
|
|
@@ -18,7 +20,21 @@ export interface PickerListProps {
|
|
|
18
20
|
loading?: boolean;
|
|
19
21
|
/** Web only: focuses the search with a hardware pointer. Native never raises the keyboard on mount. */
|
|
20
22
|
autoFocus?: boolean;
|
|
23
|
+
/** `false` leaves out the search field, for a short list. Default `true`. */
|
|
24
|
+
search?: boolean;
|
|
25
|
+
/** Shows a token's balance when it is zero, where by default only a balance above zero is drawn. */
|
|
26
|
+
zeroBalances?: boolean;
|
|
27
|
+
/** A visible label over the search field, which then names it in place of the built-in label. */
|
|
28
|
+
searchLabel?: string;
|
|
29
|
+
/** A ref to the search input, for example to register it with a host bottom sheet's keyboard handling. */
|
|
30
|
+
searchRef?: React.Ref<React.ComponentRef<typeof TextInput>>;
|
|
31
|
+
/** Props for the search input, such as `onFocus`/`onBlur` for a host sheet or `returnKeyType`. The value and its change handler stay HIG's. */
|
|
32
|
+
searchInputProps?: PickerInputProps;
|
|
33
|
+
/** The list component the rows render through, such as a bottom sheet library's `FlatList`, so the list scrolls inside the host's sheet. Defaults to the `SwapHostContext` list, then React Native's `FlatList`. It receives the bounded `style` HIG sets, which the host's component may override. */
|
|
34
|
+
listComponent?: React.ComponentType<FlatListProps<SwapToken>>;
|
|
21
35
|
}
|
|
36
|
+
/** Host props for a picker's input: what a `TextInput` takes, except the value and its change handler. */
|
|
37
|
+
export type PickerInputProps = Omit<TextInputProps, 'value' | 'defaultValue' | 'onChangeText' | 'onChange'>;
|
|
22
38
|
export interface FromPickerBlockProps extends PickerListProps {
|
|
23
39
|
/** The connected wallet. Omit for a list with no wallet row at all. */
|
|
24
40
|
wallet?: SwapWallet;
|
|
@@ -45,13 +61,19 @@ export interface ToPickerBlockProps extends Partial<PickerListProps> {
|
|
|
45
61
|
addressPlaceholder?: string;
|
|
46
62
|
/** Shows the scan button. HIG ships no scanner: the host opens its own and writes the result to `address`. */
|
|
47
63
|
onScan?: () => void;
|
|
64
|
+
/** A visible label over the address field, which then names it in place of the built-in “Recipient”. */
|
|
65
|
+
addressLabel?: string;
|
|
66
|
+
/** A ref to the address input, for example to register it with a host bottom sheet's keyboard handling. */
|
|
67
|
+
addressRef?: React.Ref<React.ComponentRef<typeof TextInput>>;
|
|
68
|
+
/** Props for the address input, such as `onFocus`/`onBlur` for a host sheet, `textContentType` or a mono `style`. The value and its change handler stay HIG's. */
|
|
69
|
+
addressInputProps?: PickerInputProps;
|
|
48
70
|
style?: StyleProp<ViewStyle>;
|
|
49
71
|
}
|
|
50
72
|
/**
|
|
51
73
|
* Where the assets go. On its own it is a destination address field with a scan button. With `tokens` it adds the
|
|
52
74
|
* searchable token list, with the chain filter or, with `chainFilter={false}`, without it.
|
|
53
75
|
*/
|
|
54
|
-
export declare function ToPickerBlock({ address, onAddressChange, addressPlaceholder, onScan, style, tokens, onSelect, ...list }: ToPickerBlockProps): React.JSX.Element;
|
|
76
|
+
export declare function ToPickerBlock({ address, onAddressChange, addressPlaceholder, onScan, addressLabel, addressRef, addressInputProps, style, tokens, onSelect, ...list }: ToPickerBlockProps): React.JSX.Element;
|
|
55
77
|
/** @deprecated Renamed `FromPickerBlock`. The old name keeps working until the next major release. */
|
|
56
78
|
export declare const FromPicker: typeof FromPickerBlock;
|
|
57
79
|
/** @deprecated Renamed `FromPickerBlockProps`. */
|
package/native/dist/pickers.js
CHANGED
|
@@ -4,24 +4,29 @@ import { FlatList, Pressable, View, useWindowDimensions } from 'react-native';
|
|
|
4
4
|
import { useColors, useFills, useHIG, useMessages } from './provider.js';
|
|
5
5
|
import { Text } from './surface.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 './radio-group.js';
|
|
9
9
|
import { AnimatedNumberReadout } from './animated-number.js';
|
|
10
10
|
import { SwitchRow } from './switch-row.js';
|
|
11
11
|
import { LeaveIcon, LockIcon, ScanIcon, SwapHostContext, TokenIcon, WalletIcon } from './swap-parts.js';
|
|
12
12
|
import { addressColor, pickerRows, shortAddress } from './swap-shared.js';
|
|
13
|
+
/** The list component (and height animation) a sheet hands to the pickers it holds; `listComponent` on a picker block does the same for one block. */
|
|
14
|
+
export { SwapHostContext } from './swap-parts.js';
|
|
13
15
|
/** Chains present in a token list, in first-seen order. */
|
|
14
16
|
function chainsOf(tokens) { const seen = new Map(); for (const token of tokens)
|
|
15
17
|
if (!seen.has(token.chainId))
|
|
16
18
|
seen.set(token.chainId, { chainId: token.chainId, name: token.chain, icon: typeof token.chainIcon === 'string' ? token.chainIcon : undefined }); return [...seen.values()]; }
|
|
17
|
-
|
|
19
|
+
/** A row shows a known balance above zero, or a zero one when the host asks for it. */
|
|
20
|
+
const showBalance = (token, zero) => token.balance != null && Number.isFinite(token.balance) && (token.balance > 0 || (!!zero && token.balance === 0));
|
|
21
|
+
function TokenList({ tokens, chains, chainFilter = true, hotTokenIds, selected = null, onSelect, loading, search = true, zeroBalances, searchLabel, searchRef, searchInputProps, listComponent, side, title }) {
|
|
18
22
|
const { direction } = useHIG();
|
|
19
23
|
const colors = useColors();
|
|
20
24
|
const fills = useFills();
|
|
21
25
|
const t = useMessages();
|
|
22
26
|
const window = useWindowDimensions();
|
|
23
|
-
// A sheet passes its backend's list through the host context so drags hand off to the sheet.
|
|
24
|
-
const
|
|
27
|
+
// A sheet passes its backend's list, through the prop or the host context, so drags hand off to the sheet.
|
|
28
|
+
const host = useContext(SwapHostContext).listComponent;
|
|
29
|
+
const List = listComponent ?? host ?? FlatList;
|
|
25
30
|
const [query, setQuery] = useState('');
|
|
26
31
|
const [chain, pickChain] = useState('');
|
|
27
32
|
const options = useMemo(() => chains ?? chainsOf(tokens), [chains, tokens]);
|
|
@@ -31,9 +36,11 @@ function TokenList({ tokens, chains, chainFilter = true, hotTokenIds, selected =
|
|
|
31
36
|
const section = (heading) => _jsx(Text, { accessibilityRole: 'header', style: { paddingHorizontal: 8, paddingTop: 12, paddingBottom: 6, fontSize: 12, lineHeight: 18, fontWeight: '600', letterSpacing: 1, textTransform: 'uppercase', color: colors.muted }, children: heading });
|
|
32
37
|
const chainOptions = useMemo(() => [{ value: '', label: t.swapAllChains }, ...options.map(item => ({ value: String(item.chainId), label: item.name, icon: item.icon }))], [options, t.swapAllChains]);
|
|
33
38
|
const empty = _jsx(Text, { accessibilityLiveRegion: 'polite', testID: `swap-empty-${side}`, style: { paddingVertical: 32, textAlign: 'center', fontSize: 14, lineHeight: 21, color: colors.muted }, children: loading ? `${t.loading}…` : t.swapNoTokens });
|
|
34
|
-
|
|
39
|
+
// A visible label names the field through the Field context instead of the built-in name.
|
|
40
|
+
const field = _jsx(SearchInput, { ref: searchRef, accessibilityLabel: searchLabel ? undefined : t.swapSearchTokens, placeholder: t.swapSearchTokens, testID: `swap-search-${side}`, autoCapitalize: 'none', autoCorrect: false, autoComplete: 'off', spellCheck: false, ...searchInputProps, value: query, onChangeText: setQuery });
|
|
41
|
+
return _jsxs(_Fragment, { children: [search ? searchLabel ? _jsx(Field, { label: searchLabel, children: field }) : field : null, chainFilter && options.length > 1 ? _jsx(Filter, { label: t.swapChains, options: chainOptions, value: chain, onValueChange: pickChain }) : null, _jsx(List, { style: { height: Math.max(240, Math.round(window.height * 0.5)) }, data: rows, keyExtractor: token => token.id, keyboardShouldPersistTaps: 'handled', accessibilityLabel: title, testID: `swap-list-${side}`, initialNumToRender: 12, ListEmptyComponent: empty, renderItem: ({ item: token, index }) => {
|
|
35
42
|
const isSelected = selected?.id === token.id, balance = token.balance ?? 0, price = token.price ?? 0;
|
|
36
|
-
return _jsxs(View, { children: [hotCount > 0 && index === 0 ? section(t.swapHot) : null, hotCount > 0 && index === hotCount ? section(t.swapAllTokens) : null, _jsxs(Pressable, { accessibilityRole: 'button', accessibilityState: { selected: isSelected }, testID: `swap-token-${token.id}`, onPress: () => onSelect(token), style: ({ pressed }) => ({ direction, flexDirection: 'row', alignItems: 'center', gap: 12, marginBottom: 4, paddingVertical: 8, paddingStart: 8, paddingEnd: 16, borderRadius: 9999, backgroundColor: pressed ? fills.well : 'transparent', opacity: isSelected ? 0.5 : 1 }), children: [_jsx(TokenIcon, { token: token }), _jsxs(View, { style: { flex: 1, minWidth: 0 }, children: [_jsx(Text, { style: { fontWeight: '600' }, children: token.name }), _jsxs(Text, { style: { fontSize: 14, lineHeight: 21, color: colors.muted }, children: [token.chain, isSelected ? ` · ${t.swapSelected}` : ''] })] }),
|
|
43
|
+
return _jsxs(View, { children: [hotCount > 0 && index === 0 ? section(t.swapHot) : null, hotCount > 0 && index === hotCount ? section(t.swapAllTokens) : null, _jsxs(Pressable, { accessibilityRole: 'button', accessibilityState: { selected: isSelected }, testID: `swap-token-${token.id}`, onPress: () => onSelect(token), style: ({ pressed }) => ({ direction, flexDirection: 'row', alignItems: 'center', gap: 12, marginBottom: 4, paddingVertical: 8, paddingStart: 8, paddingEnd: 16, borderRadius: 9999, backgroundColor: pressed ? fills.well : 'transparent', opacity: isSelected ? 0.5 : 1 }), children: [_jsx(TokenIcon, { token: token }), _jsxs(View, { style: { flex: 1, minWidth: 0 }, children: [_jsx(Text, { style: { fontWeight: '600' }, children: token.name }), _jsxs(Text, { style: { fontSize: 14, lineHeight: 21, color: colors.muted }, children: [token.detail ?? token.chain, isSelected ? ` · ${t.swapSelected}` : ''] })] }), showBalance(token, zeroBalances) ? _jsxs(View, { style: { alignItems: 'flex-end' }, children: [_jsx(AnimatedNumberReadout, { testID: `swap-token-balance-${token.id}`, value: balance, options: { maximumFractionDigits: 6 }, suffix: token.unitsSuffix, style: { fontWeight: '600', textAlign: 'right' } }), price > 0 ? _jsx(AnimatedNumberReadout, { testID: `swap-token-value-${token.id}`, value: balance * price, options: { style: 'currency', currency: 'USD' }, tone: 'muted', style: { fontSize: 14, lineHeight: 21, textAlign: 'right' } }) : null] }) : null] })] });
|
|
37
44
|
} })] });
|
|
38
45
|
}
|
|
39
46
|
/**
|
|
@@ -53,10 +60,11 @@ export function FromPickerBlock({ wallet, onConnect, onDisconnect, generateAddre
|
|
|
53
60
|
* Where the assets go. On its own it is a destination address field with a scan button. With `tokens` it adds the
|
|
54
61
|
* searchable token list, with the chain filter or, with `chainFilter={false}`, without it.
|
|
55
62
|
*/
|
|
56
|
-
export function ToPickerBlock({ address, onAddressChange, addressPlaceholder, onScan, style, tokens, onSelect, ...list }) {
|
|
63
|
+
export function ToPickerBlock({ address, onAddressChange, addressPlaceholder, onScan, addressLabel, addressRef, addressInputProps, style, tokens, onSelect, ...list }) {
|
|
57
64
|
const colors = useColors();
|
|
58
65
|
const t = useMessages();
|
|
59
|
-
|
|
66
|
+
const row = onAddressChange ? _jsxs(View, { testID: 'picker-address-row', style: { flexDirection: 'row', alignItems: 'center', gap: 8 }, children: [_jsx(View, { style: { flex: 1 }, children: _jsx(Input, { ref: addressRef, accessibilityLabel: addressLabel ? undefined : t.swapRecipient, placeholder: addressPlaceholder ?? t.swapRecipient, testID: 'picker-address', autoCapitalize: 'none', autoCorrect: false, autoComplete: 'off', spellCheck: false, ...addressInputProps, value: address ?? '', onChangeText: onAddressChange }) }), onScan ? _jsx(IconButton, { intent: 'secondary', label: t.swapScan, testID: 'picker-scan', onPress: onScan, style: { minWidth: 48, minHeight: 48 }, children: _jsx(ScanIcon, { color: colors.text }) }) : null] }) : null;
|
|
67
|
+
return _jsxs(View, { accessibilityLabel: t.swapTo, testID: 'to-picker', style: [{ gap: 16 }, style], children: [row && addressLabel ? _jsx(Field, { label: addressLabel, children: row }) : row, tokens && onSelect ? _jsx(TokenList, { ...list, tokens: tokens, onSelect: onSelect, side: 'to', title: t.swapTo }) : null] });
|
|
60
68
|
}
|
|
61
69
|
/** @deprecated Renamed `FromPickerBlock`. The old name keeps working until the next major release. */
|
|
62
70
|
export const FromPicker = FromPickerBlock;
|
|
@@ -1,25 +1,39 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
suffix?: string;
|
|
8
|
-
}
|
|
2
|
+
import { type ScrollViewProps, type StyleProp, type ViewStyle } from 'react-native';
|
|
3
|
+
import { type ScreenHeaderControlProps } from './screen-header.js';
|
|
4
|
+
import { type Figure } from './figure.js';
|
|
5
|
+
/** 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. */
|
|
6
|
+
export type PositionBlockFigure = Figure;
|
|
9
7
|
/** One line of the summary: Notional, Fee, Liquidation. `value` is host text (`2% of profit`) or a live figure. `tone` colours the value; the default is the text colour. */
|
|
10
8
|
export interface PositionBlockDetail {
|
|
11
9
|
id?: string;
|
|
12
10
|
label: string;
|
|
13
11
|
value: string | PositionBlockFigure;
|
|
14
12
|
tone?: 'positive' | 'negative' | 'muted';
|
|
13
|
+
/** Draws the value struck through, for a charge that does not apply, and reads this host text after it: Waived. */
|
|
14
|
+
struck?: string;
|
|
15
|
+
/** Host content right after the label, such as a badge that explains the line. It may be pressable; it is then its own accessibility element. */
|
|
16
|
+
labelAccessory?: React.ReactNode;
|
|
15
17
|
}
|
|
16
|
-
/** One setting of the position: Size, Leverage, Stop Loss. With `onSelect` the row opens the host's own view and shows a chevron. */
|
|
18
|
+
/** 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. */
|
|
17
19
|
export interface PositionBlockRow {
|
|
18
20
|
id: string;
|
|
19
21
|
label: string;
|
|
20
|
-
|
|
22
|
+
/** Host text on the trailing edge, or a live figure that updates place by place. */
|
|
23
|
+
value?: string | PositionBlockFigure;
|
|
21
24
|
onSelect?: () => void;
|
|
22
25
|
disabled?: boolean;
|
|
26
|
+
/** With `onCheckedChange`, the row is a switch named by its label, and the whole row toggles it. */
|
|
27
|
+
checked?: boolean;
|
|
28
|
+
onCheckedChange?: (checked: boolean) => void;
|
|
29
|
+
}
|
|
30
|
+
/** An action on the paper trading row's card, under the switch, such as collecting what the paper position earned. */
|
|
31
|
+
export interface PositionBlockFlagAction {
|
|
32
|
+
label: string;
|
|
33
|
+
onSelect: () => void;
|
|
34
|
+
intent?: 'primary' | 'secondary' | 'destructive';
|
|
35
|
+
busy?: boolean;
|
|
36
|
+
disabled?: boolean;
|
|
23
37
|
}
|
|
24
38
|
/** The paper trading switch. The host supplies its name, because HIG ships no trading terms. */
|
|
25
39
|
export interface PositionBlockFlag {
|
|
@@ -27,6 +41,32 @@ export interface PositionBlockFlag {
|
|
|
27
41
|
checked: boolean;
|
|
28
42
|
onCheckedChange: (checked: boolean) => void;
|
|
29
43
|
disabled?: boolean;
|
|
44
|
+
/** A button on the row's card, under the switch. */
|
|
45
|
+
action?: PositionBlockFlagAction;
|
|
46
|
+
}
|
|
47
|
+
/** The header of a PositionBlock on its own, for a host scroller that pins it: Back, the title and Close. */
|
|
48
|
+
export interface PositionBlockHeaderProps {
|
|
49
|
+
/** Heading: Position. */
|
|
50
|
+
title: string;
|
|
51
|
+
/** Shows Close on the trailing edge. */
|
|
52
|
+
onClose?: () => void;
|
|
53
|
+
/** Shows Back on the leading edge. */
|
|
54
|
+
onBack?: () => void;
|
|
55
|
+
/** A control on the trailing edge in place of Close. */
|
|
56
|
+
headerAction?: React.ReactNode;
|
|
57
|
+
/** Sets `nativeID` on the title, so a sheet around the pane can name itself with `accessibilityLabelledBy` (Android). */
|
|
58
|
+
headingId?: string;
|
|
59
|
+
/** Style of the header's container, such as padding of the host's scroller. */
|
|
60
|
+
style?: StyleProp<ViewStyle>;
|
|
61
|
+
/** Content has scrolled under the header (`useStickyHeaderScroll().scrolled`): it is transparent while false and takes `stickyHeaderBackground` while true. Omitted, the header draws no fill of its own. */
|
|
62
|
+
scrolled?: boolean;
|
|
63
|
+
/** The fill once `scrolled`. Defaults to the background role. */
|
|
64
|
+
stickyHeaderBackground?: string;
|
|
65
|
+
/** Pressable props for Back, such as `{android_disableSound: true}`. */
|
|
66
|
+
backProps?: ScreenHeaderControlProps;
|
|
67
|
+
/** Pressable props for Close. */
|
|
68
|
+
closeProps?: ScreenHeaderControlProps;
|
|
69
|
+
testID?: string;
|
|
30
70
|
}
|
|
31
71
|
export interface PositionBlockProps {
|
|
32
72
|
/** Heading: Position. */
|
|
@@ -45,7 +85,23 @@ export interface PositionBlockProps {
|
|
|
45
85
|
onBack?: () => void;
|
|
46
86
|
/** A control on the trailing edge of the header in place of Close. */
|
|
47
87
|
headerAction?: React.ReactNode;
|
|
88
|
+
/** Sets `nativeID` on the title, so a sheet around the pane can name itself with `accessibilityLabelledBy` (Android). */
|
|
89
|
+
headingId?: string;
|
|
90
|
+
/** Set false to leave the header out, when the host draws `PositionBlockHeader` itself, for example as a sticky header of its scroller. The two stack exactly as the whole block does. */
|
|
91
|
+
header?: boolean;
|
|
92
|
+
/** Keeps the header pinned while the rest scrolls: the block becomes its own scroll view with the header as its sticky first child, transparent at rest and filled once content scrolls under it. Place it in a bounded container, such as a sheet body. */
|
|
93
|
+
stickyHeader?: boolean;
|
|
94
|
+
/** Fill behind the pinned header once content scrolls under it. Defaults to the background role; in a sheet pass the sheet's fill (`useColors().overlay`). */
|
|
95
|
+
stickyHeaderBackground?: string;
|
|
96
|
+
/** The scroll view used with `stickyHeader`, such as a sheet library's own. Defaults to React Native's ScrollView. */
|
|
97
|
+
scrollComponent?: React.ComponentType<ScrollViewProps>;
|
|
98
|
+
/** Pressable props for the header's Back, such as `{android_disableSound: true}`. */
|
|
99
|
+
backProps?: ScreenHeaderControlProps;
|
|
100
|
+
/** Pressable props for the header's Close. */
|
|
101
|
+
closeProps?: ScreenHeaderControlProps;
|
|
48
102
|
testID?: string;
|
|
49
103
|
}
|
|
104
|
+
/** The PositionBlock header on its own: put it in a scroller's sticky header and render `PositionBlock` with `header={false}` under it. It carries the block's top and side padding. */
|
|
105
|
+
export declare function PositionBlockHeader({ style, testID, scrolled, stickyHeaderBackground, ...props }: PositionBlockHeaderProps): React.JSX.Element;
|
|
50
106
|
/** The position being opened or edited as a screen: 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. */
|
|
51
|
-
export declare function PositionBlock({ title, details, note, paperTrade, groups, onClose, onBack, headerAction, testID }: PositionBlockProps): React.JSX.Element;
|
|
107
|
+
export declare function PositionBlock({ title, details, note, paperTrade, groups, onClose, onBack, headerAction, headingId, header, stickyHeader, stickyHeaderBackground, scrollComponent, backProps, closeProps, testID }: PositionBlockProps): React.JSX.Element;
|