@lifi/widget 1.6.1 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/App.js +2 -1
- package/LICENSE.md +201 -21
- package/components/AppContainer.js +2 -2
- package/components/Header/Header.js +1 -1
- package/components/Header/NavigationHeader.js +1 -1
- package/components/InsufficientGasOrFundsMessage/InsufficientGasOrFundsMessage.d.ts +3 -0
- package/components/InsufficientGasOrFundsMessage/InsufficientGasOrFundsMessage.js +31 -0
- package/{pages/MainPage → components/InsufficientGasOrFundsMessage}/InsufficientGasOrFundsMessage.style.d.ts +0 -0
- package/{pages/MainPage → components/InsufficientGasOrFundsMessage}/InsufficientGasOrFundsMessage.style.js +3 -2
- package/components/InsufficientGasOrFundsMessage/index.d.ts +1 -0
- package/components/InsufficientGasOrFundsMessage/index.js +1 -0
- package/components/NotFound.d.ts +2 -0
- package/components/NotFound.js +14 -0
- package/components/StepActions/StepActions.d.ts +1 -1
- package/components/StepActions/types.d.ts +1 -1
- package/components/StepToken.d.ts +1 -1
- package/components/SwapButton/ButtonTooltip.d.ts +1 -0
- package/components/SwapButton/SwapButton.js +3 -3
- package/components/SwapButton/SwapButton.style.d.ts +2 -2
- package/components/SwapButton/SwapButton.style.js +0 -4
- package/components/SwapInput/SwapInputAdornment.d.ts +1 -0
- package/components/SwapRouteCard/types.d.ts +1 -1
- package/components/TokenList/types.d.ts +1 -1
- package/components/TokenList/utils.d.ts +2 -2
- package/config/theme.js +17 -2
- package/config/version.d.ts +1 -1
- package/config/version.js +1 -1
- package/hooks/useChain.d.ts +1 -1
- package/hooks/useChains.d.ts +12 -12
- package/hooks/useHasSufficientBalance.d.ts +1 -1
- package/hooks/useHasSufficientBalance.js +27 -22
- package/hooks/useRouteExecution.d.ts +1 -1
- package/hooks/useSwapRoutes.d.ts +2 -2
- package/hooks/useSwapRoutes.js +2 -2
- package/hooks/useToken.d.ts +1 -1
- package/hooks/useTokenBalance.d.ts +1 -1
- package/hooks/useTokenBalances.d.ts +1 -1
- package/hooks/useTokens.d.ts +1 -1
- package/hooks/useTools.d.ts +1 -1
- package/i18n/en/translation.json +9 -7
- package/i18n/index.d.ts +5 -3
- package/lifi.d.ts +1 -1
- package/lifi.js +1 -1
- package/package.json +10 -10
- package/pages/MainPage/MainPage.js +2 -2
- package/pages/MainPage/MainPage.style.d.ts +1 -1
- package/pages/MainPage/MainPage.style.js +1 -1
- package/pages/SelectTokenPage/ChainSelect.d.ts +1 -0
- package/pages/SelectTokenPage/SearchTokenInput.d.ts +1 -0
- package/pages/SelectWalletPage/SelectWalletPage.d.ts +1 -0
- package/pages/SettingsPage/AdvancedPreferences.d.ts +1 -0
- package/pages/SettingsPage/GasPriceSelect.d.ts +1 -0
- package/pages/SettingsPage/RoutePrioritySelect.js +1 -1
- package/pages/SettingsPage/SettingsPage.d.ts +1 -0
- package/pages/SettingsPage/SlippageInput.d.ts +1 -0
- package/pages/SwapPage/CircularProgress.d.ts +2 -1
- package/pages/SwapPage/CircularProgress.style.d.ts +1 -1
- package/pages/SwapPage/ExecutionItem.d.ts +1 -1
- package/pages/SwapPage/StepItem.d.ts +1 -1
- package/pages/SwapPage/StepTimer.d.ts +1 -1
- package/pages/SwapPage/SwapPage.js +5 -2
- package/pages/SwapPage/utils.d.ts +1 -1
- package/pages/SwapPage/utils.js +1 -1
- package/providers/WalletProvider/types.d.ts +1 -1
- package/providers/WidgetProvider/WidgetProvider.js +1 -1
- package/stores/route/types.d.ts +1 -1
- package/stores/route/useCurrentRoute.d.ts +1 -1
- package/stores/route/useSetExecutableRoute.d.ts +1 -1
- package/stores/settings/types.d.ts +1 -1
- package/stores/settings/useSettingsStore.d.ts +1 -1
- package/types/widget.d.ts +1 -1
- package/pages/MainPage/InsufficientGasOrFundsMessage.d.ts +0 -2
- package/pages/MainPage/InsufficientGasOrFundsMessage.js +0 -28
|
@@ -1,58 +1,63 @@
|
|
|
1
|
-
import { isSwapStep } from '@
|
|
1
|
+
import { isSwapStep } from '@lifi/sdk';
|
|
2
2
|
import Big from 'big.js';
|
|
3
3
|
import { useMemo } from 'react';
|
|
4
4
|
import { useWatch } from 'react-hook-form';
|
|
5
|
-
import {
|
|
5
|
+
import { useDebouncedWatch } from '.';
|
|
6
|
+
import { SwapFormKey, SwapFormKeyHelper } from '../providers/SwapFormProvider';
|
|
6
7
|
import { useCurrentRoute } from '../stores';
|
|
7
8
|
import { useTokenBalances } from './useTokenBalances';
|
|
8
9
|
export const useHasSufficientBalance = () => {
|
|
9
10
|
var _a;
|
|
10
11
|
const [route] = useCurrentRoute();
|
|
11
|
-
const [fromChainId, toChainId] = useWatch({
|
|
12
|
+
const [fromChainId, toChainId, fromToken] = useWatch({
|
|
12
13
|
name: [
|
|
13
14
|
SwapFormKeyHelper.getChainKey('from'),
|
|
14
15
|
SwapFormKeyHelper.getChainKey('to'),
|
|
16
|
+
SwapFormKey.FromToken,
|
|
15
17
|
],
|
|
16
18
|
});
|
|
19
|
+
const fromAmount = useDebouncedWatch(SwapFormKey.FromAmount, 250);
|
|
17
20
|
const lastStep = route === null || route === void 0 ? void 0 : route.steps.at(-1);
|
|
18
21
|
const { tokens: fromChainTokenBalances } = useTokenBalances(fromChainId);
|
|
19
22
|
const { tokens: toChainTokenBalances } = useTokenBalances((_a = lastStep === null || lastStep === void 0 ? void 0 : lastStep.action.fromChainId) !== null && _a !== void 0 ? _a : toChainId);
|
|
20
|
-
const
|
|
21
|
-
var _a, _b, _c;
|
|
22
|
-
const
|
|
23
|
-
if (!
|
|
23
|
+
const hasGasOnStartChain = useMemo(() => {
|
|
24
|
+
var _a, _b, _c, _d, _e;
|
|
25
|
+
const gasToken = (_a = route === null || route === void 0 ? void 0 : route.steps[0].estimate.gasCosts) === null || _a === void 0 ? void 0 : _a[0].token;
|
|
26
|
+
if (!gasToken) {
|
|
24
27
|
return true;
|
|
25
28
|
}
|
|
26
|
-
const
|
|
27
|
-
|
|
29
|
+
const gasTokenBalance = Big((_c = (_b = fromChainTokenBalances === null || fromChainTokenBalances === void 0 ? void 0 : fromChainTokenBalances.find((t) => t.address === gasToken.address)) === null || _b === void 0 ? void 0 : _b.amount) !== null && _c !== void 0 ? _c : 0);
|
|
30
|
+
let requiredAmount = route.steps
|
|
28
31
|
.filter((step) => step.action.fromChainId === route.fromChainId)
|
|
29
32
|
.reduce((big, step) => { var _a; return big.plus(Big(((_a = step.estimate.gasCosts) === null || _a === void 0 ? void 0 : _a[0].amount) || 0)); }, Big(0))
|
|
30
|
-
.div(Math.pow(10,
|
|
31
|
-
|
|
33
|
+
.div(Math.pow(10, gasToken.decimals));
|
|
34
|
+
if (route.fromToken.address === gasToken.address) {
|
|
35
|
+
const tokenBalance = Big((_e = (_d = fromChainTokenBalances === null || fromChainTokenBalances === void 0 ? void 0 : fromChainTokenBalances.find((t) => t.address === route.fromToken.address)) === null || _d === void 0 ? void 0 : _d.amount) !== null && _e !== void 0 ? _e : 0);
|
|
36
|
+
requiredAmount = requiredAmount.plus(tokenBalance);
|
|
37
|
+
}
|
|
38
|
+
return gasTokenBalance.gt(0) && gasTokenBalance.gte(requiredAmount);
|
|
32
39
|
}, [fromChainTokenBalances, route]);
|
|
33
40
|
const hasGasOnCrossChain = useMemo(() => {
|
|
34
41
|
var _a, _b, _c, _d, _e, _f;
|
|
35
|
-
const
|
|
36
|
-
if (!
|
|
42
|
+
const gasToken = (_a = lastStep === null || lastStep === void 0 ? void 0 : lastStep.estimate.gasCosts) === null || _a === void 0 ? void 0 : _a[0].token;
|
|
43
|
+
if (!gasToken || !isSwapStep(lastStep)) {
|
|
37
44
|
return true;
|
|
38
45
|
}
|
|
39
|
-
const balance = Big((_c = (_b = toChainTokenBalances === null || toChainTokenBalances === void 0 ? void 0 : toChainTokenBalances.find((t) => t.address ===
|
|
46
|
+
const balance = Big((_c = (_b = toChainTokenBalances === null || toChainTokenBalances === void 0 ? void 0 : toChainTokenBalances.find((t) => t.address === gasToken.address)) === null || _b === void 0 ? void 0 : _b.amount) !== null && _c !== void 0 ? _c : 0);
|
|
40
47
|
const gasEstimate = (_d = lastStep.estimate.gasCosts) === null || _d === void 0 ? void 0 : _d[0].amount;
|
|
41
48
|
const requiredAmount = Big(gasEstimate || 0).div(Math.pow(10, ((_f = (_e = lastStep.estimate.gasCosts) === null || _e === void 0 ? void 0 : _e[0].token.decimals) !== null && _f !== void 0 ? _f : 0)));
|
|
42
49
|
return balance.gt(0) && balance.gte(requiredAmount);
|
|
43
50
|
}, [lastStep, toChainTokenBalances]);
|
|
44
51
|
const hasSufficientBalance = useMemo(() => {
|
|
45
|
-
var _a, _b
|
|
46
|
-
if (!
|
|
52
|
+
var _a, _b;
|
|
53
|
+
if (!fromToken || !fromAmount) {
|
|
47
54
|
return true;
|
|
48
55
|
}
|
|
49
|
-
const balance = Big((_b = (_a = fromChainTokenBalances === null || fromChainTokenBalances === void 0 ? void 0 : fromChainTokenBalances.find((t) => t.address ===
|
|
50
|
-
return Big(
|
|
51
|
-
|
|
52
|
-
.lte(balance);
|
|
53
|
-
}, [fromChainTokenBalances, route]);
|
|
56
|
+
const balance = Big((_b = (_a = fromChainTokenBalances === null || fromChainTokenBalances === void 0 ? void 0 : fromChainTokenBalances.find((t) => t.address === fromToken)) === null || _a === void 0 ? void 0 : _a.amount) !== null && _b !== void 0 ? _b : 0);
|
|
57
|
+
return Big(fromAmount).lte(balance);
|
|
58
|
+
}, [fromAmount, fromChainTokenBalances, fromToken]);
|
|
54
59
|
return {
|
|
55
|
-
|
|
60
|
+
hasGasOnStartChain,
|
|
56
61
|
hasGasOnCrossChain,
|
|
57
62
|
hasSufficientBalance,
|
|
58
63
|
};
|
package/hooks/useSwapRoutes.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export declare const useSwapRoutes: () => {
|
|
2
|
-
routes: import("@
|
|
2
|
+
routes: import("@lifi/types").Route[] | undefined;
|
|
3
3
|
isLoading: boolean;
|
|
4
4
|
isFetching: boolean;
|
|
5
5
|
dataUpdatedAt: number;
|
|
6
6
|
refetchTime: number;
|
|
7
|
-
refetch: <TPageData>(options?: (import("react-query").RefetchOptions & import("react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("react-query").QueryObserverResult<import("@
|
|
7
|
+
refetch: <TPageData>(options?: (import("react-query").RefetchOptions & import("react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("react-query").QueryObserverResult<import("@lifi/types").RoutesResponse, unknown>>;
|
|
8
8
|
};
|
package/hooks/useSwapRoutes.js
CHANGED
|
@@ -97,10 +97,10 @@ export const useSwapRoutes = () => {
|
|
|
97
97
|
const isCurrentRouteInSet = data === null || data === void 0 ? void 0 : data.routes.some((route) => route.id === (currentRoute === null || currentRoute === void 0 ? void 0 : currentRoute.id));
|
|
98
98
|
const recommendedRoute = data === null || data === void 0 ? void 0 : data.routes[0];
|
|
99
99
|
// we don't want to set the current route again if it's already selected from existing routes
|
|
100
|
-
if (!isCurrentRouteInSet && recommendedRoute) {
|
|
100
|
+
if (!isCurrentRouteInSet && currentRoute !== recommendedRoute) {
|
|
101
101
|
setCurrentRoute(recommendedRoute);
|
|
102
102
|
}
|
|
103
|
-
}, [currentRoute
|
|
103
|
+
}, [currentRoute, data === null || data === void 0 ? void 0 : data.routes, setCurrentRoute]);
|
|
104
104
|
return {
|
|
105
105
|
routes: data === null || data === void 0 ? void 0 : data.routes,
|
|
106
106
|
isLoading: isEnabled && isLoading,
|
package/hooks/useToken.d.ts
CHANGED
package/hooks/useTokens.d.ts
CHANGED
package/hooks/useTools.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useTools: () => import("@
|
|
1
|
+
export declare const useTools: () => import("@lifi/types").ToolsResponse | undefined;
|
package/i18n/en/translation.json
CHANGED
|
@@ -70,14 +70,12 @@
|
|
|
70
70
|
},
|
|
71
71
|
"warning": {
|
|
72
72
|
"title": {
|
|
73
|
-
"
|
|
74
|
-
"insufficientGasOnStartChain": "Insufficient gas on start chain",
|
|
75
|
-
"insufficientGasOnDestinationChain": "Insufficient gas on destination chain"
|
|
73
|
+
"insufficientGas": "Insufficient gas"
|
|
76
74
|
},
|
|
77
75
|
"message": {
|
|
78
|
-
"insufficientFunds": "You don't have enough funds
|
|
79
|
-
"insufficientGasOnStartChain": "
|
|
80
|
-
"insufficientGasOnDestinationChain": "
|
|
76
|
+
"insufficientFunds": "You don't have enough funds for this transaction on the start “from” chain.",
|
|
77
|
+
"insufficientGasOnStartChain": "You need to have enough gas to pay for this transaction on the start “from” chain.",
|
|
78
|
+
"insufficientGasOnDestinationChain": "You need to have enough gas to pay for this transaction on the destination “to” chain."
|
|
81
79
|
}
|
|
82
80
|
},
|
|
83
81
|
"error": {
|
|
@@ -100,7 +98,7 @@
|
|
|
100
98
|
"process": {
|
|
101
99
|
"tokenAllowance": {
|
|
102
100
|
"started": "Setting token allowance.",
|
|
103
|
-
"pending": "Waiting for token allowance
|
|
101
|
+
"pending": "Waiting for token allowance.",
|
|
104
102
|
"done": "Token allowance approved."
|
|
105
103
|
},
|
|
106
104
|
"switchChain": {
|
|
@@ -145,6 +143,10 @@
|
|
|
145
143
|
"extensionNotFound": "Please make sure that only the {{name}} browser extension is active before choosing this wallet."
|
|
146
144
|
},
|
|
147
145
|
"tooltip": {
|
|
146
|
+
"notFound": {
|
|
147
|
+
"title": "Sorry 🥲",
|
|
148
|
+
"text": "We couldn't find this page."
|
|
149
|
+
},
|
|
148
150
|
"progressToNextUpdate": "Displayed data will auto-refresh after {{value}} seconds. Click this circle to update manually."
|
|
149
151
|
}
|
|
150
152
|
}
|
package/i18n/index.d.ts
CHANGED
|
@@ -73,9 +73,7 @@ export declare const resources: {
|
|
|
73
73
|
};
|
|
74
74
|
warning: {
|
|
75
75
|
title: {
|
|
76
|
-
|
|
77
|
-
insufficientGasOnStartChain: string;
|
|
78
|
-
insufficientGasOnDestinationChain: string;
|
|
76
|
+
insufficientGas: string;
|
|
79
77
|
};
|
|
80
78
|
message: {
|
|
81
79
|
insufficientFunds: string;
|
|
@@ -148,6 +146,10 @@ export declare const resources: {
|
|
|
148
146
|
extensionNotFound: string;
|
|
149
147
|
};
|
|
150
148
|
tooltip: {
|
|
149
|
+
notFound: {
|
|
150
|
+
title: string;
|
|
151
|
+
text: string;
|
|
152
|
+
};
|
|
151
153
|
progressToNextUpdate: string;
|
|
152
154
|
};
|
|
153
155
|
};
|
package/lifi.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import LIFI from '@
|
|
1
|
+
import LIFI from '@lifi/sdk';
|
|
2
2
|
export declare const LiFi: LIFI;
|
package/lifi.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/widget",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.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
|
"sideEffects": false,
|
|
6
6
|
"main": "./index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"bugs": {
|
|
24
24
|
"url": "https://github.com/lifinance/widget/issues"
|
|
25
25
|
},
|
|
26
|
-
"license": "
|
|
26
|
+
"license": "Apache-2.0",
|
|
27
27
|
"keywords": [
|
|
28
28
|
"widget",
|
|
29
29
|
"lifi-widget",
|
|
@@ -41,15 +41,15 @@
|
|
|
41
41
|
"@emotion/styled": "^11.9.3",
|
|
42
42
|
"@ethersproject/experimental": "^5.6.3",
|
|
43
43
|
"@ethersproject/providers": "^5.6.8",
|
|
44
|
-
"@lifi/
|
|
45
|
-
"@
|
|
44
|
+
"@lifi/sdk": "^1.0.0",
|
|
45
|
+
"@lifi/wallet-management": "^1.1.1",
|
|
46
46
|
"@mui/icons-material": "^5.8.4",
|
|
47
|
-
"@mui/lab": "^5.0.0-alpha.
|
|
48
|
-
"@mui/material": "^5.
|
|
49
|
-
"@sentry/integrations": "^7.
|
|
50
|
-
"@sentry/react": "^7.
|
|
51
|
-
"@sentry/tracing": "^7.
|
|
52
|
-
"big.js": "^6.2.
|
|
47
|
+
"@mui/lab": "^5.0.0-alpha.90",
|
|
48
|
+
"@mui/material": "^5.9.0",
|
|
49
|
+
"@sentry/integrations": "^7.6.0",
|
|
50
|
+
"@sentry/react": "^7.6.0",
|
|
51
|
+
"@sentry/tracing": "^7.6.0",
|
|
52
|
+
"big.js": "^6.2.1",
|
|
53
53
|
"i18next": "^21.8.13",
|
|
54
54
|
"immer": "^9.0.15",
|
|
55
55
|
"react": "^18.2.0",
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Box } from '@mui/material';
|
|
3
|
+
import { InsufficientGasOrFundsMessage } from '../../components/InsufficientGasOrFundsMessage';
|
|
3
4
|
import { SelectChainAndToken } from '../../components/SelectChainAndToken';
|
|
4
5
|
import { SwapButton } from '../../components/SwapButton';
|
|
5
6
|
import { SwapInProgress } from '../../components/SwapInProgress';
|
|
6
7
|
import { SwapInput } from '../../components/SwapInput';
|
|
7
8
|
import { SwapRoutes } from '../../components/SwapRoutes';
|
|
8
|
-
import { InsufficientGasOrFundsMessage } from './InsufficientGasOrFundsMessage';
|
|
9
9
|
import { FormContainer } from './MainPage.style';
|
|
10
10
|
export const MainPage = () => {
|
|
11
|
-
return (_jsxs(FormContainer, Object.assign({ disableGutters: true }, { children: [_jsx(SwapInProgress, { mx: 3, mt: 2, mb: 1 }), _jsx(SelectChainAndToken, { mt: 2, mx: 3, mb: 3 }), _jsx(Box, Object.assign({ mx: 3, mb: 3 }, { children: _jsx(SwapInput, { formType: "from" }) })), _jsx(SwapRoutes, { mx: 3, mb: 3 }), _jsx(InsufficientGasOrFundsMessage, {}), _jsx(Box, Object.assign({ mx: 3, mb: 1 }, { children: _jsx(SwapButton, {}) }))] })));
|
|
11
|
+
return (_jsxs(FormContainer, Object.assign({ disableGutters: true }, { children: [_jsx(SwapInProgress, { mx: 3, mt: 2, mb: 1 }), _jsx(SelectChainAndToken, { mt: 2, mx: 3, mb: 3 }), _jsx(Box, Object.assign({ mx: 3, mb: 3 }, { children: _jsx(SwapInput, { formType: "from" }) })), _jsx(SwapRoutes, { mx: 3, mb: 3 }), _jsx(InsufficientGasOrFundsMessage, { mx: 3, mb: 3 }), _jsx(Box, Object.assign({ mx: 3, mb: 1 }, { children: _jsx(SwapButton, {}) }))] })));
|
|
12
12
|
};
|
|
@@ -8,4 +8,4 @@ export declare const FormContainer: import("@emotion/styled").StyledComponent<{
|
|
|
8
8
|
sx?: import("@mui/material").SxProps<import("@mui/material").Theme> | undefined;
|
|
9
9
|
} & import("@mui/material/OverridableComponent").CommonProps & Omit<Pick<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof import("react").HTMLAttributes<HTMLDivElement>> & {
|
|
10
10
|
ref?: import("react").RefObject<HTMLDivElement> | ((instance: HTMLDivElement | null) => void) | null | undefined;
|
|
11
|
-
}, keyof import("@mui/material/OverridableComponent").CommonProps | "children" | "sx" | "maxWidth" | "fixed" | "disableGutters"> & import("@mui/system").MUIStyledCommonProps<import("@mui/
|
|
11
|
+
}, keyof import("@mui/material/OverridableComponent").CommonProps | "children" | "sx" | "maxWidth" | "fixed" | "disableGutters"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, {}, {}>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Orders } from '@
|
|
2
|
+
import { Orders } from '@lifi/sdk';
|
|
3
3
|
import { KeyboardArrowDown as KeyboardArrowDownIcon } from '@mui/icons-material';
|
|
4
4
|
import { FormControl, MenuItem } from '@mui/material';
|
|
5
5
|
import { useTranslation } from 'react-i18next';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Status } from '@
|
|
1
|
+
import { Status } from '@lifi/sdk';
|
|
2
2
|
import { Theme } from '@mui/material';
|
|
3
3
|
export declare const CircularProgress: import("@emotion/styled").StyledComponent<import("@mui/material").CircularProgressProps & import("@mui/system").MUIStyledCommonProps<Theme> & {
|
|
4
4
|
status: Status;
|
|
@@ -2,7 +2,8 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
2
2
|
import { Fragment } from 'react';
|
|
3
3
|
import { useTranslation } from 'react-i18next';
|
|
4
4
|
import { useLocation, useNavigate } from 'react-router-dom';
|
|
5
|
-
import {
|
|
5
|
+
import { InsufficientGasOrFundsMessage } from '../../components/InsufficientGasOrFundsMessage';
|
|
6
|
+
import { useHasSufficientBalance, useRouteExecution } from '../../hooks';
|
|
6
7
|
import { StatusBottomSheet } from './StatusBottomSheet';
|
|
7
8
|
import { StepDivider } from './StepDivider';
|
|
8
9
|
import { StepItem } from './StepItem';
|
|
@@ -11,12 +12,14 @@ export const SwapPage = () => {
|
|
|
11
12
|
const { t } = useTranslation();
|
|
12
13
|
const { state } = useLocation();
|
|
13
14
|
const navigate = useNavigate();
|
|
15
|
+
const { hasGasOnStartChain, hasGasOnCrossChain, hasSufficientBalance } = useHasSufficientBalance();
|
|
14
16
|
const { route, status, executeRoute, restartRoute, removeRoute } = useRouteExecution(state.routeId);
|
|
15
17
|
const handleRemoveRoute = () => {
|
|
16
18
|
removeRoute();
|
|
17
19
|
navigate(-1);
|
|
18
20
|
};
|
|
21
|
+
const isDisabled = !hasSufficientBalance || !hasGasOnStartChain || !hasGasOnCrossChain;
|
|
19
22
|
return (_jsxs(Container, { children: [route === null || route === void 0 ? void 0 : route.steps.map((step, index, steps) => (_jsxs(Fragment, { children: [_jsx(StepItem, { step: step, fromToken: index === 0
|
|
20
23
|
? Object.assign(Object.assign({}, route.fromToken), { amount: route.fromAmount }) : undefined, toToken: index === steps.length - 1
|
|
21
|
-
? Object.assign(Object.assign({}, route.toToken), { amount: route.toAmount }) : undefined }), steps.length > 1 && index !== steps.length - 1 ? (_jsx(StepDivider, {})) : null] }, step.id))), status === 'idle' ? (_jsx(Button, Object.assign({ variant: "contained", disableElevation: true, fullWidth: true, onClick: executeRoute }, { children: t('button.startSwap') }))) : null, status === 'error' ? (_jsxs(_Fragment, { children: [_jsx(Button, Object.assign({ variant: "contained", disableElevation: true, fullWidth: true, onClick: restartRoute }, { children: t('button.restartSwap') })), _jsx(Button, Object.assign({ variant: "outlined", disableElevation: true, fullWidth: true, onClick: handleRemoveRoute }, { children: t('button.removeSwap') }))] })) : null, _jsx(StatusBottomSheet, { status: status, route: route })] }));
|
|
24
|
+
? Object.assign(Object.assign({}, route.toToken), { amount: route.toAmount }) : undefined }), steps.length > 1 && index !== steps.length - 1 ? (_jsx(StepDivider, {})) : null] }, step.id))), _jsx(InsufficientGasOrFundsMessage, { mt: 2 }), status === 'idle' ? (_jsx(Button, Object.assign({ variant: "contained", disableElevation: true, fullWidth: true, onClick: executeRoute, disabled: isDisabled }, { children: t('button.startSwap') }))) : null, status === 'error' ? (_jsxs(_Fragment, { children: [_jsx(Button, Object.assign({ variant: "contained", disableElevation: true, fullWidth: true, onClick: restartRoute, disabled: isDisabled }, { children: t('button.restartSwap') })), _jsx(Button, Object.assign({ variant: "outlined", disableElevation: true, fullWidth: true, onClick: handleRemoveRoute, disabled: isDisabled }, { children: t('button.removeSwap') }))] })) : null, _jsx(StatusBottomSheet, { status: status, route: route })] }));
|
|
22
25
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EVMChain, Process, Step } from '@
|
|
1
|
+
import { EVMChain, Process, Step } from '@lifi/sdk';
|
|
2
2
|
import { TFunction } from 'react-i18next';
|
|
3
3
|
export declare function getProcessMessage(t: TFunction<'translation', undefined>, getChainById: (chainId: number) => EVMChain | undefined, step: Step, process: Process): {
|
|
4
4
|
title?: string;
|
package/pages/SwapPage/utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LifiErrorCode, MetaMaskProviderErrorCode, } from '@
|
|
1
|
+
import { LifiErrorCode, MetaMaskProviderErrorCode, } from '@lifi/sdk';
|
|
2
2
|
import { formatTokenAmount } from '../../utils/format';
|
|
3
3
|
const formatProcessMessage = (initialMessage, args = {}) => {
|
|
4
4
|
return Object.keys(args).reduce((message, key) => {
|
|
@@ -10,7 +10,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
-
import { ChainId, getChainByKey } from '@
|
|
13
|
+
import { ChainId, getChainByKey } from '@lifi/sdk';
|
|
14
14
|
import { createContext, useContext, useMemo } from 'react';
|
|
15
15
|
const stub = () => {
|
|
16
16
|
throw new Error('You forgot to wrap your component in <WidgetProvider>.');
|
package/stores/route/types.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Route } from '@
|
|
1
|
+
import { Route } from '@lifi/sdk';
|
|
2
2
|
export declare const useCurrentRoute: () => [Route | undefined, (route?: Route) => void];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useSetExecutableRoute: () => (route: import("@
|
|
1
|
+
export declare const useSetExecutableRoute: () => (route: import("@lifi/types").Route) => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Bridge, Exchange, Order } from '@
|
|
1
|
+
import { Bridge, Exchange, Order } from '@lifi/sdk';
|
|
2
2
|
import { Appearance } from '../../types';
|
|
3
3
|
export declare type ValueSetter<S> = <K extends keyof S>(key: K, value: S[Extract<K, string>]) => void;
|
|
4
4
|
export declare type ValuesSetter<S> = <K extends keyof S>(values: Record<K, S[Extract<K, string>]>) => void;
|
|
@@ -5,7 +5,7 @@ export declare const useSettingsStore: import("zustand").UseBoundStore<Omit<Omit
|
|
|
5
5
|
setValue: import("./types").ValueSetter<SettingsState>;
|
|
6
6
|
setValues: import("./types").ValuesSetter<SettingsState>;
|
|
7
7
|
initializeTools(toolType: import("./types").SettingsToolType, tools: string[]): void;
|
|
8
|
-
setTools(toolType: import("./types").SettingsToolType, tools: string[], availableTools: (Pick<import("@
|
|
8
|
+
setTools(toolType: import("./types").SettingsToolType, tools: string[], availableTools: (Pick<import("@lifi/types").Bridge, "key"> | Pick<import("@lifi/types").Exchange, "key">)[]): void;
|
|
9
9
|
advancedPreferences: boolean;
|
|
10
10
|
appearance: import("../..").Appearance;
|
|
11
11
|
routePriority: "RECOMMENDED" | "FASTEST" | "CHEAPEST" | "SAFEST";
|
package/types/widget.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChainKey, Token } from '@
|
|
1
|
+
import { ChainKey, Token } from '@lifi/sdk';
|
|
2
2
|
import { PaletteMode, PaletteOptions, Shape } from '@mui/material';
|
|
3
3
|
import { TypographyOptions } from '@mui/material/styles/createTypography';
|
|
4
4
|
import { Signer } from 'ethers';
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Typography } from '@mui/material';
|
|
3
|
-
import { useTranslation } from 'react-i18next';
|
|
4
|
-
import { CardTitle } from '../../components/Card';
|
|
5
|
-
import { useHasSufficientBalance } from '../../hooks';
|
|
6
|
-
import { MessageCard } from './InsufficientGasOrFundsMessage.style';
|
|
7
|
-
export const InsufficientGasOrFundsMessage = () => {
|
|
8
|
-
const { t } = useTranslation();
|
|
9
|
-
const { hasGasBalanceOnStartChain, hasGasOnCrossChain, hasSufficientBalance, } = useHasSufficientBalance();
|
|
10
|
-
if (hasSufficientBalance && hasGasBalanceOnStartChain && hasGasOnCrossChain) {
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
let title;
|
|
14
|
-
let message;
|
|
15
|
-
if (!hasSufficientBalance) {
|
|
16
|
-
title = t(`swap.warning.title.insufficientFunds`);
|
|
17
|
-
message = t(`swap.warning.message.insufficientFunds`);
|
|
18
|
-
}
|
|
19
|
-
if (!hasGasBalanceOnStartChain) {
|
|
20
|
-
title = t(`swap.warning.title.insufficientGasOnStartChain`);
|
|
21
|
-
message = t(`swap.warning.message.insufficientGasOnStartChain`);
|
|
22
|
-
}
|
|
23
|
-
if (!hasGasOnCrossChain) {
|
|
24
|
-
title = t(`swap.warning.title.insufficientGasOnDestinationChain`);
|
|
25
|
-
message = t(`swap.warning.message.insufficientGasOnDestinationChain`);
|
|
26
|
-
}
|
|
27
|
-
return (_jsxs(MessageCard, Object.assign({ mx: 3, mb: 3 }, { children: [_jsx(CardTitle, { children: title }), _jsx(Typography, Object.assign({ variant: "body2", px: 2, pb: 2, pt: 1 }, { children: message }))] })));
|
|
28
|
-
};
|