@lifi/widget 1.32.8 → 2.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/App.js +3 -3
- package/AppDrawer.js +4 -3
- package/AppDrawer.style.d.ts +5 -5
- package/AppProvider.js +4 -3
- package/cjs/App.js +3 -3
- package/cjs/AppDrawer.js +4 -3
- package/cjs/AppDrawer.style.d.ts +5 -5
- package/cjs/AppProvider.js +2 -1
- package/cjs/components/ActiveSwaps/ActiveSwaps.style.d.ts +5 -5
- 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 +6 -6
- 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/ListItemButton.d.ts +1 -1
- package/cjs/components/NFT/NFT.style.d.ts +1 -1
- package/cjs/components/PoweredBy/PoweredBy.style.d.ts +3 -12
- 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.d.ts +2 -2
- package/cjs/components/Step/DestinationWalletAddress.js +4 -8
- package/cjs/components/Step/GasStepProcess.d.ts +2 -2
- package/cjs/components/Step/GasStepProcess.js +3 -3
- package/cjs/components/Step/Step.d.ts +2 -2
- package/cjs/components/Step/Step.js +6 -8
- package/cjs/components/Step/StepList.d.ts +1 -1
- package/cjs/components/Step/StepProcess.d.ts +2 -2
- package/cjs/components/Step/StepProcess.js +1 -5
- package/cjs/components/Step/StepProcess.style.d.ts +3 -39
- package/cjs/components/Step/StepTimer.d.ts +2 -2
- package/cjs/components/Step/StepTimer.js +1 -1
- package/cjs/components/StepActions/StepActions.d.ts +6 -1
- package/cjs/components/StepActions/StepActions.js +54 -17
- package/cjs/components/StepActions/StepActions.style.d.ts +1 -1
- package/cjs/components/StepActions/types.d.ts +2 -2
- 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 +4 -11
- 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/Token/Token.d.ts +2 -2
- package/cjs/components/Token/Token.style.d.ts +2 -2
- package/cjs/components/TokenList/TokenList.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/useProcessMessage.d.ts +3 -3
- 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/SelectEnabledToolsPage/SelectEnabledToolsPage.style.d.ts +1 -1
- package/cjs/pages/SettingsPage/ColorSchemeButtonGroup.js +2 -2
- package/cjs/pages/SettingsPage/ColorSchemeButtonGroup.style.d.ts +2 -2
- package/cjs/pages/SettingsPage/EnabledToolsButton.style.d.ts +1 -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/pages/SwapRoutesPage/SwapRoutesPage.style.d.ts +2 -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/SwapFormProvider/SwapFormProvider.js +2 -3
- package/cjs/providers/SwapFormProvider/index.d.ts +1 -0
- package/cjs/providers/SwapFormProvider/index.js +1 -0
- 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 +1 -0
- package/cjs/stores/settings/useSettingsStore.js +1 -0
- package/cjs/types/widget.d.ts +5 -10
- package/cjs/utils/format.js +4 -1
- package/components/ActiveSwaps/ActiveSwaps.style.d.ts +5 -5
- 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 +6 -6
- 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/ListItemButton.d.ts +1 -1
- package/components/NFT/NFT.style.d.ts +1 -1
- package/components/PoweredBy/PoweredBy.style.d.ts +3 -12
- 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.d.ts +2 -2
- package/components/Step/DestinationWalletAddress.js +4 -8
- package/components/Step/GasStepProcess.d.ts +2 -2
- package/components/Step/GasStepProcess.js +3 -3
- package/components/Step/Step.d.ts +2 -2
- package/components/Step/Step.js +6 -8
- package/components/Step/StepList.d.ts +1 -1
- package/components/Step/StepProcess.d.ts +2 -2
- package/components/Step/StepProcess.js +1 -5
- package/components/Step/StepProcess.style.d.ts +3 -39
- package/components/Step/StepTimer.d.ts +2 -2
- package/components/Step/StepTimer.js +1 -1
- package/components/StepActions/StepActions.d.ts +6 -1
- package/components/StepActions/StepActions.js +51 -16
- package/components/StepActions/StepActions.style.d.ts +1 -1
- package/components/StepActions/types.d.ts +2 -2
- 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 +4 -11
- 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/Token/Token.d.ts +2 -2
- package/components/Token/Token.style.d.ts +2 -2
- package/components/TokenList/TokenList.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/useProcessMessage.d.ts +3 -3
- 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 -12
- 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/SelectEnabledToolsPage/SelectEnabledToolsPage.style.d.ts +1 -1
- package/pages/SettingsPage/ColorSchemeButtonGroup.js +2 -2
- package/pages/SettingsPage/ColorSchemeButtonGroup.style.d.ts +2 -2
- package/pages/SettingsPage/EnabledToolsButton.style.d.ts +1 -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/pages/SwapRoutesPage/SwapRoutesPage.style.d.ts +2 -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/SwapFormProvider/SwapFormProvider.js +2 -3
- package/providers/SwapFormProvider/index.d.ts +1 -0
- package/providers/SwapFormProvider/index.js +1 -0
- 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 +1 -0
- package/stores/settings/useSettingsStore.js +1 -0
- 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
package/config/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name = "@lifi/widget";
|
|
2
|
-
export declare const version = "
|
|
2
|
+
export declare const version = "2.0.0-alpha.1";
|
package/config/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/widget';
|
|
2
|
-
export const version = '
|
|
2
|
+
export const version = '2.0.0-alpha.1';
|
package/hooks/index.d.ts
CHANGED
|
@@ -5,7 +5,11 @@ export * from './useDebouncedWatch';
|
|
|
5
5
|
export * from './useDefaultElementId';
|
|
6
6
|
export * from './useExpandableVariant';
|
|
7
7
|
export * from './useFeaturedTokens';
|
|
8
|
+
export * from './useFundsSufficiency';
|
|
9
|
+
export * from './useGasRecommendation';
|
|
10
|
+
export * from './useGasRefuel';
|
|
8
11
|
export * from './useGasSufficiency';
|
|
12
|
+
export * from './useGetTokenBalancesWithRetry';
|
|
9
13
|
export * from './useInitializer';
|
|
10
14
|
export * from './useNavigateBack';
|
|
11
15
|
export * from './useProcessMessage';
|
package/hooks/index.js
CHANGED
|
@@ -5,7 +5,11 @@ export * from './useDebouncedWatch';
|
|
|
5
5
|
export * from './useDefaultElementId';
|
|
6
6
|
export * from './useExpandableVariant';
|
|
7
7
|
export * from './useFeaturedTokens';
|
|
8
|
+
export * from './useFundsSufficiency';
|
|
9
|
+
export * from './useGasRecommendation';
|
|
10
|
+
export * from './useGasRefuel';
|
|
8
11
|
export * from './useGasSufficiency';
|
|
12
|
+
export * from './useGetTokenBalancesWithRetry';
|
|
9
13
|
export * from './useInitializer';
|
|
10
14
|
export * from './useNavigateBack';
|
|
11
15
|
export * from './useProcessMessage';
|
package/hooks/useChains.js
CHANGED
|
@@ -4,13 +4,13 @@ import { useFormContext } from 'react-hook-form';
|
|
|
4
4
|
import { isItemAllowed, SwapFormKey, useLiFi, useWidgetConfig, } from '../providers';
|
|
5
5
|
import { useChainOrderStore } from '../stores';
|
|
6
6
|
export const useChains = () => {
|
|
7
|
-
const {
|
|
7
|
+
const { chains } = useWidgetConfig();
|
|
8
8
|
const lifi = useLiFi();
|
|
9
9
|
const { getValues, setValue } = useFormContext();
|
|
10
10
|
const initializeChains = useChainOrderStore((state) => state.initializeChains);
|
|
11
11
|
const { data, isLoading } = useQuery(['chains'], async () => {
|
|
12
12
|
const availableChains = await lifi.getChains();
|
|
13
|
-
const filteredChains = availableChains.filter((chain) => isItemAllowed(chain.id, chains
|
|
13
|
+
const filteredChains = availableChains.filter((chain) => isItemAllowed(chain.id, chains));
|
|
14
14
|
const chainOrder = initializeChains(filteredChains.map((chain) => chain.id));
|
|
15
15
|
const [fromChainValue, toChainValue] = getValues([
|
|
16
16
|
SwapFormKey.FromChain,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useFeaturedTokens: (selectedChainId?: number) => import("@lifi/types").Token[];
|
|
1
|
+
export declare const useFeaturedTokens: (selectedChainId?: number) => import("@lifi/types").Token[] | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
2
|
import { useWidgetConfig } from '../providers';
|
|
3
3
|
export const useFeaturedTokens = (selectedChainId) => {
|
|
4
|
-
const {
|
|
5
|
-
return useMemo(() =>
|
|
4
|
+
const { tokens } = useWidgetConfig();
|
|
5
|
+
return useMemo(() => tokens?.featured?.filter((token) => token.chainId === selectedChainId), [selectedChainId, tokens?.featured]);
|
|
6
6
|
};
|
|
@@ -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
|
+
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { EVMChain,
|
|
1
|
+
import type { EVMChain, LifiStep, Process } from '@lifi/sdk';
|
|
2
2
|
import type { TFunction } from 'i18next';
|
|
3
|
-
export declare const useProcessMessage: (step?:
|
|
3
|
+
export declare const useProcessMessage: (step?: LifiStep, process?: Process) => {
|
|
4
4
|
title?: string | undefined;
|
|
5
5
|
message?: string | undefined;
|
|
6
6
|
};
|
|
7
|
-
export declare function getProcessMessage(t: TFunction, getChainById: (chainId: number) => EVMChain | undefined, step:
|
|
7
|
+
export declare function getProcessMessage(t: TFunction, getChainById: (chainId: number) => EVMChain | undefined, step: LifiStep, process: Process): {
|
|
8
8
|
title?: string;
|
|
9
9
|
message?: string;
|
|
10
10
|
};
|
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,
|