@bloxwap/hig 0.6.0 → 0.8.1
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 +2 -2
- package/chart/README.md +13 -2
- package/chart/dist/altimeter-burst.d.ts +4 -0
- package/chart/dist/altimeter-burst.js +43 -0
- package/chart/dist/altimeter-chart.d.ts +52 -0
- package/chart/dist/altimeter-chart.js +275 -0
- package/chart/dist/altimeter-model.d.ts +43 -0
- package/chart/dist/altimeter-model.js +148 -0
- package/chart/dist/altimeter-targets.d.ts +33 -0
- package/chart/dist/altimeter-targets.js +88 -0
- package/chart/dist/bitcoin-price.d.ts +8 -0
- package/chart/dist/bitcoin-price.js +41 -0
- package/chart/dist/champions-league.d.ts +19 -0
- package/chart/dist/champions-league.js +104 -0
- package/chart/dist/index.d.ts +6 -0
- package/chart/dist/index.js +5 -0
- package/chart/dist/outcome-chart.d.ts +37 -0
- package/chart/dist/outcome-chart.js +212 -0
- package/chart/dist/outcome-model.d.ts +43 -0
- package/chart/dist/outcome-model.js +71 -0
- package/chart/dist/plus-grid.d.ts +6 -0
- package/chart/dist/plus-grid.js +29 -0
- package/contracts/README.md +1 -1
- package/contracts/dist/avatar.d.ts +68 -0
- package/contracts/dist/avatar.js +93 -0
- package/contracts/dist/confetti.d.ts +174 -0
- package/contracts/dist/confetti.js +138 -0
- package/contracts/dist/decimal.d.ts +7 -0
- package/contracts/dist/decimal.js +35 -0
- package/contracts/dist/index.d.ts +45 -2
- package/contracts/dist/index.js +145 -4
- package/contracts/dist/invariants.d.ts +17 -0
- package/contracts/dist/invariants.js +24 -0
- package/contracts/dist/messages.d.ts +62 -2
- package/contracts/dist/messages.js +22 -2
- package/contracts/dist/number-flow.d.ts +90 -0
- package/contracts/dist/number-flow.js +150 -0
- package/contracts/dist/qr.d.ts +151 -0
- package/contracts/dist/qr.js +581 -0
- package/contracts/dist/toast.d.ts +168 -0
- package/contracts/dist/toast.js +171 -0
- package/feedback/README.md +1 -1
- package/feedback/dist/contract.js +1 -1
- package/feedback/dist/react.js +2 -4
- package/native/README.md +6 -1
- package/native/dist/account-block.d.ts +62 -7
- package/native/dist/account-block.js +54 -11
- package/native/dist/animated-number-model.d.ts +47 -1
- package/native/dist/animated-number-model.js +248 -21
- package/native/dist/animated-number.d.ts +41 -1
- package/native/dist/animated-number.js +165 -17
- package/native/dist/announce.d.ts +2 -0
- package/native/dist/announce.js +10 -0
- package/native/dist/asset-balance-row.d.ts +19 -1
- package/native/dist/asset-balance-row.js +24 -8
- package/native/dist/assets-block.d.ts +115 -0
- package/native/dist/assets-block.js +87 -0
- package/native/dist/async-result.d.ts +2 -0
- package/native/dist/async-result.js +11 -0
- package/native/dist/avatar-frame.d.ts +29 -0
- package/native/dist/avatar-frame.js +56 -0
- package/native/dist/avatar.d.ts +21 -0
- package/native/dist/avatar.js +31 -0
- package/native/dist/bar-mark.d.ts +16 -2
- package/native/dist/bar-mark.js +23 -7
- package/native/dist/bar-pnl.js +7 -5
- package/native/dist/blocks.d.ts +13 -14
- package/native/dist/blocks.js +10 -6
- package/native/dist/brand.js +2 -1
- package/native/dist/button.d.ts +7 -2
- package/native/dist/button.js +16 -4
- package/native/dist/checkbox.js +2 -1
- package/native/dist/confetti.d.ts +33 -0
- package/native/dist/confetti.js +143 -0
- package/native/dist/confirm-block.d.ts +98 -0
- package/native/dist/confirm-block.js +48 -0
- package/native/dist/data.d.ts +1 -1
- package/native/dist/data.js +8 -4
- package/native/dist/explainer-block.d.ts +91 -0
- package/native/dist/explainer-block.js +34 -0
- package/native/dist/field.d.ts +19 -5
- package/native/dist/field.js +56 -9
- package/native/dist/figure.d.ts +23 -0
- package/native/dist/figure.js +10 -0
- package/native/dist/gesture-sheet-model.d.ts +50 -0
- package/native/dist/gesture-sheet-model.js +105 -0
- package/native/dist/gesture-sheet-next.d.ts +82 -0
- package/native/dist/gesture-sheet-next.js +315 -0
- package/native/dist/gesture-sheet.d.ts +5 -1
- package/native/dist/gesture-sheet.js +13 -6
- package/native/dist/icons.d.ts +9 -6
- package/native/dist/icons.js +25 -24
- package/native/dist/language-block.d.ts +14 -1
- package/native/dist/language-block.js +11 -4
- package/native/dist/list-group.d.ts +44 -8
- package/native/dist/list-group.js +84 -13
- package/native/dist/manage-position-block.d.ts +35 -2
- package/native/dist/manage-position-block.js +41 -11
- package/native/dist/market-row.d.ts +46 -0
- package/native/dist/market-row.js +41 -0
- package/native/dist/navigation.js +5 -3
- package/native/dist/notifications-block.d.ts +30 -2
- package/native/dist/notifications-block.js +16 -8
- package/native/dist/number-format.d.ts +6 -0
- package/native/dist/number-format.js +9 -0
- package/native/dist/pickers.d.ts +32 -2
- package/native/dist/pickers.js +17 -9
- package/native/dist/position-block.d.ts +66 -10
- package/native/dist/position-block.js +45 -11
- package/native/dist/preset-group.d.ts +31 -0
- package/native/dist/preset-group.js +39 -0
- package/native/dist/preset-picker-block.d.ts +107 -0
- package/native/dist/preset-picker-block.js +43 -0
- package/native/dist/profile-block.d.ts +38 -5
- package/native/dist/profile-block.js +31 -6
- package/native/dist/provider.d.ts +14 -5
- package/native/dist/provider.js +32 -6
- package/native/dist/qr-code.d.ts +33 -0
- package/native/dist/qr-code.js +29 -0
- package/native/dist/radio-group.d.ts +23 -5
- package/native/dist/radio-group.js +40 -12
- package/native/dist/recipes.d.ts +6 -0
- package/native/dist/recipes.js +6 -0
- package/native/dist/reward-block.d.ts +55 -13
- package/native/dist/reward-block.js +37 -14
- package/native/dist/screen-header.d.ts +59 -0
- package/native/dist/screen-header.js +37 -0
- package/native/dist/select.js +4 -2
- package/native/dist/selection.d.ts +3 -2
- package/native/dist/selection.js +1 -0
- package/native/dist/setting-header.d.ts +2 -8
- package/native/dist/setting-header.js +2 -11
- package/native/dist/setting-switch.d.ts +15 -2
- package/native/dist/setting-switch.js +11 -4
- package/native/dist/signals-block.d.ts +26 -2
- package/native/dist/signals-block.js +14 -4
- package/native/dist/slider.js +5 -1
- package/native/dist/sound-haptics-block.d.ts +29 -2
- package/native/dist/sound-haptics-block.js +19 -8
- package/native/dist/status.d.ts +47 -14
- package/native/dist/status.js +39 -22
- package/native/dist/sticky-header.d.ts +28 -0
- package/native/dist/sticky-header.js +29 -0
- package/native/dist/surface.d.ts +3 -1
- package/native/dist/surface.js +2 -1
- package/native/dist/swap-amount-card.d.ts +57 -0
- package/native/dist/swap-amount-card.js +31 -0
- package/native/dist/swap-panel-block.d.ts +11 -4
- package/native/dist/swap-panel-block.js +67 -38
- package/native/dist/swap-parts.d.ts +5 -10
- package/native/dist/swap-parts.js +22 -24
- package/native/dist/swap-shared.d.ts +8 -2
- package/native/dist/swap-shared.js +10 -6
- package/native/dist/swap-views.js +6 -4
- package/native/dist/switch-row.d.ts +3 -2
- package/native/dist/switch-row.js +5 -3
- package/native/dist/switch.d.ts +4 -2
- package/native/dist/switch.js +3 -3
- package/native/dist/target-block.d.ts +40 -7
- package/native/dist/target-block.js +31 -11
- package/native/dist/toast.d.ts +47 -0
- package/native/dist/toast.js +386 -0
- package/native/dist/token-action-block.d.ts +26 -9
- package/native/dist/token-action-block.js +21 -8
- package/native/dist/trade-history-detail-block.d.ts +26 -1
- package/native/dist/trade-history-detail-block.js +17 -9
- package/native/dist/trade-history-list-block.d.ts +71 -5
- package/native/dist/trade-history-list-block.js +55 -17
- package/native/dist/wallet-address-core.d.ts +25 -0
- package/native/dist/wallet-address-core.js +34 -0
- package/native/dist/wallet-address.d.ts +6 -10
- package/native/dist/wallet-address.js +16 -20
- package/native-fonts/README.md +1 -1
- package/og-fonts/README.md +1 -1
- package/package.json +131 -2
- package/react/README.md +3 -1
- package/react/dist/animated-number-flow.d.ts +72 -0
- package/react/dist/animated-number-flow.js +316 -0
- package/react/dist/animated-number-model.d.ts +24 -0
- package/react/dist/animated-number-model.js +106 -3
- package/react/dist/animated-number.d.ts +49 -1
- package/react/dist/animated-number.js +146 -11
- package/react/dist/asset-balance-row.d.ts +19 -1
- package/react/dist/asset-balance-row.js +17 -3
- package/react/dist/async-result.d.ts +2 -0
- package/react/dist/async-result.js +11 -0
- package/react/dist/avatar.d.ts +25 -0
- package/react/dist/avatar.js +50 -0
- package/react/dist/bar-mark.d.ts +5 -2
- package/react/dist/bar-mark.js +5 -3
- package/react/dist/blocks/account-block.d.ts +57 -7
- package/react/dist/blocks/account-block.js +51 -11
- package/react/dist/blocks/assets-block.d.ts +106 -0
- package/react/dist/blocks/assets-block.js +135 -0
- package/react/dist/blocks/confirm-block.d.ts +91 -0
- package/react/dist/blocks/confirm-block.js +31 -0
- package/react/dist/blocks/explainer-block.d.ts +80 -0
- package/react/dist/blocks/explainer-block.js +20 -0
- package/react/dist/blocks/install-command.js +3 -1
- package/react/dist/blocks/language-block.d.ts +9 -1
- package/react/dist/blocks/language-block.js +8 -6
- package/react/dist/blocks/manage-position-block.d.ts +30 -2
- package/react/dist/blocks/manage-position-block.js +23 -4
- package/react/dist/blocks/market-row.d.ts +20 -9
- package/react/dist/blocks/market-row.js +17 -4
- package/react/dist/blocks/notifications-block.d.ts +27 -2
- package/react/dist/blocks/notifications-block.js +11 -2
- package/react/dist/blocks/pickers.d.ts +30 -1
- package/react/dist/blocks/pickers.js +32 -10
- package/react/dist/blocks/position-block.d.ts +34 -11
- package/react/dist/blocks/position-block.js +16 -5
- package/react/dist/blocks/preset-picker-block.d.ts +85 -0
- package/react/dist/blocks/preset-picker-block.js +19 -0
- package/react/dist/blocks/profile-block.d.ts +33 -6
- package/react/dist/blocks/profile-block.js +31 -6
- package/react/dist/blocks/reward-block.d.ts +65 -21
- package/react/dist/blocks/reward-block.js +24 -11
- package/react/dist/blocks/screen-header.d.ts +34 -2
- package/react/dist/blocks/screen-header.js +17 -6
- package/react/dist/blocks/setting-switch.d.ts +14 -1
- package/react/dist/blocks/setting-switch.js +11 -4
- package/react/dist/blocks/signals-block.d.ts +23 -2
- package/react/dist/blocks/signals-block.js +6 -5
- package/react/dist/blocks/sound-haptics-block.d.ts +27 -3
- package/react/dist/blocks/sound-haptics-block.js +11 -7
- package/react/dist/blocks/sticky-header.d.ts +19 -0
- package/react/dist/blocks/sticky-header.js +103 -0
- package/react/dist/blocks/swap/amount-card.js +2 -1
- package/react/dist/blocks/swap/settings.js +4 -3
- package/react/dist/blocks/swap/shared.d.ts +29 -23
- package/react/dist/blocks/swap/shared.js +36 -32
- package/react/dist/blocks/swap-panel-block.d.ts +12 -3
- package/react/dist/blocks/swap-panel-block.js +72 -37
- package/react/dist/blocks/target-block.d.ts +35 -7
- package/react/dist/blocks/target-block.js +26 -12
- package/react/dist/blocks/token-action-block.d.ts +21 -8
- package/react/dist/blocks/token-action-block.js +9 -6
- package/react/dist/blocks/trade-history-detail-block.d.ts +23 -1
- package/react/dist/blocks/trade-history-detail-block.js +5 -4
- package/react/dist/blocks/trade-history-list-block.d.ts +31 -5
- package/react/dist/blocks/trade-history-list-block.js +20 -10
- package/react/dist/blocks.d.ts +12 -8
- package/react/dist/blocks.js +6 -2
- package/react/dist/brand.js +2 -1
- package/react/dist/button.d.ts +9 -3
- package/react/dist/button.js +12 -5
- package/react/dist/confetti.d.ts +27 -0
- package/react/dist/confetti.js +240 -0
- package/react/dist/data.js +11 -4
- package/react/dist/field.d.ts +20 -5
- package/react/dist/field.js +30 -8
- package/react/dist/figure.d.ts +23 -0
- package/react/dist/figure.js +12 -0
- package/react/dist/gesture-sheet.d.ts +15 -1
- package/react/dist/gesture-sheet.js +53 -8
- package/react/dist/list-group.d.ts +41 -8
- package/react/dist/list-group.js +49 -13
- package/react/dist/navigation.js +11 -3
- package/react/dist/overlay.d.ts +28 -3
- package/react/dist/overlay.js +29 -3
- package/react/dist/preset-group.d.ts +30 -0
- package/react/dist/preset-group.js +13 -0
- package/react/dist/provider.d.ts +42 -5
- package/react/dist/provider.js +84 -10
- package/react/dist/qr-code.d.ts +32 -0
- package/react/dist/qr-code.js +28 -0
- package/react/dist/select.js +10 -3
- package/react/dist/selection.d.ts +18 -4
- package/react/dist/selection.js +20 -10
- package/react/dist/slider.js +5 -1
- package/react/dist/status.d.ts +14 -10
- package/react/dist/status.js +17 -9
- package/react/dist/styles.css +380 -150
- package/react/dist/surface.d.ts +5 -1
- package/react/dist/surface.js +1 -1
- package/react/dist/toast.d.ts +19 -12
- package/react/dist/toast.js +29 -7
- package/react/dist/wallet-address-core.d.ts +27 -0
- package/react/dist/wallet-address-core.js +29 -0
- package/react/dist/wallet-address.d.ts +6 -12
- package/react/dist/wallet-address.js +5 -16
- package/tokens/README.md +2 -2
- package/tokens/dist/index.d.ts +16 -0
- package/tokens/dist/index.js +16 -0
- package/tokens/dist/manifest.json +8 -0
- package/tokens/dist/tokens.css +6 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type NativeScrollEvent, type NativeSyntheticEvent, type ScrollViewProps, type StyleProp, type ViewStyle } from 'react-native';
|
|
3
|
+
/** What a scroller needs so a pinned header knows when content is under it. Spread `onScroll` and `scrollEventThrottle` on the scroll view and pass `scrolled` to the header. */
|
|
4
|
+
export interface StickyHeaderScroll {
|
|
5
|
+
/** True once the scroll view has moved, so content sits under the pinned header. */
|
|
6
|
+
scrolled: boolean;
|
|
7
|
+
onScroll: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
|
|
8
|
+
scrollEventThrottle: number;
|
|
9
|
+
}
|
|
10
|
+
/** Tracks a scroll view's offset for a pinned header: `scrolled` turns true once it has moved and false again at the top. It re-renders only when that changes. */
|
|
11
|
+
export declare function useStickyHeaderScroll(onScroll?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void): StickyHeaderScroll;
|
|
12
|
+
/** The fill of a pinned header: transparent at rest so what the host draws behind it shows through, `background` once content has scrolled under it. */
|
|
13
|
+
export declare function stickyHeaderFill(scrolled: boolean, background: string): ViewStyle;
|
|
14
|
+
export interface StickyHeaderLayoutProps {
|
|
15
|
+
/** The header, pinned as the scroll view's first child. */
|
|
16
|
+
header: React.ReactNode;
|
|
17
|
+
children: React.ReactNode;
|
|
18
|
+
/** Fill once content scrolls under the header. Defaults to the background role. */
|
|
19
|
+
background?: string;
|
|
20
|
+
scrollComponent?: React.ComponentType<ScrollViewProps>;
|
|
21
|
+
testID?: string;
|
|
22
|
+
/** Test ID of the header's container. */
|
|
23
|
+
headerTestID?: string;
|
|
24
|
+
/** Layout of the content under the header, such as its gap. Side padding is 16dp. */
|
|
25
|
+
bodyStyle?: StyleProp<ViewStyle>;
|
|
26
|
+
}
|
|
27
|
+
/** A block as its own scroll view with its header pinned: 16dp around the content as the block draws it, the header transparent until content scrolls under it. Place it in a bounded container, such as a sheet body. */
|
|
28
|
+
export declare function StickyHeaderLayout({ header, children, background, scrollComponent: Scroll, testID, headerTestID, bodyStyle }: StickyHeaderLayoutProps): React.JSX.Element;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useState } from 'react';
|
|
3
|
+
import { ScrollView, View } from 'react-native';
|
|
4
|
+
import { useColors } from './provider.js';
|
|
5
|
+
/** Tracks a scroll view's offset for a pinned header: `scrolled` turns true once it has moved and false again at the top. It re-renders only when that changes. */
|
|
6
|
+
export function useStickyHeaderScroll(onScroll) {
|
|
7
|
+
const [scrolled, setScrolled] = useState(false);
|
|
8
|
+
const handle = useCallback((event) => {
|
|
9
|
+
const next = (event.nativeEvent?.contentOffset?.y ?? 0) > 0.5;
|
|
10
|
+
setScrolled(current => current === next ? current : next);
|
|
11
|
+
onScroll?.(event);
|
|
12
|
+
}, [onScroll]);
|
|
13
|
+
return { scrolled, onScroll: handle, scrollEventThrottle: 16 };
|
|
14
|
+
}
|
|
15
|
+
/** The fill of a pinned header: transparent at rest so what the host draws behind it shows through, `background` once content has scrolled under it. */
|
|
16
|
+
export function stickyHeaderFill(scrolled, background) { return { backgroundColor: scrolled ? background : 'transparent' }; }
|
|
17
|
+
const stickySlotStyle = { flexDirection: 'row' };
|
|
18
|
+
const stickyScrollStyle = { flexGrow: 1, flexShrink: 1, minHeight: 0 };
|
|
19
|
+
/** A block as its own scroll view with its header pinned: 16dp around the content as the block draws it, the header transparent until content scrolls under it. Place it in a bounded container, such as a sheet body. */
|
|
20
|
+
export function StickyHeaderLayout({ header, children, background, scrollComponent: Scroll = ScrollView, testID, headerTestID, bodyStyle }) {
|
|
21
|
+
const colors = useColors(), { scrolled, onScroll, scrollEventThrottle } = useStickyHeaderScroll();
|
|
22
|
+
// React Native's sticky slot moves the pinned child's style onto its own wrapper and gives the child flex:1, which measures 0 tall in a column.
|
|
23
|
+
// So the pinned child carries only a row direction (the wrapper lays out as a row, where flex:1 fills the width and the height follows content),
|
|
24
|
+
// and the inset and fill sit on the inner view, which keeps its full height whether or not the scroller pins it.
|
|
25
|
+
// The scroller fills a bounded parent and may shrink below its content, whatever scroll component the host passes, so the
|
|
26
|
+
// content scrolls inside it. It cannot bound itself: in a parent whose height follows its content (a View with no flex or
|
|
27
|
+
// height, a content-sized sheet) it grows to its content and nothing scrolls.
|
|
28
|
+
return _jsxs(Scroll, { testID: testID, style: stickyScrollStyle, stickyHeaderIndices: [0], onScroll: onScroll, scrollEventThrottle: scrollEventThrottle, contentContainerStyle: { paddingBottom: 16 }, children: [_jsx(View, { style: stickySlotStyle, children: _jsx(View, { testID: headerTestID, style: [{ flexGrow: 1, paddingHorizontal: 16, paddingTop: 16 }, stickyHeaderFill(scrolled, background ?? colors.background)], children: header }) }), _jsx(View, { style: [{ paddingHorizontal: 16 }, bodyStyle], children: children })] });
|
|
29
|
+
}
|
package/native/dist/surface.d.ts
CHANGED
|
@@ -7,7 +7,9 @@ export declare const scriptLetterSpacing: Readonly<Record<Exclude<TextScript, 'l
|
|
|
7
7
|
export declare function detectScript(text: string, locale: string): TextScript;
|
|
8
8
|
export interface HIGTextProps extends TextProps {
|
|
9
9
|
script?: TextScript; /** Caps Dynamic Type / Android font scale for dense numeric readouts (2 = 200%). Defaults to HIGProvider `maxFontSizeMultiplier`; never disable scaling. */
|
|
10
|
-
maxFontSizeMultiplier?: number;
|
|
10
|
+
maxFontSizeMultiplier?: number; /** `muted` draws secondary text, such as a note under a group, in the muted role. A `style` colour still wins. */
|
|
11
|
+
tone?: 'muted'; /** `caption` draws the 12/18 caption size instead of the 16/24 body size. A `style` size still wins. */
|
|
12
|
+
size?: 'caption';
|
|
11
13
|
}
|
|
12
14
|
export declare const Text: React.ForwardRefExoticComponent<HIGTextProps & React.RefAttributes<React.ComponentRef<typeof RNText>>>;
|
|
13
15
|
export declare const Heading: React.ForwardRefExoticComponent<HIGTextProps & React.RefAttributes<React.ComponentRef<typeof RNText>>>;
|
package/native/dist/surface.js
CHANGED
|
@@ -22,9 +22,10 @@ function scriptFont(families, weight) {
|
|
|
22
22
|
weights.sort((a, b) => Math.abs(a - Number(weight)) - Math.abs(b - Number(weight)) || a - b);
|
|
23
23
|
return weights.length ? families[weights[0]] : undefined;
|
|
24
24
|
}
|
|
25
|
-
export const Text = forwardRef(function Text({ style, script, maxFontSizeMultiplier, ...props }, ref) {
|
|
25
|
+
export const Text = forwardRef(function Text({ style: own, script, maxFontSizeMultiplier, tone, size, ...props }, ref) {
|
|
26
26
|
const env = useHIG();
|
|
27
27
|
const colors = useColors();
|
|
28
|
+
const style = tone || size ? [tone === 'muted' ? { color: colors.muted } : null, size === 'caption' ? { fontSize: 12, lineHeight: 18 } : null, own] : own;
|
|
28
29
|
const resolved = StyleSheet.flatten(style);
|
|
29
30
|
const requested = resolved?.fontWeight ?? 400;
|
|
30
31
|
const weight = requested === 'normal' ? 400 : requested === 'bold' ? 700 : requested;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type PressableProps, type StyleProp, type ViewStyle } from 'react-native';
|
|
3
|
+
import type { SwapArtwork } from './swap-shared.js';
|
|
4
|
+
export interface SwapPillProps extends Omit<PressableProps, 'children' | 'style' | 'accessibilityRole' | 'accessibilityState'> {
|
|
5
|
+
/** The pill's text, drawn small and muted, such as Max; or host nodes drawn as given, such as a live figure. */
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
/** Called on a press. */
|
|
8
|
+
onPress?: () => void;
|
|
9
|
+
/** Dims the pill, ignores presses and reads as unavailable. */
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/** A small capsule action on a swap card, as the web `SwapPill`: Max, Test, a converted value. 32dp tall with a 44dp target; text is drawn small and muted, and other children as given. Other Pressable props, such as `accessibilityLabel`, `testID` or `android_disableSound`, reach it. */
|
|
13
|
+
export declare function SwapPill({ children, onPress, disabled, hitSlop, ...props }: SwapPillProps): React.JSX.Element;
|
|
14
|
+
export interface SwapAmountCardProps {
|
|
15
|
+
/** Asset name, drawn in the slot. */
|
|
16
|
+
name: string;
|
|
17
|
+
/** Asset symbol; its first letters stand in when there is no `icon`. */
|
|
18
|
+
symbol: string;
|
|
19
|
+
/** Asset artwork: an image URL, or an element the host draws. */
|
|
20
|
+
icon?: SwapArtwork;
|
|
21
|
+
/** Chain or venue artwork, stacked above the asset. */
|
|
22
|
+
chainIcon?: string;
|
|
23
|
+
/** Line above the name: the chain, venue or account the amount comes from. A string is drawn small and muted. */
|
|
24
|
+
context?: React.ReactNode;
|
|
25
|
+
/** Capsule actions on the trailing edge, such as Max. Use `SwapPill`. They stay their own targets. */
|
|
26
|
+
actions?: React.ReactNode;
|
|
27
|
+
/** Supporting line under the actions, such as the available balance. A string is drawn small and muted; a node, such as a live figure, as given. */
|
|
28
|
+
meta?: React.ReactNode;
|
|
29
|
+
/** The entered amount. */
|
|
30
|
+
value: number;
|
|
31
|
+
/** Accessible name of the amount: From amount. */
|
|
32
|
+
amountLabel: string;
|
|
33
|
+
/** Text before the amount, such as a currency sign. */
|
|
34
|
+
prefix?: string;
|
|
35
|
+
/** Text after the amount, such as a percent sign. */
|
|
36
|
+
suffix?: string;
|
|
37
|
+
/** Decimal places typed so far, so `1.50` keeps its zero. */
|
|
38
|
+
fractionDigits?: number;
|
|
39
|
+
/** Set while the entry ends with a decimal point that has no digits after it yet. */
|
|
40
|
+
trailingDot?: boolean;
|
|
41
|
+
/** Most decimal places the amount can show. Defaults to 8. */
|
|
42
|
+
maximumFractionDigits?: number;
|
|
43
|
+
/** Capsule under the amount, such as the converted value. Use `SwapPill`. */
|
|
44
|
+
conversion?: React.ReactNode;
|
|
45
|
+
/** Makes the slot a button that chooses the asset. Requires `selectLabel`. */
|
|
46
|
+
onSelect?: () => void;
|
|
47
|
+
/** Accessible name of the slot's button: Select token, From. */
|
|
48
|
+
selectLabel?: string;
|
|
49
|
+
style?: StyleProp<ViewStyle>;
|
|
50
|
+
/** Prefix of the test IDs: `<testID>` (the card), `-slot`, `-select`, `-name`, `-context`, `-actions`, `-meta`, `-amount` and `-conversion`. Defaults to `swap-amount-card`. */
|
|
51
|
+
testID?: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The swap panel's From card on its own, as the web `SwapAmountCard`: the asset with its actions and balance in the slot, the entered amount
|
|
55
|
+
* under it. The host owns the entry, the keypad and what the amount means.
|
|
56
|
+
*/
|
|
57
|
+
export declare function SwapAmountCard({ name, symbol, icon, chainIcon, context, actions, meta, value, amountLabel, prefix, suffix, fractionDigits, trailingDot, maximumFractionDigits, conversion, onSelect, selectLabel, style, testID }: SwapAmountCardProps): React.JSX.Element;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Pressable, StyleSheet, View } from 'react-native';
|
|
3
|
+
import { formatNumber } from './number-format.js';
|
|
4
|
+
import { Raised, useColors, useFills, useHIG, useNumberLocale } from './provider.js';
|
|
5
|
+
import { Text } from './surface.js';
|
|
6
|
+
import { AnimatedNumberReadout } from './animated-number.js';
|
|
7
|
+
import { TokenArt } from './swap-parts.js';
|
|
8
|
+
const hidden = { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants' };
|
|
9
|
+
const smallType = { fontSize: 14, lineHeight: 19 };
|
|
10
|
+
/** Test ID parts. */
|
|
11
|
+
const contextPart = 'context', metaPart = 'meta';
|
|
12
|
+
/** A small capsule action on a swap card, as the web `SwapPill`: Max, Test, a converted value. 32dp tall with a 44dp target; text is drawn small and muted, and other children as given. Other Pressable props, such as `accessibilityLabel`, `testID` or `android_disableSound`, reach it. */
|
|
13
|
+
export function SwapPill({ children, onPress, disabled, hitSlop, ...props }) {
|
|
14
|
+
const colors = useColors(), fills = useFills(), { direction } = useHIG();
|
|
15
|
+
const text = typeof children === 'string' || typeof children === 'number';
|
|
16
|
+
return _jsx(Pressable, { ...props, accessibilityRole: 'button', accessibilityState: { disabled: !!disabled }, disabled: disabled, onPress: onPress, hitSlop: hitSlop ?? { top: 6, bottom: 6 }, style: ({ pressed }) => ({ direction, flexDirection: 'row', alignItems: 'center', gap: 6, minHeight: 32, paddingVertical: 4, paddingHorizontal: 12, borderRadius: 9999, backgroundColor: pressed && !disabled ? fills.raised : fills.well, opacity: disabled ? 0.5 : 1 }), children: text ? _jsx(Text, { style: { ...smallType, color: colors.muted }, children: children }) : children });
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The swap panel's From card on its own, as the web `SwapAmountCard`: the asset with its actions and balance in the slot, the entered amount
|
|
20
|
+
* under it. The host owns the entry, the keypad and what the amount means.
|
|
21
|
+
*/
|
|
22
|
+
export function SwapAmountCard({ name, symbol, icon, chainIcon, context, actions, meta, value, amountLabel, prefix = '', suffix = '', fractionDigits = 0, trailingDot = false, maximumFractionDigits = 8, conversion, onSelect, selectLabel, style, testID = 'swap-amount-card' }) {
|
|
23
|
+
const colors = useColors(), { direction } = useHIG(), locale = useNumberLocale();
|
|
24
|
+
const id = (part) => `${testID}-${part}`;
|
|
25
|
+
const small = { ...smallType, color: colors.muted };
|
|
26
|
+
const options = { minimumFractionDigits: Math.min(fractionDigits, maximumFractionDigits), maximumFractionDigits, useGrouping: false };
|
|
27
|
+
const after = (trailingDot ? '.' : '') + suffix;
|
|
28
|
+
const line = (node, part) => typeof node === 'string' || typeof node === 'number' ? _jsx(Text, { testID: id(part), style: small, children: node }) : _jsx(View, { testID: id(part), children: node });
|
|
29
|
+
const shown = (node) => node != null && node !== false;
|
|
30
|
+
return _jsx(View, { testID: testID, style: [{ direction, backgroundColor: colors.surface, borderRadius: 24, overflow: 'hidden' }, style], children: _jsxs(Raised, { children: [_jsxs(View, { testID: id('slot'), children: [onSelect ? _jsx(Pressable, { testID: id('select'), accessibilityRole: 'button', accessibilityLabel: selectLabel, onPress: onSelect, style: StyleSheet.absoluteFill }) : null, _jsxs(View, { pointerEvents: 'box-none', style: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', gap: 12, minHeight: 84, padding: 16 }, children: [_jsxs(View, { pointerEvents: 'none', style: { flex: 1, minWidth: 0, flexDirection: 'row', alignItems: 'flex-start', gap: 12 }, children: [_jsxs(View, { ...hidden, style: { alignItems: 'center' }, children: [chainIcon ? _jsx(TokenArt, { uri: chainIcon, size: 28, ring: colors.surface }) : null, _jsx(View, { style: { marginTop: chainIcon ? -14 : 0 }, children: _jsx(TokenArt, { uri: icon, symbol: symbol, size: 28, ring: colors.surface }) })] }), _jsxs(View, { style: { flex: 1, minWidth: 0 }, children: [shown(context) ? line(context, contextPart) : null, _jsx(Text, { testID: id('name'), style: { fontWeight: '600', lineHeight: 21 }, children: name })] })] }), shown(actions) || shown(meta) ? _jsxs(View, { pointerEvents: 'box-none', style: { alignItems: 'flex-end', gap: 8, maxWidth: '60%' }, children: [shown(actions) ? _jsx(View, { testID: id('actions'), pointerEvents: 'box-none', style: { flexDirection: 'row', flexWrap: 'wrap', justifyContent: 'flex-end', gap: 8 }, children: actions }) : null, shown(meta) ? line(meta, metaPart) : null] }) : null] })] }), _jsxs(View, { pointerEvents: 'box-none', style: { alignItems: 'center', gap: 8, paddingTop: 4, paddingHorizontal: 16, paddingBottom: 20 }, children: [_jsx(View, { accessible: true, accessibilityLabel: amountLabel, accessibilityValue: { text: `${prefix}${formatNumber(value, locale, options)}${after}` }, testID: id('amount'), children: _jsx(AnimatedNumberReadout, { value: value, prefix: prefix, suffix: after, options: options, maxFontSizeMultiplier: 1.5, style: { fontSize: 44, lineHeight: 50, fontWeight: '700', letterSpacing: -0.9, textAlign: 'center' } }) }), shown(conversion) ? _jsx(View, { testID: id('conversion'), children: conversion }) : null] })] }) });
|
|
31
|
+
}
|
|
@@ -4,6 +4,7 @@ import { type SwapAction, type SwapArtwork, type SwapChain, type SwapDenominatio
|
|
|
4
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
|
+
export { SwapAmountCard, SwapPill, type SwapAmountCardProps, type SwapPillProps } from './swap-amount-card.js';
|
|
7
8
|
/** 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. */
|
|
8
9
|
export interface SwapDestination {
|
|
9
10
|
title: string;
|
|
@@ -26,7 +27,8 @@ export interface SwapDetail {
|
|
|
26
27
|
value: string | number;
|
|
27
28
|
options?: Intl.NumberFormatOptions;
|
|
28
29
|
prefix?: string;
|
|
29
|
-
suffix?: string;
|
|
30
|
+
suffix?: string; /** With a number `value`: host-formatted text drawn and read in place of Intl's, still moving place by place. */
|
|
31
|
+
formattedValue?: string;
|
|
30
32
|
}
|
|
31
33
|
/** The receive view: the host's address and its rendered QR code. HIG ships no QR encoder. */
|
|
32
34
|
export interface SwapReceive {
|
|
@@ -79,7 +81,10 @@ export interface SwapPanelBlockProps {
|
|
|
79
81
|
onReceivingChange?: (receiving: boolean) => void;
|
|
80
82
|
/** The host validates, quotes and executes. HIG never submits a transaction. */
|
|
81
83
|
onSubmit: (action: SwapAction) => void;
|
|
84
|
+
/** The host's submit is in flight: the action shows a spinner and ignores presses, the keypad, Max and Test leave the amount as it is, and the action keeps its ready name (or `submittingLabel`, or a held action's `actionStatus`) even when the host has cleared the amount meanwhile, never “Enter an amount” or the balance check. */
|
|
82
85
|
submitting?: boolean;
|
|
86
|
+
/** What the action says while `submitting`, in place of its ready name: Burning…. Host text. */
|
|
87
|
+
submittingLabel?: string;
|
|
83
88
|
/** Called after the panel clears its entry and both tokens (through `onFromChange(null)` / `onToChange(null)`), so the host can drop its quote. */
|
|
84
89
|
onReset?: () => void;
|
|
85
90
|
/** On native there is no hardware keyboard to rely on, so `auto` shows the keypad; `never` hides it. */
|
|
@@ -92,9 +97,11 @@ export interface SwapPanelBlockProps {
|
|
|
92
97
|
/** A line under the cards: a limit, a delay, a warning. `noteTone` tints it. */
|
|
93
98
|
note?: React.ReactNode;
|
|
94
99
|
noteTone?: 'muted' | 'warning' | 'negative';
|
|
95
|
-
/** Heading above the cards, for a panel that is its own screen or sheet. `onBack` adds
|
|
100
|
+
/** Heading above the cards, for a panel that is its own screen or sheet, drawn as the shared `ScreenHeader` (the title centred, 17/24, in a 44dp row) like every other block. `onBack` adds Back on its leading edge. Test IDs `swap-header`, `swap-back` and `swap-title`. */
|
|
96
101
|
title?: string;
|
|
97
102
|
onBack?: () => void;
|
|
103
|
+
/** With `title`: `nativeID` of the heading, so a sheet around the panel can name itself with `accessibilityLabelledBy` (Android). */
|
|
104
|
+
headingId?: string;
|
|
98
105
|
/** `false` leaves the action button on its own, full width: no settings and no reset button. */
|
|
99
106
|
controls?: boolean;
|
|
100
107
|
/** Decoration before the action text. */
|
|
@@ -106,7 +113,7 @@ export interface SwapPanelBlockProps {
|
|
|
106
113
|
actionLabel?: string;
|
|
107
114
|
/** 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
115
|
actionDisabled?: boolean;
|
|
109
|
-
/** What the held action says, for example “Below minimum
|
|
116
|
+
/** What the held action says, for example “Below minimum” or, while `submitting`, “Signing…” (a `submittingLabel` wins over it). Without it the action keeps its ready name. */
|
|
110
117
|
actionStatus?: string;
|
|
111
118
|
/** `destructive` for an action that cannot be undone, such as a burn. */
|
|
112
119
|
actionIntent?: 'primary' | 'destructive';
|
|
@@ -137,7 +144,7 @@ export interface SwapPanelBlockProps {
|
|
|
137
144
|
* or token units through the keypad, token pickers, settings, and one action that names itself from the chosen pair.
|
|
138
145
|
* Presentation only. The host owns tokens, balances, prices, the quote, the wallet and the transaction.
|
|
139
146
|
*/
|
|
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;
|
|
147
|
+
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, submittingLabel, onReset, keypad, destination, details, note, noteTone, title, onBack, headingId, controls, actionIcon, lockFrom, lockTo, actionLabel, actionDisabled, actionStatus, actionIntent, limitToBalance, banner, footer, oneWay: oneWayProp, denominationSwitch, settings, view: viewProp, onViewChange, style }: SwapPanelBlockProps): React.JSX.Element;
|
|
141
148
|
/** @deprecated Renamed `SwapPanelBlock`. The old name keeps working until the next major release. */
|
|
142
149
|
export declare const SwapPanel: typeof SwapPanelBlock;
|
|
143
150
|
/** @deprecated Renamed `SwapPanelBlockProps`. */
|
|
@@ -1,36 +1,44 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { decimal, decimalDivide, decimalCompare, localizeDecimal } from '@bloxwap/hig/contracts';
|
|
3
|
+
import { useAsyncResult } from './async-result.js';
|
|
2
4
|
import { useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
5
|
import { Animated, BackHandler, Easing, Platform, Pressable, StyleSheet, View } from 'react-native';
|
|
4
|
-
import { formatNumber } from '
|
|
5
|
-
import { Raised, useColors, useControllable, useHIG, useMessages } from './provider.js';
|
|
6
|
+
import { formatNumber } from './number-format.js';
|
|
7
|
+
import { Raised, useColors, useControllable, useHIG, useMessages, useNumberLocale, usePresentNumber } from './provider.js';
|
|
6
8
|
import { Text } from './surface.js';
|
|
7
9
|
import { Button, IconButton } from './button.js';
|
|
8
10
|
import { AnimatedNumberReadout } from './animated-number.js';
|
|
11
|
+
import { figureProps } from './figure.js';
|
|
9
12
|
import { Toast, useTransientNotice } from './status.js';
|
|
10
13
|
import { VerticalAddress, addressKind } from './data.js';
|
|
11
14
|
import { withAlpha } from '@bloxwap/hig/tokens';
|
|
12
|
-
import { DownIcon, FlipIcon, MenuIcon, ResetIcon, SmallChevron, SwapCapsule,
|
|
15
|
+
import { DownIcon, FlipIcon, MenuIcon, ResetIcon, SmallChevron, SwapCapsule, SwapHostContext, SwapKeypad, SwapNumberText, TokenArt } from './swap-parts.js';
|
|
16
|
+
import { ScreenHeader } from './screen-header.js';
|
|
13
17
|
import { SwapPicker, SwapSettings } from './swap-views.js';
|
|
14
|
-
import { addressColor, applyAmountKey, formatPercent, shortAddress, swapAction, swapParentView, testAmount,
|
|
18
|
+
import { addressColor, applyAmountKey, formatPercent, shortAddress, swapAction, swapParentView, testAmount, unitsToEntry } from './swap-shared.js';
|
|
15
19
|
export { swapAction, swapParentView } from './swap-shared.js';
|
|
16
20
|
/** 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. */
|
|
17
21
|
export { SwapHostContext } from './swap-parts.js';
|
|
22
|
+
export { SwapAmountCard, SwapPill } from './swap-amount-card.js';
|
|
18
23
|
/**
|
|
19
24
|
* Send, swap and bridge in one panel: a From card and a To card joined by a flip control, an amount entered in dollars
|
|
20
25
|
* or token units through the keypad, token pickers, settings, and one action that names itself from the chosen pair.
|
|
21
26
|
* Presentation only. The host owns tokens, balances, prices, the quote, the wallet and the transaction.
|
|
22
27
|
*/
|
|
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 }) {
|
|
28
|
+
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, submittingLabel, onReset, keypad = 'auto', destination, details, note, noteTone = 'muted', title, onBack, headingId, 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
29
|
const env = useHIG();
|
|
25
|
-
const {
|
|
30
|
+
const { direction } = env;
|
|
31
|
+
const locale = useNumberLocale();
|
|
32
|
+
const present = usePresentNumber();
|
|
26
33
|
const colors = useColors();
|
|
27
34
|
const t = useMessages();
|
|
28
35
|
const [from, setFrom] = useControllable(fromProp, defaultFrom, onFromChange);
|
|
29
36
|
const [to, setTo] = useControllable(toProp, defaultTo, onToChange);
|
|
37
|
+
const boundedUnits = (raw) => { const canonical = decimal(raw, from?.decimals ?? 100); return limitToBalance && from?.balance != null && Number.isFinite(from.balance) && from.balance >= 0 && decimalCompare(canonical, from.balance) > 0 ? decimal(from.balance, from?.decimals ?? 100) : canonical; };
|
|
30
38
|
const [defaultMode, setDefaultMode] = useControllable(denomination, 'usd', onDenominationChange);
|
|
31
39
|
const [isReceiving, setReceiving] = useControllable(receiving, false, onReceivingChange);
|
|
32
40
|
// `amount` seeds the first render too, in the default denomination at the initial From token's price.
|
|
33
|
-
const [entry, setEntry] = useState(() => amount === undefined ? '0' : unitsToEntry(
|
|
41
|
+
const [entry, setEntry] = useState(() => amount === undefined ? '0' : unitsToEntry(boundedUnits(amount), defaultMode, from?.price ?? 0));
|
|
34
42
|
const [fromMode, setFromMode] = useState(defaultMode);
|
|
35
43
|
const [toMode, applyToMode] = useState(defaultMode);
|
|
36
44
|
const host = useContext(SwapHostContext);
|
|
@@ -47,7 +55,9 @@ export function SwapPanelBlock({ tokens, fromTokens, fromTokensLoading, chains,
|
|
|
47
55
|
return; const subscription = BackHandler.addEventListener('hardwareBackPress', () => { pop.current(); return true; }); return () => subscription.remove(); }, [view === 'main']);
|
|
48
56
|
const { notice, show: showNotice, dismiss: dismissNotice } = useTransientNotice();
|
|
49
57
|
const fromPrice = from?.price ?? 0, toPrice = to?.price ?? 0, input = Number(entry) || 0;
|
|
50
|
-
const
|
|
58
|
+
const exact = useRef(amount === undefined ? null : { entry, mode: fromMode, units: boundedUnits(amount), asset: from?.id });
|
|
59
|
+
const unitsText = exact.current && exact.current.entry === entry && exact.current.mode === fromMode && exact.current.asset === from?.id ? exact.current.units : fromMode === 'token' ? decimal(entry, from?.decimals ?? 100) : decimalDivide(entry, fromPrice, from?.decimals ?? 18);
|
|
60
|
+
const units = Number(unitsText), usd = units * fromPrice;
|
|
51
61
|
const showReceive = isReceiving && !!receive;
|
|
52
62
|
// Report the amount in token units; resync the entry when the host sets a different amount.
|
|
53
63
|
const reported = useRef(amount ?? '0');
|
|
@@ -55,42 +65,53 @@ export function SwapPanelBlock({ tokens, fromTokens, fromTokensLoading, chains,
|
|
|
55
65
|
reported.current = unitsText;
|
|
56
66
|
onAmountChange?.(unitsText);
|
|
57
67
|
} }, [unitsText]);
|
|
58
|
-
useEffect(() => { if (amount === undefined ||
|
|
59
|
-
return;
|
|
60
|
-
|
|
68
|
+
useEffect(() => { if (amount === undefined || boundedUnits(amount) === reported.current)
|
|
69
|
+
return; const canonical = boundedUnits(amount), next = unitsToEntry(canonical, fromMode, fromPrice); reported.current = canonical; if (decimal(amount) !== canonical)
|
|
70
|
+
onAmountChange?.(canonical); exact.current = { entry: next, mode: fromMode, units: canonical, asset: from?.id }; setEntry(next); }, [amount]);
|
|
71
|
+
const sameAsset = !!from && !!to && swapAction(from, to) === 'send';
|
|
61
72
|
const receivedUnits = sameAsset ? units : received ?? (toPrice > 0 ? usd / toPrice : 0);
|
|
62
73
|
const receivedUsd = toPrice > 0 ? receivedUnits * toPrice : sameAsset ? usd : 0;
|
|
63
74
|
const action = swapAction(from, to);
|
|
64
|
-
const insufficient = !!from &&
|
|
75
|
+
const insufficient = !!from && from.balance != null && (!Number.isFinite(from.balance) || from.balance < 0 || decimalCompare(unitsText, from.balance) > 0);
|
|
65
76
|
// A destination or a details card stands in for the To token: one way, and ready from the From side alone.
|
|
66
77
|
const fixed = !!destination || (!!details && !to);
|
|
67
78
|
const oneWay = oneWayProp || fixed;
|
|
68
|
-
const eligible = !!from && (!!to || fixed) && !destination?.pending && units > 0 && !insufficient;
|
|
79
|
+
const eligible = !!from && (!!to || fixed) && !destination?.pending && Number.isFinite(units) && units > 0 && !insufficient;
|
|
69
80
|
const ready = eligible && !actionDisabled;
|
|
70
|
-
const
|
|
81
|
+
const readyText = actionLabel ?? (action === 'swap' && !fixed ? t.swapActionSwap : action === 'bridge' && !fixed ? t.swapActionBridge : t.swapActionSend);
|
|
82
|
+
// While the host's submit is in flight the amount may already be cleared: the action keeps its name rather than asking for an amount.
|
|
83
|
+
const actionText = showReceive ? t.swapSendFromWallet : !from || (!to && !fixed) ? t.swapChooseToken : destination?.pending ? t.swapChooseDestination : submitting ? submittingLabel ?? (actionDisabled && actionStatus ? actionStatus : readyText) : units <= 0 ? t.swapEnterAmount : insufficient ? t.swapInsufficient(from.symbol) : actionDisabled && actionStatus ? actionStatus : readyText;
|
|
71
84
|
const pristine = (lockFrom || !from) && (lockTo || !to) && input === 0;
|
|
72
85
|
// Updater form: several keys can land before the next render, and each must build on the last.
|
|
73
86
|
const latest = useRef(fromMode);
|
|
74
87
|
latest.current = fromMode;
|
|
75
88
|
// Read at key time: several keys can land in one render.
|
|
76
|
-
const limits = useRef({ decimals: from?.decimals, balance: from?.balance
|
|
77
|
-
limits.current = { decimals: from?.decimals, balance: from?.balance
|
|
78
|
-
const over = (next) => { const { balance, price, cap } = limits.current; if (!cap ||
|
|
79
|
-
return false;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
89
|
+
const limits = useRef({ decimals: from?.decimals, balance: from?.balance, price: from?.price ?? 0, cap: limitToBalance });
|
|
90
|
+
limits.current = { decimals: from?.decimals, balance: from?.balance, price: from?.price ?? 0, cap: limitToBalance };
|
|
91
|
+
const over = (next) => { const { balance, price, cap } = limits.current; if (!cap || balance == null)
|
|
92
|
+
return false; if (!Number.isFinite(balance) || balance < 0)
|
|
93
|
+
return true; const value = latest.current === 'token' ? next : decimalDivide(next, price, limits.current.decimals ?? 18); return decimalCompare(value, balance) > 0; };
|
|
94
|
+
// While the host's submit is in flight the keypad, Max and Test leave the amount as it is.
|
|
95
|
+
const typed = next => { if (!submitting)
|
|
96
|
+
setEntry(current => { const value = typeof next === 'function' ? next(current) : next; if (value === current || value.length > 1000)
|
|
97
|
+
return current; const normalized = decimal(value, latest.current === 'usd' ? 2 : limits.current.decimals ?? 100); if (over(normalized))
|
|
98
|
+
return current; exact.current = null; const [whole, fraction] = value.split('.'); const places = latest.current === 'usd' ? 2 : limits.current.decimals ?? 100; return fraction === undefined ? whole : places > 0 ? whole + '.' + fraction.slice(0, places) : whole; }); };
|
|
99
|
+
const press = (key) => typed(current => { const next = applyAmountKey(current, key, latest.current, limits.current.decimals); return key !== 'back' && over(next) ? current : next; });
|
|
100
|
+
const switchFromMode = (mode) => { if (submitting || mode === fromMode)
|
|
101
|
+
return; const next = unitsToEntry(unitsText, mode, fromPrice); exact.current = { entry: next, mode, units: unitsText, asset: from?.id }; setEntry(next); setFromMode(mode); };
|
|
102
|
+
const changeDenomination = (mode) => { if (submitting)
|
|
103
|
+
return; setDefaultMode(mode); switchFromMode(mode); applyToMode(mode); };
|
|
84
104
|
// A new default applies to an untouched entry at once; a typed amount keeps its denomination until reset.
|
|
85
105
|
useEffect(() => { if (input === 0) {
|
|
86
106
|
setFromMode(defaultMode);
|
|
87
107
|
applyToMode(defaultMode);
|
|
88
108
|
} }, [defaultMode]);
|
|
89
|
-
const reset = () => {
|
|
109
|
+
const reset = () => { if (submitting)
|
|
110
|
+
return; exact.current = null; setEntry('0'); setFromMode(defaultMode); applyToMode(defaultMode); if (isReceiving)
|
|
90
111
|
setReceiving(false); if (!lockFrom)
|
|
91
112
|
setFrom(null); if (!lockTo)
|
|
92
113
|
setTo(null); onReset?.(); };
|
|
93
|
-
const flip = () => { if (!from || !to)
|
|
114
|
+
const flip = () => { if (submitting || !from || !to)
|
|
94
115
|
return; setFrom(to); setTo(from); };
|
|
95
116
|
const submit = () => { if (submitting)
|
|
96
117
|
return; if (showReceive) {
|
|
@@ -99,21 +120,23 @@ export function SwapPanelBlock({ tokens, fromTokens, fromTokensLoading, chains,
|
|
|
99
120
|
} if (ready)
|
|
100
121
|
onSubmit(fixed ? 'send' : action); };
|
|
101
122
|
// A copied address shows as a transient toast capsule (about 4s, dismissible), announced the way Toast announces any notice.
|
|
102
|
-
const
|
|
103
|
-
|
|
123
|
+
const beginCopy = useAsyncResult(receive?.address);
|
|
124
|
+
const copyAddress = () => { const current = beginCopy(); if (!receive?.onCopy)
|
|
125
|
+
return; Promise.resolve().then(receive.onCopy).then(() => { if (current())
|
|
126
|
+
showNotice(t.addressCopied); }).catch(() => { }); };
|
|
104
127
|
const chainList = useMemo(() => { if (chains)
|
|
105
128
|
return chains; const seen = new Map(); for (const token of tokens)
|
|
106
129
|
if (!seen.has(token.chainId))
|
|
107
130
|
seen.set(token.chainId, { chainId: token.chainId, name: token.chain, icon: typeof token.chainIcon === 'string' ? token.chainIcon : undefined }); return [...seen.values()]; }, [chains, tokens]);
|
|
108
|
-
const usdText = (value) => formatNumber(value, locale, { style: 'currency', currency: 'USD' });
|
|
131
|
+
const usdText = (value) => formatNumber(value, locale, present({ style: 'currency', currency: 'USD' }));
|
|
109
132
|
const fraction = entry.includes('.') ? Math.min(entry.length - entry.indexOf('.') - 1, fromMode === 'usd' ? 2 : 8) : 0;
|
|
110
133
|
const smallType = { fontSize: 14, lineHeight: 19 }, small = { ...smallType, color: colors.muted };
|
|
111
134
|
// Live numbers: the fee and slippage sentences keep their translated wording around a number that updates in place.
|
|
112
135
|
const usdOptions = { style: 'currency', currency: 'USD' }, feeKnown = !quoteLoading && fee != null, feeAmount = quoteLoading ? '…' : fee != null ? usdText(fee) : '—', slippageText = formatPercent(slippage);
|
|
113
136
|
// An account (a token with a `caption`) reads name over caption beside one disc, and offers Max only.
|
|
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: () =>
|
|
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: () =>
|
|
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 }) })] })] });
|
|
137
|
+
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', ...figureProps(token.caption), tone: 'muted', style: smallType }) : _jsx(Text, { style: small, children: token.caption })] })] }), side === 'from' && (token.balance ?? 0) > 0 ? _jsx(SwapCapsule, { disabled: submitting, testID: 'swap-max', onPress: () => typed(unitsToEntry(token.balance ?? 0, fromMode, fromPrice)), children: _jsx(Text, { style: small, children: t.swapMax }) }) : null] });
|
|
138
|
+
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, { disabled: submitting, testID: 'swap-test', onPress: () => typed(unitsToEntry(testAmount(token), fromMode, fromPrice)), children: _jsx(Text, { style: small, children: t.swapTest }) }), _jsx(SwapCapsule, { disabled: submitting, testID: 'swap-max', onPress: () => typed(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)
|
|
139
|
+
: _jsxs(View, { pointerEvents: 'box-none', style: { alignItems: 'flex-end', gap: 8, maxWidth: '60%' }, children: [_jsx(SwapCapsule, { disabled: submitting, testID: 'swap-slippage', label: t.swapSlippage(slippageText), onPress: () => !submitting && 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 }) })] })] });
|
|
117
140
|
const receiveView = (view) => {
|
|
118
141
|
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 }) })] });
|
|
119
142
|
const layout = { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-evenly', gap: 12, paddingTop: 8, paddingHorizontal: 16, paddingBottom: 20 };
|
|
@@ -125,26 +148,32 @@ export function SwapPanelBlock({ tokens, fromTokens, fromTokensLoading, chains,
|
|
|
125
148
|
const shown = side === 'from' ? input : mode === 'token' ? receivedUnits : receivedUsd;
|
|
126
149
|
const options = { minimumFractionDigits: side === 'from' ? fraction : 0, maximumFractionDigits: mode === 'usd' ? 2 : 8, useGrouping: false };
|
|
127
150
|
const prefix = mode === 'usd' ? '$' : '', suffix = side === 'from' && entry.endsWith('.') ? '.' : '';
|
|
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 })] })] })] })] }) });
|
|
151
|
+
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), disabled: submitting, testID: `swap-slot-${side}`, onPress: () => !submitting && 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: () => !submitting && 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: side === 'from' && mode === 'token' ? localizeDecimal(entry, locale) : `${prefix}${formatNumber(shown, locale, options)}${suffix}` }, testID: `swap-amount-${side}`, children: _jsx(AnimatedNumberReadout, { value: shown, formattedValue: side === 'from' && mode === 'token' ? localizeDecimal(entry, locale) : undefined, prefix: prefix, suffix: side === 'from' && mode === 'token' ? '' : 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, { disabled: submitting, label: t.swapSwitchDenomination, testID: `swap-mode-${side}`, onPress: () => !submitting && (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 })] })] })] })] }) });
|
|
129
152
|
};
|
|
130
153
|
// 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.
|
|
131
154
|
const fixedCard = () => {
|
|
132
155
|
if (!fixed)
|
|
133
156
|
return null;
|
|
134
157
|
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) }) });
|
|
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;
|
|
158
|
+
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', ...figureProps(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;
|
|
159
|
+
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, formattedValue: detail.formattedValue, animateFormatted: !!detail.formattedValue, style: { lineHeight: 21, textAlign: 'right' } }) : _jsx(Text, { style: { lineHeight: 21, textAlign: 'right', flexShrink: 1 }, children: detail.value })] }, detail.label)) }) : null;
|
|
137
160
|
const shape = { backgroundColor: colors.surface, borderRadius: 24, overflow: 'hidden' };
|
|
138
161
|
// With a pressable destination the whole card is the button; the rows inside it are read as part of it.
|
|
139
|
-
return destination?.onPress ? _jsx(Pressable, { accessibilityRole: 'button', accessibilityLabel: destination.title, testID: 'swap-destination',
|
|
162
|
+
return destination?.onPress ? _jsx(Pressable, { accessibilityRole: 'button', accessibilityLabel: destination.title, testID: 'swap-destination', disabled: submitting, onPress: () => { if (!submitting)
|
|
163
|
+
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] }) });
|
|
140
164
|
};
|
|
141
165
|
const fromCard = card('from'), toCard = fixedCard() ?? card('to');
|
|
142
166
|
const tone = noteTone === 'warning' ? colors.warning : noteTone === 'negative' ? colors.negative : null;
|
|
143
|
-
const main = _jsxs(View, { testID: 'swap-view-main', children: [title ? _jsx(View, { style: { marginBottom: 12 }, children: _jsx(
|
|
167
|
+
const main = _jsxs(View, { testID: 'swap-view-main', children: [title ? _jsx(View, { style: { marginBottom: 12 }, children: _jsx(ScreenHeader, { testID: 'swap', title: title, onBack: onBack, headingId: headingId }) }) : 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: submitting || !from || !to }, disabled: submitting || !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', disabled: submitting, onPress: () => !submitting && 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] });
|
|
144
168
|
const body = view === 'main' ? main
|
|
145
|
-
: view === 'from' ? _jsx(SwapPicker, { side: view, onBack: back, tokens: fromTokens ?? tokens, loading: fromTokensLoading, chains: chainList, hotTokenIds: hotTokenIds, selected: from, onSelect:
|
|
146
|
-
|
|
147
|
-
|
|
169
|
+
: view === 'from' ? _jsx(SwapPicker, { side: view, onBack: back, tokens: fromTokens ?? tokens, loading: fromTokensLoading, chains: chainList, hotTokenIds: hotTokenIds, selected: from, onSelect: token => { if (!submitting)
|
|
170
|
+
setFrom(token); }, wallet: wallet, onConnect: submitting ? undefined : onConnect, onDisconnect: submitting ? undefined : onDisconnect, receiving: isReceiving, onReceivingChange: receive ? value => { if (!submitting)
|
|
171
|
+
setReceiving(value); } : undefined })
|
|
172
|
+
: view === 'to' ? _jsx(SwapPicker, { side: view, onBack: back, tokens: tokens, chains: chainList, hotTokenIds: hotTokenIds, selected: to, onSelect: token => { if (!submitting)
|
|
173
|
+
setTo(token); }, wallet: wallet, recipient: recipient, onRecipientChange: value => { if (!submitting)
|
|
174
|
+
onRecipientChange?.(value); }, onScanRecipient: submitting ? undefined : onScanRecipient })
|
|
175
|
+
: _jsx(SwapSettings, { view: view, onViewChange: show, onBack: back, denomination: defaultMode, onDenominationChange: denominationSwitch ? changeDenomination : undefined, slippage: slippage, onSlippageChange: value => { if (!submitting)
|
|
176
|
+
onSlippageChange?.(value); }, fee: fee, fees: fees, quoteLoading: quoteLoading, children: settings });
|
|
148
177
|
return _jsx(View, { testID: 'swap-panel', style: [{ direction, width: '100%', maxWidth: 448, alignSelf: 'center' }, style], children: _jsx(SwapStage, { view: view, animateHeight: host.animateHeight !== false, children: body }) });
|
|
149
178
|
}
|
|
150
179
|
const viewDepth = (view) => view === 'main' ? 0 : view === 'slippage' || view === 'fees' ? 2 : 1;
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { type FlatListProps } from 'react-native';
|
|
2
|
+
import { View, type FlatListProps, type Insets } from 'react-native';
|
|
3
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>>;
|
|
7
7
|
animateHeight?: boolean;
|
|
8
8
|
}>;
|
|
9
|
-
/** One arrow, top to bottom: a one-way panel. */
|
|
10
9
|
export declare function DownIcon({ color, size }: {
|
|
11
10
|
color: string;
|
|
12
11
|
size?: number;
|
|
13
12
|
}): React.JSX.Element;
|
|
14
|
-
/** Two opposed arrows: exchange the pair, or switch the denomination. */
|
|
15
13
|
export declare function FlipIcon({ color, size }: {
|
|
16
14
|
color: string;
|
|
17
15
|
size?: number;
|
|
@@ -19,27 +17,21 @@ export declare function FlipIcon({ color, size }: {
|
|
|
19
17
|
export declare function MenuIcon({ color }: {
|
|
20
18
|
color: string;
|
|
21
19
|
}): React.JSX.Element;
|
|
22
|
-
/** An open ring with an arrowhead at its gap. */
|
|
23
20
|
export declare function ResetIcon({ color }: {
|
|
24
21
|
color: string;
|
|
25
22
|
}): React.JSX.Element;
|
|
26
|
-
/** Keypad delete: a key outline holding an x. */
|
|
27
23
|
export declare function DeleteIcon({ color }: {
|
|
28
24
|
color: string;
|
|
29
25
|
}): React.JSX.Element;
|
|
30
|
-
/** Four viewfinder corners. */
|
|
31
26
|
export declare function ScanIcon({ color }: {
|
|
32
27
|
color: string;
|
|
33
28
|
}): React.JSX.Element;
|
|
34
|
-
/** A wallet: a rounded body with a clasp on the trailing edge. */
|
|
35
29
|
export declare function WalletIcon({ color }: {
|
|
36
30
|
color: string;
|
|
37
31
|
}): React.JSX.Element;
|
|
38
|
-
/** A padlock: a shackle over a body. */
|
|
39
32
|
export declare function LockIcon({ color }: {
|
|
40
33
|
color: string;
|
|
41
34
|
}): React.JSX.Element;
|
|
42
|
-
/** A doorway with an arrow leaving it. */
|
|
43
35
|
export declare function LeaveIcon({ color }: {
|
|
44
36
|
color: string;
|
|
45
37
|
}): React.JSX.Element;
|
|
@@ -56,11 +48,14 @@ export declare function TokenIcon({ token, size }: {
|
|
|
56
48
|
size?: number;
|
|
57
49
|
}): React.JSX.Element;
|
|
58
50
|
/** Small capsule action that sits on a card: Max, Test, the slippage setting and the denomination switch. 32dp tall with a 44dp target. */
|
|
59
|
-
export declare function SwapCapsule({ children, onPress, label, testID }: {
|
|
51
|
+
export declare function SwapCapsule({ children, onPress, label, testID, disabled, hitSlop, ref }: {
|
|
60
52
|
children: React.ReactNode;
|
|
61
53
|
onPress: () => void;
|
|
62
54
|
label?: string;
|
|
63
55
|
testID?: string;
|
|
56
|
+
disabled?: boolean; /** Defaults to a 44dp target, as on the swap card. */
|
|
57
|
+
hitSlop?: Insets; /** Reaches the capsule, for example to move accessibility focus back to it. */
|
|
58
|
+
ref?: React.Ref<View>;
|
|
64
59
|
}): React.JSX.Element;
|
|
65
60
|
/** Numeric keypad: a 3 by 4 grid of 56dp keys. Emits `0`–`9`, `.` or `back`. */
|
|
66
61
|
export declare function SwapKeypad({ onKey, label, deleteLabel }: {
|