@bloxwap/hig 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/chart/README.md +1 -1
- package/contracts/README.md +1 -1
- package/contracts/dist/messages.d.ts +31 -4
- package/contracts/dist/messages.js +11 -2
- package/feedback/README.md +1 -1
- package/native/README.md +1 -1
- package/native/dist/account-block.d.ts +46 -0
- package/native/dist/account-block.js +28 -0
- package/native/dist/asset-balance-row.d.ts +20 -0
- package/native/dist/asset-balance-row.js +21 -0
- package/native/dist/bar-mark.d.ts +45 -0
- package/native/dist/bar-mark.js +34 -0
- package/native/dist/bar-pnl.d.ts +50 -0
- package/native/dist/bar-pnl.js +59 -0
- package/native/dist/blocks.d.ts +44 -0
- package/native/dist/{recipes.js → blocks.js} +20 -9
- package/native/dist/field.d.ts +0 -1
- package/native/dist/field.js +0 -1
- package/native/dist/icons.d.ts +8 -0
- package/native/dist/icons.js +4 -0
- package/native/dist/language-block.d.ts +31 -0
- package/native/dist/language-block.js +30 -0
- package/native/dist/list-group.d.ts +26 -0
- package/native/dist/list-group.js +27 -0
- package/native/dist/manage-position-block.d.ts +69 -0
- package/native/dist/manage-position-block.js +57 -0
- package/native/dist/notifications-block.d.ts +25 -0
- package/native/dist/notifications-block.js +14 -0
- package/native/dist/pickers.d.ts +13 -5
- package/native/dist/pickers.js +10 -6
- package/native/dist/position-block.d.ts +51 -0
- package/native/dist/position-block.js +21 -0
- package/native/dist/profile-block.d.ts +42 -0
- package/native/dist/profile-block.js +28 -0
- package/native/dist/reward-block.d.ts +83 -0
- package/native/dist/reward-block.js +35 -0
- package/native/dist/setting-header.d.ts +8 -0
- package/native/dist/setting-header.js +11 -0
- package/native/dist/setting-switch.d.ts +18 -0
- package/native/dist/setting-switch.js +17 -0
- package/native/dist/signals-block.d.ts +37 -0
- package/native/dist/signals-block.js +16 -0
- package/native/dist/sound-haptics-block.d.ts +39 -0
- package/native/dist/sound-haptics-block.js +21 -0
- package/native/dist/{swap-panel.d.ts → swap-panel-block.d.ts} +28 -9
- package/native/dist/{swap-panel.js → swap-panel-block.js} +24 -14
- package/native/dist/swap-parts.d.ts +14 -3
- package/native/dist/swap-parts.js +16 -1
- package/native/dist/swap-shared.d.ts +18 -6
- package/native/dist/swap-shared.js +3 -2
- package/native/dist/swap-sheet.d.ts +4 -4
- package/native/dist/swap-sheet.js +4 -4
- package/native/dist/swap-views.d.ts +1 -1
- package/native/dist/swap-views.js +11 -8
- package/native/dist/target-block.d.ts +83 -0
- package/native/dist/target-block.js +61 -0
- package/native/dist/token-action-block.d.ts +39 -0
- package/native/dist/token-action-block.js +20 -0
- package/native/dist/trade-history-detail-block.d.ts +59 -0
- package/native/dist/trade-history-detail-block.js +38 -0
- package/native/dist/trade-history-list-block.d.ts +44 -0
- package/native/dist/trade-history-list-block.js +29 -0
- package/native-fonts/README.md +1 -1
- package/og-fonts/README.md +1 -1
- package/package.json +246 -41
- package/react/README.md +1 -1
- package/react/dist/asset-balance-row.d.ts +19 -0
- package/react/dist/asset-balance-row.js +10 -0
- package/react/dist/bar-mark.d.ts +35 -0
- package/react/dist/bar-mark.js +21 -0
- package/react/dist/bar-pnl.d.ts +49 -0
- package/react/dist/bar-pnl.js +45 -0
- package/react/dist/blocks/account-block.d.ts +46 -0
- package/react/dist/blocks/account-block.js +27 -0
- package/react/dist/blocks/language-block.d.ts +32 -0
- package/react/dist/blocks/language-block.js +51 -0
- package/react/dist/blocks/manage-position-block.d.ts +67 -0
- package/react/dist/blocks/manage-position-block.js +28 -0
- package/react/dist/blocks/notifications-block.d.ts +23 -0
- package/react/dist/blocks/notifications-block.js +8 -0
- package/react/dist/{recipes → blocks}/pickers.d.ts +12 -4
- package/react/dist/{recipes → blocks}/pickers.js +9 -6
- package/react/dist/blocks/position-block.d.ts +49 -0
- package/react/dist/blocks/position-block.js +14 -0
- package/react/dist/blocks/profile-block.d.ts +48 -0
- package/react/dist/blocks/profile-block.js +15 -0
- package/react/dist/blocks/reward-block.d.ts +81 -0
- package/react/dist/blocks/reward-block.js +24 -0
- package/react/dist/blocks/screen-header.d.ts +9 -0
- package/react/dist/blocks/screen-header.js +12 -0
- package/react/dist/blocks/setting-switch.d.ts +10 -0
- package/react/dist/blocks/setting-switch.js +8 -0
- package/react/dist/blocks/signals-block.d.ts +35 -0
- package/react/dist/blocks/signals-block.js +15 -0
- package/react/dist/blocks/sound-haptics-block.d.ts +37 -0
- package/react/dist/blocks/sound-haptics-block.js +18 -0
- package/react/dist/{recipes → blocks}/swap/picker.d.ts +1 -1
- package/react/dist/{recipes → blocks}/swap/picker.js +4 -4
- package/react/dist/{recipes → blocks}/swap/settings.js +5 -7
- package/react/dist/{recipes → blocks}/swap/shared.d.ts +44 -6
- package/react/dist/{recipes → blocks}/swap/shared.js +25 -5
- package/react/dist/{recipes/swap-panel.d.ts → blocks/swap-panel-block.d.ts} +29 -9
- package/react/dist/{recipes/swap-panel.js → blocks/swap-panel-block.js} +22 -14
- package/react/dist/{recipes → blocks}/swap-sheet.d.ts +4 -4
- package/react/dist/{recipes → blocks}/swap-sheet.js +4 -4
- package/react/dist/blocks/target-block.d.ts +81 -0
- package/react/dist/blocks/target-block.js +65 -0
- package/react/dist/blocks/token-action-block.d.ts +37 -0
- package/react/dist/blocks/token-action-block.js +18 -0
- package/react/dist/{recipes → blocks}/trade-entry.js +2 -2
- package/react/dist/blocks/trade-history-detail-block.d.ts +58 -0
- package/react/dist/blocks/trade-history-detail-block.js +16 -0
- package/react/dist/blocks/trade-history-list-block.d.ts +43 -0
- package/react/dist/blocks/trade-history-list-block.js +21 -0
- package/react/dist/blocks.d.ts +20 -0
- package/react/dist/blocks.js +21 -0
- package/react/dist/field.d.ts +0 -2
- package/react/dist/field.js +0 -2
- package/react/dist/list-group.d.ts +26 -0
- package/react/dist/list-group.js +20 -0
- package/react/dist/styles.css +275 -8
- package/tokens/README.md +1 -1
- package/native/dist/recipes.d.ts +0 -45
- package/react/dist/recipes/activity-list.d.ts +0 -8
- package/react/dist/recipes/activity-list.js +0 -6
- package/react/dist/recipes/balance-card.d.ts +0 -6
- package/react/dist/recipes/balance-card.js +0 -5
- package/react/dist/recipes/code-window.d.ts +0 -4
- package/react/dist/recipes/code-window.js +0 -4
- package/react/dist/recipes.d.ts +0 -10
- package/react/dist/recipes.js +0 -11
- /package/react/dist/{recipes → blocks}/install-command.d.ts +0 -0
- /package/react/dist/{recipes → blocks}/install-command.js +0 -0
- /package/react/dist/{recipes → blocks}/market-row.d.ts +0 -0
- /package/react/dist/{recipes → blocks}/market-row.js +0 -0
- /package/react/dist/{recipes → blocks}/marketing-hero.d.ts +0 -0
- /package/react/dist/{recipes → blocks}/marketing-hero.js +0 -0
- /package/react/dist/{recipes → blocks}/swap/amount-card.d.ts +0 -0
- /package/react/dist/{recipes → blocks}/swap/amount-card.js +0 -0
- /package/react/dist/{recipes → blocks}/swap/settings.d.ts +0 -0
- /package/react/dist/{recipes → blocks}/trade-entry.d.ts +0 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { AssetArtwork } from './asset-balance-row.js';
|
|
3
|
+
/** The promotion above the standings: a prize pool filling towards a goal, or a draw with a top prize. Every word is host text. */
|
|
4
|
+
export interface RewardPromo {
|
|
5
|
+
/** The small capitals line: Season 01. */
|
|
6
|
+
eyebrow: string;
|
|
7
|
+
/** A text link with a chevron on the trailing edge of the eyebrow: Rules. */
|
|
8
|
+
rules?: {
|
|
9
|
+
label: string;
|
|
10
|
+
onSelect: () => void;
|
|
11
|
+
};
|
|
12
|
+
/** The headline figure: the pool so far, or the top prize. `null` reads as unknown. */
|
|
13
|
+
amount: number | null;
|
|
14
|
+
/** Format of `amount` and `goal`. Defaults to whole US dollars. */
|
|
15
|
+
amountOptions?: Intl.NumberFormatOptions;
|
|
16
|
+
/** The amount the pool is filling towards. Draws the progress bar under the caption. */
|
|
17
|
+
goal?: number;
|
|
18
|
+
/** The line under the figure. A function receives the formatted goal: `goal => 'of ' + goal + ' prize pool'`. A string is drawn as given: top prize. */
|
|
19
|
+
caption?: string | ((goal: string) => string);
|
|
20
|
+
/** The lead of the explaining sentence, in the text colour: Top 100 traders split the pool. */
|
|
21
|
+
headline?: string;
|
|
22
|
+
/** Continues the sentence after the headline in the muted colour: Funded by builder fees on every trade. */
|
|
23
|
+
description?: string;
|
|
24
|
+
/** A full-width action under the description: Draws and winners. The host opens its own destination. */
|
|
25
|
+
action?: {
|
|
26
|
+
label: string;
|
|
27
|
+
onSelect: () => void;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** One trader in the standings. */
|
|
31
|
+
export interface RewardEntry {
|
|
32
|
+
id: string;
|
|
33
|
+
rank: number;
|
|
34
|
+
/** A short address, a handle, or the host's word for the viewer. */
|
|
35
|
+
name: string;
|
|
36
|
+
/** An image URL or a host element. Without one the first letters of the name are shown. */
|
|
37
|
+
avatar?: AssetArtwork;
|
|
38
|
+
/** Shows the verified mark after the name. */
|
|
39
|
+
verified?: boolean;
|
|
40
|
+
/** The line under the name: `$1,090,779 vol`. */
|
|
41
|
+
detail?: string;
|
|
42
|
+
/** Points or entries. `null` reads as unknown. */
|
|
43
|
+
score: number | null;
|
|
44
|
+
/** Marks the viewer's own row: the name and score take the action colour. */
|
|
45
|
+
you?: boolean;
|
|
46
|
+
}
|
|
47
|
+
export interface RewardBlockProps {
|
|
48
|
+
/** Heading: Leaderboard. */
|
|
49
|
+
title: string;
|
|
50
|
+
promo?: RewardPromo;
|
|
51
|
+
/** A choice between standings, such as Upcoming draw and Top winners. `label` names the control. */
|
|
52
|
+
tabs?: {
|
|
53
|
+
label: string;
|
|
54
|
+
options: readonly {
|
|
55
|
+
value: string;
|
|
56
|
+
label: string;
|
|
57
|
+
}[];
|
|
58
|
+
value: string;
|
|
59
|
+
onValueChange: (value: string) => void;
|
|
60
|
+
};
|
|
61
|
+
/** The viewer's own standing, pinned above the list on a tinted row. */
|
|
62
|
+
you?: RewardEntry;
|
|
63
|
+
/** The column heading over the names: Top 25 by volume. */
|
|
64
|
+
listTitle?: string;
|
|
65
|
+
/** The column heading over the scores: Entries. */
|
|
66
|
+
scoreTitle?: string;
|
|
67
|
+
entries: readonly RewardEntry[];
|
|
68
|
+
/** Format of every score. Defaults to a whole number. */
|
|
69
|
+
scoreOptions?: Intl.NumberFormatOptions;
|
|
70
|
+
/** Words for the verified mark, read after the name. */
|
|
71
|
+
verifiedLabel?: string;
|
|
72
|
+
/** A line under the list: Entries are provisional until audited. */
|
|
73
|
+
footnote?: string;
|
|
74
|
+
/** Shows Back on the leading edge of the header. */
|
|
75
|
+
onBack?: () => void;
|
|
76
|
+
/** A control on the trailing edge of the header, usually an IconButton that shares. */
|
|
77
|
+
headerAction?: React.ReactNode;
|
|
78
|
+
testID?: string;
|
|
79
|
+
}
|
|
80
|
+
/** The share of the goal reached, from 0 to 1. Unknown amounts and goals that are not above zero give `null`. */
|
|
81
|
+
export declare function rewardProgress(amount: number | null | undefined, goal: number | null | undefined): number | null;
|
|
82
|
+
/** A competition as a screen: an optional promotion (a prize pool filling towards its goal, or a draw with its top prize), an optional choice of standings, the viewer's own standing pinned on a tinted row, and the ranked list. */
|
|
83
|
+
export declare function RewardBlock({ title, promo, tabs, you, listTitle, scoreTitle, entries, scoreOptions, verifiedLabel, footnote, onBack, headerAction, testID }: RewardBlockProps): React.JSX.Element;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Image, Pressable, View } from 'react-native';
|
|
3
|
+
import { formatNumber } from '@bloxwap/hig/contracts';
|
|
4
|
+
import { withAlpha } from '@bloxwap/hig/tokens';
|
|
5
|
+
import { useColors, useFills, useHIG, useMessages } from './provider.js';
|
|
6
|
+
import { Surface, Text } from './surface.js';
|
|
7
|
+
import { 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 wholeDollars = { style: 'currency', currency: 'USD', maximumFractionDigits: 0 };
|
|
13
|
+
const whole = { maximumFractionDigits: 0 };
|
|
14
|
+
const hidden = { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants' };
|
|
15
|
+
const avatar = 40, space = ' ';
|
|
16
|
+
/** The share of the goal reached, from 0 to 1. Unknown amounts and goals that are not above zero give `null`. */
|
|
17
|
+
export function rewardProgress(amount, goal) {
|
|
18
|
+
return amount == null || goal == null || !Number.isFinite(amount) || !Number.isFinite(goal) || !(goal > 0) ? null : Math.min(1, Math.max(0, amount / goal));
|
|
19
|
+
}
|
|
20
|
+
/** A competition as a screen: an optional promotion (a prize pool filling towards its goal, or a draw with its top prize), an optional choice of standings, the viewer's own standing pinned on a tinted row, and the ranked list. */
|
|
21
|
+
export function RewardBlock({ title, promo, tabs, you, listTitle, scoreTitle, entries, scoreOptions = whole, verifiedLabel, footnote, onBack, headerAction, testID }) {
|
|
22
|
+
const colors = useColors(), fills = useFills(), t = useMessages(), { direction, locale, monoFontFamily } = useHIG();
|
|
23
|
+
const money = promo?.amountOptions ?? wholeDollars, reached = promo ? rewardProgress(promo.amount, promo.goal) : null;
|
|
24
|
+
const caption = typeof promo?.caption === 'function' ? promo.goal !== undefined ? promo.caption(formatNumber(promo.goal, locale, money)) : undefined : promo?.caption;
|
|
25
|
+
const caps = { fontFamily: monoFontFamily, fontSize: 12, lineHeight: 16, letterSpacing: 1.5, textTransform: 'uppercase' };
|
|
26
|
+
const standing = (entry, id, style) => {
|
|
27
|
+
const mine = !!entry.you, reading = [String(entry.rank), entry.name, entry.verified && verifiedLabel ? verifiedLabel : null, entry.detail, formatNumberReadout(entry.score, locale, scoreOptions).text].filter(Boolean).join(', ');
|
|
28
|
+
const disc = { width: avatar, height: avatar, borderRadius: avatar / 2, backgroundColor: fills.raised, alignItems: 'center', justifyContent: 'center', overflow: 'hidden' };
|
|
29
|
+
return _jsxs(View, { testID: id, accessible: true, accessibilityLabel: reading, style: { direction, flexDirection: 'row', alignItems: 'center', gap: 12, minHeight: 64, paddingVertical: 8, paddingHorizontal: 20, backgroundColor: fills.well, ...style }, children: [_jsx(Text, { ...hidden, style: { minWidth: 24, fontFamily: monoFontFamily, fontSize: 16, lineHeight: 24, fontWeight: '600', color: colors.muted }, children: entry.rank }), _jsx(View, { ...hidden, children: typeof entry.avatar === 'string' ? _jsx(Image, { accessible: false, accessibilityIgnoresInvertColors: true, source: { uri: entry.avatar }, style: disc }) : _jsx(View, { style: disc, children: entry.avatar ?? _jsx(Text, { maxFontSizeMultiplier: 1, style: { fontSize: 12, lineHeight: 16, fontWeight: '600', color: colors.muted }, children: entry.name.slice(0, 2) }) }) }), _jsxs(View, { ...hidden, style: { flex: 1, flexShrink: 1, minWidth: 0 }, children: [_jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: 6 }, children: [_jsx(Text, { testID: `${id}-name`, numberOfLines: 1, style: { flexShrink: 1, fontFamily: monoFontFamily, fontSize: 16, lineHeight: 24, fontWeight: '600', color: mine ? colors.action : colors.text }, children: entry.name }), entry.verified ? _jsx(View, { testID: `${id}-verified`, style: { transform: [{ scale: 0.8 }] }, children: _jsx(SeverityIcon, { kind: 'success', color: colors.warning }) }) : null] }), entry.detail ? _jsx(Text, { numberOfLines: 1, style: { fontFamily: monoFontFamily, fontSize: 14, lineHeight: 20, color: colors.muted }, children: entry.detail }) : null] }), _jsx(View, { ...hidden, children: _jsx(AnimatedNumberReadout, { value: entry.score, options: scoreOptions, tone: mine ? 'positive' : 'text', testID: `${id}-score`, style: { fontSize: 16, lineHeight: 24, fontWeight: '600' } }) })] }, entry.id);
|
|
30
|
+
};
|
|
31
|
+
// Rows are built here so their test ids are code, not JSX text.
|
|
32
|
+
const pinned = you ? standing({ ...you, you: true }, 'reward-you', { marginTop: 16, borderRadius: 20, backgroundColor: withAlpha(colors.action, 0.12) }) : null;
|
|
33
|
+
const rows = entries.map(entry => standing(entry, `reward-row-${entry.id}`));
|
|
34
|
+
return _jsxs(View, { testID: testID, style: { padding: 16 }, children: [_jsxs(View, { testID: 'reward-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: 'reward-back', onPress: onBack, children: _jsx(View, { style: { transform: [{ rotate: direction === 'rtl' ? '-90deg' : '90deg' }] }, children: _jsx(ChevronIcon, { color: colors.text }) }) }) : null }), _jsx(Text, { testID: 'reward-title', accessibilityRole: 'header', numberOfLines: 1, style: { flex: 1, textAlign: 'center', fontSize: 17, lineHeight: 24, fontWeight: '600', color: colors.text }, children: title }), _jsx(View, { style: { minWidth: 44, alignItems: 'flex-end' }, children: headerAction })] }), promo ? _jsxs(Surface, { testID: 'reward-promo', style: { gap: 12, marginTop: 16 }, children: [_jsxs(View, { style: { direction, flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', gap: 12 }, children: [_jsx(Text, { testID: 'reward-eyebrow', style: { ...caps, flexShrink: 1, color: colors.muted }, children: promo.eyebrow }), promo.rules ? _jsxs(Pressable, { testID: 'reward-rules', accessibilityRole: 'button', hitSlop: 12, onPress: promo.rules.onSelect, style: ({ pressed }) => ({ flexDirection: 'row', alignItems: 'center', gap: 4, opacity: pressed ? 0.6 : 1 }), children: [_jsx(Text, { style: { fontSize: 16, lineHeight: 24, fontWeight: '500', color: colors.muted }, children: promo.rules.label }), _jsx(View, { ...hidden, style: { transform: [{ rotate: direction === 'rtl' ? '90deg' : '-90deg' }] }, children: _jsx(ChevronIcon, { color: colors.muted }) })] }) : null] }), _jsxs(View, { testID: 'reward-amount', accessible: true, accessibilityLabel: [formatNumberReadout(promo.amount, locale, money).text, caption].filter(Boolean).join(' '), style: { gap: 4 }, children: [_jsx(View, { ...hidden, style: { alignItems: 'flex-start' }, children: _jsx(AnimatedNumberReadout, { value: promo.amount, options: money, tone: 'positive', style: { fontSize: 44, lineHeight: 50, fontWeight: '700', letterSpacing: -0.9 } }) }), caption ? _jsx(Text, { ...hidden, testID: 'reward-caption', style: { fontFamily: monoFontFamily, fontSize: 15, lineHeight: 22, color: colors.muted }, children: caption }) : null] }), promo.goal !== undefined ? _jsx(View, { ...hidden, testID: 'reward-track', style: { direction, flexDirection: 'row', height: 4, borderRadius: 2, backgroundColor: fills.raised, overflow: 'hidden' }, children: _jsx(View, { testID: 'reward-fill', style: { width: `${(reached ?? 0) * 100}%`, minWidth: 8, borderRadius: 2, backgroundColor: colors.action } }) }) : null, promo.headline || promo.description ? _jsxs(Text, { testID: 'reward-summary', style: { fontSize: 16, lineHeight: 24, color: colors.muted }, children: [promo.headline ? _jsx(Text, { style: { fontWeight: '600', color: colors.text }, children: promo.headline }) : null, promo.headline && promo.description ? space : null, promo.description] }) : null, promo.action ? _jsxs(Pressable, { testID: 'reward-action', accessibilityRole: 'button', accessibilityLabel: promo.action.label, onPress: promo.action.onSelect, style: { direction, flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', gap: 12, minHeight: 44, marginTop: 4, marginBottom: -8, paddingTop: 12, borderTopWidth: 1, borderTopColor: fills.raised }, children: [_jsx(Text, { ...hidden, style: { flexShrink: 1, fontSize: 16, lineHeight: 24, fontWeight: '500', color: colors.muted }, children: promo.action.label }), _jsx(View, { ...hidden, style: { transform: [{ rotate: direction === 'rtl' ? '90deg' : '-90deg' }] }, children: _jsx(ChevronIcon, { color: colors.muted }) })] }) : null] }) : null, tabs ? _jsx(View, { testID: 'reward-tabs', style: { marginTop: 16 }, children: _jsx(SegmentedControl, { label: tabs.label, options: tabs.options, value: tabs.value, onValueChange: tabs.onValueChange }) }) : null, pinned, entries.length > 0 || listTitle || scoreTitle ? _jsxs(View, { testID: 'reward-list', style: { gap: 8, marginTop: 16 }, children: [listTitle || scoreTitle ? _jsxs(View, { style: { direction, flexDirection: 'row', justifyContent: 'space-between', gap: 12, paddingHorizontal: 4 }, children: [_jsx(Text, { testID: 'reward-list-title', style: { ...caps, flexShrink: 1, color: colors.muted }, children: listTitle }), _jsx(Text, { testID: 'reward-score-title', style: { ...caps, flexShrink: 1, color: colors.muted, textAlign: 'right' }, children: scoreTitle })] }) : null, entries.length > 0 ? _jsx(View, { testID: 'reward-rows', style: { gap: 2, borderRadius: 20, overflow: 'hidden' }, children: rows }) : null] }) : null, footnote ? _jsx(Text, { testID: 'reward-footnote', style: { fontSize: 14, lineHeight: 21, color: colors.muted, marginTop: 16, paddingHorizontal: 4 }, children: footnote }) : null] });
|
|
35
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/** The header of a block that is its own screen: Back on the leading edge, the title centred, an optional control on the trailing edge. */
|
|
3
|
+
export declare function SettingHeader({ title, onBack, action, testID }: {
|
|
4
|
+
title: string;
|
|
5
|
+
onBack?: () => void;
|
|
6
|
+
action?: React.ReactNode;
|
|
7
|
+
testID: string;
|
|
8
|
+
}): React.JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import { useColors, useHIG, useMessages } from './provider.js';
|
|
4
|
+
import { Text } from './surface.js';
|
|
5
|
+
import { IconButton } from './button.js';
|
|
6
|
+
import { ChevronIcon } from './icons.js';
|
|
7
|
+
/** The header of a block that is its own screen: Back on the leading edge, the title centred, an optional control on the trailing edge. */
|
|
8
|
+
export function SettingHeader({ title, onBack, action, testID }) {
|
|
9
|
+
const colors = useColors(), t = useMessages(), { direction } = useHIG();
|
|
10
|
+
return _jsxs(View, { testID: `${testID}-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: `${testID}-back`, onPress: onBack, children: _jsx(View, { style: { transform: [{ rotate: direction === 'rtl' ? '-90deg' : '90deg' }] }, children: _jsx(ChevronIcon, { color: colors.text }) }) }) : null }), _jsx(Text, { testID: `${testID}-title`, accessibilityRole: 'header', numberOfLines: 1, style: { flex: 1, textAlign: 'center', fontSize: 17, lineHeight: 24, fontWeight: '600', color: colors.text }, children: title }), _jsx(View, { style: { minWidth: 44, alignItems: 'flex-end' }, children: action })] });
|
|
11
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface SettingSwitchProps {
|
|
3
|
+
label: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
checked: boolean;
|
|
6
|
+
onCheckedChange: (checked: boolean) => void;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
testID?: string;
|
|
9
|
+
}
|
|
10
|
+
/** One setting as a switch: the label over an optional description on the leading edge, the track on the trailing edge. The whole row is the switch; the label names it and the description is its hint. */
|
|
11
|
+
export declare function SettingSwitch({ label, description, checked, onCheckedChange, disabled, testID }: SettingSwitchProps): React.JSX.Element;
|
|
12
|
+
/** The card a setting sits in. Inside a list the cards share one rounded container, so they drop their own radius. */
|
|
13
|
+
export declare function SettingCard({ children, joined, testID }: React.PropsWithChildren<{
|
|
14
|
+
joined?: boolean;
|
|
15
|
+
testID?: string;
|
|
16
|
+
}>): React.JSX.Element;
|
|
17
|
+
/** The shared header of a settings screen: Back on the leading edge, the title centred, a host control on the trailing edge. */
|
|
18
|
+
export { SettingHeader } from './setting-header.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import { useColors, useFills, useHIG } from './provider.js';
|
|
4
|
+
import { Text } from './surface.js';
|
|
5
|
+
import { SwitchRow } from './switch-row.js';
|
|
6
|
+
/** One setting as a switch: the label over an optional description on the leading edge, the track on the trailing edge. The whole row is the switch; the label names it and the description is its hint. */
|
|
7
|
+
export function SettingSwitch({ label, description, checked, onCheckedChange, disabled, testID }) {
|
|
8
|
+
const colors = useColors(), fills = useFills(), { direction } = useHIG();
|
|
9
|
+
return _jsx(SwitchRow, { testID: testID, label: label, accessibilityHint: description, checked: checked, disabled: disabled, onCheckedChange: onCheckedChange, style: { minHeight: 32, opacity: disabled ? 0.5 : 1 }, children: _jsxs(View, { style: { direction, flex: 1, flexDirection: 'row', alignItems: 'flex-start', gap: 12 }, children: [_jsxs(View, { style: { flex: 1, minWidth: 0, gap: 2 }, children: [_jsx(Text, { style: { fontSize: 16, lineHeight: 24, color: colors.text }, children: label }), description ? _jsx(Text, { style: { fontSize: 14, lineHeight: 21, color: colors.muted }, children: description }) : null] }), _jsx(View, { testID: testID ? `${testID}-track` : undefined, style: { width: 40, height: 24, borderRadius: 12, padding: 3, backgroundColor: checked ? colors.action : fills.raised, alignItems: checked ? 'flex-end' : 'flex-start' }, children: _jsx(View, { style: { width: 18, height: 18, borderRadius: 9, backgroundColor: checked ? colors.onAction : colors.text } }) })] }) });
|
|
10
|
+
}
|
|
11
|
+
/** The card a setting sits in. Inside a list the cards share one rounded container, so they drop their own radius. */
|
|
12
|
+
export function SettingCard({ children, joined, testID }) {
|
|
13
|
+
const fills = useFills();
|
|
14
|
+
return _jsx(View, { testID: testID, style: { gap: 12, paddingVertical: 12, paddingHorizontal: 20, borderRadius: joined ? 0 : 20, backgroundColor: fills.well }, children: children });
|
|
15
|
+
}
|
|
16
|
+
/** The shared header of a settings screen: Back on the leading edge, the title centred, a host control on the trailing edge. */
|
|
17
|
+
export { SettingHeader } from './setting-header.js';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/** One signal the viewer can turn on. */
|
|
3
|
+
export interface SignalsItem {
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
checked: boolean;
|
|
8
|
+
onCheckedChange: (checked: boolean) => void;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/** A family of signals under one heading: Trend, Swing. Every word is host text. */
|
|
12
|
+
export interface SignalsGroup {
|
|
13
|
+
id: string;
|
|
14
|
+
title: string;
|
|
15
|
+
/** Shows the verified mark after the title. */
|
|
16
|
+
verified?: boolean;
|
|
17
|
+
/** A small pill on the trailing edge of the heading: How it works. The host opens its own explanation. */
|
|
18
|
+
help?: {
|
|
19
|
+
label: string;
|
|
20
|
+
onSelect: () => void;
|
|
21
|
+
};
|
|
22
|
+
items: readonly SignalsItem[];
|
|
23
|
+
}
|
|
24
|
+
export interface SignalsBlockProps {
|
|
25
|
+
/** Heading: Signals. */
|
|
26
|
+
title: string;
|
|
27
|
+
groups: readonly SignalsGroup[];
|
|
28
|
+
/** Words for the verified mark, read after the group title. */
|
|
29
|
+
verifiedLabel?: string;
|
|
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
|
+
/** The signals the viewer receives, as a screen, in groups: each group has a heading with an optional verified mark and a small help pill, and its signals as switches with a line of explanation, sharing one rounded container. */
|
|
37
|
+
export declare function SignalsBlock({ title, groups, verifiedLabel, onBack, headerAction, testID }: SignalsBlockProps): React.JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import { useColors, useHIG } from './provider.js';
|
|
4
|
+
import { Text } from './surface.js';
|
|
5
|
+
import { SwapCapsule } from './swap-parts.js';
|
|
6
|
+
import { SeverityIcon } from './icons.js';
|
|
7
|
+
import { SettingCard, SettingHeader, SettingSwitch } from './setting-switch.js';
|
|
8
|
+
/** The signals the viewer receives, as a screen, in groups: each group has a heading with an optional verified mark and a small help pill, and its signals as switches with a line of explanation, sharing one rounded container. */
|
|
9
|
+
export function SignalsBlock({ title, groups, verifiedLabel, onBack, headerAction, testID }) {
|
|
10
|
+
const colors = useColors(), { direction } = useHIG();
|
|
11
|
+
const sections = groups.map(group => {
|
|
12
|
+
const id = `signals-${group.id}`;
|
|
13
|
+
return _jsxs(View, { testID: id, style: { gap: 8, marginTop: 16 }, children: [_jsxs(View, { style: { direction, flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', gap: 12, minHeight: 44, paddingStart: 4 }, children: [_jsxs(View, { accessible: true, accessibilityRole: 'header', accessibilityLabel: [group.title, group.verified && verifiedLabel ? verifiedLabel : null].filter(Boolean).join(', '), testID: `${id}-title`, style: { flexDirection: 'row', alignItems: 'center', gap: 6, flexShrink: 1 }, children: [_jsx(Text, { accessible: false, numberOfLines: 1, style: { flexShrink: 1, fontSize: 16, lineHeight: 24, fontWeight: '500', color: colors.muted }, children: group.title }), group.verified ? _jsx(View, { testID: `${id}-verified`, style: { transform: [{ scale: 0.8 }] }, children: _jsx(SeverityIcon, { kind: 'success', color: colors.warning }) }) : null] }), group.help ? _jsx(SwapCapsule, { testID: `${id}-help`, onPress: group.help.onSelect, children: _jsx(Text, { style: { fontSize: 14, lineHeight: 20, fontWeight: '500', color: colors.muted }, children: group.help.label }) }) : null] }), group.items.length > 0 ? _jsx(View, { testID: `${id}-items`, style: { gap: 2, borderRadius: 20, overflow: 'hidden' }, children: group.items.map(item => _jsx(SettingCard, { joined: true, testID: `${id}-${item.id}`, children: _jsx(SettingSwitch, { testID: `${id}-${item.id}-switch`, label: item.label, description: item.description, checked: item.checked, disabled: item.disabled, onCheckedChange: item.onCheckedChange }) }, item.id)) }) : null] }, group.id);
|
|
14
|
+
});
|
|
15
|
+
return _jsxs(View, { testID: testID, style: { padding: 16 }, children: [_jsx(SettingHeader, { testID: 'signals', title: title, onBack: onBack, action: headerAction }), sections] });
|
|
16
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/** A volume as a few fixed steps. `value` and `options` are fractions: 0.25 reads 25%. */
|
|
3
|
+
export interface SoundVolume {
|
|
4
|
+
/** Names the steps and is drawn above them: Volume. */
|
|
5
|
+
label: string;
|
|
6
|
+
/** Defaults to 25%, 50%, 75% and 100%. */
|
|
7
|
+
options?: readonly number[];
|
|
8
|
+
value: number;
|
|
9
|
+
onValueChange: (value: number) => void;
|
|
10
|
+
}
|
|
11
|
+
/** One feedback channel: sound effects, the microphone, haptics, the flash. Every word is host text. */
|
|
12
|
+
export interface SoundSection {
|
|
13
|
+
id: string;
|
|
14
|
+
label: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
checked: boolean;
|
|
17
|
+
onCheckedChange: (checked: boolean) => void;
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
/** The device in use, under the switch: iPhone Microphone. */
|
|
20
|
+
source?: string;
|
|
21
|
+
/** A live input level from 0 to 1, drawn as a meter. `null` draws an empty meter. */
|
|
22
|
+
level?: number | null;
|
|
23
|
+
volume?: SoundVolume;
|
|
24
|
+
}
|
|
25
|
+
export interface SoundHapticsBlockProps {
|
|
26
|
+
/** Heading: Sound & Haptics. */
|
|
27
|
+
title: string;
|
|
28
|
+
/** One card each, in order. A section's source, meter and volume show only while it is on. */
|
|
29
|
+
sections: readonly SoundSection[];
|
|
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
|
+
/** The share of the meter filled, from 0 to 1. Unknown and out-of-range levels are clamped. */
|
|
37
|
+
export declare const soundLevel: (level: number | null | undefined) => number;
|
|
38
|
+
/** The settings for what the app plays and feels like, as a screen: each channel is a card with a switch, and a channel that is on can show the device it uses, a live input meter and its volume as fixed steps. */
|
|
39
|
+
export declare function SoundHapticsBlock({ title, sections, onBack, headerAction, testID }: SoundHapticsBlockProps): React.JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
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 { useColors, useFills, useHIG } from './provider.js';
|
|
5
|
+
import { Text } from './surface.js';
|
|
6
|
+
import { Button } from './button.js';
|
|
7
|
+
import { SettingCard, SettingHeader, SettingSwitch } from './setting-switch.js';
|
|
8
|
+
const steps = [0.25, 0.5, 0.75, 1], percent = { style: 'percent', maximumFractionDigits: 0 };
|
|
9
|
+
const hidden = { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants' };
|
|
10
|
+
/** The share of the meter filled, from 0 to 1. Unknown and out-of-range levels are clamped. */
|
|
11
|
+
export const soundLevel = (level) => level == null || !Number.isFinite(level) ? 0 : Math.min(1, Math.max(0, level));
|
|
12
|
+
/** The settings for what the app plays and feels like, as a screen: each channel is a card with a switch, and a channel that is on can show the device it uses, a live input meter and its volume as fixed steps. */
|
|
13
|
+
export function SoundHapticsBlock({ title, sections, onBack, headerAction, testID }) {
|
|
14
|
+
const colors = useColors(), fills = useFills(), { direction, locale } = useHIG();
|
|
15
|
+
const caption = { fontSize: 14, lineHeight: 21, color: colors.muted };
|
|
16
|
+
const cards = sections.map(section => {
|
|
17
|
+
const { source, level, volume } = section, open = section.checked && (!!source || level !== undefined || !!volume), id = `sound-${section.id}`;
|
|
18
|
+
return _jsxs(SettingCard, { testID: id, children: [_jsx(SettingSwitch, { testID: `${id}-switch`, label: section.label, description: section.description, checked: section.checked, disabled: section.disabled, onCheckedChange: section.onCheckedChange }), open ? _jsxs(View, { testID: `${id}-body`, style: { gap: 8 }, children: [source ? _jsx(Text, { testID: `${id}-source`, style: caption, children: source }) : null, level !== undefined ? _jsx(View, { ...hidden, testID: `${id}-meter`, style: { direction, flexDirection: 'row', height: 4, borderRadius: 2, backgroundColor: fills.raised, overflow: 'hidden' }, children: _jsx(View, { testID: `${id}-level`, style: { width: `${soundLevel(level) * 100}%`, borderRadius: 2, backgroundColor: colors.action } }) }) : null, volume ? _jsxs(View, { testID: `${id}-volume`, accessibilityRole: 'radiogroup', accessibilityLabel: volume.label, style: { gap: 8 }, children: [_jsx(Text, { ...hidden, style: caption, children: volume.label }), _jsx(View, { style: { direction, flexDirection: 'row', gap: 8 }, children: (volume.options ?? steps).map(option => _jsx(Button, { testID: `${id}-volume-${option}`, intent: option === volume.value ? 'primary' : 'secondary', accessibilityState: { selected: option === volume.value }, disabled: section.disabled, onPress: () => volume.onValueChange(option), style: { flex: 1, alignSelf: 'auto', paddingHorizontal: 8 }, children: formatNumber(option, locale, percent) }, option)) })] }) : null] }) : null] }, section.id);
|
|
19
|
+
});
|
|
20
|
+
return _jsxs(View, { testID: testID, style: { padding: 16 }, children: [_jsx(SettingHeader, { testID: 'sound', title: title, onBack: onBack, action: headerAction }), sections.length > 0 ? _jsx(View, { testID: 'sound-sections', style: { gap: 8, marginTop: 16 }, children: cards }) : null] });
|
|
21
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { type StyleProp, type ViewStyle } from 'react-native';
|
|
3
|
-
import { type SwapAction, type SwapChain, type SwapDenomination, type SwapFee, type SwapToken, type SwapView, type SwapWallet } from './swap-shared.js';
|
|
4
|
-
export { swapAction, swapParentView, type SwapAction, type SwapChain, type SwapDenomination, type SwapFee, type SwapToken, type SwapView, type SwapWallet } from './swap-shared.js';
|
|
3
|
+
import { type SwapAction, type SwapArtwork, type SwapChain, type SwapDenomination, type SwapFee, type SwapFigure, type SwapToken, type SwapView, type SwapWallet } from './swap-shared.js';
|
|
4
|
+
export { swapAction, swapParentView, type SwapAction, type SwapArtwork, type SwapChain, type SwapDenomination, type SwapFee, type SwapFigure, type SwapToken, type SwapView, type SwapWallet } from './swap-shared.js';
|
|
5
5
|
/** What a host surface lends the panel. A sheet passes its backend's list, so list drags hand off to the sheet, and sizes itself, so the panel does not animate its own height. */
|
|
6
6
|
export { SwapHostContext } from './swap-parts.js';
|
|
7
7
|
/** A fixed place the assets go, in place of a token the user picks: a wallet, a staking pool, a trading account. Shown as a compact To card with no amount. */
|
|
@@ -9,12 +9,12 @@ export interface SwapDestination {
|
|
|
9
9
|
title: string;
|
|
10
10
|
/** One muted line under the title, such as the chain or a rate. */
|
|
11
11
|
subtitle?: string;
|
|
12
|
-
/**
|
|
13
|
-
icon?:
|
|
12
|
+
/** An image URL or the host's own element. Without one, `address` draws the wallet's colour disc. */
|
|
13
|
+
icon?: SwapArtwork;
|
|
14
14
|
/** A wallet address; shown shortened under the subtitle. */
|
|
15
15
|
address?: string;
|
|
16
16
|
/** Muted trailing text, such as an arrival time or a rate. */
|
|
17
|
-
detail?: string;
|
|
17
|
+
detail?: string | SwapFigure;
|
|
18
18
|
/** Makes the card a button with a trailing chevron, for example to change the recipient. */
|
|
19
19
|
onPress?: () => void;
|
|
20
20
|
/** Still to be chosen: the card shows `title` / `subtitle` as a placeholder and the action stays disabled, asking for a destination. */
|
|
@@ -22,8 +22,11 @@ export interface SwapDestination {
|
|
|
22
22
|
}
|
|
23
23
|
/** One label and value row of the details card. */
|
|
24
24
|
export interface SwapDetail {
|
|
25
|
-
label: string;
|
|
26
|
-
value: string;
|
|
25
|
+
label: string; /** Text is shown as given. A number is formatted with `options` between `prefix` and `suffix`, and updates through `AnimatedNumberReadout` when it changes. */
|
|
26
|
+
value: string | number;
|
|
27
|
+
options?: Intl.NumberFormatOptions;
|
|
28
|
+
prefix?: string;
|
|
29
|
+
suffix?: string;
|
|
27
30
|
}
|
|
28
31
|
/** The receive view: the host's address and its rendered QR code. HIG ships no QR encoder. */
|
|
29
32
|
export interface SwapReceive {
|
|
@@ -31,7 +34,7 @@ export interface SwapReceive {
|
|
|
31
34
|
qr?: React.ReactNode; /** Host clipboard adapter. When set, the whole view copies the address. */
|
|
32
35
|
onCopy?: () => Promise<void> | void;
|
|
33
36
|
}
|
|
34
|
-
export interface
|
|
37
|
+
export interface SwapPanelBlockProps {
|
|
35
38
|
/** Catalog for the To side, and for the From side unless `fromTokens` is given. */
|
|
36
39
|
tokens: readonly SwapToken[];
|
|
37
40
|
/** Assets offered on the From side, typically the connected wallet's holdings. */
|
|
@@ -101,6 +104,18 @@ export interface SwapPanelProps {
|
|
|
101
104
|
lockTo?: boolean;
|
|
102
105
|
/** Names the action when it is ready, in place of Send, Swap or Bridge: for example Stake, Deposit or Withdraw. The host supplies the translated text. */
|
|
103
106
|
actionLabel?: string;
|
|
107
|
+
/** Holds the action for a reason only the host knows: below a minimum, no quote yet, a closed market. The panel's own checks (a token, an amount, the balance) still apply first. */
|
|
108
|
+
actionDisabled?: boolean;
|
|
109
|
+
/** What the held action says, for example “Below minimum”. Without it the action keeps its ready name. */
|
|
110
|
+
actionStatus?: string;
|
|
111
|
+
/** `destructive` for an action that cannot be undone, such as a burn. */
|
|
112
|
+
actionIntent?: 'primary' | 'destructive';
|
|
113
|
+
/** Refuses a key that would take the amount past the From balance, so the entry never reads more than the user holds. */
|
|
114
|
+
limitToBalance?: boolean;
|
|
115
|
+
/** Host content above the From card, such as a pending transfer. */
|
|
116
|
+
banner?: React.ReactNode;
|
|
117
|
+
/** Host content under the action, such as recent activity. */
|
|
118
|
+
footer?: React.ReactNode;
|
|
104
119
|
/** One direction only, top to bottom: the control between the cards becomes a down arrow instead of the flip button, and the pair cannot be exchanged. */
|
|
105
120
|
oneWay?: boolean;
|
|
106
121
|
keypad?: 'auto' | 'always' | 'never';
|
|
@@ -122,4 +137,8 @@ export interface SwapPanelProps {
|
|
|
122
137
|
* or token units through the keypad, token pickers, settings, and one action that names itself from the chosen pair.
|
|
123
138
|
* Presentation only. The host owns tokens, balances, prices, the quote, the wallet and the transaction.
|
|
124
139
|
*/
|
|
125
|
-
export declare function
|
|
140
|
+
export declare function SwapPanelBlock({ tokens, fromTokens, fromTokensLoading, chains, hotTokenIds, from: fromProp, to: toProp, defaultFrom, defaultTo, onFromChange, onToChange, amount, onAmountChange, received, fee, fees, quoteLoading, slippage, onSlippageChange, denomination, onDenominationChange, wallet, onConnect, onDisconnect, recipient, onRecipientChange, onScanRecipient, receive, receiving, onReceivingChange, onSubmit, submitting, onReset, keypad, destination, details, note, noteTone, title, onBack, controls, actionIcon, lockFrom, lockTo, actionLabel, actionDisabled, actionStatus, actionIntent, limitToBalance, banner, footer, oneWay: oneWayProp, denominationSwitch, settings, view: viewProp, onViewChange, style }: SwapPanelBlockProps): React.JSX.Element;
|
|
141
|
+
/** @deprecated Renamed `SwapPanelBlock`. The old name keeps working until the next major release. */
|
|
142
|
+
export declare const SwapPanel: typeof SwapPanelBlock;
|
|
143
|
+
/** @deprecated Renamed `SwapPanelBlockProps`. */
|
|
144
|
+
export type SwapPanelProps = SwapPanelBlockProps;
|
|
@@ -9,7 +9,7 @@ import { AnimatedNumberReadout } from './animated-number.js';
|
|
|
9
9
|
import { Toast, useTransientNotice } from './status.js';
|
|
10
10
|
import { VerticalAddress, addressKind } from './data.js';
|
|
11
11
|
import { withAlpha } from '@bloxwap/hig/tokens';
|
|
12
|
-
import { DownIcon, FlipIcon, MenuIcon, ResetIcon, SmallChevron, SwapCapsule, SwapHeader, SwapHostContext, SwapKeypad, TokenArt } from './swap-parts.js';
|
|
12
|
+
import { DownIcon, FlipIcon, MenuIcon, ResetIcon, SmallChevron, SwapCapsule, SwapHeader, SwapHostContext, SwapKeypad, SwapNumberText, TokenArt } from './swap-parts.js';
|
|
13
13
|
import { SwapPicker, SwapSettings } from './swap-views.js';
|
|
14
14
|
import { addressColor, applyAmountKey, formatPercent, shortAddress, swapAction, swapParentView, testAmount, trimNumber, unitsToEntry } from './swap-shared.js';
|
|
15
15
|
export { swapAction, swapParentView } from './swap-shared.js';
|
|
@@ -20,7 +20,7 @@ export { SwapHostContext } from './swap-parts.js';
|
|
|
20
20
|
* or token units through the keypad, token pickers, settings, and one action that names itself from the chosen pair.
|
|
21
21
|
* Presentation only. The host owns tokens, balances, prices, the quote, the wallet and the transaction.
|
|
22
22
|
*/
|
|
23
|
-
export function
|
|
23
|
+
export function SwapPanelBlock({ tokens, fromTokens, fromTokensLoading, chains, hotTokenIds, from: fromProp, to: toProp, defaultFrom = null, defaultTo = null, onFromChange, onToChange, amount, onAmountChange, received, fee, fees, quoteLoading, slippage = 0.005, onSlippageChange, denomination, onDenominationChange, wallet, onConnect, onDisconnect, recipient, onRecipientChange, onScanRecipient, receive, receiving, onReceivingChange, onSubmit, submitting = false, onReset, keypad = 'auto', destination, details, note, noteTone = 'muted', title, onBack, controls = true, actionIcon, lockFrom = false, lockTo = false, actionLabel, actionDisabled = false, actionStatus, actionIntent = 'primary', limitToBalance = false, banner, footer, oneWay: oneWayProp = false, denominationSwitch = true, settings, view: viewProp, onViewChange, style }) {
|
|
24
24
|
const env = useHIG();
|
|
25
25
|
const { locale, direction } = env;
|
|
26
26
|
const colors = useColors();
|
|
@@ -65,13 +65,19 @@ export function SwapPanel({ tokens, fromTokens, fromTokensLoading, chains, hotTo
|
|
|
65
65
|
// A destination or a details card stands in for the To token: one way, and ready from the From side alone.
|
|
66
66
|
const fixed = !!destination || (!!details && !to);
|
|
67
67
|
const oneWay = oneWayProp || fixed;
|
|
68
|
-
const
|
|
69
|
-
const
|
|
68
|
+
const eligible = !!from && (!!to || fixed) && !destination?.pending && units > 0 && !insufficient;
|
|
69
|
+
const ready = eligible && !actionDisabled;
|
|
70
|
+
const actionText = showReceive ? t.swapSendFromWallet : !from || (!to && !fixed) ? t.swapChooseToken : destination?.pending ? t.swapChooseDestination : units <= 0 ? t.swapEnterAmount : insufficient ? t.swapInsufficient(from.symbol) : actionDisabled && actionStatus ? actionStatus : actionLabel ?? (action === 'swap' && !fixed ? t.swapActionSwap : action === 'bridge' && !fixed ? t.swapActionBridge : t.swapActionSend);
|
|
70
71
|
const pristine = (lockFrom || !from) && (lockTo || !to) && input === 0;
|
|
71
72
|
// Updater form: several keys can land before the next render, and each must build on the last.
|
|
72
73
|
const latest = useRef(fromMode);
|
|
73
74
|
latest.current = fromMode;
|
|
74
|
-
|
|
75
|
+
// Read at key time: several keys can land in one render.
|
|
76
|
+
const limits = useRef({ decimals: from?.decimals, balance: from?.balance ?? 0, price: from?.price ?? 0, cap: limitToBalance });
|
|
77
|
+
limits.current = { decimals: from?.decimals, balance: from?.balance ?? 0, price: from?.price ?? 0, cap: limitToBalance };
|
|
78
|
+
const over = (next) => { const { balance, price, cap } = limits.current; if (!cap || !(balance > 0))
|
|
79
|
+
return false; const value = Number(next) || 0; return (latest.current === 'token' ? value : price > 0 ? value / price : 0) > balance; };
|
|
80
|
+
const press = (key) => setEntry(current => { const next = applyAmountKey(current, key, latest.current, limits.current.decimals); return key !== 'back' && over(next) ? current : next; });
|
|
75
81
|
const switchFromMode = (mode) => { if (mode === fromMode)
|
|
76
82
|
return; setEntry(mode === 'usd' ? trimNumber(usd, 2) : trimNumber(units)); setFromMode(mode); };
|
|
77
83
|
const changeDenomination = (mode) => { setDefaultMode(mode); switchFromMode(mode); applyToMode(mode); };
|
|
@@ -98,14 +104,16 @@ export function SwapPanel({ tokens, fromTokens, fromTokensLoading, chains, hotTo
|
|
|
98
104
|
const chainList = useMemo(() => { if (chains)
|
|
99
105
|
return chains; const seen = new Map(); for (const token of tokens)
|
|
100
106
|
if (!seen.has(token.chainId))
|
|
101
|
-
seen.set(token.chainId, { chainId: token.chainId, name: token.chain, icon: token.chainIcon }); return [...seen.values()]; }, [chains, tokens]);
|
|
107
|
+
seen.set(token.chainId, { chainId: token.chainId, name: token.chain, icon: typeof token.chainIcon === 'string' ? token.chainIcon : undefined }); return [...seen.values()]; }, [chains, tokens]);
|
|
102
108
|
const usdText = (value) => formatNumber(value, locale, { style: 'currency', currency: 'USD' });
|
|
103
109
|
const fraction = entry.includes('.') ? Math.min(entry.length - entry.indexOf('.') - 1, fromMode === 'usd' ? 2 : 8) : 0;
|
|
104
|
-
const
|
|
110
|
+
const smallType = { fontSize: 14, lineHeight: 19 }, small = { ...smallType, color: colors.muted };
|
|
111
|
+
// Live numbers: the fee and slippage sentences keep their translated wording around a number that updates in place.
|
|
112
|
+
const usdOptions = { style: 'currency', currency: 'USD' }, feeKnown = !quoteLoading && fee != null, feeAmount = quoteLoading ? '…' : fee != null ? usdText(fee) : '—', slippageText = formatPercent(slippage);
|
|
105
113
|
// An account (a token with a `caption`) reads name over caption beside one disc, and offers Max only.
|
|
106
|
-
const account = (side, token, locked) => _jsxs(_Fragment, { children: [_jsxs(View, { pointerEvents: 'none', testID: `swap-account-${side}`, style: { flex: 1, minWidth: 0, flexDirection: 'row', alignItems: 'center', gap: 12 }, children: [_jsx(View, { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', children: _jsx(TokenArt, { uri: token.icon, symbol: token.symbol, size: 40 }) }), _jsxs(View, { style: { flex: 1, minWidth: 0 }, children: [_jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: 4 }, children: [_jsx(Text, { style: { fontWeight: '600', lineHeight: 21, flexShrink: 1 }, children: token.name }), locked ? null : _jsx(View, { testID: `swap-account-chevron-${side}`, children: _jsx(SmallChevron, { color: colors.muted }) })] }), _jsx(Text, { style: small, children: token.caption })] })] }), side === 'from' && (token.balance ?? 0) > 0 ? _jsx(SwapCapsule, { testID: 'swap-max', onPress: () => setEntry(unitsToEntry(token.balance ?? 0, fromMode, fromPrice)), children: _jsx(Text, { style: small, children: t.swapMax }) }) : null] });
|
|
107
|
-
const header = (side, token) => _jsxs(_Fragment, { children: [_jsxs(View, { pointerEvents: 'none', style: { flex: 1, minWidth: 0, flexDirection: 'row', alignItems: 'flex-start', gap: 12 }, children: [_jsx(View, { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', style: { alignItems: 'center' }, children: [wallet?.address ? _jsx(View, { style: { width: 28, height: 28, borderRadius: 14, backgroundColor: addressColor(wallet.address), borderWidth: 2, borderColor: colors.surface } }) : null, token.chainIcon ? _jsx(TokenArt, { uri: token.chainIcon, size: 28, ring: colors.surface }) : null, _jsx(TokenArt, { uri: token.icon, symbol: token.symbol, size: 28, ring: colors.surface })].filter(Boolean).map((layer, index) => _jsx(View, { style: { marginTop: index ? -14 : 0 }, children: layer }, index)) }), _jsxs(View, { style: { flex: 1, minWidth: 0 }, children: [wallet?.address ? _jsx(Text, { style: small, children: shortAddress(wallet.address) }) : null, _jsx(Text, { style: small, children: token.chain }), _jsx(Text, { style: { fontWeight: '600', lineHeight: 21 }, children: token.name })] })] }), side === 'from' ? ((token.balance ?? 0) > 0 ? _jsxs(View, { pointerEvents: 'box-none', style: { alignItems: 'flex-end', gap: 8, maxWidth: '60%' }, children: [_jsxs(View, { pointerEvents: 'box-none', style: { flexDirection: 'row', flexWrap: 'wrap', justifyContent: 'flex-end', gap: 8 }, children: [_jsx(SwapCapsule, { testID: 'swap-test', onPress: () => setEntry(unitsToEntry(testAmount(token), fromMode, fromPrice)), children: _jsx(Text, { style: small, children: t.swapTest }) }), _jsx(SwapCapsule, { testID: 'swap-max', onPress: () => setEntry(unitsToEntry(token.balance ?? 0, fromMode, fromPrice)), children: _jsx(Text, { style: small, children: t.swapMax }) })] }), _jsx(View, { pointerEvents: 'none', children:
|
|
108
|
-
: _jsxs(View, { pointerEvents: 'box-none', style: { alignItems: 'flex-end', gap: 8, maxWidth: '60%' }, children: [_jsx(SwapCapsule, { testID: 'swap-slippage', onPress: () => show(onSlippageChange ? 'slippage' : 'settings'), children: _jsx(
|
|
114
|
+
const account = (side, token, locked) => _jsxs(_Fragment, { children: [_jsxs(View, { pointerEvents: 'none', testID: `swap-account-${side}`, style: { flex: 1, minWidth: 0, flexDirection: 'row', alignItems: 'center', gap: 12 }, children: [_jsx(View, { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', children: _jsx(TokenArt, { uri: token.icon, symbol: token.symbol, size: 40 }) }), _jsxs(View, { style: { flex: 1, minWidth: 0 }, children: [_jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: 4 }, children: [_jsx(Text, { style: { fontWeight: '600', lineHeight: 21, flexShrink: 1 }, children: token.name }), locked ? null : _jsx(View, { testID: `swap-account-chevron-${side}`, children: _jsx(SmallChevron, { color: colors.muted }) })] }), typeof token.caption === 'object' ? _jsx(AnimatedNumberReadout, { testID: 'swap-caption', ...token.caption, tone: 'muted', style: smallType }) : _jsx(Text, { style: small, children: token.caption })] })] }), side === 'from' && (token.balance ?? 0) > 0 ? _jsx(SwapCapsule, { testID: 'swap-max', onPress: () => setEntry(unitsToEntry(token.balance ?? 0, fromMode, fromPrice)), children: _jsx(Text, { style: small, children: t.swapMax }) }) : null] });
|
|
115
|
+
const header = (side, token) => _jsxs(_Fragment, { children: [_jsxs(View, { pointerEvents: 'none', style: { flex: 1, minWidth: 0, flexDirection: 'row', alignItems: 'flex-start', gap: 12 }, children: [_jsx(View, { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', style: { alignItems: 'center' }, children: [wallet?.address ? _jsx(View, { style: { width: 28, height: 28, borderRadius: 14, backgroundColor: addressColor(wallet.address), borderWidth: 2, borderColor: colors.surface } }) : null, token.chainIcon ? _jsx(TokenArt, { uri: token.chainIcon, size: 28, ring: colors.surface }) : null, _jsx(TokenArt, { uri: token.icon, symbol: token.symbol, size: 28, ring: colors.surface })].filter(Boolean).map((layer, index) => _jsx(View, { style: { marginTop: index ? -14 : 0 }, children: layer }, index)) }), _jsxs(View, { style: { flex: 1, minWidth: 0 }, children: [wallet?.address ? _jsx(Text, { style: small, children: shortAddress(wallet.address) }) : null, _jsx(Text, { style: small, children: token.chain }), _jsx(Text, { style: { fontWeight: '600', lineHeight: 21 }, children: token.name })] })] }), side === 'from' ? ((token.balance ?? 0) > 0 ? _jsxs(View, { pointerEvents: 'box-none', style: { alignItems: 'flex-end', gap: 8, maxWidth: '60%' }, children: [_jsxs(View, { pointerEvents: 'box-none', style: { flexDirection: 'row', flexWrap: 'wrap', justifyContent: 'flex-end', gap: 8 }, children: [_jsx(SwapCapsule, { testID: 'swap-test', onPress: () => setEntry(unitsToEntry(testAmount(token), fromMode, fromPrice)), children: _jsx(Text, { style: small, children: t.swapTest }) }), _jsx(SwapCapsule, { testID: 'swap-max', onPress: () => setEntry(unitsToEntry(token.balance ?? 0, fromMode, fromPrice)), children: _jsx(Text, { style: small, children: t.swapMax }) })] }), _jsx(View, { pointerEvents: 'none', children: _jsx(AnimatedNumberReadout, { testID: 'swap-balance', value: token.balance, options: { maximumFractionDigits: 6 }, suffix: ` ${token.symbol}`, tone: 'muted', style: smallType }) })] }) : null)
|
|
116
|
+
: _jsxs(View, { pointerEvents: 'box-none', style: { alignItems: 'flex-end', gap: 8, maxWidth: '60%' }, children: [_jsx(SwapCapsule, { testID: 'swap-slippage', label: t.swapSlippage(slippageText), onPress: () => show(onSlippageChange ? 'slippage' : 'settings'), children: _jsx(SwapNumberText, { template: t.swapSlippage, text: slippageText, value: slippage * 100, formattedValue: slippageText.slice(0, -1), suffix: '%' }) }), _jsx(View, { pointerEvents: 'none', children: _jsx(SwapNumberText, { testID: 'swap-fee', template: t.swapFee, text: feeAmount, value: feeKnown ? fee : null, options: usdOptions }) })] })] });
|
|
109
117
|
const receiveView = (view) => {
|
|
110
118
|
const body = _jsxs(_Fragment, { children: [view.qr ? _jsx(View, { style: { width: 132, height: 132, padding: 8, borderRadius: 16, backgroundColor: colors.background }, children: view.qr }) : null, _jsx(View, { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', children: _jsx(VerticalAddress, { address: view.address, rowHeight: addressKind(view.address) === 'ethereum' ? 22 : 16 }) })] });
|
|
111
119
|
const layout = { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-evenly', gap: 12, paddingTop: 8, paddingHorizontal: 16, paddingBottom: 20 };
|
|
@@ -117,22 +125,22 @@ export function SwapPanel({ tokens, fromTokens, fromTokensLoading, chains, hotTo
|
|
|
117
125
|
const shown = side === 'from' ? input : mode === 'token' ? receivedUnits : receivedUsd;
|
|
118
126
|
const options = { minimumFractionDigits: side === 'from' ? fraction : 0, maximumFractionDigits: mode === 'usd' ? 2 : 8, useGrouping: false };
|
|
119
127
|
const prefix = mode === 'usd' ? '$' : '', suffix = side === 'from' && entry.endsWith('.') ? '.' : '';
|
|
120
|
-
return _jsx(View, { testID: `swap-card-${side}`, style: { backgroundColor: colors.surface, borderRadius: 24, overflow: 'hidden' }, children: _jsxs(Raised, { children: [_jsxs(View, { children: [locked ? null : _jsx(Pressable, { accessibilityRole: 'button', accessibilityLabel: t.swapSelectToken(label), testID: `swap-slot-${side}`, onPress: () => show(side), style: StyleSheet.absoluteFill }), _jsx(View, { pointerEvents: 'box-none', style: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', gap: 12, minHeight: 84, padding: 16 }, children: token ? token.caption !== undefined ? account(side, token, locked) : header(side, token) : _jsx(View, { pointerEvents: 'none', children: _jsxs(Text, { accessible: false, style: { fontSize: 40, lineHeight: 46, fontWeight: '500', letterSpacing: -0.8, color: colors.faint }, children: [label, "\u2026"] }) }) })] }), side === 'from' && showReceive && receive ? receiveView(receive) : side === 'to' && showReceive ? null : _jsxs(View, { children: [locked ? null : _jsx(Pressable, { accessible: false, importantForAccessibility: 'no', testID: `swap-area-${side}`, onPress: () => show(side), style: StyleSheet.absoluteFill }), _jsxs(View, { pointerEvents: 'box-none', style: { alignItems: 'center', gap: 8, paddingTop: 4, paddingHorizontal: 16, paddingBottom: 20 }, children: [_jsx(View, { pointerEvents: 'none', accessible: true, accessibilityLabel: t.swapAmount(label), accessibilityValue: { text: `${prefix}${formatNumber(shown, locale, options)}${suffix}` }, testID: `swap-amount-${side}`, children: _jsx(AnimatedNumberReadout, { value: shown, prefix: prefix, suffix: suffix, options: options, tone: side === 'to' ? 'muted' : 'text', maxFontSizeMultiplier: 1.5, style: { fontSize: 44, lineHeight: 50, fontWeight: '700', letterSpacing: -0.9, textAlign: 'center' } }) }), denominationSwitch && _jsxs(SwapCapsule, { label: t.swapSwitchDenomination, testID: `swap-mode-${side}`, onPress: () => side === 'from' ? switchFromMode(fromMode === 'usd' ? 'token' : 'usd') : applyToMode(toMode === 'usd' ? 'token' : 'usd'), children: [_jsx(Text, { accessible: false, style: [small, { opacity: 0.5 }], children: "=" }), _jsx(
|
|
128
|
+
return _jsx(View, { testID: `swap-card-${side}`, style: { backgroundColor: colors.surface, borderRadius: 24, overflow: 'hidden' }, children: _jsxs(Raised, { children: [_jsxs(View, { children: [locked ? null : _jsx(Pressable, { accessibilityRole: 'button', accessibilityLabel: t.swapSelectToken(label), testID: `swap-slot-${side}`, onPress: () => show(side), style: StyleSheet.absoluteFill }), _jsx(View, { pointerEvents: 'box-none', style: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', gap: 12, minHeight: 84, padding: 16 }, children: token ? token.caption !== undefined ? account(side, token, locked) : header(side, token) : _jsx(View, { pointerEvents: 'none', children: _jsxs(Text, { accessible: false, style: { fontSize: 40, lineHeight: 46, fontWeight: '500', letterSpacing: -0.8, color: colors.faint }, children: [label, "\u2026"] }) }) })] }), side === 'from' && showReceive && receive ? receiveView(receive) : side === 'to' && showReceive ? null : _jsxs(View, { children: [locked ? null : _jsx(Pressable, { accessible: false, importantForAccessibility: 'no', testID: `swap-area-${side}`, onPress: () => show(side), style: StyleSheet.absoluteFill }), _jsxs(View, { pointerEvents: 'box-none', style: { alignItems: 'center', gap: 8, paddingTop: 4, paddingHorizontal: 16, paddingBottom: 20 }, children: [_jsx(View, { pointerEvents: 'none', accessible: true, accessibilityLabel: t.swapAmount(label), accessibilityValue: { text: `${prefix}${formatNumber(shown, locale, options)}${suffix}` }, testID: `swap-amount-${side}`, children: _jsx(AnimatedNumberReadout, { value: shown, prefix: prefix, suffix: suffix, options: options, tone: side === 'to' ? 'muted' : 'text', maxFontSizeMultiplier: 1.5, style: { fontSize: 44, lineHeight: 50, fontWeight: '700', letterSpacing: -0.9, textAlign: 'center' } }) }), denominationSwitch && _jsxs(SwapCapsule, { label: t.swapSwitchDenomination, testID: `swap-mode-${side}`, onPress: () => side === 'from' ? switchFromMode(fromMode === 'usd' ? 'token' : 'usd') : applyToMode(toMode === 'usd' ? 'token' : 'usd'), children: [_jsx(Text, { accessible: false, style: [small, { opacity: 0.5 }], children: "=" }), mode === 'token' ? _jsx(AnimatedNumberReadout, { testID: `swap-conversion-${side}`, value: cardUsd, options: usdOptions, tone: 'muted', style: smallType }) : _jsx(AnimatedNumberReadout, { testID: `swap-conversion-${side}`, value: cardUnits, options: { maximumFractionDigits: 8, useGrouping: false }, suffix: token ? ` ${token.symbol}` : '', tone: 'muted', style: smallType }), _jsx(FlipIcon, { color: colors.muted, size: 14 })] })] })] })] }) });
|
|
121
129
|
};
|
|
122
130
|
// The fixed bottom card is one compact row for the destination (artwork, where it goes, a trailing detail and fee), label and value rows, or both.
|
|
123
131
|
const fixedCard = () => {
|
|
124
132
|
if (!fixed)
|
|
125
133
|
return null;
|
|
126
134
|
const art = !destination ? null : destination.icon ? _jsx(TokenArt, { uri: destination.icon, size: 40 }) : destination.address ? _jsx(View, { style: { width: 40, height: 40, borderRadius: 20, backgroundColor: addressColor(destination.address) } }) : _jsx(View, { style: { width: 40, height: 40, borderRadius: 20, backgroundColor: colors.nested, alignItems: 'center', justifyContent: 'center' }, children: _jsx(Text, { style: { fontSize: 12, lineHeight: 16, fontWeight: '600', color: colors.muted }, children: destination.title.slice(0, 2) }) });
|
|
127
|
-
const row = destination ? _jsxs(View, { pointerEvents: 'none', style: { flexDirection: 'row', alignItems: 'center', gap: 12, minHeight: 84, padding: 16 }, children: [_jsx(View, { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', children: art }), _jsxs(View, { style: { flex: 1, minWidth: 0 }, children: [_jsx(Text, { testID: 'swap-destination-title', style: { fontWeight: destination.pending ? '500' : '600', lineHeight: 21 }, children: destination.title }), destination.subtitle ? _jsx(Text, { style: small, children: destination.subtitle }) : null, destination.address ? _jsx(Text, { style: small, children: shortAddress(destination.address) }) : null] }), destination.detail || fee !== undefined || destination.onPress ? _jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: 8, maxWidth: '60%' }, children: [_jsxs(View, { style: { alignItems: 'flex-end', gap: 8, flexShrink: 1 }, children: [destination.detail ? _jsx(Text, { style: [small, { textAlign: 'right' }], children: destination.detail }) : null, fee !== undefined ? _jsx(
|
|
128
|
-
const rows = details && details.length > 0 ? _jsx(View, { testID: 'swap-details', style: { gap: 12, padding: 16, paddingTop: destination ? 0 : 16 }, children: details.map(detail => _jsxs(View, { style: { flexDirection: 'row', justifyContent: 'space-between', gap: 12 }, children: [_jsx(Text, { style: { color: colors.muted, lineHeight: 21 }, children: detail.label }), _jsx(Text, { style: { lineHeight: 21, textAlign: 'right', flexShrink: 1 }, children: detail.value })] }, detail.label)) }) : null;
|
|
135
|
+
const row = destination ? _jsxs(View, { pointerEvents: 'none', style: { flexDirection: 'row', alignItems: 'center', gap: 12, minHeight: 84, padding: 16 }, children: [_jsx(View, { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', children: art }), _jsxs(View, { style: { flex: 1, minWidth: 0 }, children: [_jsx(Text, { testID: 'swap-destination-title', style: { fontWeight: destination.pending ? '500' : '600', lineHeight: 21 }, children: destination.title }), destination.subtitle ? _jsx(Text, { style: small, children: destination.subtitle }) : null, destination.address ? _jsx(Text, { style: small, children: shortAddress(destination.address) }) : null] }), destination.detail || fee !== undefined || destination.onPress ? _jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: 8, maxWidth: '60%' }, children: [_jsxs(View, { style: { alignItems: 'flex-end', gap: 8, flexShrink: 1 }, children: [typeof destination.detail === 'object' ? _jsx(AnimatedNumberReadout, { testID: 'swap-destination-detail', ...destination.detail, tone: 'muted', style: { ...smallType, textAlign: 'right' } }) : destination.detail ? _jsx(Text, { style: [small, { textAlign: 'right' }], children: destination.detail }) : null, fee !== undefined ? _jsx(SwapNumberText, { testID: 'swap-destination-fee', align: 'right', template: t.swapFee, text: feeAmount, value: feeKnown ? fee : null, options: usdOptions }) : null] }), destination.onPress ? _jsx(View, { testID: 'swap-destination-chevron', children: _jsx(SmallChevron, { color: colors.muted, trailing: true }) }) : null] }) : null] }) : null;
|
|
136
|
+
const rows = details && details.length > 0 ? _jsx(View, { testID: 'swap-details', style: { gap: 12, padding: 16, paddingTop: destination ? 0 : 16 }, children: details.map(detail => _jsxs(View, { style: { flexDirection: 'row', justifyContent: 'space-between', gap: 12 }, children: [_jsx(Text, { style: { color: colors.muted, lineHeight: 21 }, children: detail.label }), typeof detail.value === 'number' ? _jsx(AnimatedNumberReadout, { value: detail.value, options: detail.options, prefix: detail.prefix, suffix: detail.suffix, style: { lineHeight: 21, textAlign: 'right' } }) : _jsx(Text, { style: { lineHeight: 21, textAlign: 'right', flexShrink: 1 }, children: detail.value })] }, detail.label)) }) : null;
|
|
129
137
|
const shape = { backgroundColor: colors.surface, borderRadius: 24, overflow: 'hidden' };
|
|
130
138
|
// With a pressable destination the whole card is the button; the rows inside it are read as part of it.
|
|
131
139
|
return destination?.onPress ? _jsx(Pressable, { accessibilityRole: 'button', accessibilityLabel: destination.title, testID: 'swap-destination', onPress: destination.onPress, style: ({ pressed }) => [shape, { opacity: pressed ? 0.85 : 1 }], children: _jsxs(Raised, { children: [row, rows] }) }) : _jsx(View, { testID: 'swap-destination', style: shape, children: _jsxs(Raised, { children: [row, rows] }) });
|
|
132
140
|
};
|
|
133
141
|
const fromCard = card('from'), toCard = fixedCard() ?? card('to');
|
|
134
142
|
const tone = noteTone === 'warning' ? colors.warning : noteTone === 'negative' ? colors.negative : null;
|
|
135
|
-
const main = _jsxs(View, { testID: 'swap-view-main', children: [title ? _jsx(View, { style: { marginBottom: 12 }, children: _jsx(SwapHeader, { title: title, onBack: onBack }) }) : null, fromCard, _jsx(View, { style: { height: 8, zIndex: 1, alignItems: 'center' }, children: _jsx(View, { style: { position: 'absolute', top: -15, width: 38, height: 38, borderRadius: 19, backgroundColor: colors.background, alignItems: 'center', justifyContent: 'center' }, children: oneWay ? _jsx(View, { testID: 'swap-one-way', style: { width: 32, height: 32, borderRadius: 16, alignItems: 'center', justifyContent: 'center', backgroundColor: colors.nested }, children: _jsx(DownIcon, { color: colors.muted }) }) : _jsx(Pressable, { accessibilityRole: 'button', accessibilityLabel: t.swapFlip, accessibilityState: { disabled: !from || !to }, disabled: !from || !to, testID: 'swap-flip', onPress: flip, hitSlop: 6, style: ({ pressed }) => ({ width: 32, height: 32, borderRadius: 16, alignItems: 'center', justifyContent: 'center', backgroundColor: !from || !to ? colors.surface : colors.nested, opacity: pressed ? 0.85 : 1 }), children: _jsx(FlipIcon, { color: !from || !to ? colors.faint : colors.muted }) }) }) }), toCard, note ? _jsx(View, { testID: 'swap-note', style: tone ? { marginTop: 8, paddingVertical: 12, paddingHorizontal: 16, borderRadius: 16, backgroundColor: withAlpha(tone, 0.
|
|
143
|
+
const main = _jsxs(View, { testID: 'swap-view-main', children: [title ? _jsx(View, { style: { marginBottom: 12 }, children: _jsx(SwapHeader, { title: title, onBack: onBack }) }) : null, banner ? _jsx(View, { testID: 'swap-banner', style: { marginBottom: 8 }, children: banner }) : null, fromCard, _jsx(View, { style: { height: 8, zIndex: 1, alignItems: 'center' }, children: _jsx(View, { style: { position: 'absolute', top: -15, width: 38, height: 38, borderRadius: 19, backgroundColor: colors.background, alignItems: 'center', justifyContent: 'center' }, children: oneWay ? _jsx(View, { testID: 'swap-one-way', style: { width: 32, height: 32, borderRadius: 16, alignItems: 'center', justifyContent: 'center', backgroundColor: colors.nested }, children: _jsx(DownIcon, { color: colors.muted }) }) : _jsx(Pressable, { accessibilityRole: 'button', accessibilityLabel: t.swapFlip, accessibilityState: { disabled: !from || !to }, disabled: !from || !to, testID: 'swap-flip', onPress: flip, hitSlop: 6, style: ({ pressed }) => ({ width: 32, height: 32, borderRadius: 16, alignItems: 'center', justifyContent: 'center', backgroundColor: !from || !to ? colors.surface : colors.nested, opacity: pressed ? 0.85 : 1 }), children: _jsx(FlipIcon, { color: !from || !to ? colors.faint : colors.muted }) }) }) }), toCard, note ? _jsx(View, { testID: 'swap-note', style: tone ? { marginTop: 8, paddingVertical: 12, paddingHorizontal: 16, borderRadius: 16, backgroundColor: withAlpha(tone, 0.1) } : { marginTop: 8, paddingHorizontal: 4 }, children: _jsx(Text, { style: { fontSize: 14, lineHeight: 21, color: tone ?? colors.muted }, children: note }) }) : null, !showReceive && keypad !== 'never' ? _jsx(SwapKeypad, { onKey: press, label: t.swapKeypad, deleteLabel: t.swapDelete }) : null, _jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: 8, marginTop: 16 }, children: [controls ? _jsx(IconButton, { intent: 'secondary', label: t.swapSettings, suppressFeedback: true, testID: 'swap-settings-button', onPress: () => show('settings'), children: _jsx(MenuIcon, { color: colors.text }) }) : null, _jsxs(Button, { intent: actionIntent, busy: submitting, disabled: !showReceive && !ready, testID: 'swap-action', onPress: submit, style: { flex: 1, alignSelf: 'auto' }, children: [actionIcon ? _jsx(View, { testID: 'swap-action-icon', accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', children: actionIcon }, 'icon') : null, actionText] }), controls ? _jsx(IconButton, { intent: 'secondary', label: t.swapReset, disabled: pristine || submitting, testID: 'swap-reset', onPress: reset, children: _jsx(ResetIcon, { color: colors.text }) }) : null] }), notice ? _jsx(View, { style: { marginTop: 8, alignItems: 'center' }, children: _jsx(Toast, { notices: [notice], onDismiss: dismissNotice }) }) : null, footer ? _jsx(View, { testID: 'swap-footer', style: { marginTop: 16 }, children: footer }) : null] });
|
|
136
144
|
const body = view === 'main' ? main
|
|
137
145
|
: view === 'from' ? _jsx(SwapPicker, { side: view, onBack: back, tokens: fromTokens ?? tokens, loading: fromTokensLoading, chains: chainList, hotTokenIds: hotTokenIds, selected: from, onSelect: setFrom, wallet: wallet, onConnect: onConnect, onDisconnect: onDisconnect, receiving: isReceiving, onReceivingChange: receive ? setReceiving : undefined })
|
|
138
146
|
: view === 'to' ? _jsx(SwapPicker, { side: view, onBack: back, tokens: tokens, chains: chainList, hotTokenIds: hotTokenIds, selected: to, onSelect: setTo, wallet: wallet, recipient: recipient, onRecipientChange: onRecipientChange, onScanRecipient: onScanRecipient })
|
|
@@ -175,3 +183,5 @@ function SwapStage({ view, animateHeight, children }) {
|
|
|
175
183
|
const fitted = sizing && sized;
|
|
176
184
|
return _jsx(Animated.View, { testID: 'swap-stage', style: fitted ? { height, overflow: 'hidden' } : undefined, children: _jsx(Animated.View, { onLayout: onLayout, style: [fitted ? { position: 'absolute', left: 0, right: 0, top: 0 } : null, { opacity: slide, transform: [{ translateX: slide.interpolate({ inputRange: [0, 1], outputRange: [travel.current * 48, 0] }) }] }], children: children }) });
|
|
177
185
|
}
|
|
186
|
+
/** @deprecated Renamed `SwapPanelBlock`. The old name keeps working until the next major release. */
|
|
187
|
+
export const SwapPanel = SwapPanelBlock;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { type FlatListProps } from 'react-native';
|
|
3
|
-
import type { SwapToken } from './swap-shared.js';
|
|
3
|
+
import type { SwapArtwork, SwapToken } from './swap-shared.js';
|
|
4
4
|
/** 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. */
|
|
5
5
|
export declare const SwapHostContext: React.Context<{
|
|
6
6
|
listComponent?: React.ComponentType<FlatListProps<SwapToken>>;
|
|
@@ -43,9 +43,9 @@ export declare function LockIcon({ color }: {
|
|
|
43
43
|
export declare function LeaveIcon({ color }: {
|
|
44
44
|
color: string;
|
|
45
45
|
}): React.JSX.Element;
|
|
46
|
-
/** Circular artwork from a URL, or the symbol's first letters when the host has none. */
|
|
46
|
+
/** Circular artwork from a URL or the host's own element, or the symbol's first letters when the host has none. */
|
|
47
47
|
export declare function TokenArt({ uri, symbol, size, ring }: {
|
|
48
|
-
uri?:
|
|
48
|
+
uri?: SwapArtwork;
|
|
49
49
|
symbol?: string;
|
|
50
50
|
size: number;
|
|
51
51
|
ring?: string;
|
|
@@ -84,3 +84,14 @@ export declare function SwapSubview({ title, onBack, testID, children }: React.P
|
|
|
84
84
|
onBack: () => void;
|
|
85
85
|
testID?: string;
|
|
86
86
|
}>): React.JSX.Element;
|
|
87
|
+
/** 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`. */
|
|
88
|
+
export declare function SwapNumberText({ template, text, value, options, formattedValue, suffix, align, testID }: {
|
|
89
|
+
template: (amount: string) => string;
|
|
90
|
+
text: string;
|
|
91
|
+
value?: number | null;
|
|
92
|
+
options?: Intl.NumberFormatOptions;
|
|
93
|
+
formattedValue?: string;
|
|
94
|
+
suffix?: string;
|
|
95
|
+
align?: 'right';
|
|
96
|
+
testID?: string;
|
|
97
|
+
}): React.JSX.Element;
|