@lifi/widget 1.23.1 → 1.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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/StepActions/StepActions.js +2 -2
- 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 +12 -9
- 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/useTelemetry.js +3 -1
- package/cjs/hooks/useTools.d.ts +5 -2
- package/cjs/i18n/en.json +3 -1
- package/cjs/i18n/uk.json +11 -6
- package/cjs/pages/SettingsPage/RoutePrioritySelect.js +2 -1
- package/cjs/pages/SettingsPage/SlippageInput.js +2 -1
- package/cjs/pages/SwapHistoryPage/SwapHistoryItem.js +4 -2
- package/cjs/pages/SwapPage/StatusBottomSheet.js +63 -15
- 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/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 +13 -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/StepActions/StepActions.js +2 -2
- 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 +13 -10
- 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/useTelemetry.js +3 -1
- package/hooks/useTools.d.ts +5 -2
- package/i18n/en.json +3 -1
- package/i18n/uk.json +11 -6
- package/package.json +13 -13
- package/pages/SettingsPage/RoutePrioritySelect.js +2 -1
- package/pages/SettingsPage/SlippageInput.js +2 -1
- package/pages/SwapHistoryPage/SwapHistoryItem.js +4 -2
- package/pages/SwapPage/StatusBottomSheet.js +64 -16
- 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/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 +13 -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
|
@@ -9,16 +9,18 @@ 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;
|
|
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);
|
|
19
20
|
const { getChainById } = useChains();
|
|
20
21
|
const { setValue } = useFormContext();
|
|
21
|
-
const
|
|
22
|
+
const toToken = Object.assign(Object.assign({}, ((_c = (_b = (_a = route.steps.at(-1)) === null || _a === void 0 ? void 0 : _a.execution) === null || _b === void 0 ? void 0 : _b.toToken) !== null && _c !== void 0 ? _c : route.toToken)), { amount: (_h = (_f = (_e = (_d = route.steps.at(-1)) === null || _d === void 0 ? void 0 : _d.execution) === null || _e === void 0 ? void 0 : _e.toAmount) !== null && _f !== void 0 ? _f : (_g = route.steps.at(-1)) === null || _g === void 0 ? void 0 : _g.estimate.toAmount) !== null && _h !== void 0 ? _h : route.toAmount });
|
|
23
|
+
const { token, refetch, refetchNewBalance, refetchAllBalances } = useTokenBalance(toToken, route.toAddress);
|
|
22
24
|
const clearFromAmount = () => {
|
|
23
25
|
refetchAllBalances();
|
|
24
26
|
setValue(SwapFormKey.FromAmount, '');
|
|
@@ -27,6 +29,22 @@ export const StatusBottomSheet = ({ status, route, }) => {
|
|
|
27
29
|
clearFromAmount();
|
|
28
30
|
navigateBack();
|
|
29
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
|
+
};
|
|
30
48
|
const handleClose = () => {
|
|
31
49
|
var _a;
|
|
32
50
|
clearFromAmount();
|
|
@@ -40,26 +58,50 @@ export const StatusBottomSheet = ({ status, route, }) => {
|
|
|
40
58
|
});
|
|
41
59
|
};
|
|
42
60
|
let title;
|
|
43
|
-
let
|
|
61
|
+
let primaryMessage;
|
|
62
|
+
let secondaryMessage;
|
|
63
|
+
let handlePrimaryButton = handleDone;
|
|
44
64
|
switch (status) {
|
|
45
|
-
case
|
|
65
|
+
case RouteExecutionStatus.Done: {
|
|
46
66
|
title = t('swap.success.title.swapSuccessful');
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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,
|
|
52
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;
|
|
53
93
|
break;
|
|
54
|
-
|
|
94
|
+
}
|
|
95
|
+
case RouteExecutionStatus.Failed: {
|
|
55
96
|
const step = route.steps.find((step) => { var _a; return ((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'FAILED'; });
|
|
56
|
-
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');
|
|
57
98
|
if (!step || !process) {
|
|
58
99
|
break;
|
|
59
100
|
}
|
|
60
101
|
const processMessage = getProcessMessage(t, getChainById, step, process);
|
|
61
102
|
title = processMessage.title;
|
|
62
|
-
|
|
103
|
+
primaryMessage = processMessage.message;
|
|
104
|
+
handlePrimaryButton = handleClose;
|
|
63
105
|
break;
|
|
64
106
|
}
|
|
65
107
|
default:
|
|
@@ -67,14 +109,20 @@ export const StatusBottomSheet = ({ status, route, }) => {
|
|
|
67
109
|
}
|
|
68
110
|
useEffect(() => {
|
|
69
111
|
var _a, _b;
|
|
70
|
-
|
|
112
|
+
const hasSuccessFlag = hasEnumFlag(status, RouteExecutionStatus.Done);
|
|
113
|
+
if ((hasSuccessFlag || hasEnumFlag(status, RouteExecutionStatus.Failed)) &&
|
|
71
114
|
!((_a = ref.current) === null || _a === void 0 ? void 0 : _a.isOpen())) {
|
|
72
|
-
if (
|
|
115
|
+
if (hasSuccessFlag) {
|
|
73
116
|
refetchNewBalance();
|
|
74
117
|
refetch();
|
|
75
118
|
}
|
|
76
119
|
(_b = ref.current) === null || _b === void 0 ? void 0 : _b.open();
|
|
77
120
|
}
|
|
78
121
|
}, [refetch, refetchNewBalance, status]);
|
|
79
|
-
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] })) })));
|
|
80
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;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type * as languages from '../../i18n';
|
|
2
|
-
export
|
|
2
|
+
export type PartialResource<T> = T extends object ? {
|
|
3
3
|
[P in keyof T]?: PartialResource<T[P]>;
|
|
4
4
|
} : T;
|
|
5
|
-
export
|
|
6
|
-
export
|
|
5
|
+
export type LanguageKey = keyof typeof languages;
|
|
6
|
+
export type LanguageResources = {
|
|
7
7
|
[language in LanguageKey]?: PartialResource<typeof languages.en>;
|
|
8
8
|
} | {
|
|
9
9
|
[language: string]: PartialResource<typeof languages.en>;
|
|
10
10
|
};
|
|
11
|
-
export
|
|
11
|
+
export type LanguageTranslationResource = {
|
|
12
12
|
[namespace in 'translation']: PartialResource<typeof languages.en>;
|
|
13
13
|
};
|
|
14
|
-
export
|
|
14
|
+
export type LanguageTranslationResources = {
|
|
15
15
|
[language: string]: LanguageTranslationResource;
|
|
16
16
|
};
|
|
@@ -1,47 +1,35 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
-
import { useEffect } from 'react';
|
|
2
|
+
import { useEffect, useRef } from 'react';
|
|
3
3
|
import { useFormContext } from 'react-hook-form';
|
|
4
|
-
import { useChainOrderStore } from '../../stores';
|
|
5
4
|
import { SwapFormKey } from '../SwapFormProvider';
|
|
5
|
+
import { useWallet } from '../WalletProvider';
|
|
6
6
|
import { isItemAllowed, useWidgetConfig } from '../WidgetProvider';
|
|
7
|
-
export const
|
|
7
|
+
export const FormUpdater = ({ defaultValues }) => {
|
|
8
8
|
const { fromChain, toChain, chains, disabledChains } = useWidgetConfig();
|
|
9
|
-
const {
|
|
9
|
+
const { account } = useWallet();
|
|
10
|
+
const { setValue, getValues, getFieldState, resetField,
|
|
10
11
|
// Subscription to touchedFields is required by getFieldState to work
|
|
11
12
|
formState: { touchedFields }, } = useFormContext();
|
|
13
|
+
const previousDefaultValues = useRef(defaultValues);
|
|
12
14
|
// Set wallet chain as default if no chains are provided by config and if they were not changed during widget usage
|
|
13
15
|
useEffect(() => {
|
|
14
16
|
const chainAllowed = account.chainId && isItemAllowed(account.chainId, chains, disabledChains);
|
|
15
17
|
if (!account.isActive || !account.chainId || !chainAllowed) {
|
|
16
18
|
return;
|
|
17
19
|
}
|
|
18
|
-
const [fromChainValue, toChainValue] = getValues([
|
|
19
|
-
SwapFormKey.FromChain,
|
|
20
|
-
SwapFormKey.ToChain,
|
|
21
|
-
]);
|
|
22
20
|
const { isTouched: isFromChainTouched } = getFieldState(SwapFormKey.FromChain);
|
|
23
21
|
const { isTouched: isToChainTouched } = getFieldState(SwapFormKey.ToChain);
|
|
24
22
|
const { isTouched: isFromTokenTouched } = getFieldState(SwapFormKey.FromToken);
|
|
25
23
|
const { isTouched: isToTokenTouched } = getFieldState(SwapFormKey.ToToken);
|
|
26
24
|
const { isTouched: isFromAmountTouched } = getFieldState(SwapFormKey.FromAmount);
|
|
27
|
-
|
|
28
|
-
// Users can switch chains in the wallet.
|
|
29
|
-
// If we don't have a chain in the ordered chain list we should add it.
|
|
30
|
-
setChain(account.chainId);
|
|
31
|
-
// If we ran out of slots for the ordered chain list and the current chain isn't there
|
|
32
|
-
// we should make a recently switched chain as current.
|
|
33
|
-
const hasFromChainInOrderedList = chainOrder.includes(fromChainValue);
|
|
34
|
-
const hasToChainInOrderedList = chainOrder.includes(toChainValue);
|
|
35
|
-
if ((!fromChain && !isFromChainTouched && !isFromTokenTouched) ||
|
|
36
|
-
!hasFromChainInOrderedList) {
|
|
25
|
+
if (!fromChain && !isFromChainTouched && !isFromTokenTouched) {
|
|
37
26
|
setValue(SwapFormKey.FromChain, account.chainId);
|
|
38
27
|
setValue(SwapFormKey.FromToken, '');
|
|
39
28
|
if (isFromAmountTouched) {
|
|
40
29
|
setValue(SwapFormKey.FromAmount, '');
|
|
41
30
|
}
|
|
42
31
|
}
|
|
43
|
-
if (
|
|
44
|
-
!hasToChainInOrderedList) {
|
|
32
|
+
if (!toChain && !isToChainTouched && !isToTokenTouched) {
|
|
45
33
|
setValue(SwapFormKey.ToChain, account.chainId);
|
|
46
34
|
setValue(SwapFormKey.ToToken, '');
|
|
47
35
|
}
|
|
@@ -56,5 +44,20 @@ export const WalletFormUpdate = ({ account, }) => {
|
|
|
56
44
|
setValue,
|
|
57
45
|
toChain,
|
|
58
46
|
]);
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
Object.keys(defaultValues).forEach((key) => {
|
|
49
|
+
if (previousDefaultValues.current[key] !== defaultValues[key]) {
|
|
50
|
+
const value = defaultValues[key] ||
|
|
51
|
+
// set the chain to the current user one if it is not present in the config
|
|
52
|
+
(key === SwapFormKey.FromChain || key === SwapFormKey.ToChain
|
|
53
|
+
? account.chainId || ''
|
|
54
|
+
: '');
|
|
55
|
+
setValue(key, value);
|
|
56
|
+
resetField(key, { defaultValue: value });
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
previousDefaultValues.current = defaultValues;
|
|
60
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
61
|
+
}, [defaultValues, getValues, resetField, setValue]);
|
|
59
62
|
return null;
|
|
60
63
|
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from 'react';
|
|
2
3
|
import { FormProvider, useForm } from 'react-hook-form';
|
|
3
4
|
import { useWidgetConfig } from '../WidgetProvider';
|
|
5
|
+
import { FormUpdater } from './FormUpdater';
|
|
4
6
|
import { SwapFormKey } from './types';
|
|
5
7
|
import { URLSearchParamsBuilder } from './URLSearchParamsBuilder';
|
|
6
8
|
export const formDefaultValues = {
|
|
@@ -10,13 +12,16 @@ export const formDefaultValues = {
|
|
|
10
12
|
};
|
|
11
13
|
export const SwapFormProvider = ({ children, }) => {
|
|
12
14
|
const { fromChain, fromToken, fromAmount, toChain, toToken, toAddress, buildSwapUrl, } = useWidgetConfig();
|
|
15
|
+
const defaultValues = useMemo(() => (Object.assign(Object.assign({}, formDefaultValues), { fromChain,
|
|
16
|
+
fromToken, fromAmount: (typeof fromAmount === 'number'
|
|
17
|
+
? fromAmount === null || fromAmount === void 0 ? void 0 : fromAmount.toPrecision()
|
|
18
|
+
: fromAmount) || formDefaultValues.fromAmount, toChain,
|
|
19
|
+
toToken,
|
|
20
|
+
toAddress })), [fromAmount, fromChain, fromToken, toAddress, toChain, toToken]);
|
|
13
21
|
const methods = useForm({
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
: fromAmount) || formDefaultValues.fromAmount, toChain,
|
|
18
|
-
toToken,
|
|
19
|
-
toAddress }),
|
|
22
|
+
// TODO: revisit after RHF release values support
|
|
23
|
+
// values,
|
|
24
|
+
defaultValues,
|
|
20
25
|
});
|
|
21
|
-
return (_jsxs(FormProvider, Object.assign({}, methods, { children: [buildSwapUrl ? _jsx(URLSearchParamsBuilder, {}) : null, children] })));
|
|
26
|
+
return (_jsxs(FormProvider, Object.assign({}, methods, { children: [_jsx(FormUpdater, { defaultValues: defaultValues }), buildSwapUrl ? _jsx(URLSearchParamsBuilder, {}) : null, children] })));
|
|
22
27
|
};
|
|
@@ -7,7 +7,7 @@ export declare enum SwapFormKey {
|
|
|
7
7
|
ToToken = "toToken",
|
|
8
8
|
TokenSearchFilter = "tokenSearchFilter"
|
|
9
9
|
}
|
|
10
|
-
export
|
|
10
|
+
export type SwapFormValues = {
|
|
11
11
|
[SwapFormKey.FromAmount]: string;
|
|
12
12
|
[SwapFormKey.FromChain]: number;
|
|
13
13
|
[SwapFormKey.FromToken]: string;
|
|
@@ -16,7 +16,7 @@ export declare type SwapFormValues = {
|
|
|
16
16
|
[SwapFormKey.ToToken]: string;
|
|
17
17
|
[SwapFormKey.TokenSearchFilter]: string;
|
|
18
18
|
};
|
|
19
|
-
export
|
|
19
|
+
export type SwapFormType = 'from' | 'to';
|
|
20
20
|
export declare const SwapFormKeyHelper: {
|
|
21
21
|
getChainKey: (formType: SwapFormType) => 'fromChain' | 'toChain';
|
|
22
22
|
getTokenKey: (formType: SwapFormType) => 'fromToken' | 'toToken';
|
|
@@ -7,11 +7,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { jsx as _jsx
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
11
|
import { addChain as walletAddChain, switchChain as walletSwitchChain, switchChainAndAddToken, useLiFiWalletManagement, } from '@lifi/wallet-management';
|
|
12
12
|
import { createContext, useCallback, useContext, useEffect, useMemo, useState, } from 'react';
|
|
13
13
|
import { useWidgetConfig } from '../WidgetProvider';
|
|
14
|
-
import { WalletFormUpdate } from './WalletFormUpdate';
|
|
15
14
|
const stub = () => {
|
|
16
15
|
throw new Error('You forgot to wrap your component in <WalletProvider>.');
|
|
17
16
|
};
|
|
@@ -91,7 +90,7 @@ export const WalletProvider = ({ children }) => {
|
|
|
91
90
|
account,
|
|
92
91
|
provider,
|
|
93
92
|
}), [account, addChain, addToken, connect, disconnect, provider, switchChain]);
|
|
94
|
-
return (
|
|
93
|
+
return (_jsx(WalletContext.Provider, Object.assign({ value: value }, { children: children })));
|
|
95
94
|
};
|
|
96
95
|
export const extractAccountFromSigner = (signer) => __awaiter(void 0, void 0, void 0, function* () {
|
|
97
96
|
try {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Signer } from '@ethersproject/abstract-signer';
|
|
2
|
+
import type { Provider } from '@ethersproject/providers';
|
|
2
3
|
import type { Token } from '@lifi/sdk';
|
|
3
4
|
import type { Wallet } from '@lifi/wallet-management';
|
|
4
|
-
import type { Signer } from 'ethers';
|
|
5
5
|
export interface WalletContextProps {
|
|
6
6
|
account: WalletAccount;
|
|
7
|
-
provider?:
|
|
7
|
+
provider?: Provider;
|
|
8
8
|
addChain(chainId: number): Promise<boolean>;
|
|
9
9
|
addToken(chainId: number, token: Token): Promise<void>;
|
|
10
10
|
disconnect(): void;
|
|
@@ -11,7 +11,8 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
13
|
import { getChainByKey } from '@lifi/sdk';
|
|
14
|
-
import { createContext, useContext, useMemo } from 'react';
|
|
14
|
+
import { createContext, useContext, useEffect, useMemo } from 'react';
|
|
15
|
+
import { setDefaultSettings } from '../../stores';
|
|
15
16
|
import { formatAmount } from '../../utils';
|
|
16
17
|
const initialContext = {
|
|
17
18
|
disabledChains: [],
|
|
@@ -55,5 +56,8 @@ export const WidgetProvider = (_a) => {
|
|
|
55
56
|
return config;
|
|
56
57
|
}
|
|
57
58
|
}, [config, fromAmount, fromChain, fromToken, toChain, toToken]);
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
setDefaultSettings(value);
|
|
61
|
+
}, [value]);
|
|
58
62
|
return (_jsx(WidgetContext.Provider, Object.assign({ value: value }, { children: children })));
|
|
59
63
|
};
|
package/stores/routes/types.d.ts
CHANGED
|
@@ -7,7 +7,14 @@ export interface RouteExecutionStore {
|
|
|
7
7
|
deleteRoute: (routeId: string) => void;
|
|
8
8
|
deleteRoutes: (type: 'completed' | 'active') => void;
|
|
9
9
|
}
|
|
10
|
-
export declare
|
|
10
|
+
export declare enum RouteExecutionStatus {
|
|
11
|
+
Idle = 0,
|
|
12
|
+
Pending = 1,
|
|
13
|
+
Done = 2,
|
|
14
|
+
Failed = 4,
|
|
15
|
+
Partial = 8,
|
|
16
|
+
Refunded = 16
|
|
17
|
+
}
|
|
11
18
|
export interface RouteExecution {
|
|
12
19
|
route: Route;
|
|
13
20
|
status: RouteExecutionStatus;
|
package/stores/routes/types.js
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
-
export
|
|
1
|
+
export var RouteExecutionStatus;
|
|
2
|
+
(function (RouteExecutionStatus) {
|
|
3
|
+
RouteExecutionStatus[RouteExecutionStatus["Idle"] = 0] = "Idle";
|
|
4
|
+
RouteExecutionStatus[RouteExecutionStatus["Pending"] = 1] = "Pending";
|
|
5
|
+
RouteExecutionStatus[RouteExecutionStatus["Done"] = 2] = "Done";
|
|
6
|
+
RouteExecutionStatus[RouteExecutionStatus["Failed"] = 4] = "Failed";
|
|
7
|
+
RouteExecutionStatus[RouteExecutionStatus["Partial"] = 8] = "Partial";
|
|
8
|
+
RouteExecutionStatus[RouteExecutionStatus["Refunded"] = 16] = "Refunded";
|
|
9
|
+
})(RouteExecutionStatus || (RouteExecutionStatus = {}));
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import shallow from 'zustand/shallow';
|
|
2
|
+
import { RouteExecutionStatus } from './types';
|
|
2
3
|
import { useRouteExecutionStore } from './useRouteExecutionStore';
|
|
3
4
|
export const useExecutingRoutesIds = (address) => {
|
|
4
5
|
return useRouteExecutionStore((state) => Object.values(state.routes)
|
|
5
6
|
.filter((item) => item.route.fromAddress === address &&
|
|
6
|
-
(item.status ===
|
|
7
|
+
(item.status === RouteExecutionStatus.Pending ||
|
|
8
|
+
item.status === RouteExecutionStatus.Failed))
|
|
7
9
|
.sort((a, b) => {
|
|
8
10
|
var _a, _b, _c, _d;
|
|
9
11
|
return ((_b = (_a = b === null || b === void 0 ? void 0 : b.route.steps[0].execution) === null || _a === void 0 ? void 0 : _a.process[0].startedAt) !== null && _b !== void 0 ? _b : 0) -
|