@lifi/widget 1.32.7 → 2.0.0-alpha.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/AppDrawer.js +4 -3
- package/AppDrawer.style.d.ts +5 -5
- package/cjs/App.js +3 -3
- package/cjs/AppDrawer.js +4 -3
- package/cjs/AppDrawer.style.d.ts +5 -5
- package/cjs/components/ActiveSwaps/ActiveSwaps.style.d.ts +3 -3
- package/cjs/components/Card/CardIconButton.d.ts +29 -0
- package/cjs/components/Card/CardIconButton.js +17 -0
- package/cjs/components/Card/CardLabel.d.ts +26 -0
- package/cjs/components/Card/CardLabel.js +45 -0
- package/cjs/components/Card/CardTitle.d.ts +2 -2
- package/cjs/components/Card/index.d.ts +2 -0
- package/cjs/components/Card/index.js +2 -0
- package/cjs/components/GasMessage/FundsSufficiencyMessage.d.ts +1 -0
- package/cjs/components/GasMessage/FundsSufficiencyMessage.js +16 -0
- package/cjs/components/{GasSufficiencyMessage/GasSufficiencyMessage.d.ts → GasMessage/GasMessage.d.ts} +4 -2
- package/cjs/components/GasMessage/GasMessage.js +19 -0
- package/cjs/components/GasMessage/GasMessage.style.d.ts +34 -0
- package/cjs/components/GasMessage/GasMessage.style.js +48 -0
- package/cjs/components/GasMessage/GasRefuelMessage.d.ts +3 -0
- package/cjs/components/GasMessage/GasRefuelMessage.js +26 -0
- package/cjs/components/GasMessage/GasSufficiencyMessage.d.ts +7 -0
- package/cjs/components/GasMessage/GasSufficiencyMessage.js +21 -0
- package/cjs/components/GasMessage/index.d.ts +2 -0
- package/cjs/components/GasMessage/index.js +18 -0
- package/cjs/components/Header/Header.style.d.ts +5 -5
- package/cjs/components/Header/NavigationHeader.js +4 -4
- package/cjs/components/Header/WalletHeader.js +5 -5
- package/cjs/components/Insurance/Insurance.d.ts +3 -0
- package/cjs/components/Insurance/Insurance.js +11 -0
- package/cjs/components/Insurance/InsuranceCard.d.ts +3 -0
- package/cjs/components/Insurance/InsuranceCard.js +20 -0
- package/cjs/components/Insurance/InsuranceCollapsed.d.ts +3 -0
- package/cjs/components/Insurance/InsuranceCollapsed.js +32 -0
- package/cjs/components/Insurance/index.d.ts +1 -0
- package/cjs/components/{GasSufficiencyMessage → Insurance}/index.js +1 -1
- package/cjs/components/Insurance/types.d.ts +14 -0
- package/cjs/components/Insurance/types.js +2 -0
- package/cjs/components/NFT/NFT.style.d.ts +1 -1
- package/cjs/components/PoweredBy/PoweredBy.style.d.ts +1 -1
- package/cjs/components/ReverseTokensButton/ReverseTokensButton.style.d.ts +2 -2
- package/cjs/components/SendToWallet/SendToWallet.js +31 -25
- package/cjs/components/SendToWallet/SendToWallet.style.d.ts +2 -2
- package/cjs/components/SendToWallet/SendToWalletButton.js +3 -3
- package/cjs/components/SmallAvatar.d.ts +2 -2
- package/cjs/components/Step/CircularProgress.style.d.ts +1 -1
- package/cjs/components/Step/DestinationWalletAddress.js +2 -2
- package/cjs/components/Step/GasStepProcess.js +2 -2
- package/cjs/components/Step/Step.js +7 -5
- package/cjs/components/Step/StepList.d.ts +1 -1
- package/cjs/components/Step/StepProcess.style.d.ts +3 -3
- package/cjs/components/StepActions/StepActions.d.ts +5 -0
- package/cjs/components/StepActions/StepActions.js +55 -17
- package/cjs/components/StepActions/StepActions.style.d.ts +1 -1
- package/cjs/components/SwapButton/SwapButton.js +2 -2
- package/cjs/components/SwapButton/types.d.ts +1 -2
- package/cjs/components/SwapInput/SwapInput.style.d.ts +2 -2
- package/cjs/components/SwapInput/SwapInputAdornment.style.d.ts +3 -3
- package/cjs/components/SwapInput/SwapInputEndAdornment.js +18 -1
- package/cjs/components/SwapRouteCard/SwapRouteCard.d.ts +1 -2
- package/cjs/components/SwapRouteCard/SwapRouteCard.js +10 -26
- package/cjs/components/SwapRouteCard/SwapRouteCard.style.d.ts +4 -36
- package/cjs/components/SwapRouteCard/SwapRouteCard.style.js +7 -38
- package/cjs/components/SwapRouteCard/SwapRouteCardEssentials.d.ts +3 -0
- package/cjs/components/SwapRouteCard/SwapRouteCardEssentials.js +27 -0
- package/cjs/components/SwapRouteCard/SwapRouteCardSkeleton.js +5 -5
- package/cjs/components/SwapRouteCard/types.d.ts +2 -2
- package/cjs/components/SwapRouteCard/utils.d.ts +5 -0
- package/cjs/components/SwapRouteCard/utils.js +32 -2
- package/cjs/components/SwapRoutes/SwapRoutes.js +3 -12
- package/cjs/components/SwapRoutes/SwapRoutesExpanded.js +3 -5
- package/cjs/components/SwapRoutes/{SwapRoutes.style.d.ts → SwapRoutesExpanded.style.d.ts} +0 -9
- package/cjs/components/SwapRoutes/{SwapRoutes.style.js → SwapRoutesExpanded.style.js} +1 -12
- package/cjs/components/Switch.js +4 -4
- package/cjs/components/TextFitter/TextFitter.js +9 -3
- package/cjs/components/Token/Token.style.d.ts +2 -2
- package/cjs/config/theme.js +1 -1
- package/cjs/config/version.d.ts +1 -1
- package/cjs/config/version.js +1 -1
- package/cjs/hooks/index.d.ts +4 -0
- package/cjs/hooks/index.js +4 -0
- package/cjs/hooks/useChains.js +2 -2
- package/cjs/hooks/useFeaturedTokens.d.ts +1 -1
- package/cjs/hooks/useFeaturedTokens.js +2 -2
- package/cjs/hooks/useFundsSufficiency.d.ts +5 -0
- package/cjs/hooks/useFundsSufficiency.js +73 -0
- package/cjs/hooks/useGasRecommendation.d.ts +2 -0
- package/cjs/hooks/useGasRecommendation.js +23 -0
- package/cjs/hooks/useGasRefuel.d.ts +7 -0
- package/cjs/hooks/useGasRefuel.js +61 -0
- package/cjs/hooks/useGasSufficiency.d.ts +2 -3
- package/cjs/hooks/useGasSufficiency.js +6 -37
- package/cjs/hooks/useGetTokenBalancesWithRetry.d.ts +3 -0
- package/cjs/hooks/useGetTokenBalancesWithRetry.js +33 -0
- package/cjs/hooks/useSwapRoutes.d.ts +7 -2
- package/cjs/hooks/useSwapRoutes.js +31 -11
- package/cjs/hooks/useTokenAddressBalance.js +4 -2
- package/cjs/hooks/useTokenBalance.js +4 -22
- package/cjs/hooks/useTokenBalances.d.ts +1 -1
- package/cjs/hooks/useTokenSearch.js +2 -2
- package/cjs/hooks/useTokens.js +2 -3
- package/cjs/i18n/en.json +14 -7
- package/cjs/i18n/it.json +6 -2
- package/cjs/i18n/pt.json +234 -0
- package/cjs/i18n/uk.json +5 -1
- package/cjs/icons/InsuraceLogo.d.ts +2 -0
- package/cjs/icons/InsuraceLogo.js +11 -0
- package/cjs/icons/index.d.ts +1 -0
- package/cjs/icons/index.js +1 -0
- package/cjs/index.d.ts +0 -6
- package/cjs/index.js +1 -6
- package/cjs/pages/MainPage/MainGasMessage.d.ts +3 -0
- package/cjs/pages/MainPage/MainGasMessage.js +12 -0
- package/cjs/pages/MainPage/MainPage.js +3 -2
- package/cjs/pages/MainPage/MainSwapButton.js +1 -1
- package/cjs/pages/SettingsPage/ColorSchemeButtonGroup.js +2 -2
- package/cjs/pages/SettingsPage/ColorSchemeButtonGroup.style.d.ts +2 -2
- package/cjs/pages/SettingsPage/ResetSettingsButton.js +3 -1
- package/cjs/pages/SettingsPage/RoutePrioritySelect.js +1 -1
- package/cjs/pages/SwapDetailsPage/SwapDetailsPage.js +4 -3
- package/cjs/pages/SwapPage/ExchangeRateBottomSheet.d.ts +1 -2
- package/cjs/pages/SwapPage/ExchangeRateBottomSheet.js +1 -14
- package/cjs/pages/SwapPage/StartSwapButton.d.ts +3 -2
- package/cjs/pages/SwapPage/StartSwapButton.js +14 -4
- package/cjs/pages/SwapPage/SwapPage.js +18 -7
- package/cjs/pages/SwapPage/types.d.ts +9 -0
- package/cjs/pages/SwapPage/types.js +2 -0
- package/cjs/pages/SwapRoutesPage/SwapRoutesPage.js +1 -1
- package/cjs/providers/SDKProvider/SDKProvider.d.ts +2 -2
- package/cjs/providers/SDKProvider/SDKProvider.js +2 -1
- package/cjs/providers/SwapFormProvider/FormUpdater.js +2 -3
- package/cjs/providers/WidgetProvider/WidgetProvider.js +17 -4
- package/cjs/providers/WidgetProvider/utils.d.ts +1 -1
- package/cjs/providers/WidgetProvider/utils.js +2 -4
- package/cjs/stores/StoreProvider.js +1 -1
- package/cjs/stores/routes/createRouteExecutionStore.js +3 -2
- package/cjs/stores/routes/index.d.ts +0 -1
- package/cjs/stores/routes/index.js +0 -1
- package/cjs/stores/routes/types.d.ts +1 -5
- package/cjs/stores/routes/useSetExecutableRoute.d.ts +1 -1
- package/cjs/stores/settings/types.d.ts +3 -2
- package/cjs/stores/settings/useSettingsStore.js +3 -1
- package/cjs/types/widget.d.ts +5 -10
- package/cjs/utils/format.js +4 -1
- package/components/ActiveSwaps/ActiveSwaps.style.d.ts +3 -3
- package/components/Card/CardIconButton.d.ts +29 -0
- package/components/Card/CardIconButton.js +14 -0
- package/components/Card/CardLabel.d.ts +26 -0
- package/components/Card/CardLabel.js +42 -0
- package/components/Card/CardTitle.d.ts +2 -2
- package/components/Card/index.d.ts +2 -0
- package/components/Card/index.js +2 -0
- package/components/GasMessage/FundsSufficiencyMessage.d.ts +1 -0
- package/components/GasMessage/FundsSufficiencyMessage.js +12 -0
- package/components/{GasSufficiencyMessage/GasSufficiencyMessage.d.ts → GasMessage/GasMessage.d.ts} +4 -2
- package/components/GasMessage/GasMessage.js +15 -0
- package/components/GasMessage/GasMessage.style.d.ts +34 -0
- package/components/GasMessage/GasMessage.style.js +45 -0
- package/components/GasMessage/GasRefuelMessage.d.ts +3 -0
- package/components/GasMessage/GasRefuelMessage.js +22 -0
- package/components/GasMessage/GasSufficiencyMessage.d.ts +7 -0
- package/components/GasMessage/GasSufficiencyMessage.js +17 -0
- package/components/GasMessage/index.d.ts +2 -0
- package/components/GasMessage/index.js +2 -0
- package/components/Header/Header.style.d.ts +5 -5
- package/components/Header/NavigationHeader.js +4 -4
- package/components/Header/WalletHeader.js +6 -6
- package/components/Insurance/Insurance.d.ts +3 -0
- package/components/Insurance/Insurance.js +7 -0
- package/components/Insurance/InsuranceCard.d.ts +3 -0
- package/components/Insurance/InsuranceCard.js +16 -0
- package/components/Insurance/InsuranceCollapsed.d.ts +3 -0
- package/components/Insurance/InsuranceCollapsed.js +28 -0
- package/components/Insurance/index.d.ts +1 -0
- package/components/Insurance/index.js +1 -0
- package/components/Insurance/types.d.ts +14 -0
- package/components/Insurance/types.js +1 -0
- package/components/NFT/NFT.style.d.ts +1 -1
- package/components/PoweredBy/PoweredBy.style.d.ts +1 -1
- package/components/ReverseTokensButton/ReverseTokensButton.style.d.ts +2 -2
- package/components/SendToWallet/SendToWallet.js +34 -28
- package/components/SendToWallet/SendToWallet.style.d.ts +2 -2
- package/components/SendToWallet/SendToWalletButton.js +4 -4
- package/components/SmallAvatar.d.ts +2 -2
- package/components/Step/CircularProgress.style.d.ts +1 -1
- package/components/Step/DestinationWalletAddress.js +2 -2
- package/components/Step/GasStepProcess.js +2 -2
- package/components/Step/Step.js +7 -5
- package/components/Step/StepList.d.ts +1 -1
- package/components/Step/StepProcess.style.d.ts +3 -3
- package/components/StepActions/StepActions.d.ts +5 -0
- package/components/StepActions/StepActions.js +52 -16
- package/components/StepActions/StepActions.style.d.ts +1 -1
- package/components/SwapButton/SwapButton.js +2 -2
- package/components/SwapButton/types.d.ts +1 -2
- package/components/SwapInput/SwapInput.style.d.ts +2 -2
- package/components/SwapInput/SwapInputAdornment.style.d.ts +3 -3
- package/components/SwapInput/SwapInputEndAdornment.js +19 -2
- package/components/SwapRouteCard/SwapRouteCard.d.ts +1 -2
- package/components/SwapRouteCard/SwapRouteCard.js +11 -26
- package/components/SwapRouteCard/SwapRouteCard.style.d.ts +4 -36
- package/components/SwapRouteCard/SwapRouteCard.style.js +7 -38
- package/components/SwapRouteCard/SwapRouteCardEssentials.d.ts +3 -0
- package/components/SwapRouteCard/SwapRouteCardEssentials.js +23 -0
- package/components/SwapRouteCard/SwapRouteCardSkeleton.js +5 -5
- package/components/SwapRouteCard/types.d.ts +2 -2
- package/components/SwapRouteCard/utils.d.ts +5 -0
- package/components/SwapRouteCard/utils.js +30 -1
- package/components/SwapRoutes/SwapRoutes.js +5 -14
- package/components/SwapRoutes/SwapRoutesExpanded.js +2 -4
- package/components/SwapRoutes/{SwapRoutes.style.d.ts → SwapRoutesExpanded.style.d.ts} +0 -9
- package/components/SwapRoutes/{SwapRoutes.style.js → SwapRoutesExpanded.style.js} +1 -12
- package/components/Switch.js +5 -5
- package/components/TextFitter/TextFitter.js +9 -3
- package/components/Token/Token.style.d.ts +2 -2
- package/config/theme.js +1 -1
- package/config/version.d.ts +1 -1
- package/config/version.js +1 -1
- package/hooks/index.d.ts +4 -0
- package/hooks/index.js +4 -0
- package/hooks/useChains.js +2 -2
- package/hooks/useFeaturedTokens.d.ts +1 -1
- package/hooks/useFeaturedTokens.js +2 -2
- package/hooks/useFundsSufficiency.d.ts +5 -0
- package/hooks/useFundsSufficiency.js +69 -0
- package/hooks/useGasRecommendation.d.ts +2 -0
- package/hooks/useGasRecommendation.js +19 -0
- package/hooks/useGasRefuel.d.ts +7 -0
- package/hooks/useGasRefuel.js +57 -0
- package/hooks/useGasSufficiency.d.ts +2 -3
- package/hooks/useGasSufficiency.js +7 -38
- package/hooks/useGetTokenBalancesWithRetry.d.ts +3 -0
- package/hooks/useGetTokenBalancesWithRetry.js +29 -0
- package/hooks/useSwapRoutes.d.ts +7 -2
- package/hooks/useSwapRoutes.js +32 -12
- package/hooks/useTokenAddressBalance.js +4 -2
- package/hooks/useTokenBalance.js +5 -23
- package/hooks/useTokenBalances.d.ts +1 -1
- package/hooks/useTokenSearch.js +2 -2
- package/hooks/useTokens.js +2 -3
- package/i18n/en.json +14 -7
- package/i18n/it.json +6 -2
- package/i18n/pt.json +234 -0
- package/i18n/uk.json +5 -1
- package/icons/InsuraceLogo.d.ts +2 -0
- package/icons/InsuraceLogo.js +7 -0
- package/icons/index.d.ts +1 -0
- package/icons/index.js +1 -0
- package/index.d.ts +0 -6
- package/index.js +0 -5
- package/package.json +12 -11
- package/pages/ActiveSwapsPage/ActiveSwapsPage.js +2 -2
- package/pages/MainPage/MainGasMessage.d.ts +3 -0
- package/pages/MainPage/MainGasMessage.js +8 -0
- package/pages/MainPage/MainPage.js +3 -2
- package/pages/MainPage/MainSwapButton.js +1 -1
- package/pages/SettingsPage/ColorSchemeButtonGroup.js +2 -2
- package/pages/SettingsPage/ColorSchemeButtonGroup.style.d.ts +2 -2
- package/pages/SettingsPage/ResetSettingsButton.js +3 -1
- package/pages/SettingsPage/RoutePrioritySelect.js +1 -1
- package/pages/SwapDetailsPage/SwapDetailsPage.js +5 -4
- package/pages/SwapHistoryPage/SwapHistoryPage.js +2 -2
- package/pages/SwapPage/ExchangeRateBottomSheet.d.ts +1 -2
- package/pages/SwapPage/ExchangeRateBottomSheet.js +0 -12
- package/pages/SwapPage/StartSwapButton.d.ts +3 -2
- package/pages/SwapPage/StartSwapButton.js +13 -4
- package/pages/SwapPage/SwapPage.js +21 -10
- package/pages/SwapPage/types.d.ts +9 -0
- package/pages/SwapPage/types.js +1 -0
- package/pages/SwapRoutesPage/SwapRoutesPage.js +1 -1
- package/providers/SDKProvider/SDKProvider.d.ts +2 -2
- package/providers/SDKProvider/SDKProvider.js +3 -2
- package/providers/SwapFormProvider/FormUpdater.js +2 -3
- package/providers/WidgetProvider/WidgetProvider.js +17 -4
- package/providers/WidgetProvider/utils.d.ts +1 -1
- package/providers/WidgetProvider/utils.js +2 -4
- package/stores/StoreProvider.js +2 -2
- package/stores/routes/createRouteExecutionStore.js +3 -2
- package/stores/routes/index.d.ts +0 -1
- package/stores/routes/index.js +0 -1
- package/stores/routes/types.d.ts +1 -5
- package/stores/routes/useSetExecutableRoute.d.ts +1 -1
- package/stores/settings/types.d.ts +3 -2
- package/stores/settings/useSettingsStore.js +3 -1
- package/tsconfig.cjs.tsbuildinfo +1 -1
- package/types/widget.d.ts +5 -10
- package/utils/format.js +4 -1
- package/cjs/components/GasSufficiencyMessage/GasSufficiencyMessage.js +0 -31
- package/cjs/components/GasSufficiencyMessage/GasSufficiencyMessage.style.d.ts +0 -9
- package/cjs/components/GasSufficiencyMessage/GasSufficiencyMessage.style.js +0 -14
- package/cjs/components/GasSufficiencyMessage/index.d.ts +0 -1
- package/cjs/components/SwapRoutes/useSetRecommendedRoute.d.ts +0 -2
- package/cjs/components/SwapRoutes/useSetRecommendedRoute.js +0 -13
- package/cjs/config/env.d.ts +0 -3
- package/cjs/config/env.js +0 -6
- package/cjs/stores/routes/useRecommendedRouteStore.d.ts +0 -10
- package/cjs/stores/routes/useRecommendedRouteStore.js +0 -39
- package/components/GasSufficiencyMessage/GasSufficiencyMessage.js +0 -27
- package/components/GasSufficiencyMessage/GasSufficiencyMessage.style.d.ts +0 -9
- package/components/GasSufficiencyMessage/GasSufficiencyMessage.style.js +0 -11
- package/components/GasSufficiencyMessage/index.d.ts +0 -1
- package/components/GasSufficiencyMessage/index.js +0 -1
- package/components/SwapRoutes/useSetRecommendedRoute.d.ts +0 -2
- package/components/SwapRoutes/useSetRecommendedRoute.js +0 -9
- package/config/env.d.ts +0 -3
- package/config/env.js +0 -3
- package/stores/routes/useRecommendedRouteStore.d.ts +0 -10
- package/stores/routes/useRecommendedRouteStore.js +0 -32
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query';
|
|
2
|
+
import Big from 'big.js';
|
|
3
|
+
import { useWatch } from 'react-hook-form';
|
|
4
|
+
import { SwapFormKey, useWallet } from '../providers';
|
|
5
|
+
import { isRouteDone } from '../stores';
|
|
6
|
+
import { useGetTokenBalancesWithRetry } from './useGetTokenBalancesWithRetry';
|
|
7
|
+
import { useTokenAddressBalance } from './useTokenAddressBalance';
|
|
8
|
+
const refetchInterval = 30000;
|
|
9
|
+
export const useFundsSufficiency = (route) => {
|
|
10
|
+
const { account, provider } = useWallet();
|
|
11
|
+
const getTokenBalancesWithRetry = useGetTokenBalancesWithRetry(provider);
|
|
12
|
+
const [fromChainId, fromTokenAddress, fromAmount] = useWatch({
|
|
13
|
+
name: [
|
|
14
|
+
SwapFormKey.FromChain,
|
|
15
|
+
SwapFormKey.FromToken,
|
|
16
|
+
SwapFormKey.FromAmount,
|
|
17
|
+
],
|
|
18
|
+
});
|
|
19
|
+
let chainId = fromChainId;
|
|
20
|
+
let tokenAddress = fromTokenAddress;
|
|
21
|
+
if (route) {
|
|
22
|
+
chainId = route.fromToken.chainId;
|
|
23
|
+
tokenAddress = route.fromToken.address;
|
|
24
|
+
}
|
|
25
|
+
const { token, isLoading } = useTokenAddressBalance(chainId, tokenAddress);
|
|
26
|
+
const { data: insufficientFunds, isInitialLoading } = useQuery([
|
|
27
|
+
'funds-sufficiency-check',
|
|
28
|
+
account.address,
|
|
29
|
+
chainId,
|
|
30
|
+
tokenAddress,
|
|
31
|
+
route?.id ?? fromAmount,
|
|
32
|
+
], async () => {
|
|
33
|
+
if (!account.address || !token) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
let currentTokenBalance = Big(token?.amount || 0);
|
|
37
|
+
if (!route || isRouteDone(route)) {
|
|
38
|
+
const insufficientFunds = currentTokenBalance.lt(Big(fromAmount || 0));
|
|
39
|
+
return insufficientFunds;
|
|
40
|
+
}
|
|
41
|
+
const currentAction = route.steps.filter((step) => !step.execution || step.execution.status !== 'DONE')[0]?.action;
|
|
42
|
+
if (token.chainId === currentAction.fromToken.chainId &&
|
|
43
|
+
token.address === currentAction.fromToken.address &&
|
|
44
|
+
currentTokenBalance.gt(0)) {
|
|
45
|
+
const insufficientFunds = Big(route.fromAmount)
|
|
46
|
+
.div(10 ** route.fromToken.decimals)
|
|
47
|
+
.gt(currentTokenBalance);
|
|
48
|
+
return insufficientFunds;
|
|
49
|
+
}
|
|
50
|
+
const tokenBalances = await getTokenBalancesWithRetry(account.address, [
|
|
51
|
+
currentAction.fromToken,
|
|
52
|
+
]);
|
|
53
|
+
currentTokenBalance = Big(tokenBalances?.[0]?.amount || 0);
|
|
54
|
+
const insufficientFunds = Big(currentAction.fromAmount)
|
|
55
|
+
.div(10 ** currentAction.fromToken.decimals)
|
|
56
|
+
.gt(currentTokenBalance);
|
|
57
|
+
return insufficientFunds;
|
|
58
|
+
}, {
|
|
59
|
+
enabled: Boolean(account.address && token && !isLoading),
|
|
60
|
+
refetchInterval,
|
|
61
|
+
staleTime: refetchInterval,
|
|
62
|
+
cacheTime: refetchInterval,
|
|
63
|
+
keepPreviousData: true,
|
|
64
|
+
});
|
|
65
|
+
return {
|
|
66
|
+
insufficientFunds,
|
|
67
|
+
isInitialLoading,
|
|
68
|
+
};
|
|
69
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { useLiFi } from '../providers';
|
|
3
|
+
const refetchInterval = 60000;
|
|
4
|
+
export const useGasRecommendation = (chainId, fromChain, fromToken) => {
|
|
5
|
+
const lifi = useLiFi();
|
|
6
|
+
return useQuery(['gas-recommendation', chainId, fromChain, fromToken], async ({ queryKey: [_, chainId, fromChain, fromToken] }) => {
|
|
7
|
+
const gasRecommendation = await lifi.getGasRecommendation({
|
|
8
|
+
chainId: chainId,
|
|
9
|
+
fromChain: fromChain,
|
|
10
|
+
fromToken: fromToken,
|
|
11
|
+
});
|
|
12
|
+
return gasRecommendation;
|
|
13
|
+
}, {
|
|
14
|
+
enabled: Boolean(chainId),
|
|
15
|
+
refetchInterval,
|
|
16
|
+
staleTime: refetchInterval,
|
|
17
|
+
cacheTime: refetchInterval,
|
|
18
|
+
});
|
|
19
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import Big from 'big.js';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { useWatch } from 'react-hook-form';
|
|
4
|
+
import { useChains } from '.';
|
|
5
|
+
import { SwapFormKey } from '../providers';
|
|
6
|
+
import { useGasRecommendation } from './useGasRecommendation';
|
|
7
|
+
import { useTokenBalance } from './useTokenBalance';
|
|
8
|
+
export const useGasRefuel = () => {
|
|
9
|
+
const { getChainById } = useChains();
|
|
10
|
+
const [fromChainId, fromTokenAddress, toChainId, toTokenAddress, toAddress] = useWatch({
|
|
11
|
+
name: [
|
|
12
|
+
SwapFormKey.FromChain,
|
|
13
|
+
SwapFormKey.FromToken,
|
|
14
|
+
SwapFormKey.ToChain,
|
|
15
|
+
SwapFormKey.ToToken,
|
|
16
|
+
SwapFormKey.ToAddress,
|
|
17
|
+
],
|
|
18
|
+
});
|
|
19
|
+
const toChain = getChainById(toChainId);
|
|
20
|
+
const { token: nativeToken } = useTokenBalance(toChainId && toChain?.nativeToken, toAddress);
|
|
21
|
+
const { data: gasRecommendation, isLoading } = useGasRecommendation(toChainId, fromChainId, fromTokenAddress);
|
|
22
|
+
const enabled = useMemo(() => {
|
|
23
|
+
if (
|
|
24
|
+
// We don't allow same chain refuel.
|
|
25
|
+
// If a user runs out of gas, he can't send a source chain transaction.
|
|
26
|
+
fromChainId === toChainId ||
|
|
27
|
+
// We don't want to apply auto refuel when swapping to native tokens
|
|
28
|
+
toChain?.nativeToken.address === toTokenAddress ||
|
|
29
|
+
!gasRecommendation?.available ||
|
|
30
|
+
!gasRecommendation.recommended ||
|
|
31
|
+
!nativeToken) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
const tokenBalance = Big(nativeToken.amount ?? 0);
|
|
35
|
+
// check if the user balance < 50% of the recommended amount
|
|
36
|
+
const recommendedAmount = Big(gasRecommendation.recommended.amount)
|
|
37
|
+
.div(10 ** gasRecommendation.recommended.token.decimals)
|
|
38
|
+
.div(2);
|
|
39
|
+
const insufficientGas = tokenBalance.lt(recommendedAmount);
|
|
40
|
+
return insufficientGas;
|
|
41
|
+
}, [
|
|
42
|
+
fromChainId,
|
|
43
|
+
gasRecommendation?.available,
|
|
44
|
+
gasRecommendation?.recommended,
|
|
45
|
+
nativeToken,
|
|
46
|
+
toChain?.nativeToken.address,
|
|
47
|
+
toChainId,
|
|
48
|
+
toTokenAddress,
|
|
49
|
+
]);
|
|
50
|
+
return {
|
|
51
|
+
enabled: enabled,
|
|
52
|
+
availble: gasRecommendation?.available,
|
|
53
|
+
isLoading: isLoading,
|
|
54
|
+
chain: toChain,
|
|
55
|
+
gasRecommendation,
|
|
56
|
+
};
|
|
57
|
+
};
|
|
@@ -9,7 +9,6 @@ export interface GasSufficiency {
|
|
|
9
9
|
chain?: EVMChain;
|
|
10
10
|
}
|
|
11
11
|
export declare const useGasSufficiency: (route?: Route) => {
|
|
12
|
-
insufficientGas: GasSufficiency[] |
|
|
13
|
-
|
|
14
|
-
isLoading: boolean;
|
|
12
|
+
insufficientGas: GasSufficiency[] | undefined;
|
|
13
|
+
isInitialLoading: boolean;
|
|
15
14
|
};
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { useQuery } from '@tanstack/react-query';
|
|
2
2
|
import Big from 'big.js';
|
|
3
|
-
import { useChains } from '.';
|
|
3
|
+
import { useChains, useGetTokenBalancesWithRetry } from '.';
|
|
4
4
|
import { useWallet } from '../providers';
|
|
5
|
-
import { isRouteDone } from '../stores';
|
|
6
|
-
import { useTokenBalance } from './useTokenBalance';
|
|
7
5
|
const refetchInterval = 30000;
|
|
8
6
|
export const useGasSufficiency = (route) => {
|
|
9
|
-
const { account } = useWallet();
|
|
7
|
+
const { account, provider } = useWallet();
|
|
10
8
|
const { getChainById } = useChains();
|
|
11
|
-
const
|
|
12
|
-
const { data: insufficientGas, isInitialLoading
|
|
9
|
+
const getTokenBalancesWithRetry = useGetTokenBalancesWithRetry(provider);
|
|
10
|
+
const { data: insufficientGas, isInitialLoading } = useQuery(['gas-sufficiency-check', account.address, route?.id], async () => {
|
|
13
11
|
if (!account.address || !route) {
|
|
14
|
-
return
|
|
12
|
+
return;
|
|
15
13
|
}
|
|
16
14
|
const gasCosts = route.steps
|
|
17
15
|
.filter((step) => !step.execution || step.execution.status !== 'DONE')
|
|
@@ -39,7 +37,7 @@ export const useGasSufficiency = (route) => {
|
|
|
39
37
|
}
|
|
40
38
|
const tokenBalances = await getTokenBalancesWithRetry(account.address, Object.values(gasCosts).map((item) => item.token));
|
|
41
39
|
if (!tokenBalances?.length) {
|
|
42
|
-
return
|
|
40
|
+
return;
|
|
43
41
|
}
|
|
44
42
|
[route.fromChainId, route.toChainId].forEach((chainId) => {
|
|
45
43
|
if (gasCosts[chainId]) {
|
|
@@ -68,37 +66,8 @@ export const useGasSufficiency = (route) => {
|
|
|
68
66
|
staleTime: refetchInterval,
|
|
69
67
|
cacheTime: refetchInterval,
|
|
70
68
|
});
|
|
71
|
-
const { data: insufficientFunds, isInitialLoading: insufficientFundsLoading, } = useQuery(['funds-sufficiency-check', account.address, route?.id], async () => {
|
|
72
|
-
if (!account.address || !fromToken || !route || isRouteDone(route)) {
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
let currentTokenBalance = Big(fromToken?.amount ?? 0);
|
|
76
|
-
const currentAction = route.steps.filter((step) => !step.execution || step.execution.status !== 'DONE')[0]?.action;
|
|
77
|
-
if (fromToken.chainId === currentAction.fromToken.chainId &&
|
|
78
|
-
fromToken.address === currentAction.fromToken.address &&
|
|
79
|
-
currentTokenBalance.gt(0)) {
|
|
80
|
-
const insufficientFunds = Big(route.fromAmount)
|
|
81
|
-
.div(10 ** route.fromToken.decimals)
|
|
82
|
-
.gt(currentTokenBalance);
|
|
83
|
-
return insufficientFunds;
|
|
84
|
-
}
|
|
85
|
-
const tokenBalances = await getTokenBalancesWithRetry(account.address, [
|
|
86
|
-
currentAction.fromToken,
|
|
87
|
-
]);
|
|
88
|
-
currentTokenBalance = Big(tokenBalances?.[0]?.amount ?? 0);
|
|
89
|
-
const insufficientFunds = Big(currentAction.fromAmount)
|
|
90
|
-
.div(10 ** currentAction.fromToken.decimals)
|
|
91
|
-
.gt(currentTokenBalance);
|
|
92
|
-
return insufficientFunds;
|
|
93
|
-
}, {
|
|
94
|
-
enabled: Boolean(account.address && route && fromToken),
|
|
95
|
-
refetchInterval,
|
|
96
|
-
staleTime: refetchInterval,
|
|
97
|
-
cacheTime: refetchInterval,
|
|
98
|
-
});
|
|
99
69
|
return {
|
|
100
70
|
insufficientGas,
|
|
101
|
-
|
|
102
|
-
isLoading: insufficientGasLoading || insufficientFundsLoading,
|
|
71
|
+
isInitialLoading,
|
|
103
72
|
};
|
|
104
73
|
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Provider } from '@ethersproject/providers';
|
|
2
|
+
import type { Token, TokenAmount } from '@lifi/sdk';
|
|
3
|
+
export declare const useGetTokenBalancesWithRetry: (provider?: Provider) => (accountAddress: string, tokens: Token[], depth?: number) => Promise<TokenAmount[] | undefined>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { isAddress } from '@ethersproject/address';
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
import { useLiFi } from '../providers';
|
|
4
|
+
export const useGetTokenBalancesWithRetry = (provider) => {
|
|
5
|
+
const lifi = useLiFi();
|
|
6
|
+
const getTokenBalancesWithRetry = useCallback(async (accountAddress, tokens, depth = 0) => {
|
|
7
|
+
try {
|
|
8
|
+
const walletAddress = isAddress(accountAddress)
|
|
9
|
+
? accountAddress
|
|
10
|
+
: await provider?.resolveName(accountAddress);
|
|
11
|
+
const tokenBalances = await lifi.getTokenBalances(walletAddress, tokens);
|
|
12
|
+
if (!tokenBalances.every((token) => token.blockNumber)) {
|
|
13
|
+
if (depth > 10) {
|
|
14
|
+
console.warn('Token balance backoff depth exceeded.');
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
await new Promise((resolve) => {
|
|
18
|
+
setTimeout(resolve, 1.5 ** depth * 100);
|
|
19
|
+
});
|
|
20
|
+
return getTokenBalancesWithRetry(accountAddress, tokens, depth + 1);
|
|
21
|
+
}
|
|
22
|
+
return tokenBalances;
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
//
|
|
26
|
+
}
|
|
27
|
+
}, [lifi, provider]);
|
|
28
|
+
return getTokenBalancesWithRetry;
|
|
29
|
+
};
|
package/hooks/useSwapRoutes.d.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import type { Route, RoutesResponse } from '@lifi/sdk';
|
|
2
|
-
|
|
2
|
+
interface SwapRoutesProps {
|
|
3
|
+
onSettled?: (data?: RoutesResponse) => void;
|
|
4
|
+
insurableRoute?: Route;
|
|
5
|
+
}
|
|
6
|
+
export declare const useSwapRoutes: ({ onSettled, insurableRoute, }?: SwapRoutesProps) => {
|
|
3
7
|
routes: Route[] | undefined;
|
|
4
8
|
isLoading: boolean;
|
|
5
9
|
isFetching: boolean;
|
|
6
10
|
isFetched: boolean;
|
|
7
11
|
dataUpdatedAt: number;
|
|
8
12
|
refetchTime: number;
|
|
9
|
-
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<RoutesResponse,
|
|
13
|
+
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<RoutesResponse, unknown>>;
|
|
10
14
|
};
|
|
15
|
+
export {};
|
package/hooks/useSwapRoutes.js
CHANGED
|
@@ -4,18 +4,19 @@ import { useQuery, useQueryClient } from '@tanstack/react-query';
|
|
|
4
4
|
import Big from 'big.js';
|
|
5
5
|
import { useWatch } from 'react-hook-form';
|
|
6
6
|
import { v4 as uuidv4 } from 'uuid';
|
|
7
|
-
import { useDebouncedWatch, useToken } from '.';
|
|
7
|
+
import { useDebouncedWatch, useGasRefuel, useToken } from '.';
|
|
8
8
|
import { SwapFormKey, useLiFi, useWallet, useWidgetConfig } from '../providers';
|
|
9
9
|
import { useSettings } from '../stores';
|
|
10
10
|
const refetchTime = 60000;
|
|
11
|
-
export const useSwapRoutes = () => {
|
|
11
|
+
export const useSwapRoutes = ({ onSettled, insurableRoute, } = {}) => {
|
|
12
12
|
const lifi = useLiFi();
|
|
13
|
-
const { variant, sdkConfig } = useWidgetConfig();
|
|
13
|
+
const { variant, sdkConfig, insurance } = useWidgetConfig();
|
|
14
14
|
const { account, provider } = useWallet();
|
|
15
15
|
const queryClient = useQueryClient();
|
|
16
|
-
const { slippage, enabledBridges, enabledExchanges, routePriority } = useSettings([
|
|
16
|
+
const { slippage, enabledBridges, enabledAutoRefuel, enabledExchanges, routePriority, } = useSettings([
|
|
17
17
|
'slippage',
|
|
18
18
|
'routePriority',
|
|
19
|
+
'enabledAutoRefuel',
|
|
19
20
|
'enabledBridges',
|
|
20
21
|
'enabledExchanges',
|
|
21
22
|
]);
|
|
@@ -35,6 +36,7 @@ export const useSwapRoutes = () => {
|
|
|
35
36
|
});
|
|
36
37
|
const { token: fromToken } = useToken(fromChainId, fromTokenAddress);
|
|
37
38
|
const { token: toToken } = useToken(toChainId, toTokenAddress);
|
|
39
|
+
const { enabled: enabledRefuel, gasRecommendation } = useGasRefuel();
|
|
38
40
|
const hasAmount = (!isNaN(fromTokenAmount) && Number(fromTokenAmount) > 0) ||
|
|
39
41
|
(!isNaN(toTokenAmount) && Number(toTokenAmount) > 0);
|
|
40
42
|
const contractCallQuoteEnabled = variant === 'nft'
|
|
@@ -66,12 +68,12 @@ export const useSwapRoutes = () => {
|
|
|
66
68
|
routePriority,
|
|
67
69
|
variant,
|
|
68
70
|
sdkConfig?.defaultRouteOptions?.allowSwitchChain,
|
|
71
|
+
enabledRefuel && enabledAutoRefuel,
|
|
72
|
+
gasRecommendation?.fromAmount,
|
|
73
|
+
insurance,
|
|
74
|
+
insurableRoute?.id,
|
|
69
75
|
];
|
|
70
|
-
const
|
|
71
|
-
const refetchInterval = previousDataUpdatedAt
|
|
72
|
-
? Math.min(Math.abs(refetchTime - (Date.now() - previousDataUpdatedAt)), refetchTime)
|
|
73
|
-
: refetchTime;
|
|
74
|
-
const { data, isLoading, isFetching, isFetched, dataUpdatedAt, refetch } = useQuery(queryKey, async ({ queryKey: [_, fromAddress, fromChainId, fromTokenAddress, fromTokenAmount, toAddress, toChainId, toTokenAddress, toTokenAmount, toContractAddress, toContractCallData, toContractGasLimit, slippage, enabledBridges, enabledExchanges, routePriority, variant, allowSwitchChain,], signal, }) => {
|
|
76
|
+
const { data, isLoading, isFetching, isFetched, dataUpdatedAt, refetch } = useQuery(queryKey, async ({ queryKey: [_, fromAddress, fromChainId, fromTokenAddress, fromTokenAmount, toAddress, toChainId, toTokenAddress, toTokenAmount, toContractAddress, toContractCallData, toContractGasLimit, slippage, enabledBridges, enabledExchanges, routePriority, variant, allowSwitchChain, enabledRefuel, gasRecommendationFromAmount, insurance, insurableRouteId,], signal, }) => {
|
|
75
77
|
let toWalletAddress;
|
|
76
78
|
try {
|
|
77
79
|
toWalletAddress =
|
|
@@ -117,9 +119,20 @@ export const useSwapRoutes = () => {
|
|
|
117
119
|
toAddress: toAddress,
|
|
118
120
|
gasCostUSD: contractCallQuote.estimate.gasCosts?.[0].amountUSD,
|
|
119
121
|
steps: [contractCallQuote],
|
|
122
|
+
insurance: { state: 'NOT_INSURABLE', feeAmountUsd: '0' },
|
|
120
123
|
};
|
|
121
124
|
return { routes: [route] };
|
|
122
125
|
}
|
|
126
|
+
const allowedBridges = insurableRoute
|
|
127
|
+
? insurableRoute.steps.flatMap((step) => step.includedSteps
|
|
128
|
+
.filter((includedStep) => includedStep.type === 'cross')
|
|
129
|
+
.map((includedStep) => includedStep.toolDetails.key))
|
|
130
|
+
: enabledBridges;
|
|
131
|
+
const allowedExchanges = insurableRoute
|
|
132
|
+
? insurableRoute.steps.flatMap((step) => step.includedSteps
|
|
133
|
+
.filter((includedStep) => includedStep.type === 'swap')
|
|
134
|
+
.map((includedStep) => includedStep.toolDetails.key))
|
|
135
|
+
: enabledExchanges;
|
|
123
136
|
return lifi.getRoutes({
|
|
124
137
|
fromChainId,
|
|
125
138
|
fromAmount,
|
|
@@ -128,23 +141,29 @@ export const useSwapRoutes = () => {
|
|
|
128
141
|
toTokenAddress,
|
|
129
142
|
fromAddress,
|
|
130
143
|
toAddress: toWalletAddress,
|
|
144
|
+
fromAmountForGas: enabledRefuel && gasRecommendationFromAmount
|
|
145
|
+
? gasRecommendationFromAmount
|
|
146
|
+
: undefined,
|
|
131
147
|
options: {
|
|
132
148
|
slippage: formattedSlippage,
|
|
133
149
|
bridges: {
|
|
134
|
-
allow:
|
|
150
|
+
allow: allowedBridges,
|
|
135
151
|
},
|
|
136
152
|
exchanges: {
|
|
137
|
-
allow:
|
|
153
|
+
allow: allowedExchanges,
|
|
138
154
|
},
|
|
139
155
|
order: routePriority,
|
|
140
156
|
allowSwitchChain: variant === 'refuel' ? false : allowSwitchChain,
|
|
157
|
+
insurance: insurance ? Boolean(insurableRoute) : undefined,
|
|
141
158
|
},
|
|
142
159
|
}, { signal });
|
|
143
160
|
}, {
|
|
144
161
|
enabled: isEnabled,
|
|
145
|
-
refetchInterval,
|
|
146
162
|
staleTime: refetchTime,
|
|
147
163
|
cacheTime: refetchTime,
|
|
164
|
+
refetchInterval(data, query) {
|
|
165
|
+
return Math.min(Math.abs(refetchTime - (Date.now() - query.state.dataUpdatedAt)), refetchTime);
|
|
166
|
+
},
|
|
148
167
|
retry(failureCount, error) {
|
|
149
168
|
if (error?.code === LifiErrorCode.NotFound) {
|
|
150
169
|
return false;
|
|
@@ -170,6 +189,7 @@ export const useSwapRoutes = () => {
|
|
|
170
189
|
});
|
|
171
190
|
}
|
|
172
191
|
},
|
|
192
|
+
onSettled,
|
|
173
193
|
});
|
|
174
194
|
return {
|
|
175
195
|
routes: data?.routes,
|
|
@@ -3,8 +3,10 @@ import { useTokenBalances } from './useTokenBalances';
|
|
|
3
3
|
export const useTokenAddressBalance = (chainId, tokenAddress) => {
|
|
4
4
|
const { tokens, tokensWithBalance, isBalanceLoading, refetch } = useTokenBalances(chainId);
|
|
5
5
|
const token = useMemo(() => {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
if (tokenAddress && chainId) {
|
|
7
|
+
const token = (tokensWithBalance ?? tokens)?.find((token) => token.address === tokenAddress && token.chainId === chainId);
|
|
8
|
+
return token;
|
|
9
|
+
}
|
|
8
10
|
}, [chainId, tokenAddress, tokens, tokensWithBalance]);
|
|
9
11
|
return {
|
|
10
12
|
token,
|
package/hooks/useTokenBalance.js
CHANGED
|
@@ -1,32 +1,14 @@
|
|
|
1
1
|
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
|
2
2
|
import { useCallback, useMemo } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { useWallet } from '../providers';
|
|
4
4
|
import { formatTokenAmount } from '../utils';
|
|
5
|
+
import { useGetTokenBalancesWithRetry } from './useGetTokenBalancesWithRetry';
|
|
5
6
|
const defaultRefetchInterval = 30000;
|
|
6
7
|
export const useTokenBalance = (token, accountAddress) => {
|
|
7
|
-
const
|
|
8
|
-
const { account } = useWallet();
|
|
8
|
+
const { account, provider } = useWallet();
|
|
9
9
|
const queryClient = useQueryClient();
|
|
10
|
-
const walletAddress = accountAddress
|
|
11
|
-
const getTokenBalancesWithRetry =
|
|
12
|
-
try {
|
|
13
|
-
const tokenBalances = await lifi.getTokenBalances(accountAddress, tokens);
|
|
14
|
-
if (!tokenBalances.every((token) => token.blockNumber)) {
|
|
15
|
-
if (depth > 10) {
|
|
16
|
-
console.warn('Token balance backoff depth exceeded.');
|
|
17
|
-
return undefined;
|
|
18
|
-
}
|
|
19
|
-
await new Promise((resolve) => {
|
|
20
|
-
setTimeout(resolve, 1.5 ** depth * 100);
|
|
21
|
-
});
|
|
22
|
-
return getTokenBalancesWithRetry(accountAddress, tokens, depth + 1);
|
|
23
|
-
}
|
|
24
|
-
return tokenBalances;
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
//
|
|
28
|
-
}
|
|
29
|
-
}, [lifi]);
|
|
10
|
+
const walletAddress = accountAddress || account.address;
|
|
11
|
+
const getTokenBalancesWithRetry = useGetTokenBalancesWithRetry(provider);
|
|
30
12
|
const tokenBalanceQueryKey = useMemo(() => ['token-balance', walletAddress, token?.chainId, token?.address], [token?.address, token?.chainId, walletAddress]);
|
|
31
13
|
const { data, isLoading, refetch } = useQuery(tokenBalanceQueryKey, async ({ queryKey: [, accountAddress] }) => {
|
|
32
14
|
const cachedToken = queryClient
|
|
@@ -2,7 +2,7 @@ import type { Token } from '../types';
|
|
|
2
2
|
export declare const useTokenBalances: (selectedChainId?: number) => {
|
|
3
3
|
tokens: Token[];
|
|
4
4
|
tokensWithBalance: Token[] | undefined;
|
|
5
|
-
featuredTokens: import("@lifi/types").Token[];
|
|
5
|
+
featuredTokens: import("@lifi/types").Token[] | undefined;
|
|
6
6
|
isLoading: boolean;
|
|
7
7
|
isBalanceLoading: boolean;
|
|
8
8
|
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<Token[], unknown>>;
|
package/hooks/useTokenSearch.js
CHANGED
|
@@ -10,9 +10,9 @@ export const useTokenSearch = (chainId, tokenQuery, enabled) => {
|
|
|
10
10
|
if (token) {
|
|
11
11
|
queryClient.setQueriesData(['tokens'], (data) => {
|
|
12
12
|
if (data &&
|
|
13
|
-
!data.tokens[chainId]
|
|
13
|
+
!data.tokens[chainId]?.some((t) => t.address === token.address)) {
|
|
14
14
|
const clonedData = { ...data };
|
|
15
|
-
clonedData.tokens[chainId]
|
|
15
|
+
clonedData.tokens[chainId]?.push(token);
|
|
16
16
|
return clonedData;
|
|
17
17
|
}
|
|
18
18
|
});
|
package/hooks/useTokens.js
CHANGED
|
@@ -8,14 +8,14 @@ export const useTokens = (selectedChainId) => {
|
|
|
8
8
|
const { data, isLoading, dataUpdatedAt } = useQuery(['tokens'], () => lifi.getTokens());
|
|
9
9
|
const { getChainById, isLoading: isSupportedChainsLoading } = useChains();
|
|
10
10
|
const featuredTokens = useFeaturedTokens(selectedChainId);
|
|
11
|
-
const { tokens: configTokens, chains: configChains
|
|
11
|
+
const { tokens: configTokens, chains: configChains } = useWidgetConfig();
|
|
12
12
|
const tokens = useMemo(() => {
|
|
13
13
|
if (isSupportedChainsLoading) {
|
|
14
14
|
return [];
|
|
15
15
|
}
|
|
16
16
|
const chainAllowed = selectedChainId &&
|
|
17
17
|
getChainById(selectedChainId) &&
|
|
18
|
-
isItemAllowed(selectedChainId, configChains
|
|
18
|
+
isItemAllowed(selectedChainId, configChains);
|
|
19
19
|
if (!chainAllowed) {
|
|
20
20
|
return [];
|
|
21
21
|
}
|
|
@@ -44,7 +44,6 @@ export const useTokens = (selectedChainId) => {
|
|
|
44
44
|
selectedChainId,
|
|
45
45
|
getChainById,
|
|
46
46
|
configChains,
|
|
47
|
-
disabledChains,
|
|
48
47
|
configTokens?.allow,
|
|
49
48
|
configTokens?.deny,
|
|
50
49
|
featuredTokens,
|
package/i18n/en.json
CHANGED
|
@@ -106,12 +106,14 @@
|
|
|
106
106
|
"inProgress": "in progress",
|
|
107
107
|
"info": {
|
|
108
108
|
"message": {
|
|
109
|
+
"autoRefuel": "You're low on {{chainName}} gas. By continuing, you'll get enough gas to complete the swap.",
|
|
109
110
|
"emptyActiveSwaps": "Swaps in progress will appear here. Once completed, find them in swap history.",
|
|
110
111
|
"emptySwapHistory": "Swap history is only stored locally and will be deleted if you clear your browser data.",
|
|
111
112
|
"emptyTokenList": "We couldn't find tokens on {{chainName}} chain or you don't have any. Please try search again or choose another chain.",
|
|
112
113
|
"routeNotFound": "Try another token combination."
|
|
113
114
|
},
|
|
114
115
|
"title": {
|
|
116
|
+
"autoRefuel": "Get gas",
|
|
115
117
|
"emptyActiveSwaps": "No active swaps",
|
|
116
118
|
"emptySwapHistory": "No recent swaps",
|
|
117
119
|
"routeNotFound": "No routes available"
|
|
@@ -154,6 +156,7 @@
|
|
|
154
156
|
"quotedAmount": "Quoted amount",
|
|
155
157
|
"rateChange": "Rate change",
|
|
156
158
|
"receiving": "Receiving",
|
|
159
|
+
"refuelStepDetails": "Get gas via {{tool}}",
|
|
157
160
|
"routes": "You get",
|
|
158
161
|
"selectChain": "Chain",
|
|
159
162
|
"selectChainAndToken": "Select chain and token",
|
|
@@ -162,6 +165,7 @@
|
|
|
162
165
|
"sendToWallet": "Send to a different wallet",
|
|
163
166
|
"sentToAddress": "Sent to {{address}}",
|
|
164
167
|
"stepBridge": "Bridge",
|
|
168
|
+
"stepDetails": "{{tool}} via LI.FI",
|
|
165
169
|
"stepSwap": "Swap",
|
|
166
170
|
"stepSwapAndBridge": "Swap and bridge",
|
|
167
171
|
"success": {
|
|
@@ -180,11 +184,13 @@
|
|
|
180
184
|
"swapStepDetails": "Swap on {{chain}} via {{tool}}",
|
|
181
185
|
"swapping": "Swapping",
|
|
182
186
|
"tags": {
|
|
183
|
-
"
|
|
184
|
-
"
|
|
185
|
-
"
|
|
186
|
-
"
|
|
187
|
-
"
|
|
187
|
+
"cheapest": "Cheap",
|
|
188
|
+
"fastest": "Fast",
|
|
189
|
+
"insurable": "Insurable",
|
|
190
|
+
"insurance": "Insurance",
|
|
191
|
+
"insured": "Insured",
|
|
192
|
+
"recommended": "Recommended",
|
|
193
|
+
"safest": "Safe"
|
|
188
194
|
},
|
|
189
195
|
"to": "To",
|
|
190
196
|
"tokenOnChain": "{{tokenSymbol}} on {{chainName}}",
|
|
@@ -197,8 +203,8 @@
|
|
|
197
203
|
"deleteActiveSwaps": "Active swaps are only stored locally and can't be recovered if you delete them.",
|
|
198
204
|
"deleteSwapHistory": "Swap history is only stored locally and can't be recovered if you delete it.",
|
|
199
205
|
"highValueLoss": "The value of the received tokens is significantly lower than the swapped tokens and transaction cost.",
|
|
200
|
-
"insufficientFunds": "You don't have enough funds to
|
|
201
|
-
"insufficientGas": "You need to add at least:",
|
|
206
|
+
"insufficientFunds": "You don't have enough funds to complete the swap.",
|
|
207
|
+
"insufficientGas": "You don't have enough gas to complete the swap. You need to add at least:",
|
|
202
208
|
"rateChanged": "The exchange rate has changed. By continuing the swap, you'll accept the new rate.",
|
|
203
209
|
"resetSettings": "This will reset your route priority, slippage, gas price, enabled bridges and exchanges."
|
|
204
210
|
},
|
|
@@ -214,6 +220,7 @@
|
|
|
214
220
|
}
|
|
215
221
|
},
|
|
216
222
|
"tooltip": {
|
|
223
|
+
"additionalProviderFee": "Additional bridges, DEXs, and service fees.",
|
|
217
224
|
"estimatedNetworkFee": "Estimated network fee.",
|
|
218
225
|
"estimatedTime": "Estimated swap execution time in minutes.",
|
|
219
226
|
"notFound": {
|
package/i18n/it.json
CHANGED
|
@@ -106,12 +106,14 @@
|
|
|
106
106
|
"inProgress": "in corso",
|
|
107
107
|
"info": {
|
|
108
108
|
"message": {
|
|
109
|
+
"autoRefuel": "Livello basso di gas su {{chainName}}. Continuando avrai abbastanza gas per completare lo scambio.",
|
|
109
110
|
"emptyActiveSwaps": "Gli scambi in corso verranno visualizzati qui. Una volta completati, saranno presenti nella cronologia di scambi.",
|
|
110
111
|
"emptySwapHistory": "La cronologia di scambi viene memorizzata solo localmente e verrà cancellata se si cancellano i dati del browser.",
|
|
111
112
|
"emptyTokenList": "Non siamo riusciti a trovare token sulla chain {{chainName}} o non ne hai. Riprova o scegli un'altra chain.",
|
|
112
113
|
"routeNotFound": "Prova un'altra combinazione di token."
|
|
113
114
|
},
|
|
114
115
|
"title": {
|
|
116
|
+
"autoRefuel": "Ottieni gas",
|
|
115
117
|
"emptyActiveSwaps": "Nessuno scambio attivo",
|
|
116
118
|
"emptySwapHistory": "Nessuno scambio recente",
|
|
117
119
|
"routeNotFound": "Nessuna rotta disponibile"
|
|
@@ -154,6 +156,7 @@
|
|
|
154
156
|
"quotedAmount": "Totale quotato",
|
|
155
157
|
"rateChange": "Tasso di scambio",
|
|
156
158
|
"receiving": "In ricezione",
|
|
159
|
+
"refuelStepDetails": "Ottieni gas tramite {{tool}}",
|
|
157
160
|
"routes": "Ottieni",
|
|
158
161
|
"selectChain": "Chain",
|
|
159
162
|
"selectChainAndToken": "Selezionare la chain ed il token",
|
|
@@ -162,6 +165,7 @@
|
|
|
162
165
|
"sendToWallet": "Invia ad un altro portafoglio",
|
|
163
166
|
"sentToAddress": "Inviati a {{address}}",
|
|
164
167
|
"stepBridge": "Bridge",
|
|
168
|
+
"stepDetails": "{{tool}} tramite LI.FI",
|
|
165
169
|
"stepSwap": "Scambio",
|
|
166
170
|
"stepSwapAndBridge": "Scambia e bridge",
|
|
167
171
|
"success": {
|
|
@@ -197,8 +201,8 @@
|
|
|
197
201
|
"deleteActiveSwaps": "Gli scambi attivi vengono memorizzati solo localmente e non possono essere recuperati se vengono cancellati.",
|
|
198
202
|
"deleteSwapHistory": "La cronologia degli scambi viene memorizzata solo localmente e, se cancellata, non può essere recuperata.",
|
|
199
203
|
"highValueLoss": "Il valore dei token ricevuti è significativamente inferiore ai token scambiati più il costo della transazione.",
|
|
200
|
-
"insufficientFunds": "Non hai abbastanza fondi per
|
|
201
|
-
"insufficientGas": "
|
|
204
|
+
"insufficientFunds": "Non hai abbastanza fondi per completare lo scambio.",
|
|
205
|
+
"insufficientGas": "Non hai abbastanza gas per completare lo scambio. Devi aggiungere almeno:",
|
|
202
206
|
"rateChanged": "Il tasso di scambio è cambiato. Se procedi, confermi di accettare il nuovo tasso.",
|
|
203
207
|
"resetSettings": "Questo porterà al ripristino della priorità di route, slittamento di prezzo, prezzo del gas, bridge abilitati ed exchanges."
|
|
204
208
|
},
|