@lifi/widget 1.24.0 → 1.25.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/AppDrawer.style.d.ts +1 -1
- package/AppProvider.js +1 -1
- package/cjs/AppDrawer.style.d.ts +1 -1
- package/cjs/AppProvider.js +1 -1
- package/cjs/components/ActiveSwaps/ActiveSwapItem.js +2 -1
- package/cjs/components/BottomSheet/types.d.ts +1 -1
- package/cjs/components/Card/Card.d.ts +2 -2
- package/cjs/components/Card/CardTitle.d.ts +1 -1
- package/cjs/components/ChainSelect/ChainSelect.js +6 -1
- package/cjs/components/ChainSelect/useChainSelect.d.ts +3 -1
- package/cjs/components/ChainSelect/useChainSelect.js +12 -3
- package/cjs/components/SendToWallet/SendToWallet.style.d.ts +1 -1
- package/cjs/components/SwapInput/FitInputText.d.ts +3 -0
- package/cjs/components/SwapInput/FitInputText.js +19 -0
- package/cjs/components/SwapInput/FormPriceHelperText.d.ts +1 -3
- package/cjs/components/SwapInput/FormPriceHelperText.js +1 -1
- package/cjs/components/SwapInput/SwapInput.js +12 -24
- package/cjs/components/SwapInput/SwapInput.style.d.ts +1 -1
- package/cjs/components/SwapInput/SwapInputEndAdornment.d.ts +3 -0
- package/cjs/components/SwapInput/{SwapInputAdornment.js → SwapInputEndAdornment.js} +3 -3
- package/cjs/components/SwapInput/SwapInputStartAdornment.d.ts +3 -0
- package/cjs/components/SwapInput/SwapInputStartAdornment.js +21 -0
- package/cjs/components/SwapRouteCard/SwapRouteCard.style.d.ts +1 -1
- package/cjs/components/SwapRoutes/SwapRoutes.style.d.ts +1 -1
- package/cjs/components/Token/Token.style.d.ts +1 -1
- package/cjs/components/TokenList/useTokenSelect.js +7 -4
- package/cjs/config/version.d.ts +1 -1
- package/cjs/config/version.js +1 -1
- package/cjs/hooks/useGasSufficiency.js +1 -1
- package/cjs/hooks/useRouteExecution.js +1 -1
- package/cjs/hooks/useSwapRoutes.js +12 -9
- package/cjs/hooks/useTools.d.ts +1 -1
- package/cjs/i18n/en.json +3 -1
- package/cjs/pages/SettingsPage/RoutePrioritySelect.js +2 -1
- package/cjs/pages/SettingsPage/SlippageInput.js +2 -1
- package/cjs/pages/SwapPage/StatusBottomSheet.js +61 -14
- package/cjs/pages/SwapPage/StatusBottomSheet.style.d.ts +4 -2
- package/cjs/pages/SwapPage/StatusBottomSheet.style.js +5 -2
- package/cjs/pages/SwapPage/SwapPage.js +8 -6
- package/cjs/pages/SwapRoutesPage/SwapRoutesPage.style.d.ts +1 -1
- package/cjs/providers/I18nProvider/types.d.ts +5 -5
- package/cjs/providers/SDKProvider/SDKProvider.js +4 -3
- package/cjs/providers/SwapFormProvider/FormUpdater.d.ts +5 -0
- package/cjs/providers/{WalletProvider/WalletFormUpdate.js → SwapFormProvider/FormUpdater.js} +24 -21
- package/cjs/providers/SwapFormProvider/SwapFormProvider.js +12 -7
- package/cjs/providers/SwapFormProvider/types.d.ts +2 -2
- package/cjs/providers/WalletProvider/WalletProvider.d.ts +1 -1
- package/cjs/providers/WalletProvider/WalletProvider.js +1 -2
- package/cjs/providers/WalletProvider/types.d.ts +3 -3
- package/cjs/providers/WidgetProvider/WidgetProvider.js +4 -0
- package/cjs/providers/WidgetProvider/types.d.ts +1 -1
- package/cjs/stores/routes/types.d.ts +8 -1
- package/cjs/stores/routes/types.js +10 -0
- package/cjs/stores/routes/useExecutingRoutesIds.js +3 -1
- package/cjs/stores/routes/useRouteExecutionStore.js +53 -18
- package/cjs/stores/routes/useSwapHistory.js +4 -1
- package/cjs/stores/routes/utils.d.ts +3 -1
- package/cjs/stores/routes/utils.js +12 -4
- package/cjs/stores/settings/types.d.ts +6 -6
- package/cjs/stores/settings/useSettingsStore.d.ts +12 -9
- package/cjs/stores/settings/useSettingsStore.js +22 -5
- package/cjs/types/events.d.ts +1 -1
- package/cjs/types/widget.d.ts +14 -8
- package/cjs/utils/enum.d.ts +1 -0
- package/cjs/utils/enum.js +5 -0
- package/cjs/utils/index.d.ts +1 -0
- package/cjs/utils/index.js +1 -0
- package/cjs/utils/navigationRoutes.d.ts +1 -1
- package/components/ActiveSwaps/ActiveSwapItem.js +2 -1
- package/components/BottomSheet/types.d.ts +1 -1
- package/components/Card/Card.d.ts +2 -2
- package/components/Card/CardTitle.d.ts +1 -1
- package/components/ChainSelect/ChainSelect.js +6 -1
- package/components/ChainSelect/useChainSelect.d.ts +3 -1
- package/components/ChainSelect/useChainSelect.js +13 -4
- package/components/SendToWallet/SendToWallet.style.d.ts +1 -1
- package/components/SwapInput/FitInputText.d.ts +3 -0
- package/components/SwapInput/FitInputText.js +16 -0
- package/components/SwapInput/FormPriceHelperText.d.ts +1 -3
- package/components/SwapInput/FormPriceHelperText.js +1 -1
- package/components/SwapInput/SwapInput.js +16 -28
- package/components/SwapInput/SwapInput.style.d.ts +1 -1
- package/components/SwapInput/SwapInputEndAdornment.d.ts +3 -0
- package/components/SwapInput/{SwapInputAdornment.js → SwapInputEndAdornment.js} +1 -1
- package/components/SwapInput/SwapInputStartAdornment.d.ts +3 -0
- package/components/SwapInput/SwapInputStartAdornment.js +17 -0
- package/components/SwapRouteCard/SwapRouteCard.style.d.ts +1 -1
- package/components/SwapRoutes/SwapRoutes.style.d.ts +1 -1
- package/components/Token/Token.style.d.ts +1 -1
- package/components/TokenList/useTokenSelect.js +8 -5
- package/config/version.d.ts +1 -1
- package/config/version.js +1 -1
- package/hooks/useGasSufficiency.js +2 -2
- package/hooks/useRouteExecution.js +2 -2
- package/hooks/useSwapRoutes.js +12 -9
- package/hooks/useTools.d.ts +1 -1
- package/i18n/en.json +3 -1
- package/package.json +13 -13
- package/pages/SettingsPage/RoutePrioritySelect.js +2 -1
- package/pages/SettingsPage/SlippageInput.js +2 -1
- package/pages/SwapPage/StatusBottomSheet.js +62 -15
- package/pages/SwapPage/StatusBottomSheet.style.d.ts +4 -2
- package/pages/SwapPage/StatusBottomSheet.style.js +5 -2
- package/pages/SwapPage/SwapPage.js +8 -6
- package/pages/SwapRoutesPage/SwapRoutesPage.style.d.ts +1 -1
- package/providers/I18nProvider/types.d.ts +5 -5
- package/providers/SDKProvider/SDKProvider.js +4 -3
- package/providers/SwapFormProvider/FormUpdater.d.ts +5 -0
- package/providers/{WalletProvider/WalletFormUpdate.js → SwapFormProvider/FormUpdater.js} +23 -20
- package/providers/SwapFormProvider/SwapFormProvider.js +12 -7
- package/providers/SwapFormProvider/types.d.ts +2 -2
- package/providers/WalletProvider/WalletProvider.d.ts +1 -1
- package/providers/WalletProvider/WalletProvider.js +2 -3
- package/providers/WalletProvider/types.d.ts +3 -3
- package/providers/WidgetProvider/WidgetProvider.js +5 -1
- package/providers/WidgetProvider/types.d.ts +1 -1
- package/stores/routes/types.d.ts +8 -1
- package/stores/routes/types.js +9 -1
- package/stores/routes/useExecutingRoutesIds.js +3 -1
- package/stores/routes/useRouteExecutionStore.js +51 -16
- package/stores/routes/useSwapHistory.js +4 -1
- package/stores/routes/utils.d.ts +3 -1
- package/stores/routes/utils.js +8 -2
- package/stores/settings/types.d.ts +6 -6
- package/stores/settings/useSettingsStore.d.ts +12 -9
- package/stores/settings/useSettingsStore.js +20 -4
- package/tsconfig.cjs.tsbuildinfo +1 -1
- package/types/events.d.ts +1 -1
- package/types/widget.d.ts +14 -8
- package/utils/enum.d.ts +1 -0
- package/utils/enum.js +1 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/navigationRoutes.d.ts +1 -1
- package/cjs/components/SwapInput/SwapInputAdornment.d.ts +0 -3
- package/cjs/providers/WalletProvider/WalletFormUpdate.d.ts +0 -5
- package/components/SwapInput/SwapInputAdornment.d.ts +0 -3
- package/providers/WalletProvider/WalletFormUpdate.d.ts +0 -5
|
@@ -1,49 +1,37 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { useRef } from 'react';
|
|
3
|
+
import { useController } from 'react-hook-form';
|
|
4
4
|
import { useTranslation } from 'react-i18next';
|
|
5
|
-
import { useChain, useToken } from '../../hooks';
|
|
6
5
|
import { SwapFormKeyHelper, useWidgetConfig } from '../../providers';
|
|
7
6
|
import { DisabledUI } from '../../types';
|
|
8
|
-
import {
|
|
7
|
+
import { formatAmount } from '../../utils';
|
|
9
8
|
import { Card, CardTitle } from '../Card';
|
|
10
|
-
import {
|
|
9
|
+
import { FitInputText } from './FitInputText';
|
|
11
10
|
import { FormPriceHelperText } from './FormPriceHelperText';
|
|
12
|
-
import { FormControl, Input
|
|
13
|
-
import {
|
|
11
|
+
import { FormControl, Input } from './SwapInput.style';
|
|
12
|
+
import { SwapInputEndAdornment } from './SwapInputEndAdornment';
|
|
13
|
+
import { SwapInputStartAdornment } from './SwapInputStartAdornment';
|
|
14
14
|
export const SwapInput = ({ formType }) => {
|
|
15
15
|
const { t } = useTranslation();
|
|
16
|
-
const { setValue } = useFormContext();
|
|
17
|
-
const { disabledUI } = useWidgetConfig();
|
|
18
|
-
const ref = useRef(null);
|
|
19
16
|
const amountKey = SwapFormKeyHelper.getAmountKey(formType);
|
|
20
|
-
const
|
|
21
|
-
name:
|
|
22
|
-
amountKey,
|
|
23
|
-
SwapFormKeyHelper.getChainKey(formType),
|
|
24
|
-
SwapFormKeyHelper.getTokenKey(formType),
|
|
25
|
-
],
|
|
17
|
+
const { field: { onChange, onBlur, value }, } = useController({
|
|
18
|
+
name: amountKey,
|
|
26
19
|
});
|
|
27
|
-
const {
|
|
28
|
-
const
|
|
29
|
-
const isSelected = !!(chain && token);
|
|
20
|
+
const { disabledUI } = useWidgetConfig();
|
|
21
|
+
const ref = useRef(null);
|
|
30
22
|
const handleChange = (event) => {
|
|
31
23
|
const { value } = event.target;
|
|
32
24
|
const formattedAmount = formatAmount(value, true);
|
|
33
|
-
|
|
34
|
-
shouldTouch: true,
|
|
35
|
-
});
|
|
25
|
+
onChange(formattedAmount);
|
|
36
26
|
};
|
|
37
27
|
const handleBlur = (event) => {
|
|
38
28
|
const { value } = event.target;
|
|
39
29
|
const formattedAmount = formatAmount(value);
|
|
40
|
-
|
|
30
|
+
onChange(formattedAmount);
|
|
31
|
+
onBlur();
|
|
41
32
|
};
|
|
42
|
-
useLayoutEffect(() => {
|
|
43
|
-
fitInputText(maxInputFontSize, minInputFontSize, ref.current);
|
|
44
|
-
}, [amount]);
|
|
45
33
|
const disabled = disabledUI === null || disabledUI === void 0 ? void 0 : disabledUI.includes(DisabledUI.FromAmount);
|
|
46
|
-
return (_jsxs(Card, { children: [_jsx(CardTitle, { children: t('swap.fromAmount') }), _jsxs(FormControl, Object.assign({ fullWidth: true }, { children: [_jsx(Input, { inputRef: ref, size: "small", autoComplete: "off", placeholder: "0", startAdornment:
|
|
34
|
+
return (_jsxs(Card, { children: [_jsx(CardTitle, { children: t('swap.fromAmount') }), _jsxs(FormControl, Object.assign({ fullWidth: true }, { children: [_jsx(Input, { inputRef: ref, size: "small", autoComplete: "off", placeholder: "0", startAdornment: _jsx(SwapInputStartAdornment, { formType: formType }), endAdornment: !disabled ? (_jsx(SwapInputEndAdornment, { formType: formType })) : undefined, inputProps: {
|
|
47
35
|
inputMode: 'decimal',
|
|
48
|
-
}, onChange: handleChange, onBlur: handleBlur, value:
|
|
36
|
+
}, onChange: handleChange, onBlur: handleBlur, value: value, name: amountKey, disabled: disabled, required: true }), _jsx(FormPriceHelperText, { formType: formType })] })), _jsx(FitInputText, { ref: ref, formType: formType })] }));
|
|
49
37
|
};
|
|
@@ -10,7 +10,7 @@ export declare const FormControl: import("@emotion/styled").StyledComponent<{
|
|
|
10
10
|
fullWidth?: boolean | undefined;
|
|
11
11
|
focused?: boolean | undefined;
|
|
12
12
|
hiddenLabel?: boolean | undefined;
|
|
13
|
-
margin?: "
|
|
13
|
+
margin?: "normal" | "none" | "dense" | undefined;
|
|
14
14
|
required?: boolean | undefined;
|
|
15
15
|
size?: "small" | "medium" | undefined;
|
|
16
16
|
sx?: import("@mui/material").SxProps<import("@mui/material").Theme> | undefined;
|
|
@@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next';
|
|
|
5
5
|
import { useTokenAddressBalance } from '../../hooks';
|
|
6
6
|
import { SwapFormKeyHelper } from '../../providers';
|
|
7
7
|
import { Button } from './SwapInputAdornment.style';
|
|
8
|
-
export const
|
|
8
|
+
export const SwapInputEndAdornment = ({ formType }) => {
|
|
9
9
|
const { t } = useTranslation();
|
|
10
10
|
const { setValue } = useFormContext();
|
|
11
11
|
const [chainId, tokenAddress] = useWatch({
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useWatch } from 'react-hook-form';
|
|
3
|
+
import { useChain, useToken } from '../../hooks';
|
|
4
|
+
import { SwapFormKeyHelper } from '../../providers';
|
|
5
|
+
import { TokenAvatar, TokenAvatarSkeleton } from '../TokenAvatar';
|
|
6
|
+
export const SwapInputStartAdornment = ({ formType, }) => {
|
|
7
|
+
const [chainId, tokenAddress] = useWatch({
|
|
8
|
+
name: [
|
|
9
|
+
SwapFormKeyHelper.getChainKey(formType),
|
|
10
|
+
SwapFormKeyHelper.getTokenKey(formType),
|
|
11
|
+
],
|
|
12
|
+
});
|
|
13
|
+
const { chain } = useChain(chainId);
|
|
14
|
+
const { token } = useToken(chainId, tokenAddress);
|
|
15
|
+
const isSelected = !!(chain && token);
|
|
16
|
+
return isSelected ? (_jsx(TokenAvatar, { token: token, chain: chain, sx: { marginLeft: 2 } })) : (_jsx(TokenAvatarSkeleton, { sx: { marginLeft: 2 } }));
|
|
17
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
export declare const Label: import("@emotion/styled").StyledComponent<import("@mui/system").SystemProps<import("@mui/material").Theme> & {
|
|
3
|
-
align?: "
|
|
3
|
+
align?: "left" | "right" | "inherit" | "center" | "justify" | undefined;
|
|
4
4
|
children?: import("react").ReactNode;
|
|
5
5
|
classes?: Partial<import("@mui/material").TypographyClasses> | undefined;
|
|
6
6
|
gutterBottom?: boolean | undefined;
|
|
@@ -34,7 +34,7 @@ export declare const Header: import("@emotion/styled").StyledComponent<import("@
|
|
|
34
34
|
export declare const Stack: import("@emotion/styled").StyledComponent<import("@mui/system").SystemProps<import("@mui/material").Theme> & {
|
|
35
35
|
ref?: import("react").Ref<unknown> | undefined;
|
|
36
36
|
children?: import("react").ReactNode;
|
|
37
|
-
direction?: import("@mui/system").ResponsiveStyleValue<"
|
|
37
|
+
direction?: import("@mui/system").ResponsiveStyleValue<"column" | "column-reverse" | "row" | "row-reverse"> | undefined;
|
|
38
38
|
spacing?: import("@mui/system").ResponsiveStyleValue<string | number> | undefined;
|
|
39
39
|
divider?: import("react").ReactNode;
|
|
40
40
|
sx?: import("@mui/material").SxProps<import("@mui/material").Theme> | undefined;
|
|
@@ -10,7 +10,7 @@ export declare const TextSecondaryContainer: import("@emotion/styled").StyledCom
|
|
|
10
10
|
connected?: boolean | undefined;
|
|
11
11
|
}, {}, {}>;
|
|
12
12
|
export declare const TextSecondary: import("@emotion/styled").StyledComponent<import("@mui/system").SystemProps<import("@mui/material").Theme> & {
|
|
13
|
-
align?: "
|
|
13
|
+
align?: "left" | "right" | "inherit" | "center" | "justify" | undefined;
|
|
14
14
|
children?: import("react").ReactNode;
|
|
15
15
|
classes?: Partial<import("@mui/material").TypographyClasses> | undefined;
|
|
16
16
|
gutterBottom?: boolean | undefined;
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
|
-
import { useFormContext } from 'react-hook-form';
|
|
2
|
+
import { useController, useFormContext } from 'react-hook-form';
|
|
3
3
|
import { SwapFormKeyHelper } from '../../providers';
|
|
4
4
|
export const useTokenSelect = (formType, onClick) => {
|
|
5
|
+
const tokenKey = SwapFormKeyHelper.getTokenKey(formType);
|
|
6
|
+
const { field: { onChange, onBlur }, } = useController({ name: tokenKey });
|
|
5
7
|
const { setValue, getValues } = useFormContext();
|
|
6
8
|
return useCallback((tokenAddress, chainId) => {
|
|
9
|
+
onChange(tokenAddress);
|
|
10
|
+
onBlur();
|
|
7
11
|
const selectedChainId = chainId !== null && chainId !== void 0 ? chainId : getValues(SwapFormKeyHelper.getChainKey(formType));
|
|
8
|
-
setValue(SwapFormKeyHelper.getTokenKey(formType), tokenAddress, {
|
|
9
|
-
shouldTouch: true,
|
|
10
|
-
});
|
|
11
12
|
// Set chain again to trigger URL builder update
|
|
12
13
|
setValue(SwapFormKeyHelper.getChainKey(formType), selectedChainId, {
|
|
14
|
+
shouldDirty: true,
|
|
13
15
|
shouldTouch: true,
|
|
14
16
|
});
|
|
15
17
|
setValue(SwapFormKeyHelper.getAmountKey(formType), '');
|
|
@@ -21,9 +23,10 @@ export const useTokenSelect = (formType, onClick) => {
|
|
|
21
23
|
if (selectedOppositeToken === tokenAddress &&
|
|
22
24
|
selectedOppositeChainId === selectedChainId) {
|
|
23
25
|
setValue(SwapFormKeyHelper.getTokenKey(oppositeFormType), '', {
|
|
26
|
+
shouldDirty: true,
|
|
24
27
|
shouldTouch: true,
|
|
25
28
|
});
|
|
26
29
|
}
|
|
27
30
|
onClick === null || onClick === void 0 ? void 0 : onClick();
|
|
28
|
-
}, [formType, getValues, onClick, setValue]);
|
|
31
|
+
}, [formType, getValues, onBlur, onChange, onClick, setValue]);
|
|
29
32
|
};
|
package/config/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name = "@lifi/widget";
|
|
2
|
-
export declare const version = "1.
|
|
2
|
+
export declare const version = "1.25.1";
|
package/config/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/widget';
|
|
2
|
-
export const version = '1.
|
|
2
|
+
export const version = '1.25.1';
|
|
@@ -11,7 +11,7 @@ import { useQuery } from '@tanstack/react-query';
|
|
|
11
11
|
import Big from 'big.js';
|
|
12
12
|
import { useChains } from '.';
|
|
13
13
|
import { useWallet } from '../providers';
|
|
14
|
-
import {
|
|
14
|
+
import { isRouteDone } from '../stores';
|
|
15
15
|
import { useTokenBalance } from './useTokenBalance';
|
|
16
16
|
const refetchInterval = 30000;
|
|
17
17
|
export const useGasSufficiency = (route) => {
|
|
@@ -75,7 +75,7 @@ export const useGasSufficiency = (route) => {
|
|
|
75
75
|
});
|
|
76
76
|
const { data: insufficientFunds, isInitialLoading: insufficientFundsLoading, } = useQuery(['funds-sufficiency-check', account.address, route === null || route === void 0 ? void 0 : route.id], () => __awaiter(void 0, void 0, void 0, function* () {
|
|
77
77
|
var _c, _d, _e, _f;
|
|
78
|
-
if (!account.address || !fromToken || !route ||
|
|
78
|
+
if (!account.address || !fromToken || !route || isRouteDone(route)) {
|
|
79
79
|
return null;
|
|
80
80
|
}
|
|
81
81
|
let currentTokenBalance = Big((_c = fromToken === null || fromToken === void 0 ? void 0 : fromToken.amount) !== null && _c !== void 0 ? _c : 0);
|
|
@@ -11,7 +11,7 @@ import { useMutation } from '@tanstack/react-query';
|
|
|
11
11
|
import { useCallback, useEffect, useRef } from 'react';
|
|
12
12
|
import shallow from 'zustand/shallow';
|
|
13
13
|
import { useLiFi, useWallet } from '../providers';
|
|
14
|
-
import { getUpdatedProcess, isRouteActive,
|
|
14
|
+
import { getUpdatedProcess, isRouteActive, isRouteDone, isRouteFailed, useRouteExecutionStore, } from '../stores';
|
|
15
15
|
import { WidgetEvent } from '../types/events';
|
|
16
16
|
import { deepClone } from '../utils';
|
|
17
17
|
import { useWidgetEvents } from './useWidgetEvents';
|
|
@@ -36,7 +36,7 @@ export const useRouteExecution = (routeId, executeInBackground) => {
|
|
|
36
36
|
process,
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
|
-
if (
|
|
39
|
+
if (isRouteDone(clonedUpdatedRoute)) {
|
|
40
40
|
emitter.emit(WidgetEvent.RouteExecutionCompleted, clonedUpdatedRoute);
|
|
41
41
|
}
|
|
42
42
|
if (isRouteFailed(clonedUpdatedRoute) && process) {
|
package/hooks/useSwapRoutes.js
CHANGED
|
@@ -16,9 +16,9 @@ import { SwapFormKey, useLiFi, useWallet, useWidgetConfig } from '../providers';
|
|
|
16
16
|
import { useSettings } from '../stores';
|
|
17
17
|
const refetchTime = 60000;
|
|
18
18
|
export const useSwapRoutes = () => {
|
|
19
|
-
var _a;
|
|
19
|
+
var _a, _b;
|
|
20
20
|
const lifi = useLiFi();
|
|
21
|
-
const { variant } = useWidgetConfig();
|
|
21
|
+
const { variant, sdkConfig } = useWidgetConfig();
|
|
22
22
|
const { account, provider } = useWallet();
|
|
23
23
|
const queryClient = useQueryClient();
|
|
24
24
|
const { slippage, enabledBridges, enabledExchanges, routePriority } = useSettings([
|
|
@@ -62,22 +62,25 @@ export const useSwapRoutes = () => {
|
|
|
62
62
|
enabledExchanges,
|
|
63
63
|
routePriority,
|
|
64
64
|
variant,
|
|
65
|
+
(_a = sdkConfig === null || sdkConfig === void 0 ? void 0 : sdkConfig.defaultRouteOptions) === null || _a === void 0 ? void 0 : _a.allowSwitchChain,
|
|
65
66
|
];
|
|
66
|
-
const previousDataUpdatedAt = (
|
|
67
|
+
const previousDataUpdatedAt = (_b = queryClient.getQueryState(queryKey)) === null || _b === void 0 ? void 0 : _b.dataUpdatedAt;
|
|
67
68
|
const refetchInterval = previousDataUpdatedAt
|
|
68
69
|
? Math.min(Math.abs(refetchTime - (Date.now() - previousDataUpdatedAt)), refetchTime)
|
|
69
70
|
: refetchTime;
|
|
70
|
-
const { data, isLoading, isFetching, isFetched, dataUpdatedAt, refetch } = useQuery(queryKey, ({ queryKey: [_, fromAddress, fromChainId, fromTokenAddress, fromTokenAmount, toChainId, toTokenAddress, toAddress, slippage, enabledBridges, enabledExchanges, routePriority, variant,], signal, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
|
-
var
|
|
71
|
+
const { data, isLoading, isFetching, isFetched, dataUpdatedAt, refetch } = useQuery(queryKey, ({ queryKey: [_, fromAddress, fromChainId, fromTokenAddress, fromTokenAmount, toChainId, toTokenAddress, toAddress, slippage, enabledBridges, enabledExchanges, routePriority, variant, allowSwitchChain,], signal, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
72
|
+
var _c, _d;
|
|
72
73
|
let toWalletAddress;
|
|
73
74
|
try {
|
|
74
75
|
toWalletAddress =
|
|
75
|
-
(
|
|
76
|
+
(_c = (yield (provider === null || provider === void 0 ? void 0 : provider.resolveName(toAddress)))) !== null && _c !== void 0 ? _c : (isAddress(toAddress) ? toAddress : fromAddress);
|
|
76
77
|
}
|
|
77
|
-
catch (
|
|
78
|
+
catch (_e) {
|
|
78
79
|
toWalletAddress = isAddress(toAddress) ? toAddress : fromAddress;
|
|
79
80
|
}
|
|
80
|
-
const fromAmount = Big(
|
|
81
|
+
const fromAmount = Big(fromTokenAmount)
|
|
82
|
+
.mul(Math.pow(10, ((_d = fromToken === null || fromToken === void 0 ? void 0 : fromToken.decimals) !== null && _d !== void 0 ? _d : 0)))
|
|
83
|
+
.toString();
|
|
81
84
|
const formattedSlippage = parseFloat(slippage) / 100;
|
|
82
85
|
return lifi.getRoutes({
|
|
83
86
|
fromChainId,
|
|
@@ -96,7 +99,7 @@ export const useSwapRoutes = () => {
|
|
|
96
99
|
allow: enabledExchanges,
|
|
97
100
|
},
|
|
98
101
|
order: routePriority,
|
|
99
|
-
allowSwitchChain: variant
|
|
102
|
+
allowSwitchChain: variant === 'refuel' ? false : allowSwitchChain,
|
|
100
103
|
},
|
|
101
104
|
}, { signal });
|
|
102
105
|
}), {
|
package/hooks/useTools.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Bridge, Exchange } from '@lifi/sdk';
|
|
|
2
2
|
interface WidgetBridge extends Omit<Bridge, 'key'> {
|
|
3
3
|
key: string;
|
|
4
4
|
}
|
|
5
|
-
|
|
5
|
+
type FormattedTool<T, K extends keyof T> = Record<string, Pick<T, K>>;
|
|
6
6
|
export declare const useTools: () => {
|
|
7
7
|
tools: import("@lifi/sdk").ToolsResponse | undefined;
|
|
8
8
|
formattedTools: {
|
package/i18n/en.json
CHANGED
|
@@ -148,10 +148,12 @@
|
|
|
148
148
|
"stepSwapAndBridge": "Swap and bridge",
|
|
149
149
|
"success": {
|
|
150
150
|
"message": {
|
|
151
|
-
"
|
|
151
|
+
"swapPartiallySuccessful": "We've tried to complete the swap, but {{tool}} ran out of liquidity for {{tokenSymbol}} token.",
|
|
152
|
+
"swapSuccessful": "There are now {{amount, number(maximumFractionDigits: 4)}} {{tokenSymbol}} in {{walletAddress}} wallet on {{chainName}} chain."
|
|
152
153
|
},
|
|
153
154
|
"title": {
|
|
154
155
|
"gasSwapSuccessful": "Gas swap successful",
|
|
156
|
+
"swapPartiallySuccessful": "Swap partially successful",
|
|
155
157
|
"swapSuccessful": "Swap successful"
|
|
156
158
|
}
|
|
157
159
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/widget",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.25.1",
|
|
4
4
|
"description": "LI.FI Widget for cross-chain bridging and swapping. It will drive your multi-chain strategy and attract new users from everywhere.",
|
|
5
5
|
"main": "./cjs/index.js",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -42,25 +42,25 @@
|
|
|
42
42
|
"@ethersproject/address": "^5.7.0",
|
|
43
43
|
"@ethersproject/experimental": "^5.7.0",
|
|
44
44
|
"@ethersproject/providers": "^5.7.2",
|
|
45
|
-
"@lifi/sdk": "^1.6.
|
|
46
|
-
"@lifi/wallet-management": "^1.2.
|
|
47
|
-
"@mui/icons-material": "^5.10.
|
|
48
|
-
"@mui/lab": "^5.0.0-alpha.
|
|
49
|
-
"@mui/material": "^5.10.
|
|
50
|
-
"@sentry/integrations": "^7.
|
|
51
|
-
"@sentry/react": "^7.
|
|
52
|
-
"@sentry/tracing": "^7.
|
|
53
|
-
"@tanstack/react-query": "^4.
|
|
54
|
-
"@tanstack/react-virtual": "^3.0.0-beta.
|
|
45
|
+
"@lifi/sdk": "^1.6.4",
|
|
46
|
+
"@lifi/wallet-management": "^1.2.1",
|
|
47
|
+
"@mui/icons-material": "^5.10.14",
|
|
48
|
+
"@mui/lab": "^5.0.0-alpha.108",
|
|
49
|
+
"@mui/material": "^5.10.14",
|
|
50
|
+
"@sentry/integrations": "^7.20.0",
|
|
51
|
+
"@sentry/react": "^7.20.0",
|
|
52
|
+
"@sentry/tracing": "^7.20.0",
|
|
53
|
+
"@tanstack/react-query": "^4.16.1",
|
|
54
|
+
"@tanstack/react-virtual": "^3.0.0-beta.23",
|
|
55
55
|
"big.js": "^6.2.1",
|
|
56
|
-
"i18next": "
|
|
56
|
+
"i18next": "22.0.4",
|
|
57
57
|
"i18next-browser-languagedetector": "^7.0.1",
|
|
58
58
|
"immer": "^9.0.16",
|
|
59
59
|
"microdiff": "^1.3.1",
|
|
60
60
|
"mitt": "^3.0.0",
|
|
61
61
|
"react": "^18.2.0",
|
|
62
62
|
"react-dom": "^18.2.0",
|
|
63
|
-
"react-hook-form": "^7.39.
|
|
63
|
+
"react-hook-form": "^7.39.4",
|
|
64
64
|
"react-i18next": "^12.0.0",
|
|
65
65
|
"react-router-dom": "^6.4.3",
|
|
66
66
|
"react-timer-hook": "^3.0.5",
|
|
@@ -10,7 +10,8 @@ export const RoutePrioritySelect = () => {
|
|
|
10
10
|
const { t } = useTranslation();
|
|
11
11
|
const setValue = useSettingsStore((state) => state.setValue);
|
|
12
12
|
const { routePriority } = useSettings(['routePriority']);
|
|
13
|
-
|
|
13
|
+
const value = routePriority !== null && routePriority !== void 0 ? routePriority : '';
|
|
14
|
+
return (_jsxs(Card, { children: [_jsx(CardTitle, { children: t(`settings.routePriority`) }), _jsx(FormControl, Object.assign({ fullWidth: true }, { children: _jsx(Select, Object.assign({ MenuProps: { elevation: 2 }, value: value, onChange: (event) => setValue('routePriority', event.target.value), IconComponent: KeyboardArrowDownIcon, dense: true }, { children: Orders.map((order) => {
|
|
14
15
|
const tag = t(`swap.tags.${order.toUpperCase()}`);
|
|
15
16
|
const tagName = `${tag[0]}${tag.slice(1).toLowerCase()}`;
|
|
16
17
|
return (_jsx(MenuItem, Object.assign({ value: order }, { children: tagName }), order));
|
|
@@ -19,7 +19,8 @@ export const SlippageInput = () => {
|
|
|
19
19
|
const { value } = event.target;
|
|
20
20
|
setValue('slippage', formatSlippage(value, defaultValue.current));
|
|
21
21
|
};
|
|
22
|
+
const value = slippage !== null && slippage !== void 0 ? slippage : '';
|
|
22
23
|
return (_jsxs(Card, { children: [_jsx(CardTitle, { children: t(`settings.slippage`) }), _jsx(FormControl, Object.assign({ fullWidth: true }, { children: _jsx(Input, { size: "small", placeholder: t(`settings.slippage`), endAdornment: _jsx(InputAdornment, Object.assign({ position: "end" }, { children: "%" })), autoComplete: "off", inputProps: {
|
|
23
24
|
inputMode: 'decimal',
|
|
24
|
-
}, onChange: handleChange, onBlur: handleBlur, value:
|
|
25
|
+
}, onChange: handleChange, onBlur: handleBlur, value: value }) }))] }));
|
|
25
26
|
};
|
|
@@ -9,10 +9,11 @@ import { BottomSheet } from '../../components/BottomSheet';
|
|
|
9
9
|
import { Token } from '../../components/Token';
|
|
10
10
|
import { getProcessMessage, useChains, useNavigateBack, useTokenBalance, } from '../../hooks';
|
|
11
11
|
import { SwapFormKey } from '../../providers';
|
|
12
|
-
import {
|
|
12
|
+
import { RouteExecutionStatus } from '../../stores';
|
|
13
|
+
import { formatTokenAmount, hasEnumFlag, navigationRoutes, shortenWalletAddress, } from '../../utils';
|
|
13
14
|
import { IconCircle, IconContainer } from './StatusBottomSheet.style';
|
|
14
15
|
export const StatusBottomSheet = ({ status, route, }) => {
|
|
15
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
16
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
16
17
|
const { t } = useTranslation();
|
|
17
18
|
const { navigateBack, navigate } = useNavigateBack();
|
|
18
19
|
const ref = useRef(null);
|
|
@@ -28,6 +29,22 @@ export const StatusBottomSheet = ({ status, route, }) => {
|
|
|
28
29
|
clearFromAmount();
|
|
29
30
|
navigateBack();
|
|
30
31
|
};
|
|
32
|
+
const handlePartialDone = () => {
|
|
33
|
+
clearFromAmount();
|
|
34
|
+
if (toToken.chainId !== route.toToken.chainId &&
|
|
35
|
+
toToken.address !== route.toToken.address) {
|
|
36
|
+
setValue(SwapFormKey.FromAmount, formatTokenAmount(toToken.amount, toToken.decimals), { shouldTouch: true });
|
|
37
|
+
setValue(SwapFormKey.FromChain, toToken.chainId, { shouldTouch: true });
|
|
38
|
+
setValue(SwapFormKey.FromToken, toToken.address, { shouldTouch: true });
|
|
39
|
+
setValue(SwapFormKey.ToChain, route.toToken.chainId, {
|
|
40
|
+
shouldTouch: true,
|
|
41
|
+
});
|
|
42
|
+
setValue(SwapFormKey.ToToken, route.toToken.address, {
|
|
43
|
+
shouldTouch: true,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
navigateBack();
|
|
47
|
+
};
|
|
31
48
|
const handleClose = () => {
|
|
32
49
|
var _a;
|
|
33
50
|
clearFromAmount();
|
|
@@ -41,26 +58,50 @@ export const StatusBottomSheet = ({ status, route, }) => {
|
|
|
41
58
|
});
|
|
42
59
|
};
|
|
43
60
|
let title;
|
|
44
|
-
let
|
|
61
|
+
let primaryMessage;
|
|
62
|
+
let secondaryMessage;
|
|
63
|
+
let handlePrimaryButton = handleDone;
|
|
45
64
|
switch (status) {
|
|
46
|
-
case
|
|
65
|
+
case RouteExecutionStatus.Done: {
|
|
47
66
|
title = t('swap.success.title.swapSuccessful');
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
67
|
+
if (token) {
|
|
68
|
+
primaryMessage = t('swap.success.message.swapSuccessful', {
|
|
69
|
+
amount: token.amount,
|
|
70
|
+
tokenSymbol: token.symbol,
|
|
71
|
+
chainName: (_j = getChainById(token.chainId)) === null || _j === void 0 ? void 0 : _j.name,
|
|
72
|
+
walletAddress: shortenWalletAddress(route.toAddress),
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
handlePrimaryButton = handleDone;
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
case RouteExecutionStatus.Done | RouteExecutionStatus.Partial: {
|
|
79
|
+
title = t('swap.success.title.swapPartiallySuccessful');
|
|
80
|
+
primaryMessage = t('swap.success.message.swapPartiallySuccessful', {
|
|
81
|
+
tool: (_k = route.steps.at(-1)) === null || _k === void 0 ? void 0 : _k.toolDetails.name,
|
|
82
|
+
tokenSymbol: (_l = route.steps.at(-1)) === null || _l === void 0 ? void 0 : _l.action.toToken.symbol,
|
|
53
83
|
});
|
|
84
|
+
if (token) {
|
|
85
|
+
secondaryMessage = t('swap.success.message.swapSuccessful', {
|
|
86
|
+
amount: token.amount,
|
|
87
|
+
tokenSymbol: token.symbol,
|
|
88
|
+
chainName: (_m = getChainById(token.chainId)) === null || _m === void 0 ? void 0 : _m.name,
|
|
89
|
+
walletAddress: shortenWalletAddress(route.toAddress),
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
handlePrimaryButton = handlePartialDone;
|
|
54
93
|
break;
|
|
55
|
-
|
|
94
|
+
}
|
|
95
|
+
case RouteExecutionStatus.Failed: {
|
|
56
96
|
const step = route.steps.find((step) => { var _a; return ((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'FAILED'; });
|
|
57
|
-
const process = (
|
|
97
|
+
const process = (_o = step === null || step === void 0 ? void 0 : step.execution) === null || _o === void 0 ? void 0 : _o.process.find((process) => process.status === 'FAILED');
|
|
58
98
|
if (!step || !process) {
|
|
59
99
|
break;
|
|
60
100
|
}
|
|
61
101
|
const processMessage = getProcessMessage(t, getChainById, step, process);
|
|
62
102
|
title = processMessage.title;
|
|
63
|
-
|
|
103
|
+
primaryMessage = processMessage.message;
|
|
104
|
+
handlePrimaryButton = handleClose;
|
|
64
105
|
break;
|
|
65
106
|
}
|
|
66
107
|
default:
|
|
@@ -68,14 +109,20 @@ export const StatusBottomSheet = ({ status, route, }) => {
|
|
|
68
109
|
}
|
|
69
110
|
useEffect(() => {
|
|
70
111
|
var _a, _b;
|
|
71
|
-
|
|
112
|
+
const hasSuccessFlag = hasEnumFlag(status, RouteExecutionStatus.Done);
|
|
113
|
+
if ((hasSuccessFlag || hasEnumFlag(status, RouteExecutionStatus.Failed)) &&
|
|
72
114
|
!((_a = ref.current) === null || _a === void 0 ? void 0 : _a.isOpen())) {
|
|
73
|
-
if (
|
|
115
|
+
if (hasSuccessFlag) {
|
|
74
116
|
refetchNewBalance();
|
|
75
117
|
refetch();
|
|
76
118
|
}
|
|
77
119
|
(_b = ref.current) === null || _b === void 0 ? void 0 : _b.open();
|
|
78
120
|
}
|
|
79
121
|
}, [refetch, refetchNewBalance, status]);
|
|
80
|
-
return (_jsx(BottomSheet, Object.assign({ ref: ref }, { children: _jsxs(Box, Object.assign({ p: 3 }, { children: [_jsxs(IconContainer, { children: [_jsxs(IconCircle, Object.assign({ status: status, mb: 1 }, { children: [status ===
|
|
122
|
+
return (_jsx(BottomSheet, Object.assign({ ref: ref }, { children: _jsxs(Box, Object.assign({ p: 3 }, { children: [_jsxs(IconContainer, { children: [_jsxs(IconCircle, Object.assign({ status: status, mb: 1 }, { children: [status === RouteExecutionStatus.Idle ? (_jsx(InfoIcon, { color: "primary" })) : null, status === RouteExecutionStatus.Done ? (_jsx(DoneIcon, { color: "success" })) : null, hasEnumFlag(status, RouteExecutionStatus.Partial) ||
|
|
123
|
+
hasEnumFlag(status, RouteExecutionStatus.Refunded) ? (_jsx(WarningIcon, { color: "warning" })) : null, hasEnumFlag(status, RouteExecutionStatus.Failed) ? (_jsx(WarningIcon, { color: "error" })) : null] })), _jsx(Typography, Object.assign({ py: 1, fontSize: 18, fontWeight: 700 }, { children: title })), hasEnumFlag(status, RouteExecutionStatus.Done) ? (_jsx(Token, { token: toToken, py: 1, disableDescription: true })) : null] }), _jsx(Typography, Object.assign({ py: 1 }, { children: primaryMessage })), secondaryMessage ? (_jsx(Typography, Object.assign({ py: 1 }, { children: secondaryMessage }))) : null, _jsx(Box, Object.assign({ mt: 2 }, { children: _jsxs(Button, Object.assign({ variant: "contained", fullWidth: true, onClick: handlePrimaryButton }, { children: [status === RouteExecutionStatus.Idle ? t('button.ok') : null, hasEnumFlag(status, RouteExecutionStatus.Done)
|
|
124
|
+
? t('button.done')
|
|
125
|
+
: null, status === RouteExecutionStatus.Failed
|
|
126
|
+
? t('button.seeDetails')
|
|
127
|
+
: null] })) })), hasEnumFlag(status, RouteExecutionStatus.Done) ? (_jsx(Box, Object.assign({ mt: 2 }, { children: _jsx(Button, Object.assign({ variant: "text", onClick: handleSeeDetails, fullWidth: true }, { children: t('button.seeDetails') })) }))) : null] })) })));
|
|
81
128
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { Theme } from '@mui/material';
|
|
3
|
-
import
|
|
3
|
+
import { RouteExecutionStatus } from '../../stores';
|
|
4
|
+
type StatusColor = RouteExecutionStatus | 'warning';
|
|
4
5
|
export declare const IconContainer: import("@emotion/styled").StyledComponent<import("@mui/system").SystemProps<Theme> & {
|
|
5
6
|
children?: import("react").ReactNode;
|
|
6
7
|
component?: import("react").ElementType<any> | undefined;
|
|
@@ -17,5 +18,6 @@ export declare const IconCircle: import("@emotion/styled").StyledComponent<impor
|
|
|
17
18
|
} & import("@mui/material/OverridableComponent").CommonProps & Omit<Pick<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof import("react").HTMLAttributes<HTMLDivElement>> & {
|
|
18
19
|
ref?: import("react").RefObject<HTMLDivElement> | ((instance: HTMLDivElement | null) => void) | null | undefined;
|
|
19
20
|
}, keyof import("@mui/material/OverridableComponent").CommonProps | "children" | "sx" | "ref" | ("p" | "color" | "border" | "boxShadow" | "fontWeight" | "zIndex" | "alignContent" | "alignItems" | "alignSelf" | "bottom" | "boxSizing" | "columnGap" | "display" | "flexBasis" | "flexDirection" | "flexGrow" | "flexShrink" | "flexWrap" | "fontFamily" | "fontSize" | "fontStyle" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "height" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "letterSpacing" | "lineHeight" | "marginBottom" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "order" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingTop" | "position" | "right" | "rowGap" | "textAlign" | "textOverflow" | "textTransform" | "top" | "visibility" | "whiteSpace" | "width" | "borderBottom" | "borderColor" | "borderLeft" | "borderRadius" | "borderRight" | "borderTop" | "flex" | "gap" | "gridArea" | "gridColumn" | "gridRow" | "margin" | "overflow" | "padding" | "bgcolor" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "marginX" | "my" | "marginY" | "pt" | "pr" | "pb" | "pl" | "px" | "paddingX" | "py" | "paddingY" | "typography" | "displayPrint") | "component"> & import("@mui/system").MUIStyledCommonProps<Theme> & {
|
|
20
|
-
status:
|
|
21
|
+
status: StatusColor;
|
|
21
22
|
}, {}, {}>;
|
|
23
|
+
export {};
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { Box } from '@mui/material';
|
|
2
2
|
import { alpha, darken, styled } from '@mui/material/styles';
|
|
3
|
+
import { RouteExecutionStatus } from '../../stores';
|
|
3
4
|
const getStatusColor = (status, theme) => {
|
|
4
5
|
switch (status) {
|
|
5
|
-
case
|
|
6
|
+
case RouteExecutionStatus.Done:
|
|
6
7
|
return { color: theme.palette.success.main, alpha: 0.15, darken: 0 };
|
|
7
|
-
case
|
|
8
|
+
case RouteExecutionStatus.Failed:
|
|
8
9
|
return { color: theme.palette.error.main, alpha: 0.2, darken: 0 };
|
|
10
|
+
case RouteExecutionStatus.Done | RouteExecutionStatus.Partial:
|
|
11
|
+
case RouteExecutionStatus.Done | RouteExecutionStatus.Refunded:
|
|
9
12
|
case 'warning':
|
|
10
13
|
return { color: theme.palette.warning.main, alpha: 0.7, darken: 0.4 };
|
|
11
14
|
default:
|
|
@@ -20,6 +20,7 @@ import { StepDivider } from '../../components/StepDivider';
|
|
|
20
20
|
import { SwapButton } from '../../components/SwapButton';
|
|
21
21
|
import { useNavigateBack, useRouteExecution } from '../../hooks';
|
|
22
22
|
import { SwapFormKey } from '../../providers';
|
|
23
|
+
import { RouteExecutionStatus } from '../../stores';
|
|
23
24
|
import { StatusBottomSheet } from './StatusBottomSheet';
|
|
24
25
|
import { Container } from './SwapPage.style';
|
|
25
26
|
import { getTokenValueLossThreshold, TokenValueBottomSheet, } from './TokenValueBottomSheet';
|
|
@@ -40,7 +41,7 @@ export const SwapPage = () => {
|
|
|
40
41
|
}, [executeRoute, setValue]);
|
|
41
42
|
const handleSwapClick = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
43
|
var _a;
|
|
43
|
-
if (status ===
|
|
44
|
+
if (status === RouteExecutionStatus.Idle) {
|
|
44
45
|
const thresholdExceeded = getTokenValueLossThreshold(route);
|
|
45
46
|
if (thresholdExceeded) {
|
|
46
47
|
(_a = tokenValueBottomSheetRef.current) === null || _a === void 0 ? void 0 : _a.open();
|
|
@@ -49,7 +50,7 @@ export const SwapPage = () => {
|
|
|
49
50
|
handleExecuteRoute();
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
|
-
if (status ===
|
|
53
|
+
if (status === RouteExecutionStatus.Failed) {
|
|
53
54
|
restartRoute();
|
|
54
55
|
}
|
|
55
56
|
});
|
|
@@ -59,9 +60,9 @@ export const SwapPage = () => {
|
|
|
59
60
|
};
|
|
60
61
|
const getSwapButtonText = () => {
|
|
61
62
|
switch (status) {
|
|
62
|
-
case
|
|
63
|
+
case RouteExecutionStatus.Idle:
|
|
63
64
|
return t('button.startSwap');
|
|
64
|
-
case
|
|
65
|
+
case RouteExecutionStatus.Failed:
|
|
65
66
|
return t('button.restartSwap');
|
|
66
67
|
default:
|
|
67
68
|
return '';
|
|
@@ -74,9 +75,10 @@ export const SwapPage = () => {
|
|
|
74
75
|
const toToken = index === steps.length - 1
|
|
75
76
|
? Object.assign(Object.assign({}, ((_b = (_a = step.execution) === null || _a === void 0 ? void 0 : _a.toToken) !== null && _b !== void 0 ? _b : (_c = step.action) === null || _c === void 0 ? void 0 : _c.toToken)), { amount: (_e = (_d = step.execution) === null || _d === void 0 ? void 0 : _d.toAmount) !== null && _e !== void 0 ? _e : step.estimate.toAmount }) : undefined;
|
|
76
77
|
return (_jsxs(Fragment, { children: [_jsx(Step, { step: step, fromToken: fromToken, toToken: toToken }), steps.length > 1 && index !== steps.length - 1 ? (_jsx(StepDivider, {})) : null] }, step.id));
|
|
77
|
-
}), status ===
|
|
78
|
+
}), status === RouteExecutionStatus.Idle ||
|
|
79
|
+
status === RouteExecutionStatus.Failed ? (_jsxs(_Fragment, { children: [_jsx(GasSufficiencyMessage, { route: route, mt: 2 }), _jsxs(Box, Object.assign({ mt: 2, display: "flex" }, { children: [_jsx(SwapButton, { text: getSwapButtonText(), onClick: handleSwapClick, currentRoute: route,
|
|
78
80
|
// disable={status === 'idle' && (isValidating || !isValid)}
|
|
79
|
-
enableLoading: true }), status ===
|
|
81
|
+
enableLoading: true }), status === RouteExecutionStatus.Failed ? (_jsx(Tooltip, Object.assign({ title: t('button.removeSwap'), placement: "bottom-end", enterDelay: 400, arrow: true }, { children: _jsx(Button, Object.assign({ onClick: handleRemoveRoute, sx: {
|
|
80
82
|
minWidth: 48,
|
|
81
83
|
marginLeft: 1,
|
|
82
84
|
} }, { children: _jsx(DeleteIcon, {}) })) }))) : null] }))] })) : null, route && status ? (_jsx(StatusBottomSheet, { status: status, route: route })) : null, route ? (_jsx(TokenValueBottomSheet, { route: route, ref: tokenValueBottomSheetRef, onContinue: handleExecuteRoute })) : null] }));
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export declare const Stack: import("@emotion/styled").StyledComponent<import("@mui/system").SystemProps<import("@mui/material").Theme> & {
|
|
3
3
|
ref?: import("react").Ref<unknown> | undefined;
|
|
4
4
|
children?: import("react").ReactNode;
|
|
5
|
-
direction?: import("@mui/system").ResponsiveStyleValue<"
|
|
5
|
+
direction?: import("@mui/system").ResponsiveStyleValue<"column" | "column-reverse" | "row" | "row-reverse"> | undefined;
|
|
6
6
|
spacing?: import("@mui/system").ResponsiveStyleValue<string | number> | undefined;
|
|
7
7
|
divider?: import("react").ReactNode;
|
|
8
8
|
sx?: import("@mui/material").SxProps<import("@mui/material").Theme> | undefined;
|