@lifi/widget 1.18.9 → 1.19.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/App.js +3 -3
- package/cjs/App.js +3 -3
- package/cjs/components/ActiveSwaps/ActiveSwaps.js +1 -1
- package/cjs/components/ActiveSwaps/ActiveSwaps.style.d.ts +0 -14
- package/cjs/components/ActiveSwaps/ActiveSwaps.style.js +1 -9
- package/cjs/components/AppContainer.d.ts +11 -1
- package/cjs/components/AppContainer.js +3 -6
- package/cjs/components/BottomSheet/BottomSheet.js +9 -32
- package/cjs/components/BottomSheet/types.d.ts +2 -2
- package/cjs/components/Card/Card.js +1 -1
- package/cjs/components/Card/CardHeader.d.ts +1 -1
- package/cjs/components/ChainSelect/ChainSelect.js +1 -1
- package/cjs/components/ChainSelect/useChainSelect.js +2 -4
- package/cjs/components/Dialog.d.ts +22 -1
- package/cjs/components/Dialog.js +23 -20
- package/cjs/components/GasSufficiencyMessage/GasSufficiencyMessage.js +19 -22
- package/cjs/components/Header/NavigationHeader.js +1 -1
- package/cjs/components/Header/WalletHeader.js +2 -2
- package/cjs/components/PoweredBy/PoweredBy.js +1 -1
- package/cjs/components/ProgressToNextUpdate/ProgressToNextUpdate.js +1 -1
- package/cjs/components/ReverseTokensButton/ReverseTokensButton.js +6 -6
- package/cjs/components/SelectTokenButton/SelectTokenButton.style.d.ts +1 -1
- package/cjs/components/SendToWallet/SendToWallet.d.ts +1 -0
- package/cjs/components/SendToWallet/SendToWallet.js +10 -5
- package/cjs/components/SendToWallet/SendToWalletButton.js +2 -2
- package/cjs/components/Step/StepProcess.js +1 -1
- package/cjs/components/SwapButton/SwapButton.js +4 -4
- package/cjs/components/SwapButton/types.d.ts +2 -0
- package/cjs/components/SwapInput/SwapInput.js +6 -2
- package/cjs/components/SwapInput/SwapInputAdornment.js +4 -2
- package/cjs/components/SwapInput/SwapInputAdornment.style.js +1 -13
- package/cjs/components/SwapRouteCard/SwapRouteCard.js +7 -6
- package/cjs/components/SwapRoutes/SwapRoutes.js +4 -4
- package/cjs/components/SwapRoutes/SwapRoutesExpanded.d.ts +1 -0
- package/cjs/components/SwapRoutes/SwapRoutesExpanded.js +17 -12
- package/cjs/components/SwapRoutes/useSetRecommendedRoute.d.ts +2 -0
- package/cjs/components/SwapRoutes/useSetRecommendedRoute.js +13 -0
- package/cjs/components/TokenList/TokenList.js +9 -6
- package/cjs/config/theme.js +22 -8
- package/cjs/config/version.d.ts +1 -1
- package/cjs/config/version.js +1 -1
- package/cjs/hooks/index.d.ts +1 -0
- package/cjs/hooks/index.js +1 -0
- package/cjs/hooks/useExpandableVariant.d.ts +1 -0
- package/cjs/hooks/useExpandableVariant.js +14 -0
- package/cjs/hooks/useGasSufficiency.d.ts +3 -2
- package/cjs/hooks/useGasSufficiency.js +50 -26
- package/cjs/hooks/useSwapRoutes.js +4 -2
- package/cjs/hooks/useTokenBalance.js +2 -2
- package/cjs/i18n/en/translation.json +8 -7
- package/cjs/i18n/index.d.ts +6 -5
- package/cjs/pages/ActiveSwapsPage/ActiveSwapsPage.js +21 -4
- package/cjs/pages/MainPage/MainPage.js +3 -3
- package/cjs/pages/SelectWalletPage/SelectWalletPage.js +1 -1
- package/cjs/pages/SwapDetailsPage/SwapDetailsPage.js +2 -2
- package/cjs/pages/SwapHistoryPage/SwapHistoryPage.js +2 -2
- package/cjs/pages/SwapPage/StatusBottomSheet.js +4 -4
- package/cjs/pages/SwapPage/SwapPage.js +4 -4
- package/cjs/providers/SwapFormProvider/SwapFormProvider.js +3 -2
- package/cjs/providers/SwapFormProvider/URLSearchParamsBuilder.d.ts +1 -0
- package/cjs/providers/SwapFormProvider/URLSearchParamsBuilder.js +46 -0
- package/cjs/providers/SwapFormProvider/types.d.ts +4 -4
- package/cjs/providers/SwapFormProvider/types.js +2 -2
- package/cjs/providers/WalletProvider/WalletFormUpdate.d.ts +5 -0
- package/cjs/providers/WalletProvider/WalletFormUpdate.js +64 -0
- package/cjs/providers/WalletProvider/WalletProvider.js +3 -58
- package/cjs/providers/WidgetProvider/WidgetProvider.js +12 -5
- package/cjs/stores/routes/index.d.ts +1 -1
- package/cjs/stores/routes/index.js +1 -1
- package/cjs/stores/routes/types.d.ts +4 -4
- package/cjs/stores/routes/useRecommendedRouteStore.d.ts +4 -0
- package/cjs/stores/routes/{useSelectedRouteStore.js → useRecommendedRouteStore.js} +4 -4
- package/cjs/stores/routes/useRouteExecutionStore.js +9 -2
- package/cjs/types/widget.d.ts +1 -0
- package/components/ActiveSwaps/ActiveSwaps.js +3 -3
- package/components/ActiveSwaps/ActiveSwaps.style.d.ts +0 -14
- package/components/ActiveSwaps/ActiveSwaps.style.js +1 -9
- package/components/AppContainer.d.ts +11 -1
- package/components/AppContainer.js +2 -4
- package/components/BottomSheet/BottomSheet.js +9 -32
- package/components/BottomSheet/types.d.ts +2 -2
- package/components/Card/Card.js +1 -1
- package/components/Card/CardHeader.d.ts +1 -1
- package/components/ChainSelect/ChainSelect.js +1 -1
- package/components/ChainSelect/useChainSelect.js +2 -4
- package/components/Dialog.d.ts +22 -1
- package/components/Dialog.js +22 -19
- package/components/GasSufficiencyMessage/GasSufficiencyMessage.js +21 -24
- package/components/Header/NavigationHeader.js +2 -2
- package/components/Header/WalletHeader.js +2 -2
- package/components/PoweredBy/PoweredBy.js +1 -1
- package/components/ProgressToNextUpdate/ProgressToNextUpdate.js +1 -1
- package/components/ReverseTokensButton/ReverseTokensButton.js +6 -6
- package/components/SelectTokenButton/SelectTokenButton.style.d.ts +1 -1
- package/components/SendToWallet/SendToWallet.d.ts +1 -0
- package/components/SendToWallet/SendToWallet.js +9 -5
- package/components/SendToWallet/SendToWalletButton.js +2 -2
- package/components/Step/StepProcess.js +1 -1
- package/components/SwapButton/SwapButton.js +4 -4
- package/components/SwapButton/types.d.ts +2 -0
- package/components/SwapInput/SwapInput.js +6 -2
- package/components/SwapInput/SwapInputAdornment.js +4 -2
- package/components/SwapInput/SwapInputAdornment.style.js +2 -14
- package/components/SwapRouteCard/SwapRouteCard.js +8 -7
- package/components/SwapRoutes/SwapRoutes.js +4 -4
- package/components/SwapRoutes/SwapRoutesExpanded.d.ts +1 -0
- package/components/SwapRoutes/SwapRoutesExpanded.js +16 -12
- package/components/SwapRoutes/useSetRecommendedRoute.d.ts +2 -0
- package/components/SwapRoutes/useSetRecommendedRoute.js +9 -0
- package/components/TokenList/TokenList.js +9 -6
- package/config/theme.js +22 -8
- package/config/version.d.ts +1 -1
- package/config/version.js +1 -1
- package/hooks/index.d.ts +1 -0
- package/hooks/index.js +1 -0
- package/hooks/useExpandableVariant.d.ts +1 -0
- package/hooks/useExpandableVariant.js +10 -0
- package/hooks/useGasSufficiency.d.ts +3 -2
- package/hooks/useGasSufficiency.js +50 -26
- package/hooks/useSwapRoutes.js +4 -2
- package/hooks/useTokenBalance.js +2 -2
- package/i18n/en/translation.json +8 -7
- package/i18n/index.d.ts +6 -5
- package/package.json +11 -11
- package/pages/ActiveSwapsPage/ActiveSwapsPage.js +24 -7
- package/pages/MainPage/MainPage.js +3 -3
- package/pages/SelectWalletPage/SelectWalletPage.js +1 -1
- package/pages/SwapDetailsPage/SwapDetailsPage.js +2 -2
- package/pages/SwapHistoryPage/SwapHistoryPage.js +2 -2
- package/pages/SwapPage/StatusBottomSheet.js +4 -4
- package/pages/SwapPage/SwapPage.js +5 -5
- package/providers/SwapFormProvider/SwapFormProvider.js +4 -3
- package/providers/SwapFormProvider/URLSearchParamsBuilder.d.ts +1 -0
- package/providers/SwapFormProvider/URLSearchParamsBuilder.js +42 -0
- package/providers/SwapFormProvider/types.d.ts +4 -4
- package/providers/SwapFormProvider/types.js +2 -2
- package/providers/WalletProvider/WalletFormUpdate.d.ts +5 -0
- package/providers/WalletProvider/WalletFormUpdate.js +60 -0
- package/providers/WalletProvider/WalletProvider.js +5 -60
- package/providers/WidgetProvider/WidgetProvider.js +12 -5
- package/stores/routes/index.d.ts +1 -1
- package/stores/routes/index.js +1 -1
- package/stores/routes/types.d.ts +4 -4
- package/stores/routes/useRecommendedRouteStore.d.ts +4 -0
- package/stores/routes/useRecommendedRouteStore.js +9 -0
- package/stores/routes/useRouteExecutionStore.js +9 -2
- package/tsconfig.cjs.tsbuildinfo +1 -1
- package/types/widget.d.ts +1 -0
- package/cjs/components/SwapRoutes/useSetSelectedRoute.d.ts +0 -2
- package/cjs/components/SwapRoutes/useSetSelectedRoute.js +0 -13
- package/cjs/stores/routes/useSelectedRouteStore.d.ts +0 -4
- package/components/SwapRoutes/useSetSelectedRoute.d.ts +0 -2
- package/components/SwapRoutes/useSetSelectedRoute.js +0 -9
- package/stores/routes/useSelectedRouteStore.d.ts +0 -4
- package/stores/routes/useSelectedRouteStore.js +0 -9
|
@@ -30,11 +30,15 @@ const SwapInput = ({ formType }) => {
|
|
|
30
30
|
const isSelected = !!(chain && token);
|
|
31
31
|
const handleChange = (event) => {
|
|
32
32
|
const { value } = event.target;
|
|
33
|
-
|
|
33
|
+
const formattedAmount = (0, utils_1.formatAmount)(value, true);
|
|
34
|
+
setValue(amountKey, formattedAmount, {
|
|
35
|
+
shouldTouch: true,
|
|
36
|
+
});
|
|
34
37
|
};
|
|
35
38
|
const handleBlur = (event) => {
|
|
36
39
|
const { value } = event.target;
|
|
37
|
-
|
|
40
|
+
const formattedAmount = (0, utils_1.formatAmount)(value);
|
|
41
|
+
setValue(amountKey, formattedAmount);
|
|
38
42
|
};
|
|
39
43
|
(0, react_1.useLayoutEffect)(() => {
|
|
40
44
|
(0, utils_1.fitInputText)(SwapInput_style_1.maxInputFontSize, SwapInput_style_1.minInputFontSize, ref.current);
|
|
@@ -20,8 +20,10 @@ const SwapInputAdornment = ({ formType }) => {
|
|
|
20
20
|
const { token, isLoading } = (0, hooks_1.useTokenAddressBalance)(chainId, tokenAddress);
|
|
21
21
|
const handleMax = () => {
|
|
22
22
|
var _a;
|
|
23
|
-
setValue(providers_1.SwapFormKeyHelper.getAmountKey(formType), (_a = token === null || token === void 0 ? void 0 : token.amount) !== null && _a !== void 0 ? _a : ''
|
|
23
|
+
setValue(providers_1.SwapFormKeyHelper.getAmountKey(formType), (_a = token === null || token === void 0 ? void 0 : token.amount) !== null && _a !== void 0 ? _a : '', {
|
|
24
|
+
shouldTouch: true,
|
|
25
|
+
});
|
|
24
26
|
};
|
|
25
|
-
return ((0, jsx_runtime_1.jsx)(material_1.InputAdornment, Object.assign({ position: "end" }, { children: isLoading && tokenAddress ? ((0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "rectangular", width: 46, height: 20, sx: { borderRadius: 0.5 } })) : formType === 'from' && (token === null || token === void 0 ? void 0 : token.amount) ? ((0, jsx_runtime_1.jsx)(SwapInputAdornment_style_1.Button, Object.assign({ onClick: handleMax
|
|
27
|
+
return ((0, jsx_runtime_1.jsx)(material_1.InputAdornment, Object.assign({ position: "end" }, { children: isLoading && tokenAddress ? ((0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "rectangular", width: 46, height: 20, sx: { borderRadius: 0.5 } })) : formType === 'from' && (token === null || token === void 0 ? void 0 : token.amount) ? ((0, jsx_runtime_1.jsx)(SwapInputAdornment_style_1.Button, Object.assign({ onClick: handleMax }, { children: t('button.max') }))) : null })));
|
|
26
28
|
};
|
|
27
29
|
exports.SwapInputAdornment = SwapInputAdornment;
|
|
@@ -4,20 +4,8 @@ exports.Button = void 0;
|
|
|
4
4
|
const material_1 = require("@mui/material");
|
|
5
5
|
const styles_1 = require("@mui/material/styles");
|
|
6
6
|
exports.Button = (0, styles_1.styled)(material_1.Button)(({ theme }) => ({
|
|
7
|
-
|
|
8
|
-
? theme.palette.grey[300]
|
|
9
|
-
: theme.palette.grey[800],
|
|
10
|
-
color: theme.palette.text.secondary,
|
|
11
|
-
padding: theme.spacing(0.125, 1, 0.375, 1),
|
|
7
|
+
padding: theme.spacing(0.5, 1, 0.625, 1),
|
|
12
8
|
lineHeight: 1,
|
|
13
9
|
fontSize: '0.875rem',
|
|
14
10
|
minWidth: 'unset',
|
|
15
|
-
'&:hover': {
|
|
16
|
-
color: theme.palette.mode === 'light'
|
|
17
|
-
? theme.palette.primary.main
|
|
18
|
-
: theme.palette.text.primary,
|
|
19
|
-
borderColor: theme.palette.mode === 'light'
|
|
20
|
-
? (0, styles_1.lighten)(theme.palette.primary.main, 0.5)
|
|
21
|
-
: theme.palette.text.secondary,
|
|
22
|
-
},
|
|
23
11
|
}));
|
|
@@ -34,17 +34,18 @@ const SwapRouteCard = (_a) => {
|
|
|
34
34
|
e.stopPropagation();
|
|
35
35
|
setCardExpanded((expanded) => !expanded);
|
|
36
36
|
};
|
|
37
|
-
return ((0, jsx_runtime_1.jsxs)(Card_1.Card, Object.assign({ dense: variant === 'dense', variant: active ? 'selected' : 'default', selectionColor: "secondary", indented: true }, other, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", justifyContent: "space-between", alignItems: "center", mb: 2 }, { children: [(0, jsx_runtime_1.jsx)(SwapRouteCard_style_1.Label, Object.assign({ active: active !== null && active !== void 0 ? active : label !== alternativeTag }, { children: label })), variant === 'stretched' ? ((0, jsx_runtime_1.jsx)(exports.SwapRouteCardEssentials, { route: route })) : null] })), (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", justifyContent: "space-between", alignItems: "center" }, { children: [(0, jsx_runtime_1.jsx)(Token_1.Token, { token: Object.assign(Object.assign({}, route.toToken), { amount: route.toAmount }), step: variant === 'stretched' ? route.steps[0] : undefined }), variant === 'stretched' && !expanded ? ((0, jsx_runtime_1.jsx)(SwapRouteCard_style_1.IconButton, Object.assign({ onClick: handleExpand, size: "small" }, { children: cardExpanded ? (0, jsx_runtime_1.jsx)(icons_material_1.ExpandLess, {}) : (0, jsx_runtime_1.jsx)(icons_material_1.ExpandMore, {}) }))) : null] })), (0, jsx_runtime_1.jsx)(material_1.Collapse, Object.assign({
|
|
37
|
+
return ((0, jsx_runtime_1.jsxs)(Card_1.Card, Object.assign({ dense: variant === 'dense', variant: active ? 'selected' : 'default', selectionColor: "secondary", indented: true }, other, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", justifyContent: "space-between", alignItems: "center", mb: 2 }, { children: [(0, jsx_runtime_1.jsx)(SwapRouteCard_style_1.Label, Object.assign({ active: active !== null && active !== void 0 ? active : label !== alternativeTag }, { children: label })), variant === 'stretched' ? ((0, jsx_runtime_1.jsx)(exports.SwapRouteCardEssentials, { route: route })) : null] })), (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", justifyContent: "space-between", alignItems: "center" }, { children: [(0, jsx_runtime_1.jsx)(Token_1.Token, { token: Object.assign(Object.assign({}, route.toToken), { amount: route.toAmount }), step: variant === 'stretched' ? route.steps[0] : undefined }), variant === 'stretched' && !expanded ? ((0, jsx_runtime_1.jsx)(SwapRouteCard_style_1.IconButton, Object.assign({ onClick: handleExpand, size: "small" }, { children: cardExpanded ? (0, jsx_runtime_1.jsx)(icons_material_1.ExpandLess, {}) : (0, jsx_runtime_1.jsx)(icons_material_1.ExpandMore, {}) }))) : null] })), (0, jsx_runtime_1.jsx)(material_1.Collapse, Object.assign({ timeout: 225, in: cardExpanded, mountOnEnter: true, unmountOnExit: true }, { children: route.steps.map((step) => ((0, jsx_runtime_1.jsx)(StepActions_1.StepActions, { step: step, mt: 2 }, step.id))) })), variant !== 'stretched' ? ((0, jsx_runtime_1.jsx)(exports.SwapRouteCardEssentials, { route: route, dense: true })) : null] })));
|
|
38
38
|
};
|
|
39
39
|
exports.SwapRouteCard = SwapRouteCard;
|
|
40
40
|
const SwapRouteCardEssentials = ({ route, dense }) => {
|
|
41
41
|
var _a;
|
|
42
42
|
const { t } = (0, react_i18next_1.useTranslation)();
|
|
43
|
-
const
|
|
43
|
+
const executionTimeMinutes = Math.ceil(route.steps
|
|
44
44
|
.map((step) => step.estimate.executionDuration)
|
|
45
|
-
.reduce((duration, x) => duration + x) / 60)
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
.reduce((duration, x) => duration + x, 0) / 60);
|
|
46
|
+
const gasCostUSD = parseFloat((_a = route.gasCostUSD) !== null && _a !== void 0 ? _a : '') || 0.01;
|
|
47
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", justifyContent: dense ? 'space-between' : 'flex-end', flex: 1, pl: dense ? 0 : 2, mt: dense ? 2 : 0 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Tooltip, Object.assign({ title: t(`tooltip.estimatedNetworkFee`), placement: "top", enterDelay: 400, enterNextDelay: 400, arrow: true }, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", alignItems: "center", mr: dense ? 0 : 2 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ lineHeight: 0, mr: 0.5, color: "grey.500" }, { children: (0, jsx_runtime_1.jsx)(icons_material_1.EvStationOutlined, { fontSize: dense ? 'medium' : 'small' }) })), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ fontSize: 14, color: "text.primary", fontWeight: "500", lineHeight: 1 }, { children: t(`swap.currency`, { value: gasCostUSD }) }))] })) })), (0, jsx_runtime_1.jsx)(material_1.Tooltip, Object.assign({ title: t(`tooltip.estimatedTime`), placement: "top", enterDelay: 400, enterNextDelay: 400, arrow: true }, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", alignItems: "center", mr: dense ? 0 : 2 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ lineHeight: 0, mr: 0.5, color: "grey.500" }, { children: (0, jsx_runtime_1.jsx)(icons_material_1.AccessTime, { fontSize: dense ? 'medium' : 'small' }) })), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ fontSize: 14, color: "text.primary", fontWeight: "500", lineHeight: 1 }, { children: t('swap.estimatedTime', {
|
|
48
|
+
value: executionTimeMinutes,
|
|
49
|
+
}) }))] })) })), !dense ? ((0, jsx_runtime_1.jsx)(material_1.Tooltip, Object.assign({ title: t(`tooltip.numberOfSteps`), placement: "top", enterDelay: 400, enterNextDelay: 400, arrow: true }, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", alignItems: "center" }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ lineHeight: 0, mr: 0.5, color: "grey.500" }, { children: (0, jsx_runtime_1.jsx)(icons_material_1.LayersOutlined, { fontSize: dense ? 'medium' : 'small' }) })), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ fontSize: 14, color: "text.primary", fontWeight: "500", lineHeight: 1 }, { children: route.steps.length }))] })) }))) : null] })));
|
|
49
50
|
};
|
|
50
51
|
exports.SwapRouteCardEssentials = SwapRouteCardEssentials;
|
|
@@ -13,14 +13,14 @@ const SwapRouteCard_1 = require("../../components/SwapRouteCard");
|
|
|
13
13
|
const hooks_1 = require("../../hooks");
|
|
14
14
|
const utils_1 = require("../../utils");
|
|
15
15
|
const SwapRoutes_style_1 = require("./SwapRoutes.style");
|
|
16
|
-
const
|
|
16
|
+
const useSetRecommendedRoute_1 = require("./useSetRecommendedRoute");
|
|
17
17
|
const SwapRoutes = (props) => {
|
|
18
18
|
const { t } = (0, react_i18next_1.useTranslation)();
|
|
19
19
|
const navigate = (0, react_router_dom_1.useNavigate)();
|
|
20
20
|
const { isValid, isValidating } = (0, react_hook_form_1.useFormState)();
|
|
21
21
|
const { routes, isLoading, isFetching, isFetched, dataUpdatedAt, refetchTime, refetch, } = (0, hooks_1.useSwapRoutes)();
|
|
22
22
|
const currentRoute = routes === null || routes === void 0 ? void 0 : routes[0];
|
|
23
|
-
(0,
|
|
23
|
+
(0, useSetRecommendedRoute_1.useSetRecommendedRoute)(currentRoute, isFetching);
|
|
24
24
|
if (!currentRoute && !isLoading && !isFetching && !isFetched) {
|
|
25
25
|
return null;
|
|
26
26
|
}
|
|
@@ -33,9 +33,9 @@ const SwapRoutes = (props) => {
|
|
|
33
33
|
top: 8,
|
|
34
34
|
right: 8,
|
|
35
35
|
} }), (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ sx: { display: 'flex' } }, { children: [(0, jsx_runtime_1.jsx)(SwapRoutes_style_1.Stack, Object.assign({ direction: "row", spacing: 2, my: 2, ml: 2, mr: routeNotFound ? 2 : 1, sx: {
|
|
36
|
-
|
|
36
|
+
borderRightWidth: !routeNotFound && (isFetching || (routes && routes.length > 1))
|
|
37
37
|
? 1
|
|
38
38
|
: 0,
|
|
39
|
-
} }, { children: isLoading || isFetching ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteCardSkeleton, { minWidth: "80%", variant: "dense" }), (0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteCardSkeleton, { minWidth: "80%", variant: "dense" })] })) : !currentRoute ? ((0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteNotFoundCard, {})) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteCard, { minWidth: routes.length > 1 ? '80%' : '100%', route: currentRoute, variant: "dense", active: true }), routes.length > 1 ? ((0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteCard, { minWidth: "80%", route: routes[1], variant: "dense" })) : null] })) })), (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ sx: { display: 'flex', alignItems: 'center' } }, { children: !routeNotFound ? ((0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ py: 1, pr: 1 }, { children: (0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ onClick: handleCardClick, size: "medium",
|
|
39
|
+
} }, { children: isLoading || isFetching ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteCardSkeleton, { minWidth: "80%", variant: "dense" }), (0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteCardSkeleton, { minWidth: "80%", variant: "dense" })] })) : !currentRoute ? ((0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteNotFoundCard, {})) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteCard, { minWidth: routes.length > 1 ? '80%' : '100%', route: currentRoute, variant: "dense", active: true }), routes.length > 1 ? ((0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteCard, { minWidth: "80%", route: routes[1], variant: "dense" })) : null] })) })), (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ sx: { display: 'flex', alignItems: 'center' } }, { children: !routeNotFound ? ((0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ py: 1, pr: 1 }, { children: (0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ onClick: handleCardClick, size: "medium", disabled: isValidating || !isValid }, { children: (0, jsx_runtime_1.jsx)(icons_material_1.KeyboardArrowRight, {}) })) }))) : null }))] }))] })));
|
|
40
40
|
};
|
|
41
41
|
exports.SwapRoutes = SwapRoutes;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SwapRoutesExpanded = void 0;
|
|
3
|
+
exports.SwapRoutesExpandedElement = exports.SwapRoutesExpanded = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const material_1 = require("@mui/material");
|
|
6
6
|
const react_hook_form_1 = require("react-hook-form");
|
|
@@ -13,8 +13,19 @@ const utils_1 = require("../../utils");
|
|
|
13
13
|
const ProgressToNextUpdate_1 = require("../ProgressToNextUpdate");
|
|
14
14
|
const SwapRouteCard_1 = require("../SwapRouteCard");
|
|
15
15
|
const SwapRoutes_style_1 = require("./SwapRoutes.style");
|
|
16
|
-
const
|
|
16
|
+
const useSetRecommendedRoute_1 = require("./useSetRecommendedRoute");
|
|
17
|
+
const timeout = { enter: 225, exit: 225, appear: 0 };
|
|
17
18
|
const SwapRoutesExpanded = () => {
|
|
19
|
+
const element = (0, react_router_dom_1.useRoutes)([
|
|
20
|
+
{
|
|
21
|
+
path: '/',
|
|
22
|
+
element: null,
|
|
23
|
+
},
|
|
24
|
+
]);
|
|
25
|
+
return ((0, jsx_runtime_1.jsx)(SwapRoutes_style_1.CollapseContainer, { children: (0, jsx_runtime_1.jsx)(material_1.Collapse, Object.assign({ timeout: timeout, in: !!element, orientation: "horizontal" }, { children: (0, jsx_runtime_1.jsx)(material_1.Grow, Object.assign({ timeout: timeout, in: !!element, mountOnEnter: true, unmountOnExit: true }, { children: (0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(exports.SwapRoutesExpandedElement, {}) }) })) })) }));
|
|
26
|
+
};
|
|
27
|
+
exports.SwapRoutesExpanded = SwapRoutesExpanded;
|
|
28
|
+
const SwapRoutesExpandedElement = () => {
|
|
18
29
|
const { t } = (0, react_i18next_1.useTranslation)();
|
|
19
30
|
const navigate = (0, react_router_dom_1.useNavigate)();
|
|
20
31
|
const setExecutableRoute = (0, stores_1.useSetExecutableRoute)();
|
|
@@ -22,13 +33,7 @@ const SwapRoutesExpanded = () => {
|
|
|
22
33
|
const { isValid, isValidating } = (0, react_hook_form_1.useFormState)();
|
|
23
34
|
const { routes, isLoading, isFetching, isFetched, dataUpdatedAt, refetchTime, refetch, } = (0, hooks_1.useSwapRoutes)();
|
|
24
35
|
const currentRoute = routes === null || routes === void 0 ? void 0 : routes[0];
|
|
25
|
-
(0,
|
|
26
|
-
const { pathname } = (0, react_router_dom_1.useLocation)();
|
|
27
|
-
const cleanedPathname = pathname.endsWith('/')
|
|
28
|
-
? pathname.slice(0, -1)
|
|
29
|
-
: pathname;
|
|
30
|
-
const path = cleanedPathname.substring(cleanedPathname.lastIndexOf('/') + 1);
|
|
31
|
-
const hasPath = utils_1.navigationRoutesValues.includes(path);
|
|
36
|
+
(0, useSetRecommendedRoute_1.useSetRecommendedRoute)(currentRoute, isFetching);
|
|
32
37
|
const handleRouteClick = (route) => {
|
|
33
38
|
if (isValid && !isValidating) {
|
|
34
39
|
setExecutableRoute(route);
|
|
@@ -37,8 +42,8 @@ const SwapRoutesExpanded = () => {
|
|
|
37
42
|
});
|
|
38
43
|
}
|
|
39
44
|
};
|
|
40
|
-
const expanded = Boolean(currentRoute || isLoading || isFetching || isFetched)
|
|
45
|
+
const expanded = Boolean(currentRoute || isLoading || isFetching || isFetched);
|
|
41
46
|
const routeNotFound = !currentRoute && !isLoading && !isFetching && expanded;
|
|
42
|
-
return ((0, jsx_runtime_1.jsx)(
|
|
47
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Collapse, Object.assign({ timeout: timeout.enter, in: expanded, orientation: "horizontal" }, { children: (0, jsx_runtime_1.jsx)(material_1.Grow, Object.assign({ timeout: timeout.enter, in: expanded, mountOnEnter: true, unmountOnExit: true }, { children: (0, jsx_runtime_1.jsx)(SwapRoutes_style_1.Container, Object.assign({ sx: containerStyle, enableColorScheme: true }, { children: (0, jsx_runtime_1.jsxs)(SwapRoutes_style_1.ScrollableContainer, { children: [(0, jsx_runtime_1.jsxs)(SwapRoutes_style_1.Header, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ fontSize: 18, fontWeight: "700", flex: 1, noWrap: true }, { children: t('swap.routes') })), (0, jsx_runtime_1.jsx)(ProgressToNextUpdate_1.ProgressToNextUpdate, { updatedAt: dataUpdatedAt || new Date().getTime(), timeToUpdate: refetchTime, isLoading: isFetching, onClick: () => refetch(), sx: { marginRight: -1 } })] }), (0, jsx_runtime_1.jsx)(material_1.Stack, Object.assign({ direction: "column", spacing: 2, flex: 1, paddingX: 3, paddingBottom: 3 }, { children: routeNotFound ? ((0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteNotFoundCard, {})) : isLoading || isFetching ? (Array.from({ length: 3 }).map((_, index) => ((0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteCardSkeleton, { variant: "stretched" }, index)))) : (routes === null || routes === void 0 ? void 0 : routes.map((route, index) => ((0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteCard, { route: route, onClick: () => handleRouteClick(route), active: index === 0, variant: "stretched", expanded: (routes === null || routes === void 0 ? void 0 : routes.length) <= 2 }, route.id)))) }))] }) })) })) })));
|
|
43
48
|
};
|
|
44
|
-
exports.
|
|
49
|
+
exports.SwapRoutesExpandedElement = SwapRoutesExpandedElement;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useSetRecommendedRoute = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const stores_1 = require("../../stores");
|
|
6
|
+
const useSetRecommendedRoute = (currentRoute, isFetching) => {
|
|
7
|
+
const setRecommendedRoute = (0, stores_1.useRecommendedRouteStore)((state) => state.setRecommendedRoute);
|
|
8
|
+
(0, react_1.useEffect)(() => {
|
|
9
|
+
setRecommendedRoute(!isFetching ? currentRoute : undefined);
|
|
10
|
+
return () => setRecommendedRoute(undefined);
|
|
11
|
+
}, [currentRoute, isFetching, setRecommendedRoute]);
|
|
12
|
+
};
|
|
13
|
+
exports.useSetRecommendedRoute = useSetRecommendedRoute;
|
|
@@ -39,23 +39,26 @@ const TokenList = ({ formType, height, onClick, }) => {
|
|
|
39
39
|
: filteredTokens;
|
|
40
40
|
const handleTokenClick = (0, react_1.useCallback)((tokenAddress) => {
|
|
41
41
|
setValue(providers_1.SwapFormKeyHelper.getTokenKey(formType), tokenAddress, {
|
|
42
|
-
|
|
42
|
+
shouldTouch: true,
|
|
43
|
+
});
|
|
44
|
+
// Set chain again to trigger URL builder update
|
|
45
|
+
setValue(providers_1.SwapFormKeyHelper.getChainKey(formType), selectedChainId, {
|
|
46
|
+
shouldTouch: true,
|
|
43
47
|
});
|
|
44
48
|
setValue(providers_1.SwapFormKeyHelper.getAmountKey(formType), '');
|
|
45
49
|
const oppositeFormType = formType === 'from' ? 'to' : 'from';
|
|
46
|
-
const [selectedOppositeToken,
|
|
50
|
+
const [selectedOppositeToken, selectedOppositeChainId] = getValues([
|
|
47
51
|
providers_1.SwapFormKeyHelper.getTokenKey(oppositeFormType),
|
|
48
52
|
providers_1.SwapFormKeyHelper.getChainKey(oppositeFormType),
|
|
49
|
-
providers_1.SwapFormKeyHelper.getChainKey(formType),
|
|
50
53
|
]);
|
|
51
54
|
if (selectedOppositeToken === tokenAddress &&
|
|
52
|
-
|
|
55
|
+
selectedOppositeChainId === selectedChainId) {
|
|
53
56
|
setValue(providers_1.SwapFormKeyHelper.getTokenKey(oppositeFormType), '', {
|
|
54
|
-
|
|
57
|
+
shouldTouch: true,
|
|
55
58
|
});
|
|
56
59
|
}
|
|
57
60
|
onClick === null || onClick === void 0 ? void 0 : onClick();
|
|
58
|
-
}, [formType, getValues, onClick, setValue]);
|
|
61
|
+
}, [formType, getValues, onClick, selectedChainId, setValue]);
|
|
59
62
|
return ((0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ ref: parentRef, style: { height, overflow: 'auto' } }, { children: [!tokens.length && !isLoading ? ((0, jsx_runtime_1.jsx)(TokenNotFound_1.TokenNotFound, { formType: formType })) : null, (0, jsx_runtime_1.jsx)(VirtualizedTokenList_1.VirtualizedTokenList, { tokens: tokens, featuredTokensLength: featuredTokens === null || featuredTokens === void 0 ? void 0 : featuredTokens.length, scrollElementRef: parentRef, chainId: selectedChainId, isLoading: isLoading, isBalanceLoading: isBalanceLoading, showBalance: account.isActive, showFeatured: !tokenSearchFilter, onClick: handleTokenClick })] })));
|
|
60
63
|
};
|
|
61
64
|
exports.TokenList = TokenList;
|
package/cjs/config/theme.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createTheme = void 0;
|
|
4
|
+
const LoadingButton_1 = require("@mui/lab/LoadingButton");
|
|
4
5
|
const colors_1 = require("@mui/material/colors");
|
|
5
6
|
const DialogActions_1 = require("@mui/material/DialogActions");
|
|
6
7
|
const styles_1 = require("@mui/material/styles");
|
|
@@ -48,6 +49,9 @@ const createTheme = (mode, theme = {}) => {
|
|
|
48
49
|
const primaryMainColor = (_c = (_b = (_a = theme.palette) === null || _a === void 0 ? void 0 : _a.primary) === null || _b === void 0 ? void 0 : _b.main) !== null && _c !== void 0 ? _c : palette.primary.main;
|
|
49
50
|
const primaryLightColor = (0, styles_1.lighten)((_f = (_e = (_d = theme.palette) === null || _d === void 0 ? void 0 : _d.primary) === null || _e === void 0 ? void 0 : _e.main) !== null && _f !== void 0 ? _f : palette.primary.main, 0.5);
|
|
50
51
|
const primaryDarkColor = (0, styles_1.darken)((_j = (_h = (_g = theme.palette) === null || _g === void 0 ? void 0 : _g.primary) === null || _h === void 0 ? void 0 : _h.main) !== null && _j !== void 0 ? _j : palette.primary.main, 0.2);
|
|
52
|
+
const contrastButtonColor = (0, styles_1.getContrastRatio)(colors_1.common.white, primaryMainColor) >= 3
|
|
53
|
+
? colors_1.common.white
|
|
54
|
+
: colors_1.common.black;
|
|
51
55
|
return (0, styles_1.createTheme)({
|
|
52
56
|
typography: Object.assign({ fontFamily: 'Inter var, Inter, sans-serif' }, theme.typography),
|
|
53
57
|
palette: Object.assign(Object.assign(Object.assign({ mode }, palette), { primary: {
|
|
@@ -83,13 +87,25 @@ const createTheme = (mode, theme = {}) => {
|
|
|
83
87
|
borderRadius: (_v = (_u = theme.shape) === null || _u === void 0 ? void 0 : _u.borderRadiusSecondary) !== null && _v !== void 0 ? _v : shape.borderRadiusSecondary,
|
|
84
88
|
textTransform: 'none',
|
|
85
89
|
fontSize: '1rem',
|
|
86
|
-
|
|
90
|
+
[`&.Mui-disabled, &.Mui-disabled:hover`]: {
|
|
87
91
|
color: mode === 'light'
|
|
88
|
-
? 'rgb(0 0 0 /
|
|
89
|
-
: 'rgb(255 255 255 /
|
|
92
|
+
? 'rgb(0 0 0 / 56%)'
|
|
93
|
+
: 'rgb(255 255 255 / 56%)',
|
|
90
94
|
cursor: 'not-allowed',
|
|
91
95
|
pointerEvents: 'auto',
|
|
92
96
|
},
|
|
97
|
+
[`&.${LoadingButton_1.loadingButtonClasses.loading}.Mui-disabled`]: {
|
|
98
|
+
backgroundColor: primaryMainColor,
|
|
99
|
+
color: contrastButtonColor,
|
|
100
|
+
cursor: 'auto',
|
|
101
|
+
pointerEvents: 'auto',
|
|
102
|
+
},
|
|
103
|
+
[`.${LoadingButton_1.loadingButtonClasses.loadingIndicator}`]: {
|
|
104
|
+
color: contrastButtonColor,
|
|
105
|
+
},
|
|
106
|
+
[`&.${LoadingButton_1.loadingButtonClasses.root}.${LoadingButton_1.loadingButtonClasses.loading}`]: {
|
|
107
|
+
color: 'transparent',
|
|
108
|
+
},
|
|
93
109
|
}, text: {
|
|
94
110
|
backgroundColor: (0, styles_1.alpha)(primaryMainColor, 0.08),
|
|
95
111
|
'&:hover': {
|
|
@@ -97,9 +113,7 @@ const createTheme = (mode, theme = {}) => {
|
|
|
97
113
|
},
|
|
98
114
|
}, contained: {
|
|
99
115
|
'&:hover': {
|
|
100
|
-
color:
|
|
101
|
-
? colors_1.common.white
|
|
102
|
-
: colors_1.common.black,
|
|
116
|
+
color: contrastButtonColor,
|
|
103
117
|
},
|
|
104
118
|
}, sizeMedium: {
|
|
105
119
|
padding: '10px 16px',
|
|
@@ -117,10 +131,10 @@ const createTheme = (mode, theme = {}) => {
|
|
|
117
131
|
},
|
|
118
132
|
},
|
|
119
133
|
text: {
|
|
120
|
-
backgroundColor: paletteDark.background.paper,
|
|
134
|
+
backgroundColor: (0, styles_1.lighten)(paletteDark.background.paper, 0.08),
|
|
121
135
|
color: colors_1.common.white,
|
|
122
136
|
'&:hover': {
|
|
123
|
-
backgroundColor: (0, styles_1.lighten)(paletteDark.background.paper, 0.
|
|
137
|
+
backgroundColor: (0, styles_1.lighten)(paletteDark.background.paper, 0.12),
|
|
124
138
|
},
|
|
125
139
|
},
|
|
126
140
|
}
|
package/cjs/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.19.0";
|
package/cjs/config/version.js
CHANGED
package/cjs/hooks/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './useChain';
|
|
|
2
2
|
export * from './useChains';
|
|
3
3
|
export * from './useContentHeight';
|
|
4
4
|
export * from './useDebouncedWatch';
|
|
5
|
+
export * from './useExpandableVariant';
|
|
5
6
|
export * from './useFeaturedTokens';
|
|
6
7
|
export * from './useGasSufficiency';
|
|
7
8
|
export * from './useInitializer';
|
package/cjs/hooks/index.js
CHANGED
|
@@ -18,6 +18,7 @@ __exportStar(require("./useChain"), exports);
|
|
|
18
18
|
__exportStar(require("./useChains"), exports);
|
|
19
19
|
__exportStar(require("./useContentHeight"), exports);
|
|
20
20
|
__exportStar(require("./useDebouncedWatch"), exports);
|
|
21
|
+
__exportStar(require("./useExpandableVariant"), exports);
|
|
21
22
|
__exportStar(require("./useFeaturedTokens"), exports);
|
|
22
23
|
__exportStar(require("./useGasSufficiency"), exports);
|
|
23
24
|
__exportStar(require("./useInitializer"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useExpandableVariant: () => boolean;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useExpandableVariant = void 0;
|
|
4
|
+
const material_1 = require("@mui/material");
|
|
5
|
+
const providers_1 = require("../providers");
|
|
6
|
+
const defaultExpandableWidth = 852;
|
|
7
|
+
const useExpandableVariant = () => {
|
|
8
|
+
const { variant } = (0, providers_1.useWidgetConfig)();
|
|
9
|
+
const expandableAllowed = (0, material_1.useMediaQuery)((theme) => {
|
|
10
|
+
return theme.breakpoints.up(defaultExpandableWidth);
|
|
11
|
+
});
|
|
12
|
+
return variant === 'expandable' && expandableAllowed;
|
|
13
|
+
};
|
|
14
|
+
exports.useExpandableVariant = useExpandableVariant;
|
|
@@ -9,7 +9,8 @@ interface GasSufficiency {
|
|
|
9
9
|
chain?: EVMChain;
|
|
10
10
|
}
|
|
11
11
|
export declare const useGasSufficiency: (route?: Route) => {
|
|
12
|
-
insufficientGas: GasSufficiency[] | undefined;
|
|
13
|
-
insufficientFunds: boolean;
|
|
12
|
+
insufficientGas: GasSufficiency[] | null | undefined;
|
|
13
|
+
insufficientFunds: boolean | null | undefined;
|
|
14
|
+
isLoading: boolean;
|
|
14
15
|
};
|
|
15
16
|
export {};
|
|
@@ -10,23 +10,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.useGasSufficiency = void 0;
|
|
13
|
+
const react_query_1 = require("@tanstack/react-query");
|
|
13
14
|
const big_js_1 = require("big.js");
|
|
14
|
-
const react_1 = require("react");
|
|
15
15
|
const _1 = require(".");
|
|
16
16
|
const providers_1 = require("../providers");
|
|
17
|
+
const stores_1 = require("../stores");
|
|
17
18
|
const useTokenBalance_1 = require("./useTokenBalance");
|
|
19
|
+
const refetchInterval = 30000;
|
|
18
20
|
const useGasSufficiency = (route) => {
|
|
19
21
|
const { account } = (0, providers_1.useWallet)();
|
|
20
22
|
const { getChainById } = (0, _1.useChains)();
|
|
21
23
|
const { token: fromToken, getTokenBalancesWithRetry } = (0, useTokenBalance_1.useTokenBalance)(route === null || route === void 0 ? void 0 : route.fromToken);
|
|
22
|
-
const
|
|
23
|
-
const checkInsufficientGas = (0, react_1.useCallback)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
const { data: insufficientGas, isInitialLoading: insufficientGasLoading } = (0, react_query_1.useQuery)(['gas-sufficiency-check', account.address, route === null || route === void 0 ? void 0 : route.id], () => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
25
|
var _a, _b;
|
|
25
26
|
if (!account.address || !route) {
|
|
26
|
-
|
|
27
|
-
return;
|
|
27
|
+
return null;
|
|
28
28
|
}
|
|
29
|
-
const gasCosts = route.steps
|
|
29
|
+
const gasCosts = route.steps
|
|
30
|
+
.filter((step) => !step.execution || step.execution.status !== 'DONE')
|
|
31
|
+
.reduce((groupedGasCosts, step) => {
|
|
30
32
|
if (step.estimate.gasCosts) {
|
|
31
33
|
const { token } = step.estimate.gasCosts[0];
|
|
32
34
|
const gasCostAmount = step.estimate.gasCosts
|
|
@@ -40,7 +42,6 @@ const useGasSufficiency = (route) => {
|
|
|
40
42
|
gasAmount,
|
|
41
43
|
tokenAmount: gasAmount,
|
|
42
44
|
token,
|
|
43
|
-
chain: getChainById(token.chainId),
|
|
44
45
|
};
|
|
45
46
|
return groupedGasCosts;
|
|
46
47
|
}
|
|
@@ -51,42 +52,65 @@ const useGasSufficiency = (route) => {
|
|
|
51
52
|
}
|
|
52
53
|
const tokenBalances = yield getTokenBalancesWithRetry(account.address, Object.values(gasCosts).map((item) => item.token));
|
|
53
54
|
if (!(tokenBalances === null || tokenBalances === void 0 ? void 0 : tokenBalances.length)) {
|
|
54
|
-
|
|
55
|
-
return;
|
|
55
|
+
return null;
|
|
56
56
|
}
|
|
57
57
|
[route.fromChainId, route.toChainId].forEach((chainId) => {
|
|
58
58
|
var _a, _b, _c, _d, _e, _f;
|
|
59
59
|
if (gasCosts[chainId]) {
|
|
60
60
|
const gasTokenBalance = (0, big_js_1.default)((_b = (_a = tokenBalances === null || tokenBalances === void 0 ? void 0 : tokenBalances.find((t) => t.chainId === gasCosts[chainId].token.chainId &&
|
|
61
61
|
t.address === gasCosts[chainId].token.address)) === null || _a === void 0 ? void 0 : _a.amount) !== null && _b !== void 0 ? _b : 0);
|
|
62
|
-
const
|
|
62
|
+
const insufficient = gasTokenBalance.lte(0) ||
|
|
63
63
|
gasTokenBalance.lt((_c = gasCosts[chainId].gasAmount) !== null && _c !== void 0 ? _c : (0, big_js_1.default)(0)) ||
|
|
64
64
|
gasTokenBalance.lt((_d = gasCosts[chainId].tokenAmount) !== null && _d !== void 0 ? _d : (0, big_js_1.default)(0));
|
|
65
|
-
const
|
|
65
|
+
const insufficientAmount = insufficient
|
|
66
66
|
? (_f = (_e = gasCosts[chainId].tokenAmount) === null || _e === void 0 ? void 0 : _e.minus(gasTokenBalance)) !== null && _f !== void 0 ? _f : gasCosts[chainId].gasAmount.minus(gasTokenBalance)
|
|
67
67
|
: undefined;
|
|
68
|
-
gasCosts[chainId] = Object.assign(Object.assign({}, gasCosts[chainId]), { insufficient
|
|
68
|
+
gasCosts[chainId] = Object.assign(Object.assign({}, gasCosts[chainId]), { insufficient, insufficientAmount: insufficientAmount === null || insufficientAmount === void 0 ? void 0 : insufficientAmount.round(5, big_js_1.default.roundUp), chain: insufficient ? getChainById(chainId) : undefined });
|
|
69
69
|
}
|
|
70
70
|
});
|
|
71
71
|
const gasCostResult = Object.values(gasCosts).filter((gasCost) => gasCost.insufficient);
|
|
72
|
-
|
|
73
|
-
}),
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
72
|
+
return gasCostResult;
|
|
73
|
+
}), {
|
|
74
|
+
enabled: Boolean(account.address && route),
|
|
75
|
+
refetchIntervalInBackground: true,
|
|
76
|
+
refetchInterval,
|
|
77
|
+
staleTime: refetchInterval,
|
|
78
|
+
cacheTime: refetchInterval,
|
|
79
|
+
});
|
|
80
|
+
const { data: insufficientFunds, isInitialLoading: insufficientFundsLoading, } = (0, react_query_1.useQuery)(['funds-sufficiency-check', account.address, route === null || route === void 0 ? void 0 : route.id], () => __awaiter(void 0, void 0, void 0, function* () {
|
|
81
|
+
var _c, _d, _e, _f;
|
|
82
|
+
if (!account.address || !fromToken || !route || (0, stores_1.isRouteCompleted)(route)) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
let currentTokenBalance = (0, big_js_1.default)((_c = fromToken === null || fromToken === void 0 ? void 0 : fromToken.amount) !== null && _c !== void 0 ? _c : 0);
|
|
86
|
+
const currentAction = (_d = route.steps.filter((step) => !step.execution || step.execution.status !== 'DONE')[0]) === null || _d === void 0 ? void 0 : _d.action;
|
|
87
|
+
if (fromToken.chainId === currentAction.fromToken.chainId &&
|
|
88
|
+
fromToken.address === currentAction.fromToken.address &&
|
|
89
|
+
currentTokenBalance.gt(0)) {
|
|
90
|
+
const insufficientFunds = (0, big_js_1.default)(route.fromAmount)
|
|
91
|
+
.div(Math.pow(10, route.fromToken.decimals))
|
|
92
|
+
.gt(currentTokenBalance);
|
|
93
|
+
return insufficientFunds;
|
|
78
94
|
}
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
95
|
+
const tokenBalances = yield getTokenBalancesWithRetry(account.address, [
|
|
96
|
+
currentAction.fromToken,
|
|
97
|
+
]);
|
|
98
|
+
currentTokenBalance = (0, big_js_1.default)((_f = (_e = tokenBalances === null || tokenBalances === void 0 ? void 0 : tokenBalances[0]) === null || _e === void 0 ? void 0 : _e.amount) !== null && _f !== void 0 ? _f : 0);
|
|
99
|
+
const insufficientFunds = (0, big_js_1.default)(currentAction.fromAmount)
|
|
100
|
+
.div(Math.pow(10, currentAction.fromToken.decimals))
|
|
101
|
+
.gt(currentTokenBalance);
|
|
102
|
+
return insufficientFunds;
|
|
103
|
+
}), {
|
|
104
|
+
enabled: Boolean(account.address && route && fromToken),
|
|
105
|
+
refetchIntervalInBackground: true,
|
|
106
|
+
refetchInterval,
|
|
107
|
+
staleTime: refetchInterval,
|
|
108
|
+
cacheTime: refetchInterval,
|
|
109
|
+
});
|
|
87
110
|
return {
|
|
88
111
|
insufficientGas,
|
|
89
112
|
insufficientFunds,
|
|
113
|
+
isLoading: insufficientGasLoading || insufficientFundsLoading,
|
|
90
114
|
};
|
|
91
115
|
};
|
|
92
116
|
exports.useGasSufficiency = useGasSufficiency;
|
|
@@ -77,16 +77,18 @@ const useSwapRoutes = () => {
|
|
|
77
77
|
catch (_d) {
|
|
78
78
|
toWalletAddress = (0, address_1.isAddress)(toAddress) ? toAddress : fromAddress;
|
|
79
79
|
}
|
|
80
|
+
const fromAmount = (0, big_js_1.default)(Number(fromTokenAmount) * Math.pow(10, ((_c = token === null || token === void 0 ? void 0 : token.decimals) !== null && _c !== void 0 ? _c : 0))).toString();
|
|
81
|
+
const formattedSlippage = parseFloat(slippage) / 100;
|
|
80
82
|
return lifi.getRoutes({
|
|
81
83
|
fromChainId,
|
|
82
|
-
fromAmount
|
|
84
|
+
fromAmount,
|
|
83
85
|
fromTokenAddress,
|
|
84
86
|
toChainId,
|
|
85
87
|
toTokenAddress,
|
|
86
88
|
fromAddress,
|
|
87
89
|
toAddress: toWalletAddress,
|
|
88
90
|
options: {
|
|
89
|
-
slippage:
|
|
91
|
+
slippage: formattedSlippage,
|
|
90
92
|
bridges: {
|
|
91
93
|
allow: enabledBridges,
|
|
92
94
|
},
|
|
@@ -24,12 +24,12 @@ const useTokenBalance = (token, accountAddress) => {
|
|
|
24
24
|
try {
|
|
25
25
|
const tokenBalances = yield lifi.getTokenBalances(accountAddress, tokens);
|
|
26
26
|
if (!tokenBalances.every((token) => token.blockNumber)) {
|
|
27
|
-
if (depth >
|
|
27
|
+
if (depth > 10) {
|
|
28
28
|
console.warn('Token balance backoff depth exceeded.');
|
|
29
29
|
return undefined;
|
|
30
30
|
}
|
|
31
31
|
yield new Promise((resolve) => {
|
|
32
|
-
setTimeout(resolve, depth * 100);
|
|
32
|
+
setTimeout(resolve, Math.pow(1.5, depth) * 100);
|
|
33
33
|
});
|
|
34
34
|
return getTokenBalancesWithRetry(accountAddress, tokens, depth + 1);
|
|
35
35
|
}
|
|
@@ -44,10 +44,6 @@
|
|
|
44
44
|
"routes": "You get",
|
|
45
45
|
"approximateCurrency": "\u2248 {{value, currency(currency: USD)}}",
|
|
46
46
|
"currency": "{{value, currency(currency: USD)}}",
|
|
47
|
-
"sendToRecipient": "Send to recipient",
|
|
48
|
-
"addressConfirmation": "I confirm that the address above is correct",
|
|
49
|
-
"gas": "gas fee",
|
|
50
|
-
"minutes": "minutes",
|
|
51
47
|
"tokenSearch": "Search your token",
|
|
52
48
|
"selectChain": "Chain",
|
|
53
49
|
"selectToken": "Token",
|
|
@@ -98,12 +94,14 @@
|
|
|
98
94
|
"title": {
|
|
99
95
|
"insufficientGas": "Insufficient gas",
|
|
100
96
|
"deleteSwap": "Delete this swap?",
|
|
101
|
-
"deleteSwapHistory": "Delete swap history?"
|
|
97
|
+
"deleteSwapHistory": "Delete swap history?",
|
|
98
|
+
"deleteActiveSwaps": "Delete all active swaps?"
|
|
102
99
|
},
|
|
103
100
|
"message": {
|
|
104
101
|
"insufficientFunds": "You don't have enough funds to execute the swap.",
|
|
105
102
|
"insufficientGas": "You need to add at least:",
|
|
106
|
-
"
|
|
103
|
+
"deleteSwapHistory": "Swap history is only stored locally and can't be recovered if you delete it.",
|
|
104
|
+
"deleteActiveSwaps": "Active swaps are only stored locally and can't be recovered if you delete them."
|
|
107
105
|
}
|
|
108
106
|
},
|
|
109
107
|
"error": {
|
|
@@ -179,6 +177,9 @@
|
|
|
179
177
|
"title": "404",
|
|
180
178
|
"text": "We couldn't find this page."
|
|
181
179
|
},
|
|
182
|
-
"progressToNextUpdate": "Displayed data will auto-refresh after {{value}} seconds. Click
|
|
180
|
+
"progressToNextUpdate": "Displayed data will auto-refresh after {{value}} seconds. Click here to update manually.",
|
|
181
|
+
"numberOfSteps": "A number of swap steps. Each step can contain 1-3 transactions that require a signature.",
|
|
182
|
+
"estimatedTime": "Estimated time in minutes.",
|
|
183
|
+
"estimatedNetworkFee": "Estimated network fee."
|
|
183
184
|
}
|
|
184
185
|
}
|