@lifi/widget 1.17.1 → 1.17.2
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/cjs/components/ChainSelect/ChainSelect.d.ts +0 -1
- package/cjs/components/Header/useHeaderActionStore.js +1 -4
- package/cjs/components/Step/CircularProgress.d.ts +0 -1
- package/cjs/components/SwapButton/ButtonTooltip.d.ts +0 -1
- package/cjs/components/SwapInput/SwapInputAdornment.d.ts +0 -1
- package/cjs/components/TokenList/TokenList.js +4 -1
- package/cjs/config/sentry.js +3 -26
- package/cjs/config/version.d.ts +1 -1
- package/cjs/config/version.js +1 -1
- package/cjs/hooks/useGasSufficiency.js +14 -37
- package/cjs/hooks/useRouteExecution.js +1 -4
- package/cjs/hooks/useSwapRoutes.js +1 -4
- package/cjs/hooks/useTelemetry.js +3 -2
- package/cjs/hooks/useTokenBalances.d.ts +1 -1
- package/cjs/hooks/useTokenBalances.js +3 -1
- package/cjs/hooks/useWidgetEvents.js +2 -5
- package/cjs/i18n/index.js +2 -5
- package/cjs/pages/ActiveSwapsPage/ActiveSwapsPage.d.ts +0 -1
- package/cjs/pages/SelectTokenPage/SearchTokenInput.d.ts +0 -1
- package/cjs/pages/SelectWalletPage/SelectWalletPage.d.ts +0 -1
- package/cjs/pages/SettingsPage/AdvancedPreferences.d.ts +0 -1
- package/cjs/pages/SettingsPage/EnabledBridgesSelect.js +1 -4
- package/cjs/pages/SettingsPage/EnabledExchangesSelect.js +1 -4
- package/cjs/pages/SettingsPage/GasPriceSelect.d.ts +0 -1
- package/cjs/pages/SettingsPage/SettingsPage.d.ts +0 -1
- package/cjs/pages/SettingsPage/ShowDestinationWallet.d.ts +0 -1
- package/cjs/pages/SettingsPage/SlippageInput.d.ts +0 -1
- package/cjs/pages/SwapDetailsPage/SwapDetailsPage.js +1 -4
- package/cjs/pages/SwapRoutesPage/SwapRoutesPage.js +2 -4
- package/cjs/providers/SDKProvider/SDKProvider.js +1 -4
- package/cjs/stores/chains/useChainOrder.js +1 -4
- package/cjs/stores/chains/useChainOrderStore.js +1 -4
- package/cjs/stores/route/useExecutingRoutesIds.js +1 -4
- package/cjs/stores/route/useRouteStore.js +1 -4
- package/cjs/stores/route/useSwapHistory.js +1 -4
- package/cjs/stores/route/utils.js +1 -4
- package/cjs/stores/settings/useAppearance.js +1 -4
- package/cjs/stores/settings/useSettings.js +1 -4
- package/cjs/stores/settings/useSettingsStore.js +1 -4
- package/cjs/utils/format.js +1 -4
- package/components/ChainSelect/ChainSelect.d.ts +0 -1
- package/components/Step/CircularProgress.d.ts +0 -1
- package/components/SwapButton/ButtonTooltip.d.ts +0 -1
- package/components/SwapInput/SwapInputAdornment.d.ts +0 -1
- package/components/TokenList/TokenList.js +4 -1
- package/config/version.d.ts +1 -1
- package/config/version.js +1 -1
- package/hooks/useGasSufficiency.js +15 -35
- package/hooks/useTelemetry.js +3 -2
- package/hooks/useTokenBalances.d.ts +1 -1
- package/hooks/useTokenBalances.js +3 -1
- package/package.json +5 -5
- package/pages/ActiveSwapsPage/ActiveSwapsPage.d.ts +0 -1
- package/pages/SelectTokenPage/SearchTokenInput.d.ts +0 -1
- package/pages/SelectWalletPage/SelectWalletPage.d.ts +0 -1
- package/pages/SettingsPage/AdvancedPreferences.d.ts +0 -1
- package/pages/SettingsPage/GasPriceSelect.d.ts +0 -1
- package/pages/SettingsPage/SettingsPage.d.ts +0 -1
- package/pages/SettingsPage/ShowDestinationWallet.d.ts +0 -1
- package/pages/SettingsPage/SlippageInput.d.ts +0 -1
- package/pages/SwapRoutesPage/SwapRoutesPage.js +3 -5
- package/tsconfig.cjs.tsbuildinfo +1 -1
|
@@ -9,27 +9,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import Big from 'big.js';
|
|
11
11
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { SwapFormKey, SwapFormKeyHelper, useLiFi, useWallet, } from '../providers';
|
|
12
|
+
import { useChains } from '.';
|
|
13
|
+
import { useLiFi, useWallet } from '../providers';
|
|
15
14
|
import { useTokenBalances } from './useTokenBalances';
|
|
16
15
|
export const useGasSufficiency = (route) => {
|
|
17
16
|
const lifi = useLiFi();
|
|
18
17
|
const { account } = useWallet();
|
|
19
|
-
const [fromChainId, toChainId, fromToken] = useWatch({
|
|
20
|
-
name: [
|
|
21
|
-
SwapFormKeyHelper.getChainKey('from'),
|
|
22
|
-
SwapFormKeyHelper.getChainKey('to'),
|
|
23
|
-
SwapFormKey.FromToken,
|
|
24
|
-
],
|
|
25
|
-
});
|
|
26
|
-
const fromAmount = useDebouncedWatch(SwapFormKey.FromAmount, 250);
|
|
27
18
|
const { getChainById } = useChains();
|
|
28
|
-
const { tokensWithBalance: fromChainTokenBalances } = useTokenBalances(fromChainId);
|
|
19
|
+
const { tokensWithBalance: fromChainTokenBalances } = useTokenBalances(route === null || route === void 0 ? void 0 : route.fromChainId);
|
|
29
20
|
const [insufficientGas, setInsufficientGas] = useState();
|
|
30
21
|
const checkInsufficientGas = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
-
var _a;
|
|
32
|
-
if (!account.isActive || !route
|
|
22
|
+
var _a, _b;
|
|
23
|
+
if (!account.isActive || !route) {
|
|
33
24
|
setInsufficientGas(undefined);
|
|
34
25
|
return;
|
|
35
26
|
}
|
|
@@ -53,16 +44,15 @@ export const useGasSufficiency = (route) => {
|
|
|
53
44
|
}
|
|
54
45
|
return groupedGasCosts;
|
|
55
46
|
}, {});
|
|
56
|
-
if (gasCosts[fromChainId]
|
|
57
|
-
route.
|
|
58
|
-
gasCosts[fromChainId].tokenAmount = (_a = gasCosts[fromChainId]) === null || _a === void 0 ? void 0 : _a.gasAmount.plus(Big(fromAmount));
|
|
47
|
+
if (route.fromToken.address === ((_a = gasCosts[route.fromChainId]) === null || _a === void 0 ? void 0 : _a.token.address)) {
|
|
48
|
+
gasCosts[route.fromChainId].tokenAmount = (_b = gasCosts[route.fromChainId]) === null || _b === void 0 ? void 0 : _b.gasAmount.plus(Big(route.fromAmount).div(Math.pow(10, route.fromToken.decimals)));
|
|
59
49
|
}
|
|
60
50
|
const tokenBalances = yield lifi.getTokenBalances(account.address, Object.values(gasCosts).map((item) => item.token));
|
|
61
51
|
if (!(tokenBalances === null || tokenBalances === void 0 ? void 0 : tokenBalances.length)) {
|
|
62
52
|
setInsufficientGas(undefined);
|
|
63
53
|
return;
|
|
64
54
|
}
|
|
65
|
-
[fromChainId, toChainId].forEach((chainId) => {
|
|
55
|
+
[route.fromChainId, route.toChainId].forEach((chainId) => {
|
|
66
56
|
var _a, _b, _c, _d, _e, _f;
|
|
67
57
|
if (gasCosts[chainId]) {
|
|
68
58
|
const gasTokenBalance = Big((_b = (_a = tokenBalances === null || tokenBalances === void 0 ? void 0 : tokenBalances.find((t) => t.chainId === gasCosts[chainId].token.chainId &&
|
|
@@ -78,27 +68,17 @@ export const useGasSufficiency = (route) => {
|
|
|
78
68
|
});
|
|
79
69
|
const gasCostResult = Object.values(gasCosts).filter((gasCost) => gasCost.insufficient);
|
|
80
70
|
setInsufficientGas(gasCostResult);
|
|
81
|
-
}), [
|
|
82
|
-
account.address,
|
|
83
|
-
account.isActive,
|
|
84
|
-
fromAmount,
|
|
85
|
-
fromChainId,
|
|
86
|
-
getChainById,
|
|
87
|
-
lifi,
|
|
88
|
-
route,
|
|
89
|
-
toChainId,
|
|
90
|
-
]);
|
|
71
|
+
}), [account.address, account.isActive, getChainById, lifi, route]);
|
|
91
72
|
const insufficientFunds = useMemo(() => {
|
|
92
73
|
var _a, _b;
|
|
93
|
-
if (!account.isActive ||
|
|
94
|
-
!fromToken ||
|
|
95
|
-
!fromAmount ||
|
|
96
|
-
!fromChainTokenBalances) {
|
|
74
|
+
if (!account.isActive || !fromChainTokenBalances || !route) {
|
|
97
75
|
return false;
|
|
98
76
|
}
|
|
99
|
-
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);
|
|
100
|
-
return Big(fromAmount)
|
|
101
|
-
|
|
77
|
+
const balance = Big((_b = (_a = fromChainTokenBalances === null || fromChainTokenBalances === void 0 ? void 0 : fromChainTokenBalances.find((t) => t.address === (route === null || route === void 0 ? void 0 : route.fromToken.address))) === null || _a === void 0 ? void 0 : _a.amount) !== null && _b !== void 0 ? _b : 0);
|
|
78
|
+
return Big(route.fromAmount)
|
|
79
|
+
.div(Math.pow(10, route.fromToken.decimals))
|
|
80
|
+
.gt(balance);
|
|
81
|
+
}, [account.isActive, fromChainTokenBalances, route]);
|
|
102
82
|
useEffect(() => {
|
|
103
83
|
checkInsufficientGas();
|
|
104
84
|
}, [checkInsufficientGas]);
|
package/hooks/useTelemetry.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/* eslint-disable consistent-return */
|
|
2
2
|
import { useEffect } from 'react';
|
|
3
3
|
import { initSentry } from '../config/sentry';
|
|
4
|
+
import { name } from '../config/version';
|
|
4
5
|
export const useTelemetry = (disabled) => {
|
|
5
6
|
useEffect(() => {
|
|
6
7
|
if (disabled) {
|
|
7
|
-
if (process.env.NODE_ENV === '
|
|
8
|
-
console.warn(
|
|
8
|
+
if (process.env.NODE_ENV === 'development') {
|
|
9
|
+
console.warn(`[${name}] Enable crash reports and diagnostic data to be collected. This helps us to better understand how the widget is performing and where improvements need to be made.`);
|
|
9
10
|
}
|
|
10
11
|
}
|
|
11
12
|
else {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Token } from '../types';
|
|
2
|
-
export declare const useTokenBalances: (selectedChainId
|
|
2
|
+
export declare const useTokenBalances: (selectedChainId?: number) => {
|
|
3
3
|
tokens: Token[] | undefined;
|
|
4
4
|
tokensWithBalance: Token[] | undefined;
|
|
5
5
|
featuredTokens: import("@lifi/types").Token[];
|
|
@@ -22,7 +22,9 @@ export const useTokenBalances = (selectedChainId) => {
|
|
|
22
22
|
const featuredTokens = useFeaturedTokens(selectedChainId);
|
|
23
23
|
const { tokens, isLoading } = useTokens(selectedChainId);
|
|
24
24
|
const [refetchInterval, setRefetchInterval] = useState(defaultRefetchInterval);
|
|
25
|
-
const isBalanceLoadingEnabled = Boolean(account.address) &&
|
|
25
|
+
const isBalanceLoadingEnabled = Boolean(account.address) &&
|
|
26
|
+
Boolean(tokens === null || tokens === void 0 ? void 0 : tokens.length) &&
|
|
27
|
+
Boolean(selectedChainId);
|
|
26
28
|
const { data: tokensWithBalance, isLoading: isBalanceLoading, refetch, } = useQuery(['token-balances', account.address, selectedChainId, tokens === null || tokens === void 0 ? void 0 : tokens.length], ({ queryKey: [, accountAddress] }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
29
|
if (!accountAddress || !tokens) {
|
|
28
30
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/widget",
|
|
3
|
-
"version": "1.17.
|
|
3
|
+
"version": "1.17.2",
|
|
4
4
|
"description": "LI.FI Widget for cross-chain bridging and swapping. It will drive your multi-chain strategy and attract new users from everywhere.",
|
|
5
5
|
"main": "./cjs/index.js",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
"@emotion/styled": "^11.10.4",
|
|
42
42
|
"@ethersproject/address": "^5.7.0",
|
|
43
43
|
"@ethersproject/experimental": "^5.7.0",
|
|
44
|
-
"@ethersproject/providers": "^5.7.
|
|
45
|
-
"@lifi/sdk": "^1.
|
|
46
|
-
"@lifi/wallet-management": "^1.1.
|
|
44
|
+
"@ethersproject/providers": "^5.7.1",
|
|
45
|
+
"@lifi/sdk": "^1.6.0",
|
|
46
|
+
"@lifi/wallet-management": "^1.1.10",
|
|
47
47
|
"@mui/icons-material": "^5.10.3",
|
|
48
48
|
"@mui/lab": "^5.0.0-alpha.99",
|
|
49
49
|
"@mui/material": "^5.10.5",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"react-dom": "^18.2.0",
|
|
62
62
|
"react-hook-form": "^7.35.0",
|
|
63
63
|
"react-i18next": "^11.18.6",
|
|
64
|
-
"react-router-dom": "^6.
|
|
64
|
+
"react-router-dom": "^6.4.0",
|
|
65
65
|
"react-timer-hook": "^3.0.5",
|
|
66
66
|
"zustand": "^4.1.1"
|
|
67
67
|
},
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect } from 'react';
|
|
3
|
-
import { useLocation, useNavigate } from 'react-router-dom';
|
|
4
3
|
import { useHeaderActionStore } from '../../components/Header';
|
|
5
4
|
import { ProgressToNextUpdate } from '../../components/ProgressToNextUpdate';
|
|
6
5
|
import { SwapRouteCard, SwapRouteCardSkeleton, SwapRouteNotFoundCard, } from '../../components/SwapRouteCard';
|
|
7
|
-
import { useSwapRoutes } from '../../hooks';
|
|
6
|
+
import { useNavigateBack, useSwapRoutes } from '../../hooks';
|
|
8
7
|
import { useSetExecutableRoute } from '../../stores';
|
|
9
8
|
import { navigationRoutes } from '../../utils';
|
|
10
9
|
import { Stack } from './SwapRoutesPage.style';
|
|
11
10
|
export const SwapRoutesPage = () => {
|
|
12
|
-
const navigate =
|
|
13
|
-
const { pathname } = useLocation();
|
|
11
|
+
const { navigateBack, navigate } = useNavigateBack();
|
|
14
12
|
const { routes: swapRoutes, isLoading, isFetching, dataUpdatedAt, refetchTime, refetch, } = useSwapRoutes();
|
|
15
13
|
const setExecutableRoute = useSetExecutableRoute();
|
|
16
14
|
const handleRouteClick = (route) => {
|
|
@@ -21,7 +19,7 @@ export const SwapRoutesPage = () => {
|
|
|
21
19
|
};
|
|
22
20
|
useEffect(() => {
|
|
23
21
|
if (!(swapRoutes === null || swapRoutes === void 0 ? void 0 : swapRoutes.length) && !isLoading && !isFetching) {
|
|
24
|
-
|
|
22
|
+
navigateBack();
|
|
25
23
|
}
|
|
26
24
|
// redirect to the home page if no routes are found on page reload
|
|
27
25
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|