@bloxwap/hig 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/chart/README.md +1 -1
- package/contracts/README.md +1 -1
- package/contracts/dist/messages.d.ts +31 -4
- package/contracts/dist/messages.js +11 -2
- package/feedback/README.md +1 -1
- package/native/README.md +1 -1
- package/native/dist/account-block.d.ts +46 -0
- package/native/dist/account-block.js +28 -0
- package/native/dist/asset-balance-row.d.ts +20 -0
- package/native/dist/asset-balance-row.js +21 -0
- package/native/dist/bar-mark.d.ts +45 -0
- package/native/dist/bar-mark.js +34 -0
- package/native/dist/bar-pnl.d.ts +50 -0
- package/native/dist/bar-pnl.js +59 -0
- package/native/dist/blocks.d.ts +44 -0
- package/native/dist/{recipes.js → blocks.js} +20 -9
- package/native/dist/field.d.ts +0 -1
- package/native/dist/field.js +0 -1
- package/native/dist/icons.d.ts +8 -0
- package/native/dist/icons.js +4 -0
- package/native/dist/language-block.d.ts +31 -0
- package/native/dist/language-block.js +30 -0
- package/native/dist/list-group.d.ts +26 -0
- package/native/dist/list-group.js +27 -0
- package/native/dist/manage-position-block.d.ts +69 -0
- package/native/dist/manage-position-block.js +57 -0
- package/native/dist/notifications-block.d.ts +25 -0
- package/native/dist/notifications-block.js +14 -0
- package/native/dist/pickers.d.ts +13 -5
- package/native/dist/pickers.js +10 -6
- package/native/dist/position-block.d.ts +51 -0
- package/native/dist/position-block.js +21 -0
- package/native/dist/profile-block.d.ts +42 -0
- package/native/dist/profile-block.js +28 -0
- package/native/dist/reward-block.d.ts +83 -0
- package/native/dist/reward-block.js +35 -0
- package/native/dist/setting-header.d.ts +8 -0
- package/native/dist/setting-header.js +11 -0
- package/native/dist/setting-switch.d.ts +18 -0
- package/native/dist/setting-switch.js +17 -0
- package/native/dist/signals-block.d.ts +37 -0
- package/native/dist/signals-block.js +16 -0
- package/native/dist/sound-haptics-block.d.ts +39 -0
- package/native/dist/sound-haptics-block.js +21 -0
- package/native/dist/{swap-panel.d.ts → swap-panel-block.d.ts} +28 -9
- package/native/dist/{swap-panel.js → swap-panel-block.js} +24 -14
- package/native/dist/swap-parts.d.ts +14 -3
- package/native/dist/swap-parts.js +16 -1
- package/native/dist/swap-shared.d.ts +18 -6
- package/native/dist/swap-shared.js +3 -2
- package/native/dist/swap-sheet.d.ts +4 -4
- package/native/dist/swap-sheet.js +4 -4
- package/native/dist/swap-views.d.ts +1 -1
- package/native/dist/swap-views.js +11 -8
- package/native/dist/target-block.d.ts +83 -0
- package/native/dist/target-block.js +61 -0
- package/native/dist/token-action-block.d.ts +39 -0
- package/native/dist/token-action-block.js +20 -0
- package/native/dist/trade-history-detail-block.d.ts +59 -0
- package/native/dist/trade-history-detail-block.js +38 -0
- package/native/dist/trade-history-list-block.d.ts +44 -0
- package/native/dist/trade-history-list-block.js +29 -0
- package/native-fonts/README.md +1 -1
- package/og-fonts/README.md +1 -1
- package/package.json +246 -41
- package/react/README.md +1 -1
- package/react/dist/asset-balance-row.d.ts +19 -0
- package/react/dist/asset-balance-row.js +10 -0
- package/react/dist/bar-mark.d.ts +35 -0
- package/react/dist/bar-mark.js +21 -0
- package/react/dist/bar-pnl.d.ts +49 -0
- package/react/dist/bar-pnl.js +45 -0
- package/react/dist/blocks/account-block.d.ts +46 -0
- package/react/dist/blocks/account-block.js +27 -0
- package/react/dist/blocks/language-block.d.ts +32 -0
- package/react/dist/blocks/language-block.js +51 -0
- package/react/dist/blocks/manage-position-block.d.ts +67 -0
- package/react/dist/blocks/manage-position-block.js +28 -0
- package/react/dist/blocks/notifications-block.d.ts +23 -0
- package/react/dist/blocks/notifications-block.js +8 -0
- package/react/dist/{recipes → blocks}/pickers.d.ts +12 -4
- package/react/dist/{recipes → blocks}/pickers.js +9 -6
- package/react/dist/blocks/position-block.d.ts +49 -0
- package/react/dist/blocks/position-block.js +14 -0
- package/react/dist/blocks/profile-block.d.ts +48 -0
- package/react/dist/blocks/profile-block.js +15 -0
- package/react/dist/blocks/reward-block.d.ts +81 -0
- package/react/dist/blocks/reward-block.js +24 -0
- package/react/dist/blocks/screen-header.d.ts +9 -0
- package/react/dist/blocks/screen-header.js +12 -0
- package/react/dist/blocks/setting-switch.d.ts +10 -0
- package/react/dist/blocks/setting-switch.js +8 -0
- package/react/dist/blocks/signals-block.d.ts +35 -0
- package/react/dist/blocks/signals-block.js +15 -0
- package/react/dist/blocks/sound-haptics-block.d.ts +37 -0
- package/react/dist/blocks/sound-haptics-block.js +18 -0
- package/react/dist/{recipes → blocks}/swap/picker.d.ts +1 -1
- package/react/dist/{recipes → blocks}/swap/picker.js +4 -4
- package/react/dist/{recipes → blocks}/swap/settings.js +5 -7
- package/react/dist/{recipes → blocks}/swap/shared.d.ts +44 -6
- package/react/dist/{recipes → blocks}/swap/shared.js +25 -5
- package/react/dist/{recipes/swap-panel.d.ts → blocks/swap-panel-block.d.ts} +29 -9
- package/react/dist/{recipes/swap-panel.js → blocks/swap-panel-block.js} +22 -14
- package/react/dist/{recipes → blocks}/swap-sheet.d.ts +4 -4
- package/react/dist/{recipes → blocks}/swap-sheet.js +4 -4
- package/react/dist/blocks/target-block.d.ts +81 -0
- package/react/dist/blocks/target-block.js +65 -0
- package/react/dist/blocks/token-action-block.d.ts +37 -0
- package/react/dist/blocks/token-action-block.js +18 -0
- package/react/dist/{recipes → blocks}/trade-entry.js +2 -2
- package/react/dist/blocks/trade-history-detail-block.d.ts +58 -0
- package/react/dist/blocks/trade-history-detail-block.js +16 -0
- package/react/dist/blocks/trade-history-list-block.d.ts +43 -0
- package/react/dist/blocks/trade-history-list-block.js +21 -0
- package/react/dist/blocks.d.ts +20 -0
- package/react/dist/blocks.js +21 -0
- package/react/dist/field.d.ts +0 -2
- package/react/dist/field.js +0 -2
- package/react/dist/list-group.d.ts +26 -0
- package/react/dist/list-group.js +20 -0
- package/react/dist/styles.css +275 -8
- package/tokens/README.md +1 -1
- package/native/dist/recipes.d.ts +0 -45
- package/react/dist/recipes/activity-list.d.ts +0 -8
- package/react/dist/recipes/activity-list.js +0 -6
- package/react/dist/recipes/balance-card.d.ts +0 -6
- package/react/dist/recipes/balance-card.js +0 -5
- package/react/dist/recipes/code-window.d.ts +0 -4
- package/react/dist/recipes/code-window.js +0 -4
- package/react/dist/recipes.d.ts +0 -10
- package/react/dist/recipes.js +0 -11
- /package/react/dist/{recipes → blocks}/install-command.d.ts +0 -0
- /package/react/dist/{recipes → blocks}/install-command.js +0 -0
- /package/react/dist/{recipes → blocks}/market-row.d.ts +0 -0
- /package/react/dist/{recipes → blocks}/market-row.js +0 -0
- /package/react/dist/{recipes → blocks}/marketing-hero.d.ts +0 -0
- /package/react/dist/{recipes → blocks}/marketing-hero.js +0 -0
- /package/react/dist/{recipes → blocks}/swap/amount-card.d.ts +0 -0
- /package/react/dist/{recipes → blocks}/swap/amount-card.js +0 -0
- /package/react/dist/{recipes → blocks}/swap/settings.d.ts +0 -0
- /package/react/dist/{recipes → blocks}/trade-entry.d.ts +0 -0
|
@@ -5,6 +5,7 @@ import { useColors, useFills, useHIG, useMessages } from './provider.js';
|
|
|
5
5
|
import { Heading, Text } from './surface.js';
|
|
6
6
|
import { IconButton } from './button.js';
|
|
7
7
|
import { ChevronIcon } from './icons.js';
|
|
8
|
+
import { AnimatedNumberReadout } from './animated-number.js';
|
|
8
9
|
/** What a host surface supplies to the swap views: a sheet passes its backend's list so drags hand off to the sheet, and turns off the panel's own height animation. */
|
|
9
10
|
export const SwapHostContext = createContext({});
|
|
10
11
|
// Outline symbols drawn from plain views, like ./icons: decorative, so the control that holds them carries the name.
|
|
@@ -30,10 +31,12 @@ export function WalletIcon({ color }) { return _jsx(View, { ...hidden, style: {
|
|
|
30
31
|
export function LockIcon({ color }) { return _jsxs(View, { ...hidden, style: { width: 16, height: 16, alignItems: 'center', justifyContent: 'flex-end' }, children: [_jsx(View, { style: { width: 8, height: 7, borderTopLeftRadius: 4, borderTopRightRadius: 4, borderWidth: stroke, borderBottomWidth: 0, borderColor: color } }), _jsx(View, { style: { width: 12, height: 8, borderRadius: 2, borderWidth: stroke, borderColor: color } })] }); }
|
|
31
32
|
/** A doorway with an arrow leaving it. */
|
|
32
33
|
export function LeaveIcon({ color }) { return _jsxs(View, { ...hidden, style: { width: 20, height: 20, flexDirection: 'row', alignItems: 'center' }, children: [_jsx(View, { style: { width: 8, height: 14, borderWidth: stroke, borderRightWidth: 0, borderColor: color, borderTopLeftRadius: 3, borderBottomLeftRadius: 3 } }), _jsx(View, { style: { width: 9, height: stroke, borderRadius: stroke, backgroundColor: color, marginStart: -2 } }), _jsx(View, { style: { width: 5, height: 5, borderRightWidth: stroke, borderTopWidth: stroke, borderColor: color, marginStart: -5, transform: [{ rotate: '45deg' }] } })] }); }
|
|
33
|
-
/** Circular artwork from a URL, or the symbol's first letters when the host has none. */
|
|
34
|
+
/** Circular artwork from a URL or the host's own element, or the symbol's first letters when the host has none. */
|
|
34
35
|
export function TokenArt({ uri, symbol, size, ring }) {
|
|
35
36
|
const colors = useColors();
|
|
36
37
|
const shape = { width: size, height: size, borderRadius: size / 2, backgroundColor: colors.nested, ...(ring ? { borderWidth: 2, borderColor: ring } : {}) };
|
|
38
|
+
if (uri && typeof uri !== 'string')
|
|
39
|
+
return _jsx(View, { style: [shape, centre, { overflow: 'hidden' }], children: uri });
|
|
37
40
|
return uri ? _jsx(Image, { accessible: false, accessibilityIgnoresInvertColors: true, source: { uri }, style: shape }) : _jsx(View, { style: [shape, centre], children: symbol ? _jsx(Text, { accessible: false, maxFontSizeMultiplier: 1, style: { fontSize: size >= 40 ? 12 : 9, lineHeight: size >= 40 ? 16 : 12, fontWeight: '600', color: colors.muted }, children: symbol.slice(0, 3) }) : null });
|
|
38
41
|
}
|
|
39
42
|
/** Token artwork with its chain badge. */
|
|
@@ -64,3 +67,15 @@ export function SmallChevron({ color, trailing }) { const { direction } = useHIG
|
|
|
64
67
|
export function SwapSubview({ title, onBack, testID, children }) {
|
|
65
68
|
return _jsxs(View, { testID: testID, style: { gap: 16 }, children: [_jsx(SwapHeader, { title: title, onBack: onBack }), children] });
|
|
66
69
|
}
|
|
70
|
+
// A private-use character stands in for the number while a localized sentence is split around it.
|
|
71
|
+
const numberMark = '';
|
|
72
|
+
/** A localized sentence with one live number, such as the fee line. The sentence keeps its translated word order; the number inside it updates through `AnimatedNumberReadout`. `text` is the number as the sentence reads it, and is the whole accessible reading. Without a `value` (loading or unknown) the sentence is plain text around `text`. */
|
|
73
|
+
export function SwapNumberText({ template, text, value, options, formattedValue, suffix, align, testID }) {
|
|
74
|
+
const colors = useColors();
|
|
75
|
+
const { direction } = useHIG();
|
|
76
|
+
const type = { fontSize: 14, lineHeight: 19 }, small = { ...type, color: colors.muted, textAlign: align };
|
|
77
|
+
const reading = template(text), parts = template(numberMark).split(numberMark);
|
|
78
|
+
if (value == null || !Number.isFinite(value) || parts.length !== 2)
|
|
79
|
+
return _jsx(Text, { testID: testID, style: small, children: reading });
|
|
80
|
+
return _jsxs(View, { accessible: true, accessibilityLabel: reading, testID: testID, style: { direction, flexDirection: 'row', alignItems: 'center', justifyContent: align === 'right' ? 'flex-end' : 'flex-start' }, children: [parts[0] ? _jsx(Text, { accessible: false, style: small, children: parts[0] }) : null, _jsx(AnimatedNumberReadout, { value: value, options: options, formattedValue: formattedValue, suffix: suffix, tone: 'muted', style: type }), parts[1] ? _jsx(Text, { accessible: false, style: small, children: parts[1] }) : null] });
|
|
81
|
+
}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
+
import type React from 'react';
|
|
1
2
|
/** An asset on one chain. The host supplies every value; HIG formats and lays it out. */
|
|
3
|
+
/** A live figure in place of a line of text: formatted with `options` between `prefix` and `suffix`, and updated through `AnimatedNumberReadout` when `value` changes. For example `{value:234.68,options:{style:'currency',currency:'USD'},suffix:' available'}`. */
|
|
4
|
+
export interface SwapFigure {
|
|
5
|
+
value: number;
|
|
6
|
+
options?: Intl.NumberFormatOptions;
|
|
7
|
+
prefix?: string;
|
|
8
|
+
suffix?: string;
|
|
9
|
+
}
|
|
2
10
|
export interface SwapToken {
|
|
3
11
|
/** Unique per asset and chain, for example `${chainId}-${address}`. */
|
|
4
12
|
id: string;
|
|
@@ -7,18 +15,22 @@ export interface SwapToken {
|
|
|
7
15
|
/** Chain display name and identity. Two tokens on the same `chainId` swap; different chains bridge. */
|
|
8
16
|
chain: string;
|
|
9
17
|
chainId: string | number;
|
|
10
|
-
/**
|
|
11
|
-
icon?:
|
|
12
|
-
chainIcon?:
|
|
18
|
+
/** Artwork: an image URL, or the host's own element (an SVG component, say), which fills the disc. A missing token icon falls back to the symbol's first letters. */
|
|
19
|
+
icon?: SwapArtwork;
|
|
20
|
+
chainIcon?: SwapArtwork;
|
|
21
|
+
/** Most decimal places a token amount may be typed with, for example 6 for USDC. Unlimited when omitted. Dollars always stop at two. */
|
|
22
|
+
decimals?: number;
|
|
13
23
|
/** Holdings in token units, when the host knows them. Enables Max, Test and the balance check. */
|
|
14
24
|
balance?: number | null;
|
|
15
25
|
/** USD per unit, when the host knows it. Enables the dollar and unit conversion. */
|
|
16
26
|
price?: number | null;
|
|
17
|
-
/** Presents the side as an account rather than a token: this line (for example `$22.72 available`) sits under the name, the artwork is a single disc, and only Max is offered. */
|
|
18
|
-
caption?: string;
|
|
27
|
+
/** Presents the side as an account rather than a token: this line (for example `$22.72 available`, as text or as a `SwapFigure` that updates in place) sits under the name, the artwork is a single disc, and only Max is offered. */
|
|
28
|
+
caption?: string | SwapFigure;
|
|
19
29
|
/** Extra text matched by the picker search, such as the contract address. */
|
|
20
30
|
keywords?: string;
|
|
21
31
|
}
|
|
32
|
+
/** An image URL, or an element the host draws. */
|
|
33
|
+
export type SwapArtwork = string | React.ReactElement;
|
|
22
34
|
export interface SwapChain {
|
|
23
35
|
chainId: string | number;
|
|
24
36
|
name: string;
|
|
@@ -48,7 +60,7 @@ export declare function sanitizeAmount(raw: string): string;
|
|
|
48
60
|
/** Token units shown in the active denomination. Dollars floor to the cent so Max never resolves to more than the balance. */
|
|
49
61
|
export declare function unitsToEntry(units: number, mode: SwapDenomination, price: number): string;
|
|
50
62
|
/** Applies one keypad key (`0`–`9`, `.`, `back`) to an amount string. Dollars stop at two decimals. */
|
|
51
|
-
export declare function applyAmountKey(current: string, key: string, mode: SwapDenomination): string;
|
|
63
|
+
export declare function applyAmountKey(current: string, key: string, mode: SwapDenomination, decimals?: number): string;
|
|
52
64
|
/** Case-insensitive substring or in-order subsequence match. */
|
|
53
65
|
export declare function fuzzyMatch(query: string, text: string): boolean;
|
|
54
66
|
/** A slippage fraction as a percent string: 0.005 is `0.5%`. */
|
|
@@ -24,7 +24,7 @@ export function unitsToEntry(units, mode, price) {
|
|
|
24
24
|
return price > 0 ? String(Math.floor(units * price * 100) / 100) : '0';
|
|
25
25
|
}
|
|
26
26
|
/** Applies one keypad key (`0`–`9`, `.`, `back`) to an amount string. Dollars stop at two decimals. */
|
|
27
|
-
export function applyAmountKey(current, key, mode) {
|
|
27
|
+
export function applyAmountKey(current, key, mode, decimals) {
|
|
28
28
|
if (key === 'back')
|
|
29
29
|
return current.length <= 1 ? '0' : current.slice(0, -1);
|
|
30
30
|
if (key === '.')
|
|
@@ -33,7 +33,8 @@ export function applyAmountKey(current, key, mode) {
|
|
|
33
33
|
return current;
|
|
34
34
|
const next = sanitizeAmount(current === '0' ? key : current + key);
|
|
35
35
|
const dot = next.indexOf('.');
|
|
36
|
-
|
|
36
|
+
const limit = mode === 'usd' ? 2 : decimals;
|
|
37
|
+
return limit !== undefined && dot !== -1 && next.length - dot - 1 > limit ? current : next;
|
|
37
38
|
}
|
|
38
39
|
/** Case-insensitive substring or in-order subsequence match. */
|
|
39
40
|
export function fuzzyMatch(query, text) {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { type
|
|
3
|
-
export interface SwapSheetProps extends
|
|
2
|
+
import { type SwapPanelBlockProps } from './swap-panel-block.js';
|
|
3
|
+
export interface SwapSheetProps extends SwapPanelBlockProps {
|
|
4
4
|
open: boolean;
|
|
5
5
|
onOpenChange: (open: boolean) => void;
|
|
6
6
|
/** Accessible name of the sheet. */
|
|
7
7
|
title: string;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* SwapPanelBlock presented in the gesture sheet. Pickers and settings push inside the same sheet, which resizes to the view
|
|
11
11
|
* on show. A back press or a dismiss gesture pops a pushed view first and closes the sheet only from the main form;
|
|
12
|
-
* closing always returns to the main form. Needs the optional gesture-sheet backend, which `
|
|
12
|
+
* closing always returns to the main form. Needs the optional gesture-sheet backend, which `blocks` does not load.
|
|
13
13
|
*/
|
|
14
14
|
export declare function SwapSheet({ open, onOpenChange, title, view: viewProp, onViewChange, style, ...panel }: SwapSheetProps): React.JSX.Element;
|
|
@@ -2,11 +2,11 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { useEffect, useMemo, useState } from 'react';
|
|
3
3
|
import { BottomSheetFlatList } from '@gorhom/bottom-sheet';
|
|
4
4
|
import { GestureSheet } from './gesture-sheet.js';
|
|
5
|
-
import { SwapHostContext,
|
|
5
|
+
import { SwapHostContext, SwapPanelBlock, swapParentView } from './swap-panel-block.js';
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* SwapPanelBlock presented in the gesture sheet. Pickers and settings push inside the same sheet, which resizes to the view
|
|
8
8
|
* on show. A back press or a dismiss gesture pops a pushed view first and closes the sheet only from the main form;
|
|
9
|
-
* closing always returns to the main form. Needs the optional gesture-sheet backend, which `
|
|
9
|
+
* closing always returns to the main form. Needs the optional gesture-sheet backend, which `blocks` does not load.
|
|
10
10
|
*/
|
|
11
11
|
export function SwapSheet({ open, onOpenChange, title, view: viewProp, onViewChange, style, ...panel }) {
|
|
12
12
|
const [ownView, keepView] = useState('main');
|
|
@@ -22,5 +22,5 @@ export function SwapSheet({ open, onOpenChange, title, view: viewProp, onViewCha
|
|
|
22
22
|
return false; show(swapParentView(view)); return true; };
|
|
23
23
|
return _jsx(GestureSheet, { open: open, onOpenChange: next => { if (!next && leave())
|
|
24
24
|
return; onOpenChange(next); }, title: title, contentMode: 'custom', enableDynamicSizing: true, keyboardBehavior: 'interactive', onHardwareBackPress: () => { if (!leave())
|
|
25
|
-
onOpenChange(false); return true; }, children: _jsx(SwapHostContext.Provider, { value: host, children: _jsx(
|
|
25
|
+
onOpenChange(false); return true; }, children: _jsx(SwapHostContext.Provider, { value: host, children: _jsx(SwapPanelBlock, { ...panel, view: view, onViewChange: show, style: [{ paddingHorizontal: 12, paddingBottom: 16 }, style] }) }) });
|
|
26
26
|
}
|
|
@@ -20,7 +20,7 @@ export interface SwapPickerProps {
|
|
|
20
20
|
onRecipientChange?: (address: string) => void;
|
|
21
21
|
onScanRecipient?: () => void;
|
|
22
22
|
}
|
|
23
|
-
/** The panel's pushed picker view: the sub-view header over the From or To picker
|
|
23
|
+
/** The panel's pushed picker view: the sub-view header over the From or To picker block. Choosing a token pops back; the Generate address switch does not. */
|
|
24
24
|
export declare function SwapPicker({ side, onBack, selected, onSelect, wallet, onConnect, onDisconnect, receiving, onReceivingChange, recipient, onRecipientChange, onScanRecipient, ...list }: SwapPickerProps): React.JSX.Element;
|
|
25
25
|
export type SwapSettingsView = 'settings' | 'slippage' | 'fees';
|
|
26
26
|
export interface SwapSettingsProps {
|
|
@@ -7,16 +7,17 @@ import { Text } from './surface.js';
|
|
|
7
7
|
import { Field, Input } from './field.js';
|
|
8
8
|
import { SegmentedControl } from './radio-group.js';
|
|
9
9
|
import { ChevronIcon } from './icons.js';
|
|
10
|
+
import { AnimatedNumberReadout } from './animated-number.js';
|
|
10
11
|
import { SwapSubview } from './swap-parts.js';
|
|
11
|
-
import {
|
|
12
|
+
import { FromPickerBlock, ToPickerBlock } from './pickers.js';
|
|
12
13
|
import { formatPercent, shortAddress, slippagePresets } from './swap-shared.js';
|
|
13
|
-
/** The panel's pushed picker view: the sub-view header over the From or To picker
|
|
14
|
+
/** The panel's pushed picker view: the sub-view header over the From or To picker block. Choosing a token pops back; the Generate address switch does not. */
|
|
14
15
|
export function SwapPicker({ side, onBack, selected, onSelect, wallet, onConnect, onDisconnect, receiving, onReceivingChange, recipient, onRecipientChange, onScanRecipient, ...list }) {
|
|
15
16
|
const t = useMessages();
|
|
16
17
|
const choose = (token) => { onSelect(token); onBack(); };
|
|
17
18
|
return _jsx(SwapSubview, { title: side === 'from' ? t.swapFrom : t.swapTo, onBack: onBack, testID: `swap-picker-${side}`, children: side === 'from'
|
|
18
|
-
? _jsx(
|
|
19
|
-
: _jsx(
|
|
19
|
+
? _jsx(FromPickerBlock, { ...list, selected: selected, onSelect: choose, wallet: wallet ?? { connected: false }, onConnect: onConnect, onDisconnect: onDisconnect, generateAddress: !!receiving, onGenerateAddressChange: onReceivingChange })
|
|
20
|
+
: _jsx(ToPickerBlock, { ...list, selected: selected, onSelect: choose, address: recipient, onAddressChange: onRecipientChange, addressPlaceholder: wallet?.address ? shortAddress(wallet.address) : undefined, onScan: onScanRecipient }) });
|
|
20
21
|
}
|
|
21
22
|
/** The settings views. Slippage and the fee breakdown push from the settings list, and Back returns to it. */
|
|
22
23
|
export function SwapSettings({ view, onViewChange, onBack, denomination, onDenominationChange, slippage, onSlippageChange, fee, fees, quoteLoading, children }) {
|
|
@@ -29,9 +30,11 @@ export function SwapSettings({ view, onViewChange, onBack, denomination, onDenom
|
|
|
29
30
|
const title = view === 'slippage' ? t.swapSlippageTitle : view === 'fees' ? t.swapFees : t.swapSettings;
|
|
30
31
|
const feeText = quoteLoading ? '…' : fee != null ? usd(fee) : '—';
|
|
31
32
|
const preset = slippagePresets.find(value => Math.abs(value - slippage) < 1e-9);
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
const
|
|
33
|
+
const usdOptions = { style: 'currency', currency: 'USD' }, feeKnown = !quoteLoading && fee != null;
|
|
34
|
+
// `value` is the accessible reading; `live` is the same value drawn as a number that updates in place.
|
|
35
|
+
const row = (name, value, target, live) => _jsxs(Pressable, { accessibilityRole: 'button', accessibilityLabel: `${name}: ${value}`, testID: `swap-setting-${target}`, onPress: () => onViewChange(target), style: ({ pressed }) => ({ direction, flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', gap: 12, minHeight: 48, paddingVertical: 8, paddingHorizontal: 16, borderRadius: 9999, backgroundColor: pressed ? fills.raised : fills.well }), children: [_jsx(Text, { style: { fontWeight: '600' }, children: name }), _jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: 6 }, children: [live ?? _jsx(Text, { style: { color: colors.muted }, children: value }), _jsx(View, { style: { transform: [{ rotate: direction === 'rtl' ? '90deg' : '-90deg' }] }, children: _jsx(ChevronIcon, { color: colors.muted }) })] })] });
|
|
36
|
+
const feeRow = (name, amount, total) => _jsxs(View, { style: { flexDirection: 'row', justifyContent: 'space-between', gap: 12, paddingTop: total ? 12 : 0 }, children: [_jsx(Text, { style: { color: total ? colors.text : colors.muted, fontWeight: total ? '600' : '400' }, children: name }), amount != null ? _jsx(AnimatedNumberReadout, { testID: total ? 'swap-fee-total' : undefined, value: amount, options: usdOptions, style: { fontWeight: total ? '600' : '400' } }) : _jsx(Text, { testID: total ? 'swap-fee-total' : undefined, style: { fontWeight: total ? '600' : '400' }, children: feeText })] }, name);
|
|
37
|
+
const slippageRow = onSlippageChange ? row(t.swapSlippageTitle, formatPercent(slippage), 'slippage', _jsx(AnimatedNumberReadout, { value: slippage * 100, formattedValue: formatPercent(slippage).slice(0, -1), suffix: '%', tone: 'muted' })) : null, feesRow = row(t.swapFees, feeText, 'fees', feeKnown ? _jsx(AnimatedNumberReadout, { value: fee, options: usdOptions, tone: 'muted' }) : undefined);
|
|
35
38
|
return _jsxs(SwapSubview, { title: title, onBack: onBack, testID: `swap-view-${view}`, children: [view === 'settings' ? _jsxs(View, { style: { gap: 12 }, children: [onDenominationChange && _jsx(SegmentedControl, { label: t.swapDenomination, options: [{ value: 'usd', label: t.swapDollars }, { value: 'token', label: t.swapUnits }], value: denomination, onValueChange: value => onDenominationChange(value) }), slippageRow, feesRow, children] }) : null, view === 'slippage' && onSlippageChange ? _jsxs(View, { style: { gap: 12 }, children: [_jsx(SegmentedControl, { label: t.swapSlippageTitle, options: slippagePresets.map(value => ({ value: String(value), label: formatPercent(value) })), value: preset === undefined ? '' : String(preset), onValueChange: value => { setCustom(null); onSlippageChange(Number(value)); } }), _jsx(Field, { label: t.swapSlippageCustom, children: _jsx(Input, { keyboardType: 'decimal-pad', value: custom ?? String(Number((slippage * 100).toFixed(4))), onChangeText: entered => { const raw = entered.replace(/[^0-9.]/g, ''); setCustom(raw); const percent = Number.parseFloat(raw); if (Number.isFinite(percent) && percent >= 0 && percent <= 50)
|
|
36
|
-
onSlippageChange(percent / 100); } }) })] }) : null, view === 'fees' ? _jsxs(View, { style: { gap: 12 }, children: [fees?.map(item => feeRow(item.label,
|
|
39
|
+
onSlippageChange(percent / 100); } }) })] }) : null, view === 'fees' ? _jsxs(View, { style: { gap: 12 }, children: [fees?.map(item => feeRow(item.label, item.usd)), feeRow(t.swapFeeTotal, feeKnown ? fee : null, true)] }) : null] });
|
|
37
40
|
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/** What the target does: close in profit, or cap the loss. */
|
|
3
|
+
export type TargetKind = 'take-profit' | 'stop-loss';
|
|
4
|
+
/** How the target is expressed: profit or loss in dollars, a price, or a share of the position. */
|
|
5
|
+
export type TargetUnit = 'dollar' | 'price' | 'percent';
|
|
6
|
+
/** The three prices on the bar. */
|
|
7
|
+
export type TargetPrice = 'entry' | 'trigger';
|
|
8
|
+
/** Every trading word of the block. HIG's built-in strings hold no trading terms, so the host supplies them, translated; only Cancel has a built-in default. */
|
|
9
|
+
export interface TargetBlockLabels {
|
|
10
|
+
/** Heading: Take Profit, Stop Loss. */
|
|
11
|
+
title: string;
|
|
12
|
+
/** The confirming action: Set Take Profit. */
|
|
13
|
+
submit: string;
|
|
14
|
+
/** Defaults to the built-in Cancel. */
|
|
15
|
+
cancel?: string;
|
|
16
|
+
entry: string;
|
|
17
|
+
/** The price the order triggers at: If triggered. */
|
|
18
|
+
trigger: string;
|
|
19
|
+
/** Name of the unit control. */
|
|
20
|
+
unit: string;
|
|
21
|
+
units: Record<TargetUnit, string>;
|
|
22
|
+
/** The row that opens the host's own entry: Custom. */
|
|
23
|
+
custom: string;
|
|
24
|
+
/** Accessible name of the info button that shows `note`: How this order fills. Without it the note is always shown. */
|
|
25
|
+
info?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface TargetBlockProps {
|
|
28
|
+
kind: TargetKind;
|
|
29
|
+
labels: TargetBlockLabels;
|
|
30
|
+
/** Title of the price card, the position the target belongs to: `BTC · Long 40×`. */
|
|
31
|
+
position?: string;
|
|
32
|
+
/** Trailing text of the price card, the order the target places: Take-limit, Stop-market. */
|
|
33
|
+
orderType?: string;
|
|
34
|
+
/** One sentence about how the order fills. With `labels.info` it opens in a popover from an info button on the trailing edge of the header; otherwise it is always shown under the headline figure. */
|
|
35
|
+
note?: string;
|
|
36
|
+
entry: number;
|
|
37
|
+
/** Price the order triggers at. Defaults to `value` when the unit is `price`; otherwise unknown until the host supplies it. */
|
|
38
|
+
trigger?: number | null;
|
|
39
|
+
unit: TargetUnit;
|
|
40
|
+
/** Units offered, in order. Defaults to all three; one unit hides the control. */
|
|
41
|
+
units?: readonly TargetUnit[];
|
|
42
|
+
onUnitChange?: (unit: TargetUnit) => void;
|
|
43
|
+
/** The target in the current unit: signed dollars (2, -0.5), a price, or a signed fraction (0.05 reads +5%). `null` reads as unknown and disables the confirming action. */
|
|
44
|
+
value: number | null;
|
|
45
|
+
onValueChange?: (value: number) => void;
|
|
46
|
+
/** Quick choices in the current unit. The one equal to `value` is shown selected. */
|
|
47
|
+
presets?: readonly number[];
|
|
48
|
+
/** Shows the Custom row; the host opens its own entry. */
|
|
49
|
+
onCustom?: () => void;
|
|
50
|
+
/** Format of prices. Defaults to US dollars. */
|
|
51
|
+
priceOptions?: Intl.NumberFormatOptions;
|
|
52
|
+
/** Set true to draw the prices inside a card: a surface fill, padding and radius. By default the title row, bar and readouts sit directly on the screen. */
|
|
53
|
+
surface?: boolean;
|
|
54
|
+
onSubmit: () => void;
|
|
55
|
+
/** Defaults to disabled while `value` is unknown. */
|
|
56
|
+
submitDisabled?: boolean;
|
|
57
|
+
busy?: boolean;
|
|
58
|
+
/** Shows Cancel beside the confirming action. */
|
|
59
|
+
onCancel?: () => void;
|
|
60
|
+
/** Shows Back on the leading edge of the header. */
|
|
61
|
+
onBack?: () => void;
|
|
62
|
+
/** A control on the trailing edge of the header, usually an IconButton. It takes the place of the info button, and the note is then always shown. */
|
|
63
|
+
headerAction?: React.ReactNode;
|
|
64
|
+
testID?: string;
|
|
65
|
+
}
|
|
66
|
+
/** Number format of a target in a unit. Dollars and percents carry their sign; `short` drops the cents of a whole dollar amount, for a preset. */
|
|
67
|
+
export declare function targetFormat(unit: TargetUnit, priceOptions?: Intl.NumberFormatOptions, short?: number): Intl.NumberFormatOptions;
|
|
68
|
+
/**
|
|
69
|
+
* Where each known price sits on the bar, as a fraction of its width from the low-price edge, the prices in price order, and
|
|
70
|
+
* the stretch (`from` to `to`) between them: the whole bar, from entry to the trigger.
|
|
71
|
+
* Without a trigger there is no stretch.
|
|
72
|
+
*/
|
|
73
|
+
export declare function targetLayout({ entry, trigger }: {
|
|
74
|
+
entry: number;
|
|
75
|
+
trigger?: number | null;
|
|
76
|
+
}): {
|
|
77
|
+
positions: Partial<Record<TargetPrice, number>>;
|
|
78
|
+
order: TargetPrice[];
|
|
79
|
+
from: number;
|
|
80
|
+
to: number;
|
|
81
|
+
};
|
|
82
|
+
/** A take profit or a stop loss on one position as a screen: the target as the headline figure, a price card whose bar shows how far the price is from the trigger, the unit, the host's quick choices, and the confirming action. The bar is decorative; each price reads its label and value. */
|
|
83
|
+
export declare function TargetBlock({ kind, labels, position, orderType, note, entry, trigger, unit, units, onUnitChange, value, onValueChange, presets, onCustom, priceOptions, surface, onSubmit, submitDisabled, busy, onCancel, onBack, headerAction, testID }: TargetBlockProps): React.JSX.Element;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { Pressable, View } from 'react-native';
|
|
4
|
+
import { formatNumber } from '@bloxwap/hig/contracts';
|
|
5
|
+
import { useColors, useFills, useHIG, useMessages } from './provider.js';
|
|
6
|
+
import { Surface, Text } from './surface.js';
|
|
7
|
+
import { Button, IconButton } from './button.js';
|
|
8
|
+
import { SegmentedControl } from './radio-group.js';
|
|
9
|
+
import { ChevronIcon, SeverityIcon } from './icons.js';
|
|
10
|
+
import { AnimatedNumberReadout } from './animated-number.js';
|
|
11
|
+
import { formatNumberReadout } from './animated-number-model.js';
|
|
12
|
+
const usd = { style: 'currency', currency: 'USD' };
|
|
13
|
+
const allUnits = ['dollar', 'price', 'percent'];
|
|
14
|
+
const hidden = { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants' };
|
|
15
|
+
const known = (value) => value != null && Number.isFinite(value);
|
|
16
|
+
/** Number format of a target in a unit. Dollars and percents carry their sign; `short` drops the cents of a whole dollar amount, for a preset. */
|
|
17
|
+
export function targetFormat(unit, priceOptions = usd, short) {
|
|
18
|
+
if (unit === 'price')
|
|
19
|
+
return priceOptions;
|
|
20
|
+
if (unit === 'percent')
|
|
21
|
+
return { style: 'percent', maximumFractionDigits: 2, signDisplay: 'exceptZero' };
|
|
22
|
+
return { ...usd, signDisplay: 'exceptZero', ...(short !== undefined && Number.isInteger(short) ? { maximumFractionDigits: 0 } : null) };
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Where each known price sits on the bar, as a fraction of its width from the low-price edge, the prices in price order, and
|
|
26
|
+
* the stretch (`from` to `to`) between them: the whole bar, from entry to the trigger.
|
|
27
|
+
* Without a trigger there is no stretch.
|
|
28
|
+
*/
|
|
29
|
+
export function targetLayout({ entry, trigger }) {
|
|
30
|
+
const values = {};
|
|
31
|
+
if (known(entry))
|
|
32
|
+
values.entry = entry;
|
|
33
|
+
if (known(trigger))
|
|
34
|
+
values.trigger = trigger;
|
|
35
|
+
const kinds = Object.keys(values), prices = kinds.map(kind => values[kind]);
|
|
36
|
+
if (!kinds.length)
|
|
37
|
+
return { positions: {}, order: [], from: 0.5, to: 0.5 };
|
|
38
|
+
const low = Math.min(...prices), span = Math.max(...prices) - low;
|
|
39
|
+
const positions = {};
|
|
40
|
+
for (const kind of kinds)
|
|
41
|
+
positions[kind] = span > 0 ? (values[kind] - low) / span : 0.5;
|
|
42
|
+
const rank = { entry: 0, trigger: 1 };
|
|
43
|
+
const order = [...kinds].sort((a, b) => values[a] - values[b] || rank[a] - rank[b]);
|
|
44
|
+
const start = positions.entry, end = positions.trigger;
|
|
45
|
+
return start === undefined || end === undefined ? { positions, order, from: 0.5, to: 0.5 } : { positions, order, from: Math.min(start, end), to: Math.max(start, end) };
|
|
46
|
+
}
|
|
47
|
+
/** A take profit or a stop loss on one position as a screen: the target as the headline figure, a price card whose bar shows how far the price is from the trigger, the unit, the host's quick choices, and the confirming action. The bar is decorative; each price reads its label and value. */
|
|
48
|
+
export function TargetBlock({ kind, labels, position, orderType, note, entry, trigger, unit, units = allUnits, onUnitChange, value, onValueChange, presets = [], onCustom, priceOptions = usd, surface = false, onSubmit, submitDisabled, busy, onCancel, onBack, headerAction, testID }) {
|
|
49
|
+
const PriceCard = surface ? Surface : View;
|
|
50
|
+
const colors = useColors(), fills = useFills(), t = useMessages(), { direction, locale } = useHIG();
|
|
51
|
+
const [open, setOpen] = useState(false);
|
|
52
|
+
const info = note && labels.info && !headerAction ? labels.info : undefined;
|
|
53
|
+
const target = trigger !== undefined ? trigger : unit === 'price' ? value : null;
|
|
54
|
+
const { positions, order, from, to } = targetLayout({ entry, trigger: target });
|
|
55
|
+
const prices = { entry, trigger: target };
|
|
56
|
+
const stop = kind === 'stop-loss', tone = stop ? colors.negative : colors.positive, intent = stop ? 'destructive' : 'primary';
|
|
57
|
+
const triggerLeads = (positions.trigger ?? 0) < (positions.entry ?? 0);
|
|
58
|
+
const align = (index) => order.length > 1 && index === order.length - 1 ? 'flex-end' : order.length === 3 && index === 1 ? 'center' : 'flex-start';
|
|
59
|
+
const part = (grow) => ({ flexGrow: grow, flexShrink: 1, flexBasis: 0, backgroundColor: fills.raised });
|
|
60
|
+
return _jsxs(View, { testID: testID, style: { padding: 16 }, children: [_jsxs(View, { testID: 'target-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: 'target-back', onPress: onBack, children: _jsx(View, { style: { transform: [{ rotate: direction === 'rtl' ? '-90deg' : '90deg' }] }, children: _jsx(ChevronIcon, { color: colors.text }) }) }) : null }), _jsx(Text, { testID: 'target-title', 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: info ? _jsx(IconButton, { intent: 'ghost', label: info, suppressFeedback: true, testID: 'target-info', accessibilityState: { expanded: open }, onPress: () => setOpen(!open), children: _jsx(SeverityIcon, { kind: 'info', color: colors.text }) }) : headerAction })] }), _jsx(View, { style: { alignItems: 'center', marginTop: 16 }, children: _jsx(AnimatedNumberReadout, { testID: 'target-amount', value: value, options: targetFormat(unit, priceOptions), style: { fontSize: 44, lineHeight: 50, fontWeight: '700', letterSpacing: -0.9, textAlign: 'center' } }) }), note && !info ? _jsx(Text, { testID: 'target-note', style: { color: colors.muted, fontSize: 14, lineHeight: 21, textAlign: 'center', marginTop: 16 }, children: note }) : null, _jsxs(PriceCard, { testID: 'target-prices', style: { gap: 12, marginTop: 16, minWidth: 0 }, children: [position || orderType ? _jsxs(View, { style: { flexDirection: 'row', alignItems: 'baseline', justifyContent: 'space-between', gap: 12 }, children: [position ? _jsx(Text, { testID: 'target-position', accessibilityRole: 'header', style: { fontSize: 16, lineHeight: 24, fontWeight: '600', flexShrink: 1 }, children: position }) : _jsx(View, {}), orderType ? _jsx(Text, { testID: 'target-order-type', style: { color: colors.muted, fontSize: 14, lineHeight: 21, flexShrink: 1 }, children: orderType }) : null] }) : null, _jsxs(View, { ...hidden, testID: 'target-bar', style: { flexDirection: 'row', height: 24, borderRadius: 8, overflow: 'hidden' }, children: [_jsx(View, { style: part(from) }), to > from ? _jsx(View, { testID: 'target-move', style: { flexGrow: to - from, flexShrink: 1, flexBasis: 0, minWidth: 6, backgroundColor: tone, borderStartWidth: 3, borderEndWidth: 3, borderStartColor: triggerLeads ? tone : colors.text, borderEndColor: triggerLeads ? colors.text : tone } }) : null, _jsx(View, { style: part(1 - to) })] }), _jsx(View, { style: { flexDirection: 'row', justifyContent: 'space-between', gap: 12 }, children: order.map((price, index) => _jsxs(View, { accessible: true, accessibilityLabel: `${labels[price]}, ${formatNumberReadout(prices[price], locale, priceOptions).text}`, testID: `target-${price}`, style: { alignItems: align(index), flexShrink: 1, minWidth: 0 }, children: [_jsx(View, { ...hidden, children: _jsx(AnimatedNumberReadout, { value: prices[price], options: priceOptions, tone: price === 'trigger' ? (stop ? 'negative' : 'positive') : 'text', style: { fontSize: 16, lineHeight: 24, fontWeight: '600' } }) }), _jsx(Text, { ...hidden, numberOfLines: 1, style: { color: colors.muted, fontSize: 12, lineHeight: 16 }, children: labels[price] })] }, price)) })] }), units.length > 1 ? _jsx(View, { testID: 'target-units', style: { marginTop: 16 }, children: _jsx(SegmentedControl, { label: labels.unit, options: units.map(option => ({ value: option, label: labels.units[option] })), value: unit, onValueChange: next => onUnitChange?.(next) }) }) : null, onCustom ? _jsxs(Pressable, { testID: 'target-custom', accessibilityRole: 'button', onPress: onCustom, style: ({ pressed }) => ({ flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', gap: 12, minHeight: 48, paddingHorizontal: 16, borderRadius: 9999, backgroundColor: pressed ? fills.raised : fills.well, marginTop: 16 }), children: [_jsx(Text, { numberOfLines: 1, style: { flexShrink: 1, fontSize: 16, lineHeight: 24, fontWeight: '600', color: colors.text }, children: labels.custom }), _jsx(View, { ...hidden, style: { transform: [{ rotate: direction === 'rtl' ? '90deg' : '-90deg' }] }, children: _jsx(ChevronIcon, { color: colors.muted }) })] }) : null, presets.length > 0 ? _jsx(View, { testID: 'target-presets', style: { direction, flexDirection: 'row', gap: 8, marginTop: 16 }, children: presets.map(preset => _jsx(Button, { testID: `target-preset-${preset}`, intent: preset === value ? intent : 'secondary', accessibilityState: { selected: preset === value }, onPress: () => onValueChange?.(preset), style: { flex: 1, alignSelf: 'auto', paddingHorizontal: 8 }, children: formatNumber(preset, locale, targetFormat(unit, priceOptions, preset)) }, preset)) }) : null, info && open ? _jsx(Pressable, { testID: 'target-popover-dismiss', ...hidden, onPress: () => setOpen(false), style: { position: 'absolute', top: 0, bottom: 0, left: 0, right: 0, zIndex: 1 } }) : null, info && open ? _jsx(View, { testID: 'target-popover', accessibilityLiveRegion: 'polite', style: { position: 'absolute', top: 64, ...(direction === 'rtl' ? { left: 16 } : { right: 16 }), maxWidth: 280, zIndex: 2, padding: 12, borderRadius: 14, backgroundColor: colors.nested }, children: _jsx(Text, { testID: 'target-note', style: { color: colors.text, fontSize: 14, lineHeight: 21 }, children: note }) }) : null, _jsxs(View, { testID: 'target-actions', style: { direction, flexDirection: 'row', gap: 8, marginTop: 16 }, children: [onCancel ? _jsx(Button, { testID: 'target-cancel', intent: 'secondary', onPress: onCancel, style: { flex: 1, alignSelf: 'auto' }, children: labels.cancel ?? t.cancel }) : null, _jsx(Button, { testID: 'target-submit', intent: intent, disabled: submitDisabled ?? value === null, busy: busy, onPress: onSubmit, style: { flex: 1, alignSelf: 'auto' }, children: labels.submit })] })] });
|
|
61
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { HIGMessages } from '@bloxwap/hig/contracts/messages';
|
|
3
|
+
import { type BarMarkElement } from './bar-mark.js';
|
|
4
|
+
export type { BarMarkElement } from './bar-mark.js';
|
|
5
|
+
/** The actions HIG names itself. */
|
|
6
|
+
export type TokenActionId = 'send' | 'receive' | 'stake' | 'unstake';
|
|
7
|
+
export interface TokenAction {
|
|
8
|
+
/** 'send' | 'receive' | 'stake' | 'unstake' take a built-in label; any other id needs `label`. */
|
|
9
|
+
id: TokenActionId | (string & {});
|
|
10
|
+
label?: string;
|
|
11
|
+
onSelect: () => void;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
/** Defaults to `secondary`: the actions are equal choices. */
|
|
14
|
+
intent?: 'primary' | 'secondary' | 'destructive';
|
|
15
|
+
}
|
|
16
|
+
export interface TokenActionBlockProps {
|
|
17
|
+
/** Heading, usually the ticker: HYPE. */
|
|
18
|
+
symbol: string;
|
|
19
|
+
/** Title of the assets bar: Hyperliquid. */
|
|
20
|
+
name: string;
|
|
21
|
+
/** Total holding in dollars, on the trailing edge of the assets bar. Defaults to the sum of the asset values; null reads as unknown. */
|
|
22
|
+
value?: number | null;
|
|
23
|
+
/** Where the token is held: Staked, Core, Paper. */
|
|
24
|
+
assets: readonly BarMarkElement[];
|
|
25
|
+
/** The chains the token sits on. */
|
|
26
|
+
chains: readonly BarMarkElement[];
|
|
27
|
+
/** Title of the chains bar. Defaults to the built-in "Chains". */
|
|
28
|
+
chainsTitle?: string;
|
|
29
|
+
actions: readonly TokenAction[];
|
|
30
|
+
/** Shows Back on the leading edge of the header. */
|
|
31
|
+
onBack?: () => void;
|
|
32
|
+
/** A control on the trailing edge of the header, usually an IconButton. */
|
|
33
|
+
headerAction?: React.ReactNode;
|
|
34
|
+
testID?: string;
|
|
35
|
+
}
|
|
36
|
+
/** An action's text: its own `label`, else the built-in name of its id, else the id. */
|
|
37
|
+
export declare const tokenActionLabel: (action: TokenAction, messages: Partial<HIGMessages>) => string;
|
|
38
|
+
/** One token as a screen: a header, where it is held, which chains it sits on, then what the user can do with it. */
|
|
39
|
+
export declare function TokenActionBlock({ symbol, name, value, assets, chains, chainsTitle, actions, onBack, headerAction, testID }: TokenActionBlockProps): React.JSX.Element;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import { formatNumber } from '@bloxwap/hig/contracts';
|
|
4
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
5
|
+
import { useColors, useHIG, useMessages } from './provider.js';
|
|
6
|
+
import { Text } from './surface.js';
|
|
7
|
+
import { Button, IconButton } from './button.js';
|
|
8
|
+
import { ChevronIcon } from './icons.js';
|
|
9
|
+
import { AnimatedNumberReadout } from './animated-number.js';
|
|
10
|
+
import { BarMark } from './bar-mark.js';
|
|
11
|
+
const usd = { style: 'currency', currency: 'USD' };
|
|
12
|
+
const held = (value) => Number.isFinite(value) && value > 0;
|
|
13
|
+
/** An action's text: its own `label`, else the built-in name of its id, else the id. */
|
|
14
|
+
export const tokenActionLabel = (action, messages) => action.label ?? (action.id === 'send' ? messages.swapActionSend ?? en.swapActionSend : action.id === 'receive' ? messages.receive ?? en.receive : action.id === 'stake' ? messages.stake ?? en.stake : action.id === 'unstake' ? messages.unstake ?? en.unstake : action.id);
|
|
15
|
+
/** One token as a screen: a header, where it is held, which chains it sits on, then what the user can do with it. */
|
|
16
|
+
export function TokenActionBlock({ symbol, name, value, assets, chains, chainsTitle, actions, onBack, headerAction, testID }) {
|
|
17
|
+
const colors = useColors(), t = useMessages(), { direction, locale } = useHIG();
|
|
18
|
+
const total = value !== undefined ? value : assets.reduce((sum, asset) => sum + (held(asset.value) ? asset.value : 0), 0);
|
|
19
|
+
return _jsxs(View, { testID: testID, style: { padding: 16 }, children: [_jsxs(View, { testID: 'token-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: 'token-back', onPress: onBack, children: _jsx(View, { style: { transform: [{ rotate: direction === 'rtl' ? '-90deg' : '90deg' }] }, children: _jsx(ChevronIcon, { color: colors.text }) }) }) : null }), _jsx(Text, { testID: 'token-title', accessibilityRole: 'header', numberOfLines: 1, style: { flex: 1, textAlign: 'center', fontSize: 17, lineHeight: 24, fontWeight: '600', color: colors.text }, children: symbol }), _jsx(View, { style: { minWidth: 44, alignItems: 'flex-end' }, children: headerAction })] }), _jsxs(View, { testID: 'token-bars', style: { gap: 20, marginTop: 16, paddingHorizontal: 4 }, children: [_jsx(BarMark, { testID: 'token-assets', surface: false, title: name, elements: assets, description: _jsx(AnimatedNumberReadout, { value: total, options: usd, tone: 'muted', testID: 'token-value', style: { fontSize: 14, lineHeight: 21 } }) }), _jsx(BarMark, { testID: 'token-chains', surface: false, title: chainsTitle ?? t.swapChains, elements: chains, description: formatNumber(chains.filter(chain => held(chain.value)).length, locale) })] }), actions.length > 0 ? _jsx(View, { testID: 'token-actions', style: { gap: 8, marginTop: 16 }, children: actions.map(action => _jsx(Button, { testID: `token-action-${action.id}`, fullWidth: true, intent: action.intent ?? 'secondary', disabled: action.disabled, onPress: action.onSelect, children: tokenActionLabel(action, t) }, action.id)) }) : null] });
|
|
20
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { AssetArtwork } from './asset-balance-row.js';
|
|
3
|
+
export type { AssetArtwork } from './asset-balance-row.js';
|
|
4
|
+
/** The trading words of the block. HIG's built-in strings hold no trading terms, so the host supplies them, translated. */
|
|
5
|
+
export interface TradeHistoryDetailLabels {
|
|
6
|
+
title: string;
|
|
7
|
+
/** Names the figure for assistive technology: Net PnL. It is not drawn; the signed figure and the line under it carry the meaning on screen. */
|
|
8
|
+
netPnl: string;
|
|
9
|
+
/** Names of the two prices under the bar. Needed with `entry` and `exit`. */
|
|
10
|
+
entry?: string;
|
|
11
|
+
exit?: string;
|
|
12
|
+
/** `+2.84% on margin`: receives the formatted percent. */
|
|
13
|
+
onMargin: (percent: string) => string;
|
|
14
|
+
long: string;
|
|
15
|
+
short: string;
|
|
16
|
+
}
|
|
17
|
+
/** One label and value row. A number is formatted with `options` between `prefix` and `suffix` and updates place by place; a string is drawn as given. */
|
|
18
|
+
export interface TradeHistoryDetail {
|
|
19
|
+
label: string;
|
|
20
|
+
value: string | number;
|
|
21
|
+
options?: Intl.NumberFormatOptions;
|
|
22
|
+
prefix?: string;
|
|
23
|
+
suffix?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface TradeHistoryAction {
|
|
26
|
+
id: string;
|
|
27
|
+
label: string;
|
|
28
|
+
onSelect: () => void;
|
|
29
|
+
intent?: 'primary' | 'secondary';
|
|
30
|
+
disabled?: boolean;
|
|
31
|
+
busy?: boolean;
|
|
32
|
+
}
|
|
33
|
+
export interface TradeHistoryDetailBlockProps {
|
|
34
|
+
labels: TradeHistoryDetailLabels;
|
|
35
|
+
/** Asset name: Amazon. */
|
|
36
|
+
name: string;
|
|
37
|
+
icon?: AssetArtwork;
|
|
38
|
+
side: 'long' | 'short';
|
|
39
|
+
/** 20 reads `20×`. */
|
|
40
|
+
leverage?: number;
|
|
41
|
+
/** Net profit and loss in dollars. `null` reads as unknown. */
|
|
42
|
+
pnl: number | null;
|
|
43
|
+
/** Return on margin as a fraction: 0.0284 reads +2.84%. */
|
|
44
|
+
pnlPercent?: number | null;
|
|
45
|
+
/** Entry and exit prices. With both, one bar runs from entry to exit in the result colour, with the two prices under it, in place of two rows. */
|
|
46
|
+
entry?: number;
|
|
47
|
+
exit?: number;
|
|
48
|
+
/** Format of the two prices. Defaults to US dollars. */
|
|
49
|
+
priceOptions?: Intl.NumberFormatOptions;
|
|
50
|
+
details: readonly TradeHistoryDetail[];
|
|
51
|
+
actions?: readonly TradeHistoryAction[];
|
|
52
|
+
/** Shows Back on the leading edge of the header. */
|
|
53
|
+
onBack?: () => void;
|
|
54
|
+
/** A control on the trailing edge of the header, usually an IconButton. */
|
|
55
|
+
headerAction?: React.ReactNode;
|
|
56
|
+
testID?: string;
|
|
57
|
+
}
|
|
58
|
+
/** The full record of one closed trade, drawn on the screen without cards because none of it is pressable: the asset with its side and leverage on one line, the net profit and loss with its return on margin, a bar from the entry price to the exit price, the host's other figures as a compact grid, and the host's actions side by side. */
|
|
59
|
+
export declare function TradeHistoryDetailBlock({ labels, name, icon, side, leverage, pnl, pnlPercent, entry, exit, priceOptions, details, actions, onBack, headerAction, testID }: TradeHistoryDetailBlockProps): React.JSX.Element;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Image, View } from 'react-native';
|
|
3
|
+
import { useColors, useFills, useHIG, useMessages } from './provider.js';
|
|
4
|
+
import { Text } from './surface.js';
|
|
5
|
+
import { BarPnl } from './bar-pnl.js';
|
|
6
|
+
import { Button, IconButton } from './button.js';
|
|
7
|
+
import { ChevronIcon } from './icons.js';
|
|
8
|
+
import { AnimatedNumberReadout } from './animated-number.js';
|
|
9
|
+
import { formatNumberReadout } from './animated-number-model.js';
|
|
10
|
+
const pnlUsd = { style: 'currency', currency: 'USD', signDisplay: 'exceptZero', maximumFractionDigits: 4 };
|
|
11
|
+
const pnlShare = { style: 'percent', minimumFractionDigits: 2, maximumFractionDigits: 2, signDisplay: 'exceptZero' };
|
|
12
|
+
const gearing = { maximumFractionDigits: 6 };
|
|
13
|
+
const numberMark = '', unknown = '—', times = '×', up = '↑', down = '↓';
|
|
14
|
+
const avatar = 24, empty = '';
|
|
15
|
+
const hidden = { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants' };
|
|
16
|
+
const known = (value) => value != null && Number.isFinite(value);
|
|
17
|
+
/** A host sentence with one live number in it. The words keep their translated order, the number updates place by place, and the whole sentence is the accessible reading. Without a value the sentence is plain text. */
|
|
18
|
+
function Sentence({ template, text, value, options, tone, testID }) {
|
|
19
|
+
const colors = useColors(), { direction } = useHIG();
|
|
20
|
+
const type = { fontSize: 14, lineHeight: 21 }, words = { ...type, color: colors[tone] };
|
|
21
|
+
const reading = template(text), parts = template(numberMark).split(numberMark);
|
|
22
|
+
if (value === null || parts.length !== 2)
|
|
23
|
+
return _jsx(Text, { testID: testID, style: { ...words, textAlign: 'center' }, children: reading });
|
|
24
|
+
return _jsxs(View, { accessible: true, accessibilityLabel: reading, testID: testID, style: { direction, flexDirection: 'row', alignItems: 'center', justifyContent: 'center', flexShrink: 1 }, children: [parts[0] ? _jsx(Text, { accessible: false, style: words, children: parts[0] }) : null, _jsx(AnimatedNumberReadout, { value: value, options: options, tone: tone, style: type }), parts[1] ? _jsx(Text, { accessible: false, style: words, children: parts[1] }) : null] });
|
|
25
|
+
}
|
|
26
|
+
/** The full record of one closed trade, drawn on the screen without cards because none of it is pressable: the asset with its side and leverage on one line, the net profit and loss with its return on margin, a bar from the entry price to the exit price, the host's other figures as a compact grid, and the host's actions side by side. */
|
|
27
|
+
export function TradeHistoryDetailBlock({ labels, name, icon, side, leverage, pnl, pnlPercent, entry, exit, priceOptions, details, actions = [], onBack, headerAction, testID }) {
|
|
28
|
+
const colors = useColors(), fills = useFills(), t = useMessages(), { direction, locale } = useHIG();
|
|
29
|
+
const long = side === 'long', word = long ? labels.long : labels.short, tint = long ? colors.up : colors.down;
|
|
30
|
+
const tone = known(pnl) && pnl > 0 ? 'up' : known(pnl) && pnl < 0 ? 'down' : 'text';
|
|
31
|
+
const turns = known(leverage) ? formatNumberReadout(leverage, locale, gearing).text + times : null;
|
|
32
|
+
const shape = { width: avatar, height: avatar, borderRadius: avatar / 2, backgroundColor: fills.raised, alignItems: 'center', justifyContent: 'center', overflow: 'hidden' };
|
|
33
|
+
const art = typeof icon === 'string' ? _jsx(Image, { accessible: false, accessibilityIgnoresInvertColors: true, source: { uri: icon }, style: shape }) : _jsx(View, { style: shape, children: icon ?? _jsx(Text, { accessible: false, maxFontSizeMultiplier: 1, style: { fontSize: 9, lineHeight: 12, fontWeight: '600', color: colors.muted }, children: name.slice(0, 3) }) });
|
|
34
|
+
const meta = { fontSize: 14, lineHeight: 20 };
|
|
35
|
+
// Three figures to a line: a small label over its value.
|
|
36
|
+
const rows = details.map(detail => _jsxs(View, { testID: `trade-detail-${detail.label}`, style: { width: '33.333%', paddingEnd: 8, gap: 2 }, children: [_jsx(Text, { numberOfLines: 1, style: { fontSize: 12, lineHeight: 16, color: colors.muted }, children: detail.label }), typeof detail.value === 'number' ? _jsx(AnimatedNumberReadout, { value: detail.value, options: detail.options, prefix: detail.prefix, suffix: detail.suffix, tone: 'text', style: { fontSize: 15, lineHeight: 22, fontWeight: '600' } }) : _jsx(Text, { style: { fontSize: 15, lineHeight: 22, fontWeight: '600', color: colors.text }, children: detail.value })] }, detail.label));
|
|
37
|
+
return _jsxs(View, { testID: testID, style: { padding: 16 }, children: [_jsxs(View, { testID: 'trade-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: 'trade-back', onPress: onBack, children: _jsx(View, { style: { transform: [{ rotate: direction === 'rtl' ? '-90deg' : '90deg' }] }, children: _jsx(ChevronIcon, { color: colors.text }) }) }) : null }), _jsx(Text, { testID: 'trade-title', 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, { testID: 'trade-asset', accessible: true, accessibilityLabel: [name, word, turns].filter(Boolean).join(', '), style: { direction, flexDirection: 'row', flexWrap: 'wrap', alignItems: 'center', justifyContent: 'center', gap: 8, marginTop: 16 }, children: [_jsx(View, { ...hidden, children: art }), _jsx(Text, { ...hidden, numberOfLines: 1, style: { flexShrink: 1, fontSize: 16, lineHeight: 24, fontWeight: '600', color: colors.text }, children: name }), _jsx(View, { ...hidden, children: _jsxs(View, { style: { direction, flexDirection: 'row', alignItems: 'center', gap: 4 }, children: [_jsx(Text, { testID: 'trade-side-arrow', style: { ...meta, fontWeight: '600', color: tint }, children: long ? up : down }), _jsx(Text, { testID: 'trade-side', style: { ...meta, fontWeight: '600', color: tint, textTransform: 'uppercase' }, children: word }), turns ? _jsx(Text, { testID: 'trade-leverage', style: { ...meta, color: colors.muted }, children: turns }) : null] }) })] }), _jsxs(View, { testID: 'trade-pnl', style: { alignItems: 'center', gap: 4, marginTop: 8 }, children: [_jsx(AnimatedNumberReadout, { testID: 'trade-pnl-value', label: labels.netPnl, value: pnl, options: pnlUsd, tone: tone, style: { fontSize: 40, lineHeight: 48, fontWeight: '700' } }), pnlPercent !== undefined ? _jsx(Sentence, { testID: 'trade-pnl-percent', template: labels.onMargin, text: known(pnlPercent) ? formatNumberReadout(pnlPercent, locale, pnlShare).text : unknown, value: known(pnlPercent) ? pnlPercent : null, options: pnlShare, tone: tone }) : null] }), known(entry) && known(exit) ? _jsx(View, { style: { marginTop: 20, paddingHorizontal: 4 }, children: _jsx(BarPnl, { testID: 'trade-bar', surface: false, fit: true, side: side, entry: entry, mark: exit, labels: { entry: labels.entry ?? empty, mark: labels.exit ?? empty, liquidation: empty }, priceOptions: priceOptions }) }) : null, details.length > 0 ? _jsx(View, { testID: 'trade-details', style: { direction, flexDirection: 'row', flexWrap: 'wrap', rowGap: 16, marginTop: 20, paddingHorizontal: 4 }, children: rows }) : null, actions.length > 0 ? _jsx(View, { testID: 'trade-actions', style: { direction, flexDirection: 'row', gap: 8, marginTop: 16 }, children: actions.map(action => _jsx(View, { style: { flex: 1, minWidth: 0 }, children: _jsx(Button, { fullWidth: true, testID: `trade-action-${action.id}`, intent: action.intent ?? 'secondary', disabled: action.disabled, busy: action.busy, onPress: action.onSelect, children: action.label }) }, action.id)) }) : null] });
|
|
38
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { AssetArtwork } from './asset-balance-row.js';
|
|
3
|
+
/** The words of the block. They are trading terms, so the host supplies them; HIG ships none. */
|
|
4
|
+
export interface TradeHistoryListLabels {
|
|
5
|
+
/** Heading of the screen: History. */
|
|
6
|
+
title: string;
|
|
7
|
+
long: string;
|
|
8
|
+
short: string;
|
|
9
|
+
/** Shown in place of the rows when there are no trades. */
|
|
10
|
+
empty: string;
|
|
11
|
+
}
|
|
12
|
+
/** One closed trade. */
|
|
13
|
+
export interface TradeHistoryItem {
|
|
14
|
+
id: string;
|
|
15
|
+
/** Asset name: Amazon. */
|
|
16
|
+
name: string;
|
|
17
|
+
/** Round artwork: an image URL or a host element. Without it the row shows the first letters of the name. */
|
|
18
|
+
icon?: AssetArtwork;
|
|
19
|
+
side: 'long' | 'short';
|
|
20
|
+
/** 20 reads `20×`. */
|
|
21
|
+
leverage?: number;
|
|
22
|
+
/** Net profit and loss in dollars. `null` reads as unknown. */
|
|
23
|
+
pnl: number | null;
|
|
24
|
+
/** Host-formatted age or time of the close, shown under the result: `2d`. */
|
|
25
|
+
time?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface TradeHistoryListBlockProps {
|
|
28
|
+
labels: TradeHistoryListLabels;
|
|
29
|
+
/** Closed trades, in the order shown. The host sorts and pages them. */
|
|
30
|
+
trades: readonly TradeHistoryItem[];
|
|
31
|
+
/** Makes each row a button that reports its trade, usually to open its detail, and shows the disclosure chevron. */
|
|
32
|
+
onSelect?: (trade: TradeHistoryItem) => void;
|
|
33
|
+
/** Shows Back on the leading edge of the header. */
|
|
34
|
+
onBack?: () => void;
|
|
35
|
+
/** A control on the trailing edge of the header, usually an IconButton. */
|
|
36
|
+
headerAction?: React.ReactNode;
|
|
37
|
+
/** Format of the result. Defaults to signed US dollars at four significant digits: `+$1.412`, `+$17.90`, `-$0.6878`. */
|
|
38
|
+
pnlOptions?: Intl.NumberFormatOptions;
|
|
39
|
+
testID?: string;
|
|
40
|
+
}
|
|
41
|
+
/** How a row reads its side: `Short 20×`, or `Short` without leverage. */
|
|
42
|
+
export declare const tradeHistorySide: (trade: Pick<TradeHistoryItem, 'side' | 'leverage'>, labels: Pick<TradeHistoryListLabels, 'long' | 'short'>, locale?: string) => string;
|
|
43
|
+
/** A history of closed trades as one screen: a header, then one row per trade with the asset, its side and leverage in the direction colour, and the net result in the result colour over its age. */
|
|
44
|
+
export declare function TradeHistoryListBlock({ labels, trades, onSelect, onBack, headerAction, pnlOptions, testID }: TradeHistoryListBlockProps): React.JSX.Element;
|