@lifi/widget 1.7.0 → 1.9.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 +2 -1
- package/AppDrawer.style.d.ts +1 -1
- package/LICENSE.md +201 -21
- 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/ReverseTokensButton/ReverseTokensButton.style.d.ts +1 -1
- 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 +3 -3
- package/components/SwapButton/SwapButton.style.js +0 -4
- package/components/SwapInput/SwapInput.style.d.ts +1 -1
- package/components/SwapInput/SwapInputAdornment.d.ts +1 -0
- package/components/SwapInput/SwapInputAdornment.style.d.ts +1 -1
- package/components/SwapRouteCard/SwapRouteCardSkeleton.d.ts +4 -0
- package/components/SwapRouteCard/SwapRouteCardSkeleton.js +32 -0
- package/components/SwapRouteCard/SwapRouteNotFoundCard.d.ts +4 -0
- package/components/SwapRouteCard/SwapRouteNotFoundCard.js +27 -0
- package/components/SwapRouteCard/index.d.ts +2 -0
- package/components/SwapRouteCard/index.js +2 -0
- package/components/SwapRouteCard/types.d.ts +6 -1
- package/components/SwapRoutes/SwapRoutes.js +7 -9
- 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 +3 -2
- package/hooks/useSwapRoutes.js +6 -6
- 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 +17 -7
- package/i18n/index.d.ts +13 -3
- package/lifi.d.ts +1 -1
- package/lifi.js +1 -1
- package/package.json +12 -12
- 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/ColorSchemeButtonGroup.style.d.ts +1 -1
- 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/ExecutionItem.style.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/SwapPage.style.d.ts +1 -1
- package/pages/SwapPage/utils.d.ts +1 -1
- package/pages/SwapPage/utils.js +1 -1
- package/pages/SwapRoutesPage/SwapRoutesPage.js +12 -13
- 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/utils/format.js +3 -3
- package/pages/MainPage/InsufficientGasOrFundsMessage.d.ts +0 -2
- package/pages/MainPage/InsufficientGasOrFundsMessage.js +0 -28
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
/* eslint-disable react/no-array-index-key */
|
|
3
3
|
import { KeyboardArrowRight as KeyboardArrowRightIcon } from '@mui/icons-material';
|
|
4
|
-
import { Box, IconButton
|
|
4
|
+
import { Box, IconButton } from '@mui/material';
|
|
5
5
|
import { useCallback } from 'react';
|
|
6
6
|
import { useTranslation } from 'react-i18next';
|
|
7
7
|
import { useNavigate } from 'react-router-dom';
|
|
@@ -9,26 +9,24 @@ import { useSwapRoutes } from '../../hooks';
|
|
|
9
9
|
import { useCurrentRoute } from '../../stores';
|
|
10
10
|
import { routes } from '../../utils/routes';
|
|
11
11
|
import { CardContainer, CardTitle } from '../Card';
|
|
12
|
-
import { SwapRouteCard } from '../SwapRouteCard';
|
|
12
|
+
import { SwapRouteCard, SwapRouteCardSkeleton, SwapRouteNotFoundCard, } from '../SwapRouteCard';
|
|
13
13
|
import { Stack } from './SwapRoutes.style';
|
|
14
14
|
import { SwapRoutesUpdateProgress } from './SwapRoutesUpdateProgress';
|
|
15
15
|
export const SwapRoutes = (props) => {
|
|
16
16
|
const { t } = useTranslation();
|
|
17
17
|
const navigate = useNavigate();
|
|
18
18
|
const [currentRoute] = useCurrentRoute();
|
|
19
|
-
const { routes: swapRoutes, isLoading, isFetching } = useSwapRoutes();
|
|
19
|
+
const { routes: swapRoutes, isLoading, isFetching, isFetched, } = useSwapRoutes();
|
|
20
20
|
const handleCardClick = useCallback(() => {
|
|
21
21
|
navigate(routes.swapRoutes);
|
|
22
22
|
}, [navigate]);
|
|
23
|
-
if (!(swapRoutes === null || swapRoutes === void 0 ? void 0 : swapRoutes.length) && !isLoading && !isFetching) {
|
|
23
|
+
if (!(swapRoutes === null || swapRoutes === void 0 ? void 0 : swapRoutes.length) && !isLoading && !isFetching && !isFetched) {
|
|
24
24
|
return null;
|
|
25
25
|
}
|
|
26
|
-
|
|
26
|
+
const routeNotFound = !(swapRoutes === null || swapRoutes === void 0 ? void 0 : swapRoutes.length) && isFetched;
|
|
27
|
+
return (_jsxs(CardContainer, Object.assign({}, props, { children: [_jsx(CardTitle, { children: t('swap.routes') }), !routeNotFound ? (_jsx(SwapRoutesUpdateProgress, { sx: {
|
|
27
28
|
position: 'absolute',
|
|
28
29
|
top: 8,
|
|
29
30
|
right: 8,
|
|
30
|
-
} }), _jsxs(Box, Object.assign({ sx: { display: 'flex', alignItems: 'center' } }, { children: [_jsx(Stack, Object.assign({ direction: "row", py: 2, pl: 2, pr: 1 }, { children: isLoading || isFetching || !currentRoute ? (_jsx(
|
|
31
|
-
borderRadius: theme.shape.borderRadiusSecondary / theme.shape.borderRadius,
|
|
32
|
-
minWidth: '100%',
|
|
33
|
-
}) })) : (_jsx(SwapRouteCard, { minWidth: "100%", route: currentRoute, active: true, dense: true })) })), _jsx(Box, Object.assign({ py: 1, pr: 1 }, { children: _jsx(IconButton, Object.assign({ onClick: handleCardClick, size: "medium", "aria-label": "swap-routes" }, { children: _jsx(KeyboardArrowRightIcon, {}) })) }))] }))] })));
|
|
31
|
+
} })) : null, _jsxs(Box, Object.assign({ sx: { display: 'flex', alignItems: 'center' } }, { children: [_jsx(Stack, Object.assign({ direction: "row", py: 2, pl: 2, pr: routeNotFound ? 2 : 1 }, { children: routeNotFound ? (_jsx(SwapRouteNotFoundCard, { minWidth: "100%", dense: true })) : isLoading || isFetching || !currentRoute ? (_jsx(SwapRouteCardSkeleton, { minWidth: "100%", active: true, dense: true })) : (_jsx(SwapRouteCard, { minWidth: "100%", route: currentRoute, active: true, dense: true })) })), !routeNotFound ? (_jsx(Box, Object.assign({ py: 1, pr: 1 }, { children: _jsx(IconButton, Object.assign({ onClick: handleCardClick, size: "medium", "aria-label": "swap-routes" }, { children: _jsx(KeyboardArrowRightIcon, {}) })) }))) : null] }))] })));
|
|
34
32
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TokenAmount } from '@
|
|
1
|
+
import { TokenAmount } from '@lifi/sdk';
|
|
2
2
|
export declare const tokenAmountMock: TokenAmount;
|
|
3
3
|
export declare const skeletonKey = "skeleton";
|
|
4
4
|
export declare const createTokenAmountSkeletons: () => {
|
|
@@ -9,7 +9,7 @@ export declare const createTokenAmountSkeletons: () => {
|
|
|
9
9
|
symbol: string;
|
|
10
10
|
decimals: number;
|
|
11
11
|
chainId: number;
|
|
12
|
-
coinKey?: import("@
|
|
12
|
+
coinKey?: import("@lifi/sdk").CoinKey | undefined;
|
|
13
13
|
priceUSD?: string | undefined;
|
|
14
14
|
logoURI?: string | undefined;
|
|
15
15
|
}[];
|
package/config/theme.js
CHANGED
|
@@ -13,6 +13,15 @@ const palette = {
|
|
|
13
13
|
success: {
|
|
14
14
|
main: '#0AA65B',
|
|
15
15
|
},
|
|
16
|
+
warning: {
|
|
17
|
+
main: '#FFE668',
|
|
18
|
+
},
|
|
19
|
+
error: {
|
|
20
|
+
main: '#E5452F',
|
|
21
|
+
},
|
|
22
|
+
info: {
|
|
23
|
+
main: '#297EFF',
|
|
24
|
+
},
|
|
16
25
|
};
|
|
17
26
|
export const createTheme = (mode, theme = {}) => {
|
|
18
27
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
@@ -64,7 +73,7 @@ export const createTheme = (mode, theme = {}) => {
|
|
|
64
73
|
},
|
|
65
74
|
},
|
|
66
75
|
MuiButton: {
|
|
67
|
-
styleOverrides: mode === 'dark'
|
|
76
|
+
styleOverrides: Object.assign(Object.assign({}, (mode === 'dark'
|
|
68
77
|
? {
|
|
69
78
|
outlined: {
|
|
70
79
|
color: palette.primary.light,
|
|
@@ -82,7 +91,13 @@ export const createTheme = (mode, theme = {}) => {
|
|
|
82
91
|
},
|
|
83
92
|
},
|
|
84
93
|
}
|
|
85
|
-
:
|
|
94
|
+
: {})), { root: {
|
|
95
|
+
'&.Mui-disabled': {
|
|
96
|
+
color: mode === 'light'
|
|
97
|
+
? 'rgb(0 0 0 / 70%)'
|
|
98
|
+
: 'rgb(255 255 255 / 70%)',
|
|
99
|
+
},
|
|
100
|
+
} }),
|
|
86
101
|
},
|
|
87
102
|
MuiIconButton: {
|
|
88
103
|
styleOverrides: {
|
package/config/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name = "@lifi/widget";
|
|
2
|
-
export declare const version = "1.
|
|
2
|
+
export declare const version = "1.9.0";
|
package/config/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/widget';
|
|
2
|
-
export const version = '1.
|
|
2
|
+
export const version = '1.9.0';
|
package/hooks/useChain.d.ts
CHANGED
package/hooks/useChains.d.ts
CHANGED
|
@@ -18,11 +18,11 @@ export declare const useChains: () => {
|
|
|
18
18
|
isPreviousData: boolean;
|
|
19
19
|
isRefetching: boolean;
|
|
20
20
|
isStale: boolean;
|
|
21
|
-
refetch: <TPageData>(options?: (import("react-query").RefetchOptions & import("react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("react-query").QueryObserverResult<import("@
|
|
21
|
+
refetch: <TPageData>(options?: (import("react-query").RefetchOptions & import("react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("react-query").QueryObserverResult<import("@lifi/types").EVMChain[], unknown>>;
|
|
22
22
|
remove: () => void;
|
|
23
23
|
fetchStatus: import("react-query").FetchStatus;
|
|
24
|
-
chains: import("@
|
|
25
|
-
getChainById: (chainId: number) => import("@
|
|
24
|
+
chains: import("@lifi/types").EVMChain[] | undefined;
|
|
25
|
+
getChainById: (chainId: number) => import("@lifi/types").EVMChain | undefined;
|
|
26
26
|
} | {
|
|
27
27
|
error: null;
|
|
28
28
|
isError: false;
|
|
@@ -43,11 +43,11 @@ export declare const useChains: () => {
|
|
|
43
43
|
isPreviousData: boolean;
|
|
44
44
|
isRefetching: boolean;
|
|
45
45
|
isStale: boolean;
|
|
46
|
-
refetch: <TPageData>(options?: (import("react-query").RefetchOptions & import("react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("react-query").QueryObserverResult<import("@
|
|
46
|
+
refetch: <TPageData>(options?: (import("react-query").RefetchOptions & import("react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("react-query").QueryObserverResult<import("@lifi/types").EVMChain[], unknown>>;
|
|
47
47
|
remove: () => void;
|
|
48
48
|
fetchStatus: import("react-query").FetchStatus;
|
|
49
|
-
chains: import("@
|
|
50
|
-
getChainById: (chainId: number) => import("@
|
|
49
|
+
chains: import("@lifi/types").EVMChain[] | undefined;
|
|
50
|
+
getChainById: (chainId: number) => import("@lifi/types").EVMChain | undefined;
|
|
51
51
|
} | {
|
|
52
52
|
error: unknown;
|
|
53
53
|
isError: true;
|
|
@@ -68,11 +68,11 @@ export declare const useChains: () => {
|
|
|
68
68
|
isPreviousData: boolean;
|
|
69
69
|
isRefetching: boolean;
|
|
70
70
|
isStale: boolean;
|
|
71
|
-
refetch: <TPageData>(options?: (import("react-query").RefetchOptions & import("react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("react-query").QueryObserverResult<import("@
|
|
71
|
+
refetch: <TPageData>(options?: (import("react-query").RefetchOptions & import("react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("react-query").QueryObserverResult<import("@lifi/types").EVMChain[], unknown>>;
|
|
72
72
|
remove: () => void;
|
|
73
73
|
fetchStatus: import("react-query").FetchStatus;
|
|
74
|
-
chains: import("@
|
|
75
|
-
getChainById: (chainId: number) => import("@
|
|
74
|
+
chains: import("@lifi/types").EVMChain[] | undefined;
|
|
75
|
+
getChainById: (chainId: number) => import("@lifi/types").EVMChain | undefined;
|
|
76
76
|
} | {
|
|
77
77
|
error: null;
|
|
78
78
|
isError: false;
|
|
@@ -93,9 +93,9 @@ export declare const useChains: () => {
|
|
|
93
93
|
isPreviousData: boolean;
|
|
94
94
|
isRefetching: boolean;
|
|
95
95
|
isStale: boolean;
|
|
96
|
-
refetch: <TPageData>(options?: (import("react-query").RefetchOptions & import("react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("react-query").QueryObserverResult<import("@
|
|
96
|
+
refetch: <TPageData>(options?: (import("react-query").RefetchOptions & import("react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("react-query").QueryObserverResult<import("@lifi/types").EVMChain[], unknown>>;
|
|
97
97
|
remove: () => void;
|
|
98
98
|
fetchStatus: import("react-query").FetchStatus;
|
|
99
|
-
chains: import("@
|
|
100
|
-
getChainById: (chainId: number) => import("@
|
|
99
|
+
chains: import("@lifi/types").EVMChain[] | undefined;
|
|
100
|
+
getChainById: (chainId: number) => import("@lifi/types").EVMChain | undefined;
|
|
101
101
|
};
|
|
@@ -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,9 @@
|
|
|
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
|
+
isFetched: boolean;
|
|
5
6
|
dataUpdatedAt: number;
|
|
6
7
|
refetchTime: number;
|
|
7
|
-
refetch: <TPageData>(options?: (import("react-query").RefetchOptions & import("react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("react-query").QueryObserverResult<import("@
|
|
8
|
+
refetch: <TPageData>(options?: (import("react-query").RefetchOptions & import("react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("react-query").QueryObserverResult<import("@lifi/types").RoutesResponse, unknown>>;
|
|
8
9
|
};
|
package/hooks/useSwapRoutes.js
CHANGED
|
@@ -7,6 +7,7 @@ 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 Big from 'big.js';
|
|
10
11
|
import { useEffect } from 'react';
|
|
11
12
|
import { useWatch } from 'react-hook-form';
|
|
12
13
|
import { useQuery, useQueryClient } from 'react-query';
|
|
@@ -62,13 +63,11 @@ export const useSwapRoutes = () => {
|
|
|
62
63
|
const refetchInterval = previousDataUpdatedAt
|
|
63
64
|
? Math.min(Math.abs(refetchTime - (Date.now() - previousDataUpdatedAt)), refetchTime)
|
|
64
65
|
: refetchTime;
|
|
65
|
-
const { data, isLoading, isFetching, dataUpdatedAt, refetch } = useQuery(queryKey, ({ queryKey: [_, address, fromChainId, fromTokenAddress, fromTokenAmount, toChainId, toTokenAddress, slippage, enabledBridges, enabledExchanges, routePriority,], signal, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
+
const { data, isLoading, isFetching, isFetched, dataUpdatedAt, refetch } = useQuery(queryKey, ({ queryKey: [_, address, fromChainId, fromTokenAddress, fromTokenAmount, toChainId, toTokenAddress, slippage, enabledBridges, enabledExchanges, routePriority,], signal, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
67
|
var _b;
|
|
67
68
|
return LiFi.getRoutes({
|
|
68
69
|
fromChainId,
|
|
69
|
-
|
|
70
|
-
fromAmount: (Number(fromTokenAmount) *
|
|
71
|
-
Math.pow(10, ((_b = token === null || token === void 0 ? void 0 : token.decimals) !== null && _b !== void 0 ? _b : 0))).toFixed(0),
|
|
70
|
+
fromAmount: Big(Number(fromTokenAmount) * Math.pow(10, ((_b = token === null || token === void 0 ? void 0 : token.decimals) !== null && _b !== void 0 ? _b : 0))).toString(),
|
|
72
71
|
fromTokenAddress,
|
|
73
72
|
toChainId,
|
|
74
73
|
toTokenAddress,
|
|
@@ -97,14 +96,15 @@ export const useSwapRoutes = () => {
|
|
|
97
96
|
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
97
|
const recommendedRoute = data === null || data === void 0 ? void 0 : data.routes[0];
|
|
99
98
|
// we don't want to set the current route again if it's already selected from existing routes
|
|
100
|
-
if (!isCurrentRouteInSet && recommendedRoute) {
|
|
99
|
+
if (!isCurrentRouteInSet && currentRoute !== recommendedRoute) {
|
|
101
100
|
setCurrentRoute(recommendedRoute);
|
|
102
101
|
}
|
|
103
|
-
}, [currentRoute
|
|
102
|
+
}, [currentRoute, data === null || data === void 0 ? void 0 : data.routes, setCurrentRoute]);
|
|
104
103
|
return {
|
|
105
104
|
routes: data === null || data === void 0 ? void 0 : data.routes,
|
|
106
105
|
isLoading: isEnabled && isLoading,
|
|
107
106
|
isFetching,
|
|
107
|
+
isFetched,
|
|
108
108
|
dataUpdatedAt,
|
|
109
109
|
refetchTime,
|
|
110
110
|
refetch,
|
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
|
@@ -68,16 +68,22 @@
|
|
|
68
68
|
"fundsReceived": "You now have {{amount}} {{tokenSymbol}} in your wallet on {{chainName}} chain."
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
|
+
"info": {
|
|
72
|
+
"title": {
|
|
73
|
+
"routeNotFound": "No routes available"
|
|
74
|
+
},
|
|
75
|
+
"message": {
|
|
76
|
+
"routeNotFound": "Try another \"from\" and \"to\" token combination."
|
|
77
|
+
}
|
|
78
|
+
},
|
|
71
79
|
"warning": {
|
|
72
80
|
"title": {
|
|
73
|
-
"
|
|
74
|
-
"insufficientGasOnStartChain": "Insufficient gas on start chain",
|
|
75
|
-
"insufficientGasOnDestinationChain": "Insufficient gas on destination chain"
|
|
81
|
+
"insufficientGas": "Insufficient gas"
|
|
76
82
|
},
|
|
77
83
|
"message": {
|
|
78
|
-
"insufficientFunds": "You don't have enough funds
|
|
79
|
-
"insufficientGasOnStartChain": "
|
|
80
|
-
"insufficientGasOnDestinationChain": "
|
|
84
|
+
"insufficientFunds": "You don't have enough funds for this transaction on the start \"from\" chain.",
|
|
85
|
+
"insufficientGasOnStartChain": "You need to have enough gas to pay for this transaction on the start \"from\" chain.",
|
|
86
|
+
"insufficientGasOnDestinationChain": "You need to have enough gas to pay for this transaction on the destination \"to\" chain."
|
|
81
87
|
}
|
|
82
88
|
},
|
|
83
89
|
"error": {
|
|
@@ -100,7 +106,7 @@
|
|
|
100
106
|
"process": {
|
|
101
107
|
"tokenAllowance": {
|
|
102
108
|
"started": "Setting token allowance.",
|
|
103
|
-
"pending": "Waiting for token allowance
|
|
109
|
+
"pending": "Waiting for token allowance.",
|
|
104
110
|
"done": "Token allowance approved."
|
|
105
111
|
},
|
|
106
112
|
"switchChain": {
|
|
@@ -145,6 +151,10 @@
|
|
|
145
151
|
"extensionNotFound": "Please make sure that only the {{name}} browser extension is active before choosing this wallet."
|
|
146
152
|
},
|
|
147
153
|
"tooltip": {
|
|
154
|
+
"notFound": {
|
|
155
|
+
"title": "Sorry 🥲",
|
|
156
|
+
"text": "We couldn't find this page."
|
|
157
|
+
},
|
|
148
158
|
"progressToNextUpdate": "Displayed data will auto-refresh after {{value}} seconds. Click this circle to update manually."
|
|
149
159
|
}
|
|
150
160
|
}
|
package/i18n/index.d.ts
CHANGED
|
@@ -71,11 +71,17 @@ export declare const resources: {
|
|
|
71
71
|
fundsReceived: string;
|
|
72
72
|
};
|
|
73
73
|
};
|
|
74
|
+
info: {
|
|
75
|
+
title: {
|
|
76
|
+
routeNotFound: string;
|
|
77
|
+
};
|
|
78
|
+
message: {
|
|
79
|
+
routeNotFound: string;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
74
82
|
warning: {
|
|
75
83
|
title: {
|
|
76
|
-
|
|
77
|
-
insufficientGasOnStartChain: string;
|
|
78
|
-
insufficientGasOnDestinationChain: string;
|
|
84
|
+
insufficientGas: string;
|
|
79
85
|
};
|
|
80
86
|
message: {
|
|
81
87
|
insufficientFunds: string;
|
|
@@ -148,6 +154,10 @@ export declare const resources: {
|
|
|
148
154
|
extensionNotFound: string;
|
|
149
155
|
};
|
|
150
156
|
tooltip: {
|
|
157
|
+
notFound: {
|
|
158
|
+
title: string;
|
|
159
|
+
text: string;
|
|
160
|
+
};
|
|
151
161
|
progressToNextUpdate: string;
|
|
152
162
|
};
|
|
153
163
|
};
|
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.9.0",
|
|
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,21 +41,21 @@
|
|
|
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.1",
|
|
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.
|
|
53
|
-
"i18next": "^21.8.
|
|
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
|
+
"i18next": "^21.8.14",
|
|
54
54
|
"immer": "^9.0.15",
|
|
55
55
|
"react": "^18.2.0",
|
|
56
56
|
"react-dom": "^18.2.0",
|
|
57
57
|
"react-hook-form": "^7.33.1",
|
|
58
|
-
"react-i18next": "^11.18.
|
|
58
|
+
"react-i18next": "^11.18.1",
|
|
59
59
|
"react-query": "^4.0.0-beta.23",
|
|
60
60
|
"react-resize-detector": "^7.1.2",
|
|
61
61
|
"react-router-dom": "^6.3.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>, {}, {}>;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export declare const ToggleButton: import("@emotion/styled").StyledComponent<{
|
|
3
3
|
children?: import("react").ReactNode;
|
|
4
4
|
classes?: Partial<import("@mui/material").ToggleButtonClasses> | undefined;
|
|
5
|
-
color?: "success" | "
|
|
5
|
+
color?: "success" | "info" | "warning" | "error" | "primary" | "secondary" | "standard" | undefined;
|
|
6
6
|
disabled?: boolean | undefined;
|
|
7
7
|
disableFocusRipple?: boolean | undefined;
|
|
8
8
|
fullWidth?: boolean | undefined;
|
|
@@ -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;
|