@lifi/widget 2.9.3 → 3.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/AppProvider.js +2 -2
- package/AppRoutes.js +75 -67
- package/cjs/AppProvider.js +1 -1
- package/cjs/AppRoutes.js +74 -66
- package/cjs/components/ActiveTransactions/ActiveTransactionItem.js +1 -5
- package/cjs/components/ActiveTransactions/ActiveTransactions.js +2 -2
- package/cjs/components/AmountInput/AmountInputEndAdornment.js +9 -10
- package/cjs/components/AmountInput/FormPriceHelperText.js +1 -1
- package/cjs/components/BaseTransactionButton/BaseTransactionButton.js +5 -4
- package/cjs/components/Card/CardLabel.d.ts +1 -1
- package/cjs/components/ChainSelect/ChainSelect.js +8 -5
- package/cjs/components/ChainSelect/useChainSelect.js +21 -2
- package/cjs/components/GasMessage/GasMessage.style.js +3 -6
- package/cjs/components/GasMessage/GasSufficiencyMessage.js +2 -1
- package/cjs/components/Header/Header.style.d.ts +8 -0
- package/cjs/components/Header/Header.style.js +16 -1
- package/cjs/components/Header/NavigationHeader.d.ts +1 -0
- package/cjs/components/Header/NavigationHeader.js +15 -8
- package/cjs/components/Header/NavigationTabs.js +2 -2
- package/cjs/components/Header/SettingsButton.d.ts +1 -0
- package/cjs/components/Header/SettingsButton.js +25 -0
- package/cjs/components/Header/SettingsButton.style.d.ts +11 -0
- package/cjs/components/Header/SettingsButton.style.js +43 -0
- package/cjs/components/Header/WalletHeader.js +11 -24
- package/cjs/components/Header/WalletMenu.d.ts +3 -1
- package/cjs/components/Header/WalletMenu.js +58 -24
- package/cjs/components/Header/WalletMenu.style.d.ts +1 -0
- package/cjs/components/Header/WalletMenu.style.js +27 -0
- package/cjs/components/Insurance/InsuranceCollapsed.js +1 -1
- package/cjs/components/NFT/NFT.js +3 -1
- package/cjs/components/NFT/types.d.ts +1 -1
- package/cjs/components/PoweredBy/PoweredBy.js +2 -1
- package/cjs/components/RouteCard/RouteCard.js +3 -3
- package/cjs/components/RouteCard/RouteCardEssentials.js +2 -1
- package/cjs/components/RouteCard/utils.d.ts +2 -3
- package/cjs/components/RouteCard/utils.js +4 -9
- package/cjs/components/SendToWallet/SendToWallet.js +24 -21
- package/cjs/components/SendToWallet/SendToWalletButton.js +3 -2
- package/{pages/SelectEnabledToolsPage/SelectEnabledToolsPage.style.d.ts → cjs/components/SettingsListItemButton.d.ts} +1 -1
- package/cjs/components/SettingsListItemButton.js +8 -0
- package/cjs/components/Step/DestinationWalletAddress.d.ts +2 -2
- package/cjs/components/Step/GasStepProcess.d.ts +2 -2
- package/cjs/components/Step/Step.d.ts +2 -2
- package/cjs/components/Step/Step.js +1 -1
- package/cjs/components/Step/StepList.d.ts +2 -2
- package/cjs/components/Step/StepList.js +4 -4
- package/cjs/components/Step/StepProcess.d.ts +2 -2
- package/cjs/components/Step/StepTimer.d.ts +2 -2
- package/cjs/components/StepActions/StepActions.d.ts +3 -3
- package/cjs/components/StepActions/StepActions.js +11 -14
- package/cjs/components/StepActions/types.d.ts +2 -2
- package/cjs/components/{Header/NavigationTabs.style.d.ts → Tabs/Tabs.style.d.ts} +2 -2
- package/cjs/components/{Header/NavigationTabs.style.js → Tabs/Tabs.style.js} +9 -31
- package/cjs/components/Tabs/index.d.ts +1 -0
- package/cjs/{providers/SDKProvider → components/Tabs}/index.js +1 -1
- package/cjs/components/Token/Token.d.ts +3 -3
- package/cjs/components/Token/Token.js +5 -5
- package/cjs/components/TokenList/TokenList.js +2 -2
- package/cjs/components/TokenList/TokenListItem.js +9 -5
- package/cjs/components/TokenList/TokenNotFound.js +1 -1
- package/cjs/components/TokenList/VirtualizedTokenList.js +2 -1
- package/cjs/config/queryClient.js +0 -4
- package/cjs/config/version.d.ts +1 -1
- package/cjs/config/version.js +1 -1
- package/cjs/hooks/index.d.ts +7 -1
- package/cjs/hooks/index.js +7 -1
- package/cjs/hooks/useAccount.d.ts +31 -0
- package/cjs/hooks/useAccount.js +53 -0
- package/cjs/hooks/useAvailableChains.d.ts +6 -0
- package/cjs/hooks/useAvailableChains.js +36 -0
- package/cjs/hooks/useChain.js +3 -6
- package/cjs/hooks/useChains.d.ts +1 -1
- package/cjs/hooks/useChains.js +7 -38
- package/cjs/hooks/useFromTokenSufficiency.d.ts +3 -3
- package/cjs/hooks/useFromTokenSufficiency.js +39 -41
- package/cjs/hooks/useGasRecommendation.d.ts +2 -2
- package/cjs/hooks/useGasRecommendation.js +23 -18
- package/cjs/hooks/useGasRefuel.js +18 -11
- package/cjs/hooks/useGasSufficiency.d.ts +6 -7
- package/cjs/hooks/useGasSufficiency.js +68 -71
- package/cjs/hooks/useLanguages.d.ts +6 -0
- package/cjs/hooks/useLanguages.js +28 -0
- package/cjs/hooks/useProcessMessage.d.ts +3 -3
- package/cjs/hooks/useProcessMessage.js +32 -28
- package/cjs/hooks/useRequiredToAddress.d.ts +1 -0
- package/cjs/hooks/useRequiredToAddress.js +19 -0
- package/cjs/hooks/useRouteExecution.d.ts +2 -2
- package/cjs/hooks/useRouteExecution.js +44 -58
- package/cjs/hooks/useRoutes.d.ts +1 -1
- package/cjs/hooks/useRoutes.js +128 -113
- package/cjs/hooks/useSettingMonitor.d.ts +11 -0
- package/cjs/hooks/useSettingMonitor.js +57 -0
- package/cjs/hooks/useTokenAddressBalance.d.ts +1 -1
- package/cjs/hooks/useTokenBalance.d.ts +5 -3
- package/cjs/hooks/useTokenBalance.js +77 -47
- package/cjs/hooks/useTokenBalances.d.ts +3 -3
- package/cjs/hooks/useTokenBalances.js +34 -24
- package/cjs/hooks/useTokenSearch.js +18 -17
- package/cjs/hooks/useTokens.d.ts +2 -1
- package/cjs/hooks/useTokens.js +18 -15
- package/cjs/hooks/useTools.d.ts +1 -1
- package/cjs/hooks/useTools.js +12 -11
- package/cjs/hooks/useTransactionDetails.d.ts +4 -0
- package/cjs/hooks/useTransactionDetails.js +56 -0
- package/cjs/hooks/useTransactionHistory.d.ts +5 -0
- package/cjs/hooks/useTransactionHistory.js +39 -0
- package/cjs/i18n/en.json +18 -9
- package/cjs/i18n/fr.json +7 -4
- package/cjs/i18n/pt.json +7 -4
- package/cjs/i18n/tr.json +7 -4
- package/cjs/i18n/uk.json +7 -4
- package/cjs/i18n/zh.json +7 -4
- package/cjs/icons/index.d.ts +1 -3
- package/cjs/icons/index.js +1 -3
- package/cjs/icons/lifi.d.ts +1 -0
- package/cjs/icons/lifi.js +4 -0
- package/cjs/index.d.ts +2 -3
- package/cjs/index.js +4 -4
- package/cjs/pages/ActiveTransactionsPage/ActiveTransactionsPage.js +2 -2
- package/cjs/pages/LanguagesPage/LanguagesPage.d.ts +2 -0
- package/cjs/pages/LanguagesPage/LanguagesPage.js +22 -0
- package/cjs/pages/LanguagesPage/index.d.ts +1 -0
- package/cjs/pages/LanguagesPage/index.js +17 -0
- package/cjs/pages/SelectEnabledToolsPage/SelectEnabledToolsPage.js +15 -5
- package/cjs/pages/SelectWalletPage/EVMListItemButton.d.ts +8 -0
- package/cjs/pages/SelectWalletPage/EVMListItemButton.js +40 -0
- package/cjs/pages/SelectWalletPage/SVMListItemButton.d.ts +6 -0
- package/cjs/pages/SelectWalletPage/SVMListItemButton.js +34 -0
- package/cjs/pages/SelectWalletPage/SelectWalletPage.js +31 -32
- package/cjs/pages/SelectWalletPage/utils.d.ts +3 -0
- package/cjs/pages/SelectWalletPage/utils.js +21 -0
- package/{pages/SettingsPage/EnabledToolsButton.d.ts → cjs/pages/SettingsPage/BridgeAndExchangeSettings.d.ts} +1 -1
- package/cjs/pages/SettingsPage/BridgeAndExchangeSettings.js +36 -0
- package/cjs/pages/SettingsPage/GasPriceSettings.d.ts +2 -0
- package/cjs/pages/SettingsPage/GasPriceSettings.js +21 -0
- package/cjs/pages/SettingsPage/LanguageSetting.d.ts +2 -0
- package/cjs/pages/SettingsPage/LanguageSetting.js +26 -0
- package/cjs/pages/SettingsPage/ResetSettingsButton.js +3 -30
- package/cjs/pages/SettingsPage/RoutePrioritySettings.d.ts +2 -0
- package/cjs/pages/SettingsPage/RoutePrioritySettings.js +25 -0
- package/cjs/pages/SettingsPage/SendToWalletOptionSetting.d.ts +1 -0
- package/cjs/pages/SettingsPage/{ShowDestinationWallet.js → SendToWalletOptionSetting.js} +6 -9
- package/cjs/pages/SettingsPage/SettingsCard/BadgedValue.d.ts +8 -0
- package/cjs/pages/SettingsPage/SettingsCard/BadgedValue.js +7 -0
- package/cjs/pages/SettingsPage/SettingsCard/SettingCard.d.ts +2 -0
- package/cjs/pages/SettingsPage/SettingsCard/SettingCard.js +11 -0
- package/cjs/pages/SettingsPage/SettingsCard/SettingCard.style.d.ts +19 -0
- package/cjs/pages/SettingsPage/SettingsCard/SettingCard.style.js +53 -0
- package/cjs/pages/SettingsPage/SettingsCard/SettingCardButton.d.ts +7 -0
- package/cjs/pages/SettingsPage/SettingsCard/SettingCardButton.js +8 -0
- package/cjs/pages/SettingsPage/SettingsCard/SettingCardExpandable.d.ts +7 -0
- package/cjs/pages/SettingsPage/SettingsCard/SettingCardExpandable.js +16 -0
- package/cjs/pages/SettingsPage/SettingsCard/SettingsAccordian.d.ts +6 -0
- package/cjs/pages/SettingsPage/SettingsCard/SettingsAccordian.js +36 -0
- package/cjs/pages/SettingsPage/SettingsCard/index.d.ts +6 -0
- package/cjs/pages/SettingsPage/SettingsCard/index.js +22 -0
- package/cjs/pages/SettingsPage/SettingsCard/types.d.ts +5 -0
- package/cjs/pages/SettingsPage/SettingsPage.js +9 -8
- package/cjs/pages/SettingsPage/SlippageSettings/SlippageSettings.d.ts +2 -0
- package/cjs/pages/SettingsPage/SlippageSettings/SlippageSettings.js +51 -0
- package/cjs/pages/SettingsPage/SlippageSettings/SlippageSettings.style.d.ts +16 -0
- package/cjs/pages/SettingsPage/SlippageSettings/SlippageSettings.style.js +74 -0
- package/cjs/pages/SettingsPage/SlippageSettings/index.d.ts +1 -0
- package/cjs/pages/SettingsPage/SlippageSettings/index.js +17 -0
- package/cjs/pages/SettingsPage/ThemeSettings.d.ts +2 -0
- package/cjs/pages/SettingsPage/ThemeSettings.js +39 -0
- package/cjs/pages/TransactionDetailsPage/ContactSupportButton.js +2 -2
- package/cjs/pages/TransactionDetailsPage/TransactionDetailsPage.js +33 -28
- package/cjs/pages/TransactionDetailsPage/TransactionDetailsSkeleton.d.ts +1 -0
- package/cjs/pages/TransactionDetailsPage/TransactionDetailsSkeleton.js +31 -0
- package/cjs/pages/TransactionHistoryPage/TransactionHistoryItem.d.ts +4 -2
- package/cjs/pages/TransactionHistoryPage/TransactionHistoryItem.js +34 -7
- package/cjs/pages/TransactionHistoryPage/TransactionHistoryPage.js +21 -22
- package/cjs/pages/TransactionHistoryPage/TransactionHistorySkeleton.d.ts +1 -0
- package/cjs/pages/TransactionHistoryPage/TransactionHistorySkeleton.js +26 -0
- package/cjs/pages/TransactionHistoryPage/constants.d.ts +1 -0
- package/cjs/pages/TransactionHistoryPage/constants.js +4 -0
- package/cjs/pages/TransactionPage/ExchangeRateBottomSheet.js +11 -10
- package/cjs/pages/TransactionPage/StartTransactionButton.js +2 -2
- package/cjs/pages/TransactionPage/StatusBottomSheet.js +12 -8
- package/cjs/pages/TransactionPage/TransactionPage.js +1 -1
- package/cjs/providers/FormProvider/FormUpdater.js +4 -4
- package/cjs/providers/I18nProvider/I18nProvider.js +3 -7
- package/cjs/providers/I18nProvider/types.d.ts +4 -3
- package/cjs/providers/WalletProvider/EVMProvider.d.ts +3 -0
- package/cjs/providers/WalletProvider/EVMProvider.js +79 -0
- package/cjs/providers/WalletProvider/SDKProviders.d.ts +1 -0
- package/cjs/providers/WalletProvider/SDKProviders.js +31 -0
- package/cjs/providers/WalletProvider/SolanaProvider.d.ts +3 -0
- package/cjs/providers/WalletProvider/SolanaProvider.js +35 -0
- package/cjs/providers/WalletProvider/WalletProvider.d.ts +1 -15
- package/cjs/providers/WalletProvider/WalletProvider.js +5 -183
- package/cjs/providers/WalletProvider/index.d.ts +1 -1
- package/cjs/providers/WalletProvider/index.js +1 -1
- package/cjs/providers/WalletProvider/utils.d.ts +3 -0
- package/cjs/providers/WalletProvider/utils.js +25 -0
- package/cjs/providers/WidgetProvider/WidgetProvider.js +51 -35
- package/cjs/providers/index.d.ts +0 -1
- package/cjs/providers/index.js +0 -1
- package/cjs/stores/chains/ChainOrderStore.js +24 -0
- package/cjs/stores/header/useHeaderStore.d.ts +1 -1
- package/cjs/stores/header/useHeaderStore.js +2 -2
- package/cjs/stores/routes/createRouteExecutionStore.js +6 -60
- package/cjs/stores/routes/index.d.ts +0 -1
- package/cjs/stores/routes/index.js +0 -1
- package/cjs/stores/routes/types.d.ts +2 -2
- package/cjs/stores/routes/utils.d.ts +8 -8
- package/cjs/stores/routes/utils.js +7 -5
- package/cjs/stores/settings/useSettingsStore.js +2 -4
- package/cjs/stores/settings/useSplitSubvariantStore.d.ts +1 -1
- package/cjs/stores/settings/useSplitSubvariantStore.js +2 -2
- package/cjs/types/events.d.ts +6 -5
- package/cjs/types/events.js +1 -1
- package/cjs/types/widget.d.ts +7 -14
- package/cjs/utils/colors.d.ts +3 -0
- package/cjs/utils/colors.js +13 -1
- package/cjs/utils/converters.d.ts +3 -0
- package/cjs/utils/converters.js +172 -0
- package/cjs/utils/format.d.ts +1 -1
- package/cjs/utils/format.js +5 -12
- package/cjs/utils/index.d.ts +1 -0
- package/cjs/utils/index.js +1 -0
- package/cjs/utils/navigationRoutes.d.ts +1 -0
- package/cjs/utils/navigationRoutes.js +3 -1
- package/cjs/utils/svm.d.ts +1 -0
- package/cjs/utils/svm.js +14 -0
- package/components/ActiveTransactions/ActiveTransactionItem.js +1 -5
- package/components/ActiveTransactions/ActiveTransactions.js +2 -2
- package/components/AmountInput/AmountInputEndAdornment.js +10 -11
- package/components/AmountInput/FormPriceHelperText.js +1 -1
- package/components/BaseTransactionButton/BaseTransactionButton.js +6 -5
- package/components/Card/CardLabel.d.ts +1 -1
- package/components/ChainSelect/ChainSelect.js +8 -5
- package/components/ChainSelect/useChainSelect.js +22 -3
- package/components/GasMessage/GasMessage.style.js +3 -6
- package/components/GasMessage/GasSufficiencyMessage.js +2 -1
- package/components/Header/Header.style.d.ts +8 -0
- package/components/Header/Header.style.js +16 -1
- package/components/Header/NavigationHeader.d.ts +1 -0
- package/components/Header/NavigationHeader.js +16 -10
- package/components/Header/NavigationTabs.js +3 -3
- package/components/Header/SettingsButton.d.ts +1 -0
- package/components/Header/SettingsButton.js +21 -0
- package/components/Header/SettingsButton.style.d.ts +11 -0
- package/components/Header/SettingsButton.style.js +40 -0
- package/components/Header/WalletHeader.js +15 -28
- package/components/Header/WalletMenu.d.ts +3 -1
- package/components/Header/WalletMenu.js +58 -25
- package/components/Header/WalletMenu.style.d.ts +1 -0
- package/components/Header/WalletMenu.style.js +24 -0
- package/components/Insurance/InsuranceCollapsed.js +1 -1
- package/components/NFT/NFT.js +3 -1
- package/components/NFT/types.d.ts +1 -1
- package/components/PoweredBy/PoweredBy.js +2 -1
- package/components/RouteCard/RouteCard.js +3 -3
- package/components/RouteCard/RouteCardEssentials.js +2 -1
- package/components/RouteCard/utils.d.ts +2 -3
- package/components/RouteCard/utils.js +4 -9
- package/components/SendToWallet/SendToWallet.js +26 -23
- package/components/SendToWallet/SendToWalletButton.js +5 -4
- package/{cjs/pages/SelectEnabledToolsPage/SelectEnabledToolsPage.style.d.ts → components/SettingsListItemButton.d.ts} +1 -1
- package/components/SettingsListItemButton.js +5 -0
- package/components/Step/DestinationWalletAddress.d.ts +2 -2
- package/components/Step/GasStepProcess.d.ts +2 -2
- package/components/Step/Step.d.ts +2 -2
- package/components/Step/Step.js +2 -2
- package/components/Step/StepList.d.ts +2 -2
- package/components/Step/StepList.js +4 -4
- package/components/Step/StepProcess.d.ts +2 -2
- package/components/Step/StepTimer.d.ts +2 -2
- package/components/StepActions/StepActions.d.ts +3 -3
- package/components/StepActions/StepActions.js +12 -15
- package/components/StepActions/types.d.ts +2 -2
- package/components/{Header/NavigationTabs.style.d.ts → Tabs/Tabs.style.d.ts} +2 -2
- package/components/Tabs/Tabs.style.js +36 -0
- package/components/Tabs/index.d.ts +1 -0
- package/components/Tabs/index.js +1 -0
- package/components/Token/Token.d.ts +3 -3
- package/components/Token/Token.js +5 -5
- package/components/TokenList/TokenList.js +4 -4
- package/components/TokenList/TokenListItem.js +9 -6
- package/components/TokenList/TokenNotFound.js +2 -2
- package/components/TokenList/VirtualizedTokenList.js +2 -1
- package/config/queryClient.js +0 -4
- package/config/version.d.ts +1 -1
- package/config/version.js +1 -1
- package/hooks/index.d.ts +7 -1
- package/hooks/index.js +7 -1
- package/hooks/useAccount.d.ts +31 -0
- package/hooks/useAccount.js +48 -0
- package/hooks/useAvailableChains.d.ts +6 -0
- package/hooks/useAvailableChains.js +32 -0
- package/hooks/useChain.js +3 -6
- package/hooks/useChains.d.ts +1 -1
- package/hooks/useChains.js +9 -40
- package/hooks/useFromTokenSufficiency.d.ts +3 -3
- package/hooks/useFromTokenSufficiency.js +41 -43
- package/hooks/useGasRecommendation.d.ts +2 -2
- package/hooks/useGasRecommendation.js +23 -18
- package/hooks/useGasRefuel.js +19 -12
- package/hooks/useGasSufficiency.d.ts +6 -7
- package/hooks/useGasSufficiency.js +69 -72
- package/hooks/useLanguages.d.ts +6 -0
- package/hooks/useLanguages.js +24 -0
- package/hooks/useProcessMessage.d.ts +3 -3
- package/hooks/useProcessMessage.js +33 -29
- package/hooks/useRequiredToAddress.d.ts +1 -0
- package/hooks/useRequiredToAddress.js +15 -0
- package/hooks/useRouteExecution.d.ts +2 -2
- package/hooks/useRouteExecution.js +44 -58
- package/hooks/useRoutes.d.ts +1 -1
- package/hooks/useRoutes.js +131 -116
- package/hooks/useSettingMonitor.d.ts +11 -0
- package/hooks/useSettingMonitor.js +53 -0
- package/hooks/useTokenAddressBalance.d.ts +1 -1
- package/hooks/useTokenBalance.d.ts +5 -3
- package/hooks/useTokenBalance.js +74 -45
- package/hooks/useTokenBalances.d.ts +3 -3
- package/hooks/useTokenBalances.js +34 -24
- package/hooks/useTokenSearch.js +18 -17
- package/hooks/useTokens.d.ts +2 -1
- package/hooks/useTokens.js +19 -16
- package/hooks/useTools.d.ts +1 -1
- package/hooks/useTools.js +13 -12
- package/hooks/useTransactionDetails.d.ts +4 -0
- package/hooks/useTransactionDetails.js +52 -0
- package/hooks/useTransactionHistory.d.ts +5 -0
- package/hooks/useTransactionHistory.js +35 -0
- package/i18n/en.json +18 -9
- package/i18n/fr.json +7 -4
- package/i18n/pt.json +7 -4
- package/i18n/tr.json +7 -4
- package/i18n/uk.json +7 -4
- package/i18n/zh.json +7 -4
- package/icons/index.d.ts +1 -3
- package/icons/index.js +1 -3
- package/icons/lifi.d.ts +1 -0
- package/icons/lifi.js +1 -0
- package/index.d.ts +2 -3
- package/index.js +2 -4
- package/package.json +19 -19
- package/pages/ActiveTransactionsPage/ActiveTransactionsPage.js +2 -2
- package/pages/LanguagesPage/LanguagesPage.d.ts +2 -0
- package/pages/LanguagesPage/LanguagesPage.js +18 -0
- package/pages/LanguagesPage/index.d.ts +1 -0
- package/pages/LanguagesPage/index.js +1 -0
- package/pages/SelectEnabledToolsPage/SelectEnabledToolsPage.js +16 -6
- package/pages/SelectWalletPage/EVMListItemButton.d.ts +8 -0
- package/pages/SelectWalletPage/EVMListItemButton.js +36 -0
- package/pages/SelectWalletPage/SVMListItemButton.d.ts +6 -0
- package/pages/SelectWalletPage/SVMListItemButton.js +30 -0
- package/pages/SelectWalletPage/SelectWalletPage.js +34 -35
- package/pages/SelectWalletPage/utils.d.ts +3 -0
- package/pages/SelectWalletPage/utils.js +17 -0
- package/{cjs/pages/SettingsPage/EnabledToolsButton.d.ts → pages/SettingsPage/BridgeAndExchangeSettings.d.ts} +1 -1
- package/pages/SettingsPage/BridgeAndExchangeSettings.js +32 -0
- package/pages/SettingsPage/GasPriceSettings.d.ts +2 -0
- package/pages/SettingsPage/GasPriceSettings.js +17 -0
- package/pages/SettingsPage/LanguageSetting.d.ts +2 -0
- package/pages/SettingsPage/LanguageSetting.js +22 -0
- package/pages/SettingsPage/ResetSettingsButton.js +4 -31
- package/pages/SettingsPage/RoutePrioritySettings.d.ts +2 -0
- package/pages/SettingsPage/RoutePrioritySettings.js +21 -0
- package/pages/SettingsPage/SendToWalletOptionSetting.d.ts +1 -0
- package/pages/SettingsPage/{ShowDestinationWallet.js → SendToWalletOptionSetting.js} +4 -7
- package/pages/SettingsPage/SettingsCard/BadgedValue.d.ts +8 -0
- package/pages/SettingsPage/SettingsCard/BadgedValue.js +3 -0
- package/pages/SettingsPage/SettingsCard/SettingCard.d.ts +2 -0
- package/pages/SettingsPage/SettingsCard/SettingCard.js +7 -0
- package/pages/SettingsPage/SettingsCard/SettingCard.style.d.ts +19 -0
- package/pages/SettingsPage/SettingsCard/SettingCard.style.js +50 -0
- package/pages/SettingsPage/SettingsCard/SettingCardButton.d.ts +7 -0
- package/pages/SettingsPage/SettingsCard/SettingCardButton.js +4 -0
- package/pages/SettingsPage/SettingsCard/SettingCardExpandable.d.ts +7 -0
- package/pages/SettingsPage/SettingsCard/SettingCardExpandable.js +12 -0
- package/pages/SettingsPage/SettingsCard/SettingsAccordian.d.ts +6 -0
- package/pages/SettingsPage/SettingsCard/SettingsAccordian.js +31 -0
- package/pages/SettingsPage/SettingsCard/index.d.ts +6 -0
- package/pages/SettingsPage/SettingsCard/index.js +6 -0
- package/pages/SettingsPage/SettingsCard/types.d.ts +5 -0
- package/pages/SettingsPage/SettingsPage.js +10 -9
- package/pages/SettingsPage/SlippageSettings/SlippageSettings.d.ts +2 -0
- package/pages/SettingsPage/SlippageSettings/SlippageSettings.js +47 -0
- package/pages/SettingsPage/SlippageSettings/SlippageSettings.style.d.ts +16 -0
- package/pages/SettingsPage/SlippageSettings/SlippageSettings.style.js +71 -0
- package/pages/SettingsPage/SlippageSettings/index.d.ts +1 -0
- package/pages/SettingsPage/SlippageSettings/index.js +1 -0
- package/pages/SettingsPage/ThemeSettings.d.ts +2 -0
- package/pages/SettingsPage/ThemeSettings.js +35 -0
- package/pages/TransactionDetailsPage/ContactSupportButton.js +2 -2
- package/pages/TransactionDetailsPage/TransactionDetailsPage.js +38 -33
- package/pages/TransactionDetailsPage/TransactionDetailsSkeleton.d.ts +1 -0
- package/pages/TransactionDetailsPage/TransactionDetailsSkeleton.js +27 -0
- package/pages/TransactionHistoryPage/TransactionHistoryItem.d.ts +4 -2
- package/pages/TransactionHistoryPage/TransactionHistoryItem.js +34 -7
- package/pages/TransactionHistoryPage/TransactionHistoryPage.js +24 -25
- package/pages/TransactionHistoryPage/TransactionHistorySkeleton.d.ts +1 -0
- package/pages/TransactionHistoryPage/TransactionHistorySkeleton.js +22 -0
- package/pages/TransactionHistoryPage/constants.d.ts +1 -0
- package/pages/TransactionHistoryPage/constants.js +1 -0
- package/pages/TransactionPage/ExchangeRateBottomSheet.js +11 -10
- package/pages/TransactionPage/StartTransactionButton.js +2 -2
- package/pages/TransactionPage/StatusBottomSheet.js +14 -10
- package/pages/TransactionPage/TransactionPage.js +1 -1
- package/providers/FormProvider/FormUpdater.js +4 -4
- package/providers/I18nProvider/I18nProvider.js +4 -8
- package/providers/I18nProvider/types.d.ts +4 -3
- package/providers/WalletProvider/EVMProvider.d.ts +3 -0
- package/providers/WalletProvider/EVMProvider.js +74 -0
- package/providers/WalletProvider/SDKProviders.d.ts +1 -0
- package/providers/WalletProvider/SDKProviders.js +27 -0
- package/providers/WalletProvider/SolanaProvider.d.ts +3 -0
- package/providers/WalletProvider/SolanaProvider.js +30 -0
- package/providers/WalletProvider/WalletProvider.d.ts +1 -15
- package/providers/WalletProvider/WalletProvider.js +5 -181
- package/providers/WalletProvider/index.d.ts +1 -1
- package/providers/WalletProvider/index.js +1 -1
- package/providers/WalletProvider/utils.d.ts +3 -0
- package/providers/WalletProvider/utils.js +21 -0
- package/providers/WidgetProvider/WidgetProvider.js +52 -36
- package/providers/index.d.ts +0 -1
- package/providers/index.js +0 -1
- package/stores/chains/ChainOrderStore.js +25 -1
- package/stores/header/useHeaderStore.d.ts +1 -1
- package/stores/header/useHeaderStore.js +2 -2
- package/stores/routes/createRouteExecutionStore.js +6 -60
- package/stores/routes/index.d.ts +0 -1
- package/stores/routes/index.js +0 -1
- package/stores/routes/types.d.ts +2 -2
- package/stores/routes/utils.d.ts +8 -8
- package/stores/routes/utils.js +5 -3
- package/stores/settings/useSettingsStore.js +2 -4
- package/stores/settings/useSplitSubvariantStore.d.ts +1 -1
- package/stores/settings/useSplitSubvariantStore.js +2 -2
- package/tsconfig.cjs.tsbuildinfo +1 -1
- package/types/events.d.ts +6 -5
- package/types/events.js +1 -1
- package/types/widget.d.ts +7 -14
- package/utils/colors.d.ts +3 -0
- package/utils/colors.js +10 -1
- package/utils/converters.d.ts +3 -0
- package/utils/converters.js +168 -0
- package/utils/format.d.ts +1 -1
- package/utils/format.js +5 -12
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/navigationRoutes.d.ts +1 -0
- package/utils/navigationRoutes.js +3 -1
- package/utils/svm.d.ts +1 -0
- package/utils/svm.js +10 -0
- package/cjs/components/LiFiLogo.d.ts +0 -5
- package/cjs/components/LiFiLogo.js +0 -10
- package/cjs/fonts/Inter-Black.woff +0 -0
- package/cjs/fonts/Inter-Black.woff2 +0 -0
- package/cjs/fonts/Inter-BlackItalic.woff +0 -0
- package/cjs/fonts/Inter-BlackItalic.woff2 +0 -0
- package/cjs/fonts/Inter-Bold.woff +0 -0
- package/cjs/fonts/Inter-Bold.woff2 +0 -0
- package/cjs/fonts/Inter-BoldItalic.woff +0 -0
- package/cjs/fonts/Inter-BoldItalic.woff2 +0 -0
- package/cjs/fonts/Inter-ExtraBold.woff +0 -0
- package/cjs/fonts/Inter-ExtraBold.woff2 +0 -0
- package/cjs/fonts/Inter-ExtraBoldItalic.woff +0 -0
- package/cjs/fonts/Inter-ExtraBoldItalic.woff2 +0 -0
- package/cjs/fonts/Inter-ExtraLight.woff +0 -0
- package/cjs/fonts/Inter-ExtraLight.woff2 +0 -0
- package/cjs/fonts/Inter-ExtraLightItalic.woff +0 -0
- package/cjs/fonts/Inter-ExtraLightItalic.woff2 +0 -0
- package/cjs/fonts/Inter-Italic.woff +0 -0
- package/cjs/fonts/Inter-Italic.woff2 +0 -0
- package/cjs/fonts/Inter-Light.woff +0 -0
- package/cjs/fonts/Inter-Light.woff2 +0 -0
- package/cjs/fonts/Inter-LightItalic.woff +0 -0
- package/cjs/fonts/Inter-LightItalic.woff2 +0 -0
- package/cjs/fonts/Inter-Medium.woff +0 -0
- package/cjs/fonts/Inter-Medium.woff2 +0 -0
- package/cjs/fonts/Inter-MediumItalic.woff +0 -0
- package/cjs/fonts/Inter-MediumItalic.woff2 +0 -0
- package/cjs/fonts/Inter-Regular.woff +0 -0
- package/cjs/fonts/Inter-Regular.woff2 +0 -0
- package/cjs/fonts/Inter-SemiBold.woff +0 -0
- package/cjs/fonts/Inter-SemiBold.woff2 +0 -0
- package/cjs/fonts/Inter-SemiBoldItalic.woff +0 -0
- package/cjs/fonts/Inter-SemiBoldItalic.woff2 +0 -0
- package/cjs/fonts/Inter-Thin.woff +0 -0
- package/cjs/fonts/Inter-Thin.woff2 +0 -0
- package/cjs/fonts/Inter-ThinItalic.woff +0 -0
- package/cjs/fonts/Inter-ThinItalic.woff2 +0 -0
- package/cjs/fonts/Inter-italic.var.woff2 +0 -0
- package/cjs/fonts/Inter-roman.var.woff2 +0 -0
- package/cjs/fonts/Inter.var.woff2 +0 -0
- package/cjs/fonts/inter.css +0 -217
- package/cjs/hooks/useGetTokenBalancesWithRetry.d.ts +0 -3
- package/cjs/hooks/useGetTokenBalancesWithRetry.js +0 -33
- package/cjs/icons/LiFiFullLogo.d.ts +0 -2
- package/cjs/icons/LiFiFullLogo.js +0 -6
- package/cjs/icons/LiFiLogo.d.ts +0 -2
- package/cjs/icons/LiFiLogo.js +0 -6
- package/cjs/icons/LiFiToolLogo.d.ts +0 -2
- package/cjs/icons/LiFiToolLogo.js +0 -6
- package/cjs/pages/SelectEnabledToolsPage/SelectEnabledToolsPage.style.js +0 -8
- package/cjs/pages/SettingsPage/ColorSchemeButtonGroup.d.ts +0 -2
- package/cjs/pages/SettingsPage/ColorSchemeButtonGroup.js +0 -27
- package/cjs/pages/SettingsPage/ColorSchemeButtonGroup.style.d.ts +0 -4
- package/cjs/pages/SettingsPage/ColorSchemeButtonGroup.style.js +0 -19
- package/cjs/pages/SettingsPage/EnabledToolsButton.js +0 -25
- package/cjs/pages/SettingsPage/EnabledToolsButton.style.d.ts +0 -5
- package/cjs/pages/SettingsPage/EnabledToolsButton.style.js +0 -17
- package/cjs/pages/SettingsPage/GasPriceSelect.d.ts +0 -1
- package/cjs/pages/SettingsPage/GasPriceSelect.js +0 -17
- package/cjs/pages/SettingsPage/LanguageSelect.d.ts +0 -2
- package/cjs/pages/SettingsPage/LanguageSelect.js +0 -37
- package/cjs/pages/SettingsPage/RoutePrioritySelect.d.ts +0 -2
- package/cjs/pages/SettingsPage/RoutePrioritySelect.js +0 -23
- package/cjs/pages/SettingsPage/ShowDestinationWallet.d.ts +0 -1
- package/cjs/pages/SettingsPage/SlippageInput.d.ts +0 -1
- package/cjs/pages/SettingsPage/SlippageInput.js +0 -30
- package/cjs/providers/SDKProvider/SDKProvider.d.ts +0 -4
- package/cjs/providers/SDKProvider/SDKProvider.js +0 -41
- package/cjs/providers/SDKProvider/index.d.ts +0 -1
- package/cjs/providers/WalletProvider/types.d.ts +0 -17
- package/cjs/stores/routes/useTransactionHistory.d.ts +0 -2
- package/cjs/stores/routes/useTransactionHistory.js +0 -15
- package/components/Header/NavigationTabs.style.js +0 -58
- package/components/LiFiLogo.d.ts +0 -5
- package/components/LiFiLogo.js +0 -6
- package/fonts/Inter-Black.woff +0 -0
- package/fonts/Inter-Black.woff2 +0 -0
- package/fonts/Inter-BlackItalic.woff +0 -0
- package/fonts/Inter-BlackItalic.woff2 +0 -0
- package/fonts/Inter-Bold.woff +0 -0
- package/fonts/Inter-Bold.woff2 +0 -0
- package/fonts/Inter-BoldItalic.woff +0 -0
- package/fonts/Inter-BoldItalic.woff2 +0 -0
- package/fonts/Inter-ExtraBold.woff +0 -0
- package/fonts/Inter-ExtraBold.woff2 +0 -0
- package/fonts/Inter-ExtraBoldItalic.woff +0 -0
- package/fonts/Inter-ExtraBoldItalic.woff2 +0 -0
- package/fonts/Inter-ExtraLight.woff +0 -0
- package/fonts/Inter-ExtraLight.woff2 +0 -0
- package/fonts/Inter-ExtraLightItalic.woff +0 -0
- package/fonts/Inter-ExtraLightItalic.woff2 +0 -0
- package/fonts/Inter-Italic.woff +0 -0
- package/fonts/Inter-Italic.woff2 +0 -0
- package/fonts/Inter-Light.woff +0 -0
- package/fonts/Inter-Light.woff2 +0 -0
- package/fonts/Inter-LightItalic.woff +0 -0
- package/fonts/Inter-LightItalic.woff2 +0 -0
- package/fonts/Inter-Medium.woff +0 -0
- package/fonts/Inter-Medium.woff2 +0 -0
- package/fonts/Inter-MediumItalic.woff +0 -0
- package/fonts/Inter-MediumItalic.woff2 +0 -0
- package/fonts/Inter-Regular.woff +0 -0
- package/fonts/Inter-Regular.woff2 +0 -0
- package/fonts/Inter-SemiBold.woff +0 -0
- package/fonts/Inter-SemiBold.woff2 +0 -0
- package/fonts/Inter-SemiBoldItalic.woff +0 -0
- package/fonts/Inter-SemiBoldItalic.woff2 +0 -0
- package/fonts/Inter-Thin.woff +0 -0
- package/fonts/Inter-Thin.woff2 +0 -0
- package/fonts/Inter-ThinItalic.woff +0 -0
- package/fonts/Inter-ThinItalic.woff2 +0 -0
- package/fonts/Inter-italic.var.woff2 +0 -0
- package/fonts/Inter-roman.var.woff2 +0 -0
- package/fonts/Inter.var.woff2 +0 -0
- package/fonts/inter.css +0 -217
- package/hooks/useGetTokenBalancesWithRetry.d.ts +0 -3
- package/hooks/useGetTokenBalancesWithRetry.js +0 -29
- package/icons/LiFiFullLogo.d.ts +0 -2
- package/icons/LiFiFullLogo.js +0 -2
- package/icons/LiFiLogo.d.ts +0 -2
- package/icons/LiFiLogo.js +0 -2
- package/icons/LiFiToolLogo.d.ts +0 -2
- package/icons/LiFiToolLogo.js +0 -2
- package/pages/SelectEnabledToolsPage/SelectEnabledToolsPage.style.js +0 -5
- package/pages/SettingsPage/ColorSchemeButtonGroup.d.ts +0 -2
- package/pages/SettingsPage/ColorSchemeButtonGroup.js +0 -23
- package/pages/SettingsPage/ColorSchemeButtonGroup.style.d.ts +0 -4
- package/pages/SettingsPage/ColorSchemeButtonGroup.style.js +0 -16
- package/pages/SettingsPage/EnabledToolsButton.js +0 -21
- package/pages/SettingsPage/EnabledToolsButton.style.d.ts +0 -5
- package/pages/SettingsPage/EnabledToolsButton.style.js +0 -14
- package/pages/SettingsPage/GasPriceSelect.d.ts +0 -1
- package/pages/SettingsPage/GasPriceSelect.js +0 -13
- package/pages/SettingsPage/LanguageSelect.d.ts +0 -2
- package/pages/SettingsPage/LanguageSelect.js +0 -33
- package/pages/SettingsPage/RoutePrioritySelect.d.ts +0 -2
- package/pages/SettingsPage/RoutePrioritySelect.js +0 -19
- package/pages/SettingsPage/ShowDestinationWallet.d.ts +0 -1
- package/pages/SettingsPage/SlippageInput.d.ts +0 -1
- package/pages/SettingsPage/SlippageInput.js +0 -26
- package/providers/SDKProvider/SDKProvider.d.ts +0 -4
- package/providers/SDKProvider/SDKProvider.js +0 -36
- package/providers/SDKProvider/index.d.ts +0 -1
- package/providers/SDKProvider/index.js +0 -1
- package/providers/WalletProvider/types.d.ts +0 -17
- package/stores/routes/useTransactionHistory.d.ts +0 -2
- package/stores/routes/useTransactionHistory.js +0 -11
- /package/cjs/{providers/WalletProvider → pages/SettingsPage/SettingsCard}/types.js +0 -0
- /package/{providers/WalletProvider → pages/SettingsPage/SettingsCard}/types.js +0 -0
package/cjs/hooks/useRoutes.js
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useRoutes = void 0;
|
|
4
|
-
const address_1 = require("@ethersproject/address");
|
|
5
4
|
const sdk_1 = require("@lifi/sdk");
|
|
6
5
|
const react_query_1 = require("@tanstack/react-query");
|
|
7
|
-
const
|
|
6
|
+
const core_1 = require("@wagmi/core");
|
|
8
7
|
const react_hook_form_1 = require("react-hook-form");
|
|
9
8
|
const uuid_1 = require("uuid");
|
|
9
|
+
const viem_1 = require("viem");
|
|
10
|
+
const ens_1 = require("viem/ens");
|
|
11
|
+
const wagmi_1 = require("wagmi");
|
|
10
12
|
const _1 = require(".");
|
|
11
13
|
const providers_1 = require("../providers");
|
|
12
14
|
const stores_1 = require("../stores");
|
|
15
|
+
const utils_1 = require("../utils");
|
|
16
|
+
const useAccount_1 = require("./useAccount");
|
|
13
17
|
const useSwapOnly_1 = require("./useSwapOnly");
|
|
14
18
|
const refetchTime = 60000;
|
|
15
19
|
const useRoutes = ({ insurableRoute } = {}) => {
|
|
16
|
-
const lifi = (0, providers_1.useLiFi)();
|
|
17
20
|
const { subvariant, sdkConfig, insurance, contractTool } = (0, providers_1.useWidgetConfig)();
|
|
18
|
-
const { account } = (0,
|
|
21
|
+
const { account } = (0, useAccount_1.useAccount)();
|
|
19
22
|
const queryClient = (0, react_query_1.useQueryClient)();
|
|
23
|
+
const config = (0, wagmi_1.useConfig)();
|
|
20
24
|
const swapOnly = (0, useSwapOnly_1.useSwapOnly)();
|
|
21
25
|
const { slippage, enabledBridges, enabledAutoRefuel, enabledExchanges, routePriority, } = (0, stores_1.useSettings)([
|
|
22
26
|
'slippage',
|
|
@@ -41,22 +45,28 @@ const useRoutes = ({ insurableRoute } = {}) => {
|
|
|
41
45
|
});
|
|
42
46
|
const { token: fromToken } = (0, _1.useToken)(fromChainId, fromTokenAddress);
|
|
43
47
|
const { token: toToken } = (0, _1.useToken)(toChainId, toTokenAddress);
|
|
48
|
+
const { chain: fromChain } = (0, _1.useChain)(fromChainId);
|
|
49
|
+
const { chain: toChain } = (0, _1.useChain)(toChainId);
|
|
44
50
|
const { enabled: enabledRefuel, fromAmount: gasRecommendationFromAmount } = (0, _1.useGasRefuel)();
|
|
45
51
|
const hasAmount = (!isNaN(fromTokenAmount) && Number(fromTokenAmount) > 0) ||
|
|
46
52
|
(!isNaN(toTokenAmount) && Number(toTokenAmount) > 0);
|
|
47
53
|
const contractCallQuoteEnabled = subvariant === 'nft'
|
|
48
54
|
? Boolean(toContractAddress && toContractCallData && toContractGasLimit)
|
|
49
55
|
: true;
|
|
56
|
+
// When we bridge between ecosystems we need to be sure toAddress is set
|
|
57
|
+
const isChainTypeSatisfied = fromChain?.chainType !== toChain?.chainType ? Boolean(toAddress) : true;
|
|
50
58
|
const isEnabled = !isNaN(fromChainId) &&
|
|
51
59
|
!isNaN(toChainId) &&
|
|
52
60
|
Boolean(fromToken?.address) &&
|
|
53
61
|
Boolean(toToken?.address) &&
|
|
54
62
|
!Number.isNaN(slippage) &&
|
|
55
63
|
hasAmount &&
|
|
64
|
+
isChainTypeSatisfied &&
|
|
56
65
|
contractCallQuoteEnabled;
|
|
66
|
+
const accountAddress = fromChain?.chainType === account.chainType ? account.address : undefined;
|
|
57
67
|
const queryKey = [
|
|
58
68
|
'routes',
|
|
59
|
-
|
|
69
|
+
accountAddress,
|
|
60
70
|
fromChainId,
|
|
61
71
|
fromToken?.address,
|
|
62
72
|
fromTokenAmount,
|
|
@@ -72,126 +82,119 @@ const useRoutes = ({ insurableRoute } = {}) => {
|
|
|
72
82
|
enabledExchanges,
|
|
73
83
|
routePriority,
|
|
74
84
|
subvariant,
|
|
75
|
-
sdkConfig?.
|
|
85
|
+
sdkConfig?.routeOptions?.allowSwitchChain,
|
|
76
86
|
enabledRefuel && enabledAutoRefuel,
|
|
77
87
|
gasRecommendationFromAmount,
|
|
78
88
|
insurance,
|
|
79
89
|
insurableRoute?.id,
|
|
80
90
|
];
|
|
81
|
-
const { data, isLoading, isFetching, isFetched, dataUpdatedAt, refetch } = (0, react_query_1.useQuery)(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
toWalletAddress =
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
.
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
91
|
+
const { data, isLoading, isFetching, isFetched, dataUpdatedAt, refetch } = (0, react_query_1.useQuery)({
|
|
92
|
+
queryKey,
|
|
93
|
+
queryFn: async ({ queryKey: [_, fromAddress, fromChainId, fromTokenAddress, fromTokenAmount, toAddress, toChainId, toTokenAddress, toTokenAmount, toContractAddress, toContractCallData, toContractGasLimit, slippage, enabledBridges, enabledExchanges, routePriority, subvariant, allowSwitchChain, enabledRefuel, gasRecommendationFromAmount, insurance, insurableRouteId,], signal, }) => {
|
|
94
|
+
let toWalletAddress = toAddress || fromAddress;
|
|
95
|
+
const isAddress = (0, viem_1.isAddress)(toAddress) || (0, utils_1.isSVMAddress)(toAddress);
|
|
96
|
+
try {
|
|
97
|
+
// FIXME: resolve address in one place
|
|
98
|
+
toWalletAddress = !isAddress
|
|
99
|
+
? await (0, core_1.getEnsAddress)(config, {
|
|
100
|
+
chainId: toChainId,
|
|
101
|
+
name: (0, ens_1.normalize)(toAddress),
|
|
102
|
+
})
|
|
103
|
+
: isAddress
|
|
104
|
+
? toAddress
|
|
105
|
+
: fromAddress;
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
toWalletAddress = isAddress ? toAddress : fromAddress;
|
|
109
|
+
}
|
|
110
|
+
const fromAmount = (0, viem_1.parseUnits)(fromTokenAmount, fromToken.decimals).toString();
|
|
111
|
+
const formattedSlippage = parseFloat(slippage) / 100;
|
|
112
|
+
const allowedBridges = insurableRoute
|
|
113
|
+
? insurableRoute.steps.flatMap((step) => step.includedSteps
|
|
114
|
+
.filter((includedStep) => includedStep.type === 'cross')
|
|
115
|
+
.map((includedStep) => includedStep.toolDetails.key))
|
|
116
|
+
: enabledBridges;
|
|
117
|
+
const allowedExchanges = insurableRoute
|
|
118
|
+
? insurableRoute.steps.flatMap((step) => step.includedSteps
|
|
119
|
+
.filter((includedStep) => includedStep.type === 'swap')
|
|
120
|
+
.map((includedStep) => includedStep.toolDetails.key))
|
|
121
|
+
: enabledExchanges;
|
|
122
|
+
if (subvariant === 'nft') {
|
|
123
|
+
const contractCallQuote = await (0, sdk_1.getContractCallQuote)({
|
|
124
|
+
fromAddress,
|
|
125
|
+
fromChain: fromChainId,
|
|
126
|
+
fromToken: fromTokenAddress,
|
|
127
|
+
toAmount: toTokenAmount,
|
|
128
|
+
toChain: toChainId,
|
|
129
|
+
toToken: toTokenAddress,
|
|
130
|
+
toContractAddress,
|
|
131
|
+
toContractCallData,
|
|
132
|
+
toContractGasLimit,
|
|
133
|
+
allowBridges: allowedBridges,
|
|
134
|
+
toFallbackAddress: toWalletAddress,
|
|
135
|
+
slippage: formattedSlippage,
|
|
136
|
+
}, { signal });
|
|
137
|
+
contractCallQuote.action.toToken = toToken;
|
|
138
|
+
const customStep = subvariant === 'nft'
|
|
139
|
+
? contractCallQuote.includedSteps?.find((step) => step.type === 'custom')
|
|
140
|
+
: undefined;
|
|
141
|
+
if (customStep && contractTool) {
|
|
142
|
+
const toolDetails = {
|
|
143
|
+
key: contractTool.name,
|
|
144
|
+
name: contractTool.name,
|
|
145
|
+
logoURI: contractTool.logoURI,
|
|
146
|
+
};
|
|
147
|
+
customStep.toolDetails = toolDetails;
|
|
148
|
+
contractCallQuote.toolDetails = toolDetails;
|
|
149
|
+
}
|
|
150
|
+
const route = {
|
|
151
|
+
id: (0, uuid_1.v4)(),
|
|
152
|
+
fromChainId: contractCallQuote.action.fromChainId,
|
|
153
|
+
fromAmountUSD: contractCallQuote.estimate.fromAmountUSD || '',
|
|
154
|
+
fromAmount: contractCallQuote.action.fromAmount,
|
|
155
|
+
fromToken: contractCallQuote.action.fromToken,
|
|
156
|
+
fromAddress: contractCallQuote.action.fromAddress,
|
|
157
|
+
toChainId: contractCallQuote.action.toChainId,
|
|
158
|
+
toAmountUSD: contractCallQuote.estimate.toAmountUSD || '',
|
|
159
|
+
toAmount: toTokenAmount,
|
|
160
|
+
toAmountMin: toTokenAmount,
|
|
161
|
+
toToken: toToken,
|
|
162
|
+
toAddress: toWalletAddress,
|
|
163
|
+
gasCostUSD: contractCallQuote.estimate.gasCosts?.[0].amountUSD,
|
|
164
|
+
steps: [contractCallQuote],
|
|
165
|
+
insurance: { state: 'NOT_INSURABLE', feeAmountUsd: '0' },
|
|
129
166
|
};
|
|
130
|
-
|
|
131
|
-
contractCallQuote.toolDetails = toolDetails;
|
|
167
|
+
return { routes: [route] };
|
|
132
168
|
}
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
fromAddress
|
|
140
|
-
toChainId: contractCallQuote.action.toChainId,
|
|
141
|
-
toAmountUSD: contractCallQuote.estimate.toAmountUSD || '',
|
|
142
|
-
toAmount: toTokenAmount,
|
|
143
|
-
toAmountMin: toTokenAmount,
|
|
144
|
-
toToken: toToken,
|
|
169
|
+
const data = await (0, sdk_1.getRoutes)({
|
|
170
|
+
fromChainId,
|
|
171
|
+
fromAmount,
|
|
172
|
+
fromTokenAddress,
|
|
173
|
+
toChainId,
|
|
174
|
+
toTokenAddress,
|
|
175
|
+
fromAddress,
|
|
145
176
|
toAddress: toWalletAddress,
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
fromAmountForGas: enabledRefuel && gasRecommendationFromAmount
|
|
161
|
-
? gasRecommendationFromAmount
|
|
162
|
-
: undefined,
|
|
163
|
-
options: {
|
|
164
|
-
slippage: formattedSlippage,
|
|
165
|
-
bridges: {
|
|
166
|
-
allow: allowedBridges,
|
|
167
|
-
},
|
|
168
|
-
exchanges: {
|
|
169
|
-
allow: allowedExchanges,
|
|
177
|
+
fromAmountForGas: enabledRefuel && gasRecommendationFromAmount
|
|
178
|
+
? gasRecommendationFromAmount
|
|
179
|
+
: undefined,
|
|
180
|
+
options: {
|
|
181
|
+
slippage: formattedSlippage,
|
|
182
|
+
bridges: {
|
|
183
|
+
allow: allowedBridges,
|
|
184
|
+
},
|
|
185
|
+
exchanges: {
|
|
186
|
+
allow: allowedExchanges,
|
|
187
|
+
},
|
|
188
|
+
order: routePriority,
|
|
189
|
+
allowSwitchChain: subvariant === 'refuel' ? false : allowSwitchChain,
|
|
190
|
+
insurance: insurance ? Boolean(insurableRoute) : undefined,
|
|
170
191
|
},
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
insurance: insurance ? Boolean(insurableRoute) : undefined,
|
|
174
|
-
},
|
|
175
|
-
}, { signal });
|
|
176
|
-
}, {
|
|
177
|
-
enabled: isEnabled,
|
|
178
|
-
staleTime: refetchTime,
|
|
179
|
-
cacheTime: refetchTime,
|
|
180
|
-
refetchInterval(data, query) {
|
|
181
|
-
return Math.min(Math.abs(refetchTime - (Date.now() - query.state.dataUpdatedAt)), refetchTime);
|
|
182
|
-
},
|
|
183
|
-
retry(failureCount, error) {
|
|
184
|
-
if (error?.code === sdk_1.LifiErrorCode.NotFound) {
|
|
185
|
-
return false;
|
|
186
|
-
}
|
|
187
|
-
return true;
|
|
188
|
-
},
|
|
189
|
-
onSuccess(data) {
|
|
190
|
-
if (data.routes[0]) {
|
|
192
|
+
}, { signal });
|
|
193
|
+
if (data.routes[0] && fromAddress) {
|
|
191
194
|
// Update local tokens cache to keep priceUSD in sync
|
|
192
195
|
const { fromToken, toToken } = data.routes[0];
|
|
193
196
|
[fromToken, toToken].forEach((token) => {
|
|
194
|
-
queryClient.setQueriesData(['token-balances',
|
|
197
|
+
queryClient.setQueriesData({ queryKey: ['token-balances', fromAddress, token.chainId] }, (data) => {
|
|
195
198
|
if (data) {
|
|
196
199
|
const clonedData = [...data];
|
|
197
200
|
const index = clonedData.findIndex((dataToken) => dataToken.address === token.address);
|
|
@@ -204,6 +207,18 @@ const useRoutes = ({ insurableRoute } = {}) => {
|
|
|
204
207
|
});
|
|
205
208
|
});
|
|
206
209
|
}
|
|
210
|
+
return data;
|
|
211
|
+
},
|
|
212
|
+
enabled: isEnabled,
|
|
213
|
+
staleTime: refetchTime,
|
|
214
|
+
refetchInterval(query) {
|
|
215
|
+
return Math.min(Math.abs(refetchTime - (Date.now() - query.state.dataUpdatedAt)), refetchTime);
|
|
216
|
+
},
|
|
217
|
+
retry(_, error) {
|
|
218
|
+
if (error?.code === sdk_1.LiFiErrorCode.NotFound) {
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
return true;
|
|
207
222
|
},
|
|
208
223
|
});
|
|
209
224
|
return {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const useSettingMonitor: () => {
|
|
2
|
+
isBridgesChanged: boolean;
|
|
3
|
+
isExchangesChanged: boolean;
|
|
4
|
+
isSlippageChanged: boolean;
|
|
5
|
+
isSlippageOutsideRecommendedLimits: boolean;
|
|
6
|
+
isRoutePriorityChanged: boolean;
|
|
7
|
+
isGasPriceChanged: boolean;
|
|
8
|
+
isCustomRouteSettings: boolean;
|
|
9
|
+
isRouteSettingsWithWarnings: boolean;
|
|
10
|
+
reset: () => void;
|
|
11
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useSettingMonitor = void 0;
|
|
4
|
+
const stores_1 = require("../stores");
|
|
5
|
+
const shallow_1 = require("zustand/shallow");
|
|
6
|
+
const useTools_1 = require("./useTools");
|
|
7
|
+
const providers_1 = require("../providers");
|
|
8
|
+
const useSettingMonitor = () => {
|
|
9
|
+
const [enabledBridges, enabledExchanges, routePriority, slippage, gasPrice] = (0, stores_1.useSettingsStore)((state) => [
|
|
10
|
+
state.enabledBridges,
|
|
11
|
+
state.enabledExchanges,
|
|
12
|
+
state.routePriority,
|
|
13
|
+
state.slippage,
|
|
14
|
+
state.gasPrice,
|
|
15
|
+
], shallow_1.shallow);
|
|
16
|
+
const { tools } = (0, useTools_1.useTools)();
|
|
17
|
+
const resetSettings = (0, stores_1.useSettingsStore)((state) => state.reset);
|
|
18
|
+
const config = (0, providers_1.useWidgetConfig)();
|
|
19
|
+
const isSlippageChanged = config.slippage
|
|
20
|
+
? Number(slippage) !== config.slippage * 100
|
|
21
|
+
: slippage !== stores_1.defaultConfigurableSettings.slippage;
|
|
22
|
+
const isSlippageOutsideRecommendedLimits = isSlippageChanged && Number(slippage) > 1;
|
|
23
|
+
const isRoutePriorityChanged = config.routePriority
|
|
24
|
+
? routePriority !== config.routePriority
|
|
25
|
+
: routePriority !== stores_1.defaultConfigurableSettings.routePriority;
|
|
26
|
+
const isGasPriceChanged = gasPrice !== stores_1.defaultConfigurableSettings.gasPrice;
|
|
27
|
+
const isBridgesChanged = tools?.bridges
|
|
28
|
+
? tools?.bridges?.length !== enabledBridges?.length
|
|
29
|
+
: false;
|
|
30
|
+
const isExchangesChanged = tools?.exchanges
|
|
31
|
+
? tools?.exchanges?.length !== enabledExchanges?.length
|
|
32
|
+
: false;
|
|
33
|
+
const isCustomRouteSettings = isBridgesChanged ||
|
|
34
|
+
isExchangesChanged ||
|
|
35
|
+
isSlippageChanged ||
|
|
36
|
+
isRoutePriorityChanged ||
|
|
37
|
+
isGasPriceChanged;
|
|
38
|
+
const isRouteSettingsWithWarnings = isSlippageOutsideRecommendedLimits;
|
|
39
|
+
const reset = () => {
|
|
40
|
+
if (tools) {
|
|
41
|
+
resetSettings(config, tools.bridges.map((tool) => tool.key), tools.exchanges.map((tool) => tool.key));
|
|
42
|
+
(0, stores_1.setDefaultSettings)(config);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
isBridgesChanged,
|
|
47
|
+
isExchangesChanged,
|
|
48
|
+
isSlippageChanged,
|
|
49
|
+
isSlippageOutsideRecommendedLimits,
|
|
50
|
+
isRoutePriorityChanged,
|
|
51
|
+
isGasPriceChanged,
|
|
52
|
+
isCustomRouteSettings,
|
|
53
|
+
isRouteSettingsWithWarnings,
|
|
54
|
+
reset,
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
exports.useSettingMonitor = useSettingMonitor;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const useTokenAddressBalance: (chainId?: number, tokenAddress?: string) => {
|
|
2
2
|
token: import("..").TokenAmount | undefined;
|
|
3
3
|
isLoading: boolean;
|
|
4
|
-
refetch:
|
|
4
|
+
refetch: (options?: import("@tanstack/query-core/build/legacy/queryClient-IoYjXsnV").Z | undefined) => Promise<import("@tanstack/query-core/build/legacy/queryClient-IoYjXsnV").ac<import("..").TokenAmount[], Error>>;
|
|
5
5
|
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { ExtendedChain } from '@lifi/sdk';
|
|
2
|
+
import { type Token, type TokenAmount } from '@lifi/sdk';
|
|
3
|
+
export declare const useTokenBalance: (accountAddress?: string, token?: Token, chain?: ExtendedChain) => {
|
|
3
4
|
token: TokenAmount | undefined;
|
|
4
5
|
isLoading: boolean;
|
|
5
|
-
refetch:
|
|
6
|
+
refetch: (options?: import("@tanstack/query-core/build/legacy/queryClient-IoYjXsnV").Z | undefined) => Promise<import("@tanstack/query-core/build/legacy/queryClient-IoYjXsnV").ac<TokenAmount, Error>>;
|
|
6
7
|
refetchNewBalance: () => void;
|
|
7
8
|
refetchAllBalances: () => void;
|
|
8
9
|
getTokenBalancesWithRetry: (accountAddress: string, tokens: Token[], depth?: number) => Promise<TokenAmount[] | undefined>;
|
|
9
10
|
};
|
|
11
|
+
export declare const getTokenBalancesWithRetry: (accountAddress: string, tokens: Token[], depth?: number) => Promise<TokenAmount[] | undefined>;
|
|
@@ -1,62 +1,72 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useTokenBalance = void 0;
|
|
3
|
+
exports.getTokenBalancesWithRetry = exports.useTokenBalance = void 0;
|
|
4
|
+
const sdk_1 = require("@lifi/sdk");
|
|
4
5
|
const react_query_1 = require("@tanstack/react-query");
|
|
5
6
|
const react_1 = require("react");
|
|
6
|
-
const
|
|
7
|
-
const useGetTokenBalancesWithRetry_1 = require("./useGetTokenBalancesWithRetry");
|
|
7
|
+
const useAccount_1 = require("./useAccount");
|
|
8
8
|
const defaultRefetchInterval = 30000;
|
|
9
|
-
const useTokenBalance = (token,
|
|
10
|
-
const { account } = (0,
|
|
9
|
+
const useTokenBalance = (accountAddress, token, chain) => {
|
|
10
|
+
const { account } = (0, useAccount_1.useAccount)();
|
|
11
11
|
const queryClient = (0, react_query_1.useQueryClient)();
|
|
12
|
-
const walletAddress = accountAddress ||
|
|
13
|
-
|
|
12
|
+
const walletAddress = accountAddress ||
|
|
13
|
+
// When we provide chain we want to be sure that account address used is from the same ecosystem as token
|
|
14
|
+
!chain
|
|
15
|
+
? account.address
|
|
16
|
+
: chain.chainType === account.chainType
|
|
17
|
+
? account.address
|
|
18
|
+
: undefined;
|
|
14
19
|
const tokenBalanceQueryKey = (0, react_1.useMemo)(() => ['token-balance', walletAddress, token?.chainId, token?.address], [token?.address, token?.chainId, walletAddress]);
|
|
15
|
-
const { data, isLoading, refetch } = (0, react_query_1.useQuery)(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (!tokenBalances?.length) {
|
|
28
|
-
throw Error('Could not get tokens balance.');
|
|
29
|
-
}
|
|
30
|
-
const cachedTokenAmount = queryClient.getQueryData(tokenBalanceQueryKey);
|
|
31
|
-
const tokenAmount = tokenBalances[0].amount;
|
|
32
|
-
if (cachedTokenAmount?.amount !== tokenAmount) {
|
|
33
|
-
queryClient.setQueryDefaults(tokenBalanceQueryKey, {
|
|
34
|
-
refetchInterval: defaultRefetchInterval,
|
|
35
|
-
staleTime: defaultRefetchInterval,
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
queryClient.setQueriesData(['token-balances', accountAddress, token.chainId], (data) => {
|
|
39
|
-
if (data) {
|
|
40
|
-
const clonedData = [...data];
|
|
41
|
-
const index = clonedData.findIndex((dataToken) => dataToken.address === token.address);
|
|
42
|
-
clonedData[index] = {
|
|
43
|
-
...clonedData[index],
|
|
44
|
-
amount: tokenAmount,
|
|
45
|
-
};
|
|
46
|
-
return clonedData;
|
|
20
|
+
const { data, isLoading, refetch } = (0, react_query_1.useQuery)({
|
|
21
|
+
queryKey: tokenBalanceQueryKey,
|
|
22
|
+
queryFn: async ({ queryKey: [, accountAddress] }) => {
|
|
23
|
+
const cachedToken = queryClient
|
|
24
|
+
.getQueryData([
|
|
25
|
+
'token-balances',
|
|
26
|
+
accountAddress,
|
|
27
|
+
token.chainId,
|
|
28
|
+
])
|
|
29
|
+
?.find((t) => t.address === token.address);
|
|
30
|
+
if (cachedToken) {
|
|
31
|
+
return cachedToken;
|
|
47
32
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
33
|
+
const tokenBalances = await (0, exports.getTokenBalancesWithRetry)(accountAddress, [token]);
|
|
34
|
+
if (!tokenBalances?.length) {
|
|
35
|
+
throw Error('Could not get tokens balance.');
|
|
36
|
+
}
|
|
37
|
+
const cachedTokenAmount = queryClient.getQueryData(tokenBalanceQueryKey);
|
|
38
|
+
const tokenAmount = tokenBalances[0].amount;
|
|
39
|
+
if (cachedTokenAmount?.amount !== tokenAmount) {
|
|
40
|
+
queryClient.setQueryDefaults(tokenBalanceQueryKey, {
|
|
41
|
+
refetchInterval: defaultRefetchInterval,
|
|
42
|
+
staleTime: defaultRefetchInterval,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
queryClient.setQueriesData({ queryKey: ['token-balances', accountAddress, token.chainId] }, (data) => {
|
|
46
|
+
if (data) {
|
|
47
|
+
const clonedData = [...data];
|
|
48
|
+
const index = clonedData.findIndex((dataToken) => dataToken.address === token.address);
|
|
49
|
+
clonedData[index] = {
|
|
50
|
+
...clonedData[index],
|
|
51
|
+
amount: tokenAmount,
|
|
52
|
+
};
|
|
53
|
+
return clonedData;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
...tokenBalances[0],
|
|
58
|
+
amount: tokenAmount,
|
|
59
|
+
};
|
|
60
|
+
},
|
|
54
61
|
enabled: Boolean(walletAddress && token),
|
|
55
62
|
refetchInterval: defaultRefetchInterval,
|
|
56
63
|
staleTime: defaultRefetchInterval,
|
|
57
64
|
});
|
|
58
65
|
const refetchAllBalances = () => {
|
|
59
|
-
queryClient.refetchQueries(
|
|
66
|
+
queryClient.refetchQueries({
|
|
67
|
+
queryKey: ['token-balances', accountAddress, token?.chainId],
|
|
68
|
+
exact: false,
|
|
69
|
+
});
|
|
60
70
|
};
|
|
61
71
|
const refetchNewBalance = (0, react_1.useCallback)(() => {
|
|
62
72
|
queryClient.setQueryDefaults(tokenBalanceQueryKey, {
|
|
@@ -70,7 +80,27 @@ const useTokenBalance = (token, accountAddress) => {
|
|
|
70
80
|
refetch,
|
|
71
81
|
refetchNewBalance,
|
|
72
82
|
refetchAllBalances,
|
|
73
|
-
getTokenBalancesWithRetry,
|
|
83
|
+
getTokenBalancesWithRetry: exports.getTokenBalancesWithRetry,
|
|
74
84
|
};
|
|
75
85
|
};
|
|
76
86
|
exports.useTokenBalance = useTokenBalance;
|
|
87
|
+
const getTokenBalancesWithRetry = async (accountAddress, tokens, depth = 0) => {
|
|
88
|
+
try {
|
|
89
|
+
const tokenBalances = await (0, sdk_1.getTokenBalances)(accountAddress, tokens);
|
|
90
|
+
if (!tokenBalances.every((token) => token.blockNumber)) {
|
|
91
|
+
if (depth > 10) {
|
|
92
|
+
console.warn('Token balance backoff depth exceeded.');
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
await new Promise((resolve) => {
|
|
96
|
+
setTimeout(resolve, 1.5 ** depth * 100);
|
|
97
|
+
});
|
|
98
|
+
return (0, exports.getTokenBalancesWithRetry)(accountAddress, tokens, depth + 1);
|
|
99
|
+
}
|
|
100
|
+
return tokenBalances;
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
//
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
exports.getTokenBalancesWithRetry = getTokenBalancesWithRetry;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { TokenAmount } from '../types';
|
|
2
2
|
export declare const useTokenBalances: (selectedChainId?: number) => {
|
|
3
|
-
tokens: TokenAmount[];
|
|
3
|
+
tokens: TokenAmount[] | undefined;
|
|
4
4
|
tokensWithBalance: TokenAmount[] | undefined;
|
|
5
|
-
featuredTokens: import("@lifi/
|
|
5
|
+
featuredTokens: import("@lifi/sdk").StaticToken[] | undefined;
|
|
6
6
|
isLoading: boolean;
|
|
7
7
|
isBalanceLoading: boolean;
|
|
8
|
-
refetch:
|
|
8
|
+
refetch: (options?: import("@tanstack/query-core/build/legacy/queryClient-IoYjXsnV").Z | undefined) => Promise<import("@tanstack/query-core/build/legacy/queryClient-IoYjXsnV").ac<TokenAmount[], Error>>;
|
|
9
9
|
};
|
|
@@ -1,38 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useTokenBalances = void 0;
|
|
4
|
+
const sdk_1 = require("@lifi/sdk");
|
|
4
5
|
const react_query_1 = require("@tanstack/react-query");
|
|
5
|
-
const
|
|
6
|
+
const viem_1 = require("viem");
|
|
7
|
+
const useAccount_1 = require("./useAccount");
|
|
6
8
|
const useFeaturedTokens_1 = require("./useFeaturedTokens");
|
|
7
9
|
const useTokens_1 = require("./useTokens");
|
|
8
10
|
const defaultRefetchInterval = 32000;
|
|
9
11
|
const useTokenBalances = (selectedChainId) => {
|
|
10
|
-
const
|
|
11
|
-
const { account } = (0, providers_1.useWallet)();
|
|
12
|
+
const { accounts } = (0, useAccount_1.useAccount)();
|
|
12
13
|
const featuredTokens = (0, useFeaturedTokens_1.useFeaturedTokens)(selectedChainId);
|
|
13
|
-
const { tokens, isLoading } = (0, useTokens_1.useTokens)(selectedChainId);
|
|
14
|
-
const
|
|
14
|
+
const { tokens, chain, isLoading } = (0, useTokens_1.useTokens)(selectedChainId);
|
|
15
|
+
const account = accounts.find((account) => account.chainType === chain?.chainType);
|
|
16
|
+
const isBalanceLoadingEnabled = Boolean(account?.address) &&
|
|
15
17
|
Boolean(tokens?.length) &&
|
|
16
18
|
Boolean(selectedChainId);
|
|
17
|
-
const { data: tokensWithBalance, isLoading: isBalanceLoading, refetch, } = (0, react_query_1.useQuery)(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
19
|
+
const { data: tokensWithBalance, isLoading: isBalanceLoading, refetch, } = (0, react_query_1.useQuery)({
|
|
20
|
+
queryKey: [
|
|
21
|
+
'token-balances',
|
|
22
|
+
account?.address,
|
|
23
|
+
selectedChainId,
|
|
24
|
+
tokens?.length,
|
|
25
|
+
],
|
|
26
|
+
queryFn: async ({ queryKey: [, accountAddress] }) => {
|
|
27
|
+
const tokenBalances = await (0, sdk_1.getTokenBalances)(accountAddress, tokens);
|
|
28
|
+
const featuredTokenAddresses = new Set(featuredTokens?.map((token) => token.address));
|
|
29
|
+
const sortFn = (a, b) => parseFloat((0, viem_1.formatUnits)(b.amount ?? 0n, b.decimals)) *
|
|
30
|
+
parseFloat(b.priceUSD ?? '0') -
|
|
31
|
+
parseFloat((0, viem_1.formatUnits)(a.amount ?? 0n, a.decimals)) *
|
|
32
|
+
parseFloat(a.priceUSD ?? '0');
|
|
33
|
+
const formattedTokens = (tokenBalances.length === 0 ? tokens : tokenBalances);
|
|
34
|
+
const result = [
|
|
35
|
+
...formattedTokens
|
|
36
|
+
.filter((token) => token.amount && featuredTokenAddresses.has(token.address))
|
|
37
|
+
.sort(sortFn),
|
|
38
|
+
...formattedTokens.filter((token) => !token.amount && featuredTokenAddresses.has(token.address)),
|
|
39
|
+
...formattedTokens
|
|
40
|
+
.filter((token) => token.amount && !featuredTokenAddresses.has(token.address))
|
|
41
|
+
.sort(sortFn),
|
|
42
|
+
...formattedTokens.filter((token) => !token.amount && !featuredTokenAddresses.has(token.address)),
|
|
43
|
+
];
|
|
44
|
+
return result;
|
|
45
|
+
},
|
|
36
46
|
enabled: isBalanceLoadingEnabled,
|
|
37
47
|
refetchInterval: defaultRefetchInterval,
|
|
38
48
|
staleTime: defaultRefetchInterval,
|