@lifi/widget 2.0.0-beta.1 → 2.0.0-beta.10
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.d.ts +4 -3
- package/AppDrawer.d.ts +1 -1
- package/AppDrawer.js +2 -1
- package/AppProvider.js +1 -1
- package/README.md +11 -12
- package/cjs/App.d.ts +4 -3
- package/cjs/AppDrawer.d.ts +1 -1
- package/cjs/AppDrawer.js +2 -1
- package/cjs/AppProvider.js +1 -1
- package/cjs/components/ChainSelect/ChainSelect.d.ts +1 -2
- package/cjs/components/ChainSelect/ChainSelect.style.js +1 -1
- package/cjs/components/ChainSelect/useChainSelect.js +6 -0
- package/cjs/components/GasMessage/FundsSufficiencyMessage.d.ts +1 -2
- package/cjs/components/GasMessage/GasMessage.js +1 -6
- package/cjs/components/Header/Header.js +2 -2
- package/cjs/components/Header/Header.style.d.ts +10 -3
- package/cjs/components/Header/Header.style.js +3 -0
- package/cjs/components/Header/NavigationHeader.js +23 -7
- package/cjs/components/Header/NavigationTabs.d.ts +1 -0
- package/cjs/components/Header/NavigationTabs.js +26 -0
- package/cjs/components/Header/NavigationTabs.style.d.ts +34 -0
- package/cjs/components/Header/NavigationTabs.style.js +61 -0
- package/cjs/components/Header/WalletHeader.d.ts +1 -0
- package/cjs/components/Header/WalletHeader.js +16 -9
- package/cjs/components/Header/useHeaderActionStore.js +0 -1
- package/cjs/components/Insurance/Insurance.js +2 -2
- package/cjs/components/Insurance/InsuranceCard.js +34 -12
- package/cjs/components/Insurance/InsuranceCollapsed.js +9 -11
- package/cjs/components/Insurance/index.d.ts +1 -0
- package/cjs/components/Insurance/index.js +1 -0
- package/cjs/components/Insurance/types.d.ts +12 -9
- package/cjs/components/NFT/NFT.js +2 -2
- package/cjs/components/NFT/types.d.ts +1 -1
- package/cjs/components/PoweredBy/PoweredBy.js +2 -3
- package/cjs/components/SelectChainAndToken.js +8 -7
- package/cjs/components/SelectTokenButton/SelectTokenButton.js +6 -3
- package/cjs/components/SendToWallet/SendToWallet.js +2 -2
- package/cjs/components/SmallAvatar.d.ts +1 -1
- package/cjs/components/Step/CircularProgress.d.ts +1 -2
- package/cjs/components/Step/Step.js +15 -5
- package/cjs/components/Step/StepList.d.ts +1 -2
- package/cjs/components/StepActions/StepActions.js +4 -20
- package/cjs/components/SwapButton/SwapButton.js +16 -4
- package/cjs/components/SwapInput/FormPriceHelperText.js +1 -1
- package/cjs/components/SwapInput/SwapInput.js +2 -2
- package/cjs/components/SwapInput/SwapInputEndAdornment.d.ts +1 -2
- package/cjs/components/SwapInput/SwapInputEndAdornment.js +2 -2
- package/cjs/components/SwapRouteCard/SwapRouteCard.js +19 -3
- package/cjs/components/SwapRouteCard/SwapRouteCardEssentials.js +1 -1
- package/cjs/components/SwapRouteCard/SwapRouteCardSkeleton.js +1 -1
- package/cjs/components/SwapRoutes/SwapRoutes.js +1 -1
- package/cjs/components/SwapRoutes/SwapRoutesExpanded.d.ts +2 -3
- package/cjs/components/SwapRoutes/SwapRoutesExpanded.js +2 -2
- package/cjs/components/SwapRoutes/SwapRoutesExpanded.style.js +1 -0
- package/cjs/components/Token/Token.js +1 -1
- package/cjs/components/TokenAvatar/TokenAvatar.d.ts +4 -4
- package/cjs/components/TokenList/TokenList.js +9 -4
- package/cjs/components/TokenList/TokenList.style.d.ts +5 -2
- package/cjs/components/TokenList/TokenList.style.js +20 -1
- package/cjs/components/TokenList/TokenListItem.d.ts +1 -1
- package/cjs/components/TokenList/TokenListItem.js +28 -5
- package/cjs/components/TokenList/VirtualizedTokenList.js +3 -3
- package/cjs/components/TokenList/types.d.ts +6 -3
- package/cjs/config/theme.js +15 -3
- package/cjs/config/version.d.ts +1 -1
- package/cjs/config/version.js +1 -1
- package/cjs/hooks/index.d.ts +2 -1
- package/cjs/hooks/index.js +2 -1
- package/cjs/hooks/useContentHeight.js +3 -5
- package/cjs/hooks/useFeaturedTokens.d.ts +1 -1
- package/cjs/hooks/useFundsSufficiency.js +2 -2
- package/cjs/hooks/useGasRefuel.d.ts +1 -1
- package/cjs/hooks/useGasRefuel.js +5 -15
- package/cjs/hooks/useGasSufficiency.js +12 -3
- package/cjs/hooks/useInitializer.js +0 -1
- package/cjs/hooks/useProcessMessage.d.ts +2 -1
- package/cjs/hooks/useProcessMessage.js +27 -9
- package/cjs/hooks/useRouteExecution.js +6 -5
- package/cjs/hooks/useSwapOnly.d.ts +1 -0
- package/cjs/hooks/useSwapOnly.js +9 -0
- package/cjs/hooks/useSwapRoutes.d.ts +1 -2
- package/cjs/hooks/useSwapRoutes.js +32 -18
- package/cjs/hooks/useToken.d.ts +1 -1
- package/cjs/hooks/useTokenAddressBalance.d.ts +2 -2
- package/cjs/hooks/useTokenBalance.js +6 -7
- package/cjs/hooks/useTokenBalances.d.ts +5 -5
- package/cjs/hooks/useTokenBalances.js +4 -19
- package/cjs/hooks/useTokenSearch.d.ts +2 -2
- package/cjs/hooks/useTokens.d.ts +2 -2
- package/cjs/i18n/bn.json +8 -0
- package/cjs/i18n/en.json +30 -5
- package/cjs/i18n/fr.json +8 -0
- package/cjs/i18n/id.json +22 -7
- package/cjs/i18n/ko.json +22 -7
- package/cjs/i18n/pt.json +32 -7
- package/cjs/i18n/th.json +21 -6
- package/cjs/i18n/uk.json +43 -18
- package/cjs/i18n/zh.json +23 -8
- package/cjs/icons/InsuraceLogo.d.ts +1 -1
- package/cjs/icons/LiFiFullLogo.d.ts +1 -1
- package/cjs/icons/LiFiLogo.d.ts +1 -1
- package/cjs/icons/LiFiToolLogo.d.ts +1 -1
- package/cjs/index.d.ts +1 -1
- package/cjs/pages/ActiveSwapsPage/ActiveSwapsPage.d.ts +1 -2
- package/cjs/pages/SelectTokenPage/SearchTokenInput.d.ts +1 -2
- package/cjs/pages/SelectTokenPage/SelectTokenPage.js +3 -1
- package/cjs/pages/SelectWalletPage/SelectWalletPage.d.ts +1 -2
- package/cjs/pages/SettingsPage/GasPriceSelect.d.ts +1 -2
- package/cjs/pages/SettingsPage/LanguageSelect.js +1 -1
- package/cjs/pages/SettingsPage/SettingsPage.d.ts +1 -2
- package/cjs/pages/SettingsPage/ShowDestinationWallet.d.ts +1 -2
- package/cjs/pages/SettingsPage/SlippageInput.d.ts +1 -2
- package/cjs/pages/SwapDetailsPage/SwapDetailsPage.js +6 -2
- package/cjs/pages/SwapPage/ExchangeRateBottomSheet.js +1 -1
- package/cjs/pages/SwapPage/StatusBottomSheet.js +15 -9
- package/cjs/pages/SwapPage/StatusBottomSheet.style.d.ts +1 -1
- package/cjs/pages/SwapPage/StatusBottomSheet.style.js +2 -2
- package/cjs/pages/SwapPage/SwapPage.js +31 -10
- package/cjs/pages/SwapPage/TokenValueBottomSheet.js +7 -12
- package/cjs/pages/SwapPage/utils.d.ts +2 -0
- package/cjs/pages/SwapPage/utils.js +10 -0
- package/cjs/providers/I18nProvider/I18nProvider.js +3 -3
- package/cjs/providers/SDKProvider/SDKProvider.js +2 -0
- package/cjs/providers/SwapFormProvider/FormUpdater.js +3 -0
- package/cjs/providers/WalletProvider/WalletProvider.js +77 -49
- package/cjs/providers/WalletProvider/types.d.ts +3 -5
- package/cjs/providers/WidgetProvider/WidgetProvider.js +1 -1
- package/cjs/stores/StoreProvider.d.ts +2 -2
- package/cjs/stores/StoreProvider.js +3 -2
- package/cjs/stores/routes/RouteExecutionStore.d.ts +1 -1
- package/cjs/stores/routes/RouteExecutionStore.js +0 -1
- package/cjs/stores/settings/index.d.ts +1 -0
- package/cjs/stores/settings/index.js +1 -0
- package/cjs/stores/settings/types.d.ts +11 -0
- package/cjs/stores/settings/useSplitSubvariantStore.d.ts +7 -0
- package/cjs/stores/settings/useSplitSubvariantStore.js +44 -0
- package/cjs/types/events.d.ts +9 -1
- package/cjs/types/events.js +1 -0
- package/cjs/types/token.d.ts +2 -2
- package/cjs/types/widget.d.ts +13 -8
- package/cjs/types/widget.js +4 -2
- package/cjs/utils/format.d.ts +1 -1
- package/cjs/utils/format.js +7 -12
- package/cjs/utils/wallet.d.ts +1 -1
- package/cjs/utils/wallet.js +3 -3
- package/components/ChainSelect/ChainSelect.d.ts +1 -2
- package/components/ChainSelect/ChainSelect.style.js +1 -1
- package/components/ChainSelect/useChainSelect.js +7 -1
- package/components/GasMessage/FundsSufficiencyMessage.d.ts +1 -2
- package/components/GasMessage/GasMessage.js +2 -7
- package/components/Header/Header.js +3 -3
- package/components/Header/Header.style.d.ts +10 -3
- package/components/Header/Header.style.js +3 -0
- package/components/Header/NavigationHeader.js +23 -7
- package/components/Header/NavigationTabs.d.ts +1 -0
- package/components/Header/NavigationTabs.js +22 -0
- package/components/Header/NavigationTabs.style.d.ts +34 -0
- package/components/Header/NavigationTabs.style.js +58 -0
- package/components/Header/WalletHeader.d.ts +1 -0
- package/components/Header/WalletHeader.js +14 -8
- package/components/Header/useHeaderActionStore.js +0 -1
- package/components/Insurance/Insurance.js +2 -2
- package/components/Insurance/InsuranceCard.js +37 -15
- package/components/Insurance/InsuranceCollapsed.js +9 -11
- package/components/Insurance/index.d.ts +1 -0
- package/components/Insurance/index.js +1 -0
- package/components/Insurance/types.d.ts +12 -9
- package/components/NFT/NFT.js +2 -2
- package/components/NFT/types.d.ts +1 -1
- package/components/PoweredBy/PoweredBy.js +2 -3
- package/components/SelectChainAndToken.js +9 -8
- package/components/SelectTokenButton/SelectTokenButton.js +7 -4
- package/components/SendToWallet/SendToWallet.js +2 -2
- package/components/SmallAvatar.d.ts +1 -1
- package/components/Step/CircularProgress.d.ts +1 -2
- package/components/Step/Step.js +16 -6
- package/components/Step/StepList.d.ts +1 -2
- package/components/StepActions/StepActions.js +4 -20
- package/components/SwapButton/SwapButton.js +16 -4
- package/components/SwapInput/FormPriceHelperText.js +2 -2
- package/components/SwapInput/SwapInput.js +3 -3
- package/components/SwapInput/SwapInputEndAdornment.d.ts +1 -2
- package/components/SwapInput/SwapInputEndAdornment.js +2 -2
- package/components/SwapRouteCard/SwapRouteCard.js +21 -5
- package/components/SwapRouteCard/SwapRouteCardEssentials.js +1 -1
- package/components/SwapRouteCard/SwapRouteCardSkeleton.js +1 -1
- package/components/SwapRoutes/SwapRoutes.js +1 -1
- package/components/SwapRoutes/SwapRoutesExpanded.d.ts +2 -3
- package/components/SwapRoutes/SwapRoutesExpanded.js +2 -2
- package/components/SwapRoutes/SwapRoutesExpanded.style.js +1 -0
- package/components/Token/Token.js +1 -1
- package/components/TokenAvatar/TokenAvatar.d.ts +4 -4
- package/components/TokenList/TokenList.js +10 -5
- package/components/TokenList/TokenList.style.d.ts +5 -2
- package/components/TokenList/TokenList.style.js +21 -2
- package/components/TokenList/TokenListItem.d.ts +1 -1
- package/components/TokenList/TokenListItem.js +32 -9
- package/components/TokenList/VirtualizedTokenList.js +3 -3
- package/components/TokenList/types.d.ts +6 -3
- package/config/theme.js +15 -3
- package/config/version.d.ts +1 -1
- package/config/version.js +1 -1
- package/hooks/index.d.ts +2 -1
- package/hooks/index.js +2 -1
- package/hooks/useContentHeight.js +4 -6
- package/hooks/useFeaturedTokens.d.ts +1 -1
- package/hooks/useFundsSufficiency.js +2 -2
- package/hooks/useGasRefuel.d.ts +1 -1
- package/hooks/useGasRefuel.js +5 -15
- package/hooks/useGasSufficiency.js +13 -4
- package/hooks/useInitializer.js +0 -1
- package/hooks/useProcessMessage.d.ts +2 -1
- package/hooks/useProcessMessage.js +27 -9
- package/hooks/useRouteExecution.js +6 -5
- package/hooks/useSwapOnly.d.ts +1 -0
- package/hooks/useSwapOnly.js +5 -0
- package/hooks/useSwapRoutes.d.ts +1 -2
- package/hooks/useSwapRoutes.js +32 -18
- package/hooks/useToken.d.ts +1 -1
- package/hooks/useTokenAddressBalance.d.ts +2 -2
- package/hooks/useTokenBalance.js +6 -7
- package/hooks/useTokenBalances.d.ts +5 -5
- package/hooks/useTokenBalances.js +4 -19
- package/hooks/useTokenSearch.d.ts +2 -2
- package/hooks/useTokens.d.ts +2 -2
- package/i18n/bn.json +8 -0
- package/i18n/en.json +30 -5
- package/i18n/fr.json +8 -0
- package/i18n/id.json +22 -7
- package/i18n/ko.json +22 -7
- package/i18n/pt.json +32 -7
- package/i18n/th.json +21 -6
- package/i18n/uk.json +43 -18
- package/i18n/zh.json +23 -8
- package/icons/InsuraceLogo.d.ts +1 -1
- package/icons/LiFiFullLogo.d.ts +1 -1
- package/icons/LiFiLogo.d.ts +1 -1
- package/icons/LiFiToolLogo.d.ts +1 -1
- package/index.d.ts +1 -1
- package/package.json +13 -13
- package/pages/ActiveSwapsPage/ActiveSwapsPage.d.ts +1 -2
- package/pages/SelectTokenPage/SearchTokenInput.d.ts +1 -2
- package/pages/SelectTokenPage/SelectTokenPage.js +4 -2
- package/pages/SelectWalletPage/SelectWalletPage.d.ts +1 -2
- package/pages/SettingsPage/GasPriceSelect.d.ts +1 -2
- package/pages/SettingsPage/LanguageSelect.js +1 -1
- package/pages/SettingsPage/SettingsPage.d.ts +1 -2
- package/pages/SettingsPage/ShowDestinationWallet.d.ts +1 -2
- package/pages/SettingsPage/SlippageInput.d.ts +1 -2
- package/pages/SwapDetailsPage/SwapDetailsPage.js +6 -2
- package/pages/SwapPage/ExchangeRateBottomSheet.js +2 -2
- package/pages/SwapPage/StatusBottomSheet.js +18 -12
- package/pages/SwapPage/StatusBottomSheet.style.d.ts +1 -1
- package/pages/SwapPage/StatusBottomSheet.style.js +1 -1
- package/pages/SwapPage/SwapPage.js +33 -12
- package/pages/SwapPage/TokenValueBottomSheet.js +8 -13
- package/pages/SwapPage/utils.d.ts +2 -0
- package/pages/SwapPage/utils.js +6 -0
- package/providers/I18nProvider/I18nProvider.js +3 -3
- package/providers/SDKProvider/SDKProvider.js +2 -0
- package/providers/SwapFormProvider/FormUpdater.js +3 -0
- package/providers/WalletProvider/WalletProvider.js +78 -50
- package/providers/WalletProvider/types.d.ts +3 -5
- package/providers/WidgetProvider/WidgetProvider.js +2 -2
- package/stores/StoreProvider.d.ts +2 -2
- package/stores/StoreProvider.js +3 -2
- package/stores/routes/RouteExecutionStore.d.ts +1 -1
- package/stores/routes/RouteExecutionStore.js +0 -1
- package/stores/settings/index.d.ts +1 -0
- package/stores/settings/index.js +1 -0
- package/stores/settings/types.d.ts +11 -0
- package/stores/settings/useSplitSubvariantStore.d.ts +7 -0
- package/stores/settings/useSplitSubvariantStore.js +37 -0
- package/tsconfig.cjs.tsbuildinfo +1 -1
- package/types/events.d.ts +9 -1
- package/types/events.js +1 -0
- package/types/token.d.ts +2 -2
- package/types/widget.d.ts +13 -8
- package/types/widget.js +4 -2
- package/utils/format.d.ts +1 -1
- package/utils/format.js +5 -10
- package/utils/wallet.d.ts +1 -1
- package/utils/wallet.js +1 -1
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ExtendedChain } from '@lifi/sdk';
|
|
2
2
|
import type { MutableRefObject } from 'react';
|
|
3
3
|
import type { SwapFormType } from '../../providers';
|
|
4
|
-
import type {
|
|
4
|
+
import type { TokenAmount } from '../../types';
|
|
5
5
|
export interface TokenListProps {
|
|
6
6
|
formType: SwapFormType;
|
|
7
7
|
height: number;
|
|
8
8
|
onClick?(): void;
|
|
9
9
|
}
|
|
10
10
|
export interface VirtualizedTokenListProps {
|
|
11
|
-
tokens:
|
|
11
|
+
tokens: TokenAmount[];
|
|
12
12
|
featuredTokensLength?: number;
|
|
13
13
|
scrollElementRef: MutableRefObject<HTMLElement | null>;
|
|
14
14
|
isLoading: boolean;
|
|
15
15
|
isBalanceLoading: boolean;
|
|
16
16
|
chainId: number;
|
|
17
|
+
chain?: ExtendedChain;
|
|
17
18
|
showBalance?: boolean;
|
|
18
19
|
showFeatured?: boolean;
|
|
19
20
|
onClick(tokenAddress: string): void;
|
|
@@ -26,6 +27,7 @@ export interface TokenListItemBaseProps {
|
|
|
26
27
|
export interface TokenListItemProps extends TokenListItemBaseProps {
|
|
27
28
|
showBalance?: boolean;
|
|
28
29
|
token: TokenAmount;
|
|
30
|
+
chain?: ExtendedChain;
|
|
29
31
|
isBalanceLoading?: boolean;
|
|
30
32
|
startAdornment?: React.ReactNode;
|
|
31
33
|
endAdornment?: React.ReactNode;
|
|
@@ -34,5 +36,6 @@ export interface TokenListItemButtonProps {
|
|
|
34
36
|
onClick?(): void;
|
|
35
37
|
showBalance?: boolean;
|
|
36
38
|
token: TokenAmount;
|
|
39
|
+
chain?: ExtendedChain;
|
|
37
40
|
isBalanceLoading?: boolean;
|
|
38
41
|
}
|
package/config/theme.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { loadingButtonClasses } from '@mui/lab/LoadingButton';
|
|
2
2
|
import { touchRippleClasses } from '@mui/material/ButtonBase';
|
|
3
|
-
import { common } from '@mui/material/colors';
|
|
4
3
|
import { dialogActionsClasses } from '@mui/material/DialogActions';
|
|
5
|
-
import {
|
|
6
|
-
import { keyframes } from '@mui/
|
|
4
|
+
import { common } from '@mui/material/colors';
|
|
5
|
+
import { alpha, createTheme as createMuiTheme, darken, getContrastRatio, keyframes, lighten, } from '@mui/material/styles';
|
|
7
6
|
const palette = {
|
|
8
7
|
primary: {
|
|
9
8
|
main: '#3F49E1',
|
|
@@ -223,6 +222,19 @@ export const createTheme = (mode, theme = {}) => {
|
|
|
223
222
|
}),
|
|
224
223
|
},
|
|
225
224
|
},
|
|
225
|
+
MuiTooltip: {
|
|
226
|
+
styleOverrides: {
|
|
227
|
+
tooltip: ({ theme }) => ({
|
|
228
|
+
backgroundColor: 'rgb(0 0 0 / 64%)',
|
|
229
|
+
backdropFilter: 'blur(3px)',
|
|
230
|
+
fontSize: '0.75rem',
|
|
231
|
+
padding: theme.spacing(1, 1.5),
|
|
232
|
+
}),
|
|
233
|
+
arrow: {
|
|
234
|
+
color: 'rgb(0 0 0 / 64%)',
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
},
|
|
226
238
|
},
|
|
227
239
|
});
|
|
228
240
|
};
|
package/config/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name = "@lifi/widget";
|
|
2
|
-
export declare const version = "2.0.0-beta.
|
|
2
|
+
export declare const version = "2.0.0-beta.10";
|
package/config/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/widget';
|
|
2
|
-
export const version = '2.0.0-beta.
|
|
2
|
+
export const version = '2.0.0-beta.10';
|
package/hooks/index.d.ts
CHANGED
|
@@ -15,12 +15,13 @@ export * from './useNavigateBack';
|
|
|
15
15
|
export * from './useProcessMessage';
|
|
16
16
|
export * from './useRouteExecution';
|
|
17
17
|
export * from './useScrollableContainer';
|
|
18
|
+
export * from './useSwapOnly';
|
|
18
19
|
export * from './useSwapRoutes';
|
|
19
20
|
export * from './useToken';
|
|
20
21
|
export * from './useTokenAddressBalance';
|
|
21
22
|
export * from './useTokenBalance';
|
|
22
23
|
export * from './useTokenBalances';
|
|
23
|
-
export * from './useTokens';
|
|
24
24
|
export * from './useTokenSearch';
|
|
25
|
+
export * from './useTokens';
|
|
25
26
|
export * from './useTools';
|
|
26
27
|
export * from './useWidgetEvents';
|
package/hooks/index.js
CHANGED
|
@@ -15,12 +15,13 @@ export * from './useNavigateBack';
|
|
|
15
15
|
export * from './useProcessMessage';
|
|
16
16
|
export * from './useRouteExecution';
|
|
17
17
|
export * from './useScrollableContainer';
|
|
18
|
+
export * from './useSwapOnly';
|
|
18
19
|
export * from './useSwapRoutes';
|
|
19
20
|
export * from './useToken';
|
|
20
21
|
export * from './useTokenAddressBalance';
|
|
21
22
|
export * from './useTokenBalance';
|
|
22
23
|
export * from './useTokenBalances';
|
|
23
|
-
export * from './useTokens';
|
|
24
24
|
export * from './useTokenSearch';
|
|
25
|
+
export * from './useTokens';
|
|
25
26
|
export * from './useTools';
|
|
26
27
|
export * from './useWidgetEvents';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { useLayoutEffect, useState } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { ElementId, createElementId } from '../utils';
|
|
3
3
|
import { useDefaultElementId } from './useDefaultElementId';
|
|
4
4
|
import { getScrollableContainer } from './useScrollableContainer';
|
|
5
5
|
const getContentHeight = (elementId) => {
|
|
6
|
-
const headerElement = document.getElementById(createElementId(ElementId.Header, elementId));
|
|
7
6
|
const containerElement = document.getElementById(createElementId(ElementId.ScrollableContainer, elementId));
|
|
7
|
+
const headerElement = document.getElementById(createElementId(ElementId.Header, elementId));
|
|
8
8
|
if (!containerElement || !headerElement) {
|
|
9
9
|
console.warn(`Can't find ${ElementId.ScrollableContainer} or ${ElementId.Header} id.`);
|
|
10
10
|
return 0;
|
|
@@ -15,11 +15,9 @@ const getContentHeight = (elementId) => {
|
|
|
15
15
|
};
|
|
16
16
|
export const useContentHeight = () => {
|
|
17
17
|
const elementId = useDefaultElementId();
|
|
18
|
-
const [contentHeight, setContentHeight] = useState(
|
|
18
|
+
const [contentHeight, setContentHeight] = useState(0);
|
|
19
19
|
useLayoutEffect(() => {
|
|
20
|
-
|
|
21
|
-
setContentHeight(getContentHeight(elementId));
|
|
22
|
-
}
|
|
20
|
+
setContentHeight(getContentHeight(elementId));
|
|
23
21
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
24
22
|
}, []);
|
|
25
23
|
return contentHeight;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useFeaturedTokens: (selectedChainId?: number) => import("@lifi/types").
|
|
1
|
+
export declare const useFeaturedTokens: (selectedChainId?: number) => import("@lifi/types").StaticToken[] | undefined;
|
|
@@ -7,8 +7,8 @@ import { useGetTokenBalancesWithRetry } from './useGetTokenBalancesWithRetry';
|
|
|
7
7
|
import { useTokenAddressBalance } from './useTokenAddressBalance';
|
|
8
8
|
const refetchInterval = 30000;
|
|
9
9
|
export const useFundsSufficiency = (route) => {
|
|
10
|
-
const { account
|
|
11
|
-
const getTokenBalancesWithRetry = useGetTokenBalancesWithRetry(provider);
|
|
10
|
+
const { account } = useWallet();
|
|
11
|
+
const getTokenBalancesWithRetry = useGetTokenBalancesWithRetry(account.signer?.provider);
|
|
12
12
|
const [fromChainId, fromTokenAddress, fromAmount] = useWatch({
|
|
13
13
|
name: [
|
|
14
14
|
SwapFormKey.FromChain,
|
package/hooks/useGasRefuel.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ export declare const useGasRefuel: () => {
|
|
|
3
3
|
availble: boolean | undefined;
|
|
4
4
|
isLoading: boolean;
|
|
5
5
|
chain: import("@lifi/types").ExtendedChain | undefined;
|
|
6
|
-
|
|
6
|
+
fromAmount: string | undefined;
|
|
7
7
|
};
|
package/hooks/useGasRefuel.js
CHANGED
|
@@ -7,12 +7,11 @@ import { useGasRecommendation } from './useGasRecommendation';
|
|
|
7
7
|
import { useTokenBalance } from './useTokenBalance';
|
|
8
8
|
export const useGasRefuel = () => {
|
|
9
9
|
const { getChainById } = useChains();
|
|
10
|
-
const [fromChainId, fromTokenAddress, toChainId,
|
|
10
|
+
const [fromChainId, fromTokenAddress, toChainId, toAddress] = useWatch({
|
|
11
11
|
name: [
|
|
12
12
|
SwapFormKey.FromChain,
|
|
13
13
|
SwapFormKey.FromToken,
|
|
14
14
|
SwapFormKey.ToChain,
|
|
15
|
-
SwapFormKey.ToToken,
|
|
16
15
|
SwapFormKey.ToAddress,
|
|
17
16
|
],
|
|
18
17
|
});
|
|
@@ -24,10 +23,7 @@ export const useGasRefuel = () => {
|
|
|
24
23
|
// We don't allow same chain refuel.
|
|
25
24
|
// If a user runs out of gas, he can't send a source chain transaction.
|
|
26
25
|
fromChainId === toChainId ||
|
|
27
|
-
// We don't want to apply auto refuel when swapping to native tokens
|
|
28
|
-
toChain?.nativeToken.address === toTokenAddress ||
|
|
29
26
|
!gasRecommendation?.available ||
|
|
30
|
-
!gasRecommendation.recommended ||
|
|
31
27
|
!nativeToken) {
|
|
32
28
|
return false;
|
|
33
29
|
}
|
|
@@ -38,20 +34,14 @@ export const useGasRefuel = () => {
|
|
|
38
34
|
.div(2);
|
|
39
35
|
const insufficientGas = tokenBalance.lt(recommendedAmount);
|
|
40
36
|
return insufficientGas;
|
|
41
|
-
}, [
|
|
42
|
-
fromChainId,
|
|
43
|
-
gasRecommendation?.available,
|
|
44
|
-
gasRecommendation?.recommended,
|
|
45
|
-
nativeToken,
|
|
46
|
-
toChain?.nativeToken.address,
|
|
47
|
-
toChainId,
|
|
48
|
-
toTokenAddress,
|
|
49
|
-
]);
|
|
37
|
+
}, [fromChainId, gasRecommendation, nativeToken, toChainId]);
|
|
50
38
|
return {
|
|
51
39
|
enabled: enabled,
|
|
52
40
|
availble: gasRecommendation?.available,
|
|
53
41
|
isLoading: isLoading,
|
|
54
42
|
chain: toChain,
|
|
55
|
-
gasRecommendation
|
|
43
|
+
fromAmount: gasRecommendation?.available
|
|
44
|
+
? gasRecommendation.fromAmount
|
|
45
|
+
: undefined,
|
|
56
46
|
};
|
|
57
47
|
};
|
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
import { useQuery } from '@tanstack/react-query';
|
|
2
2
|
import Big from 'big.js';
|
|
3
|
-
import { useChains, useGetTokenBalancesWithRetry } from '.';
|
|
3
|
+
import { useChains, useGasRefuel, useGetTokenBalancesWithRetry } from '.';
|
|
4
4
|
import { useWallet } from '../providers';
|
|
5
|
+
import { useSettings } from '../stores';
|
|
5
6
|
const refetchInterval = 30000;
|
|
6
7
|
export const useGasSufficiency = (route) => {
|
|
7
|
-
const { account
|
|
8
|
+
const { account } = useWallet();
|
|
8
9
|
const { getChainById } = useChains();
|
|
9
|
-
const getTokenBalancesWithRetry = useGetTokenBalancesWithRetry(provider);
|
|
10
|
+
const getTokenBalancesWithRetry = useGetTokenBalancesWithRetry(account.signer?.provider);
|
|
11
|
+
const { enabledAutoRefuel } = useSettings(['enabledAutoRefuel']);
|
|
12
|
+
const { enabled, isLoading: isRefuelLoading } = useGasRefuel();
|
|
13
|
+
const enabledRefuel = enabled && enabledAutoRefuel;
|
|
10
14
|
const { data: insufficientGas, isInitialLoading } = useQuery(['gas-sufficiency-check', account.address, route?.id], async () => {
|
|
11
15
|
if (!account.address || !route) {
|
|
12
16
|
return;
|
|
13
17
|
}
|
|
18
|
+
// TODO: include LI.Fuel into calculation once steps and tools are properly typed
|
|
19
|
+
// const refuelSteps = route.steps
|
|
20
|
+
// .flatMap((step) => step.includedSteps)
|
|
21
|
+
// .filter((includedStep) => includedStep.tool === 'lifuelProtocol');
|
|
14
22
|
const gasCosts = route.steps
|
|
15
23
|
.filter((step) => !step.execution || step.execution.status !== 'DONE')
|
|
16
24
|
.reduce((groupedGasCosts, step) => {
|
|
@@ -66,8 +74,9 @@ export const useGasSufficiency = (route) => {
|
|
|
66
74
|
staleTime: refetchInterval,
|
|
67
75
|
cacheTime: refetchInterval,
|
|
68
76
|
});
|
|
77
|
+
const isInsufficientGas = Boolean(insufficientGas?.length) && !isRefuelLoading && !enabledRefuel;
|
|
69
78
|
return {
|
|
70
|
-
insufficientGas,
|
|
79
|
+
insufficientGas: isInsufficientGas ? insufficientGas : undefined,
|
|
71
80
|
isInitialLoading,
|
|
72
81
|
};
|
|
73
82
|
};
|
package/hooks/useInitializer.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { EVMChain, LifiStep, Process } from '@lifi/sdk';
|
|
2
2
|
import type { TFunction } from 'i18next';
|
|
3
|
+
import type { WidgetVariant } from '../types';
|
|
3
4
|
export declare const useProcessMessage: (step?: LifiStep, process?: Process) => {
|
|
4
5
|
title?: string | undefined;
|
|
5
6
|
message?: string | undefined;
|
|
6
7
|
};
|
|
7
|
-
export declare function getProcessMessage(t: TFunction, getChainById: (chainId: number) => EVMChain | undefined, step: LifiStep, process: Process): {
|
|
8
|
+
export declare function getProcessMessage(t: TFunction, getChainById: (chainId: number) => EVMChain | undefined, step: LifiStep, process: Process, variant?: WidgetVariant): {
|
|
8
9
|
title?: string;
|
|
9
10
|
message?: string;
|
|
10
11
|
};
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { LifiErrorCode } from '@lifi/sdk';
|
|
2
2
|
import { useTranslation } from 'react-i18next';
|
|
3
|
+
import { useWidgetConfig } from '../providers';
|
|
3
4
|
import { formatTokenAmount } from '../utils';
|
|
4
5
|
import { useChains } from './useChains';
|
|
5
6
|
export const useProcessMessage = (step, process) => {
|
|
7
|
+
const { variant } = useWidgetConfig();
|
|
6
8
|
const { t } = useTranslation();
|
|
7
9
|
const { getChainById } = useChains();
|
|
8
10
|
if (!step || !process) {
|
|
9
11
|
return {};
|
|
10
12
|
}
|
|
11
|
-
return getProcessMessage(t, getChainById, step, process);
|
|
13
|
+
return getProcessMessage(t, getChainById, step, process, variant);
|
|
12
14
|
};
|
|
13
15
|
const processStatusMessages = {
|
|
14
16
|
TOKEN_ALLOWANCE: {
|
|
15
17
|
STARTED: (t) => t(`swap.process.tokenAllowance.started`),
|
|
18
|
+
ACTION_REQUIRED: (t) => t(`swap.process.tokenAllowance.pending`),
|
|
16
19
|
PENDING: (t) => t(`swap.process.tokenAllowance.pending`),
|
|
17
20
|
DONE: (t) => t(`swap.process.tokenAllowance.done`),
|
|
18
21
|
},
|
|
@@ -24,7 +27,9 @@ const processStatusMessages = {
|
|
|
24
27
|
STARTED: (t) => t(`swap.process.swap.started`),
|
|
25
28
|
ACTION_REQUIRED: (t) => t(`swap.process.swap.actionRequired`),
|
|
26
29
|
PENDING: (t) => t(`swap.process.swap.pending`),
|
|
27
|
-
DONE: (t) =>
|
|
30
|
+
DONE: (t, variant) => variant === 'nft'
|
|
31
|
+
? t(`swap.process.nft.done`)
|
|
32
|
+
: t(`swap.process.swap.done`),
|
|
28
33
|
},
|
|
29
34
|
CROSS_CHAIN: {
|
|
30
35
|
STARTED: (t) => t(`swap.process.crossChain.started`),
|
|
@@ -34,7 +39,9 @@ const processStatusMessages = {
|
|
|
34
39
|
},
|
|
35
40
|
RECEIVING_CHAIN: {
|
|
36
41
|
PENDING: (t) => t(`swap.process.receivingChain.pending`),
|
|
37
|
-
DONE: (t) =>
|
|
42
|
+
DONE: (t, variant) => variant === 'nft'
|
|
43
|
+
? t(`swap.process.nft.done`)
|
|
44
|
+
: t(`swap.process.receivingChain.done`),
|
|
38
45
|
},
|
|
39
46
|
TRANSACTION: {},
|
|
40
47
|
};
|
|
@@ -64,7 +71,7 @@ const processSubstatusMessages = {
|
|
|
64
71
|
INVALID: {},
|
|
65
72
|
NOT_FOUND: {},
|
|
66
73
|
};
|
|
67
|
-
export function getProcessMessage(t, getChainById, step, process) {
|
|
74
|
+
export function getProcessMessage(t, getChainById, step, process, variant) {
|
|
68
75
|
if (process.error && process.status === 'FAILED') {
|
|
69
76
|
const getTransactionNotSentMessage = () => t(`swap.error.message.transactionNotSent`, {
|
|
70
77
|
amount: formatTokenAmount(step.action.fromAmount, step.action.fromToken.decimals),
|
|
@@ -74,6 +81,12 @@ export function getProcessMessage(t, getChainById, step, process) {
|
|
|
74
81
|
let title = '';
|
|
75
82
|
let message = '';
|
|
76
83
|
switch (process.error.code) {
|
|
84
|
+
case LifiErrorCode.AllowanceRequired:
|
|
85
|
+
title = t(`swap.error.title.allowanceRequired`);
|
|
86
|
+
message = t(`swap.error.message.allowanceRequired`, {
|
|
87
|
+
tokenSymbol: step.action.fromToken.symbol,
|
|
88
|
+
});
|
|
89
|
+
break;
|
|
77
90
|
case LifiErrorCode.BalanceError:
|
|
78
91
|
title = t(`swap.error.title.balanceIsTooLow`);
|
|
79
92
|
message = getTransactionNotSentMessage();
|
|
@@ -86,6 +99,14 @@ export function getProcessMessage(t, getChainById, step, process) {
|
|
|
86
99
|
title = t(`swap.error.title.gasLimitIsTooLow`);
|
|
87
100
|
message = getTransactionNotSentMessage();
|
|
88
101
|
break;
|
|
102
|
+
case LifiErrorCode.InsufficientFunds:
|
|
103
|
+
title = t(`swap.error.title.insufficientFunds`);
|
|
104
|
+
message = `${t(`swap.error.message.insufficientFunds`)} ${getTransactionNotSentMessage()}`;
|
|
105
|
+
break;
|
|
106
|
+
case LifiErrorCode.SlippageError:
|
|
107
|
+
title = t(`swap.error.title.slippageNotMet`);
|
|
108
|
+
message = t(`swap.error.message.slippageThreshold`);
|
|
109
|
+
break;
|
|
89
110
|
case LifiErrorCode.TransactionFailed:
|
|
90
111
|
title = t(`swap.error.title.transactionFailed`);
|
|
91
112
|
message = t(`swap.error.message.transactionFailed`);
|
|
@@ -102,10 +123,6 @@ export function getProcessMessage(t, getChainById, step, process) {
|
|
|
102
123
|
title = t(`swap.error.title.transactionCanceled`);
|
|
103
124
|
message = getTransactionNotSentMessage();
|
|
104
125
|
break;
|
|
105
|
-
case LifiErrorCode.SlippageError:
|
|
106
|
-
title = t(`swap.error.title.slippageNotMet`);
|
|
107
|
-
message = t(`swap.error.message.slippageThreshold`);
|
|
108
|
-
break;
|
|
109
126
|
case LifiErrorCode.TransactionRejected:
|
|
110
127
|
title = t(`swap.error.title.transactionRejected`);
|
|
111
128
|
message = t(`swap.error.message.transactionRejected`, {
|
|
@@ -127,6 +144,7 @@ export function getProcessMessage(t, getChainById, step, process) {
|
|
|
127
144
|
}
|
|
128
145
|
return { title, message };
|
|
129
146
|
}
|
|
130
|
-
const title = processSubstatusMessages[process.status]?.[process.substatus]?.(t) ??
|
|
147
|
+
const title = processSubstatusMessages[process.status]?.[process.substatus]?.(t) ??
|
|
148
|
+
processStatusMessages[process.type]?.[process.status]?.(t, variant);
|
|
131
149
|
return { title };
|
|
132
150
|
}
|
|
@@ -14,7 +14,7 @@ export const useRouteExecution = ({ routeId, executeInBackground, onAcceptExchan
|
|
|
14
14
|
const routeExecutionStoreContext = useRouteExecutionStoreContext();
|
|
15
15
|
const routeExecution = useRouteExecutionStore((state) => state.routes[routeId]);
|
|
16
16
|
const [updateRoute, restartRoute, deleteRoute] = useRouteExecutionStore((state) => [state.updateRoute, state.restartRoute, state.deleteRoute], shallow);
|
|
17
|
-
const
|
|
17
|
+
const updateRouteHook = (updatedRoute) => {
|
|
18
18
|
const routeExecution = routeExecutionStoreContext.getState().routes[updatedRoute.id];
|
|
19
19
|
if (!routeExecution) {
|
|
20
20
|
return;
|
|
@@ -45,10 +45,11 @@ export const useRouteExecution = ({ routeId, executeInBackground, onAcceptExchan
|
|
|
45
45
|
}
|
|
46
46
|
const currentChainId = await account.signer.getChainId();
|
|
47
47
|
if (currentChainId !== requiredChainId) {
|
|
48
|
-
const
|
|
49
|
-
if (!
|
|
48
|
+
const signer = await switchChain(requiredChainId);
|
|
49
|
+
if (!signer) {
|
|
50
50
|
throw new Error('Chain was not switched.');
|
|
51
51
|
}
|
|
52
|
+
return signer;
|
|
52
53
|
}
|
|
53
54
|
return account.signer;
|
|
54
55
|
};
|
|
@@ -68,7 +69,7 @@ export const useRouteExecution = ({ routeId, executeInBackground, onAcceptExchan
|
|
|
68
69
|
}
|
|
69
70
|
queryClient.removeQueries(['routes'], { exact: false });
|
|
70
71
|
return lifi.executeRoute(account.signer, routeExecution.route, {
|
|
71
|
-
|
|
72
|
+
updateRouteHook,
|
|
72
73
|
switchChainHook,
|
|
73
74
|
acceptExchangeRateUpdateHook,
|
|
74
75
|
infiniteApproval: false,
|
|
@@ -90,7 +91,7 @@ export const useRouteExecution = ({ routeId, executeInBackground, onAcceptExchan
|
|
|
90
91
|
throw Error('Execution route not found.');
|
|
91
92
|
}
|
|
92
93
|
return lifi.resumeRoute(account.signer, resumedRoute ?? routeExecution.route, {
|
|
93
|
-
|
|
94
|
+
updateRouteHook,
|
|
94
95
|
switchChainHook,
|
|
95
96
|
acceptExchangeRateUpdateHook,
|
|
96
97
|
infiniteApproval: false,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useSwapOnly: () => boolean;
|
package/hooks/useSwapRoutes.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { Route, RoutesResponse } from '@lifi/sdk';
|
|
2
2
|
interface SwapRoutesProps {
|
|
3
|
-
onSettled?: (data?: RoutesResponse) => void;
|
|
4
3
|
insurableRoute?: Route;
|
|
5
4
|
}
|
|
6
|
-
export declare const useSwapRoutes: ({
|
|
5
|
+
export declare const useSwapRoutes: ({ insurableRoute }?: SwapRoutesProps) => {
|
|
7
6
|
routes: Route[] | undefined;
|
|
8
7
|
isLoading: boolean;
|
|
9
8
|
isFetching: boolean;
|
package/hooks/useSwapRoutes.js
CHANGED
|
@@ -7,12 +7,14 @@ import { v4 as uuidv4 } from 'uuid';
|
|
|
7
7
|
import { useDebouncedWatch, useGasRefuel, useToken } from '.';
|
|
8
8
|
import { SwapFormKey, useLiFi, useWallet, useWidgetConfig } from '../providers';
|
|
9
9
|
import { useSettings } from '../stores';
|
|
10
|
+
import { useSwapOnly } from './useSwapOnly';
|
|
10
11
|
const refetchTime = 60000;
|
|
11
|
-
export const useSwapRoutes = ({
|
|
12
|
+
export const useSwapRoutes = ({ insurableRoute } = {}) => {
|
|
12
13
|
const lifi = useLiFi();
|
|
13
|
-
const { variant, sdkConfig, insurance } = useWidgetConfig();
|
|
14
|
-
const { account
|
|
14
|
+
const { variant, sdkConfig, insurance, contractTool } = useWidgetConfig();
|
|
15
|
+
const { account } = useWallet();
|
|
15
16
|
const queryClient = useQueryClient();
|
|
17
|
+
const swapOnly = useSwapOnly();
|
|
16
18
|
const { slippage, enabledBridges, enabledAutoRefuel, enabledExchanges, routePriority, } = useSettings([
|
|
17
19
|
'slippage',
|
|
18
20
|
'routePriority',
|
|
@@ -36,7 +38,7 @@ export const useSwapRoutes = ({ onSettled, insurableRoute, } = {}) => {
|
|
|
36
38
|
});
|
|
37
39
|
const { token: fromToken } = useToken(fromChainId, fromTokenAddress);
|
|
38
40
|
const { token: toToken } = useToken(toChainId, toTokenAddress);
|
|
39
|
-
const { enabled: enabledRefuel,
|
|
41
|
+
const { enabled: enabledRefuel, fromAmount: gasRecommendationFromAmount } = useGasRefuel();
|
|
40
42
|
const hasAmount = (!isNaN(fromTokenAmount) && Number(fromTokenAmount) > 0) ||
|
|
41
43
|
(!isNaN(toTokenAmount) && Number(toTokenAmount) > 0);
|
|
42
44
|
const contractCallQuoteEnabled = variant === 'nft'
|
|
@@ -63,13 +65,13 @@ export const useSwapRoutes = ({ onSettled, insurableRoute, } = {}) => {
|
|
|
63
65
|
toContractCallData,
|
|
64
66
|
toContractGasLimit,
|
|
65
67
|
slippage,
|
|
66
|
-
enabledBridges,
|
|
68
|
+
swapOnly ? [] : enabledBridges,
|
|
67
69
|
enabledExchanges,
|
|
68
70
|
routePriority,
|
|
69
71
|
variant,
|
|
70
72
|
sdkConfig?.defaultRouteOptions?.allowSwitchChain,
|
|
71
73
|
enabledRefuel && enabledAutoRefuel,
|
|
72
|
-
|
|
74
|
+
gasRecommendationFromAmount,
|
|
73
75
|
insurance,
|
|
74
76
|
insurableRoute?.id,
|
|
75
77
|
];
|
|
@@ -77,7 +79,7 @@ export const useSwapRoutes = ({ onSettled, insurableRoute, } = {}) => {
|
|
|
77
79
|
let toWalletAddress;
|
|
78
80
|
try {
|
|
79
81
|
toWalletAddress =
|
|
80
|
-
(await provider?.resolveName(toAddress)) ??
|
|
82
|
+
(await account.signer?.provider?.resolveName(toAddress)) ??
|
|
81
83
|
(isAddress(toAddress) ? toAddress : fromAddress);
|
|
82
84
|
}
|
|
83
85
|
catch {
|
|
@@ -87,6 +89,16 @@ export const useSwapRoutes = ({ onSettled, insurableRoute, } = {}) => {
|
|
|
87
89
|
.mul(10 ** (fromToken?.decimals ?? 0))
|
|
88
90
|
.toFixed(0);
|
|
89
91
|
const formattedSlippage = parseFloat(slippage) / 100;
|
|
92
|
+
const allowedBridges = insurableRoute
|
|
93
|
+
? insurableRoute.steps.flatMap((step) => step.includedSteps
|
|
94
|
+
.filter((includedStep) => includedStep.type === 'cross')
|
|
95
|
+
.map((includedStep) => includedStep.toolDetails.key))
|
|
96
|
+
: enabledBridges;
|
|
97
|
+
const allowedExchanges = insurableRoute
|
|
98
|
+
? insurableRoute.steps.flatMap((step) => step.includedSteps
|
|
99
|
+
.filter((includedStep) => includedStep.type === 'swap')
|
|
100
|
+
.map((includedStep) => includedStep.toolDetails.key))
|
|
101
|
+
: enabledExchanges;
|
|
90
102
|
if (variant === 'nft') {
|
|
91
103
|
const contractCallQuote = await lifi.getContractCallQuote({
|
|
92
104
|
fromAddress,
|
|
@@ -98,12 +110,25 @@ export const useSwapRoutes = ({ onSettled, insurableRoute, } = {}) => {
|
|
|
98
110
|
toContractAddress,
|
|
99
111
|
toContractCallData,
|
|
100
112
|
toContractGasLimit,
|
|
113
|
+
allowBridges: allowedBridges,
|
|
101
114
|
// toFallbackAddress: toAddress,
|
|
102
115
|
slippage: formattedSlippage,
|
|
103
116
|
}, { signal });
|
|
104
117
|
contractCallQuote.estimate.toAmount = toTokenAmount;
|
|
105
118
|
contractCallQuote.estimate.toAmountMin = toTokenAmount;
|
|
106
119
|
contractCallQuote.action.toToken = toToken;
|
|
120
|
+
const customStep = variant === 'nft'
|
|
121
|
+
? contractCallQuote.includedSteps?.find((step) => step.type === 'custom')
|
|
122
|
+
: undefined;
|
|
123
|
+
if (customStep && contractTool) {
|
|
124
|
+
const toolDetails = {
|
|
125
|
+
key: contractTool.name,
|
|
126
|
+
name: contractTool.name,
|
|
127
|
+
logoURI: contractTool.logoURI,
|
|
128
|
+
};
|
|
129
|
+
customStep.toolDetails = toolDetails;
|
|
130
|
+
contractCallQuote.toolDetails = toolDetails;
|
|
131
|
+
}
|
|
107
132
|
const route = {
|
|
108
133
|
id: uuidv4(),
|
|
109
134
|
fromChainId: contractCallQuote.action.fromChainId,
|
|
@@ -123,16 +148,6 @@ export const useSwapRoutes = ({ onSettled, insurableRoute, } = {}) => {
|
|
|
123
148
|
};
|
|
124
149
|
return { routes: [route] };
|
|
125
150
|
}
|
|
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;
|
|
136
151
|
return lifi.getRoutes({
|
|
137
152
|
fromChainId,
|
|
138
153
|
fromAmount,
|
|
@@ -189,7 +204,6 @@ export const useSwapRoutes = ({ onSettled, insurableRoute, } = {}) => {
|
|
|
189
204
|
});
|
|
190
205
|
}
|
|
191
206
|
},
|
|
192
|
-
onSettled,
|
|
193
207
|
});
|
|
194
208
|
return {
|
|
195
209
|
routes: data?.routes,
|
package/hooks/useToken.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const useTokenAddressBalance: (chainId?: number, tokenAddress?: string) => {
|
|
2
|
-
token: import("..").
|
|
2
|
+
token: import("..").TokenAmount | undefined;
|
|
3
3
|
isLoading: boolean;
|
|
4
|
-
refetch: <TPageData>(options?: (import("@tanstack/query-core").RefetchOptions & import("@tanstack/query-core").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/query-core").QueryObserverResult<import("..").
|
|
4
|
+
refetch: <TPageData>(options?: (import("@tanstack/query-core").RefetchOptions & import("@tanstack/query-core").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/query-core").QueryObserverResult<import("..").TokenAmount[], unknown>>;
|
|
5
5
|
};
|
package/hooks/useTokenBalance.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
|
2
2
|
import { useCallback, useMemo } from 'react';
|
|
3
3
|
import { useWallet } from '../providers';
|
|
4
|
-
import { formatTokenAmount } from '../utils';
|
|
5
4
|
import { useGetTokenBalancesWithRetry } from './useGetTokenBalancesWithRetry';
|
|
6
5
|
const defaultRefetchInterval = 30000;
|
|
7
6
|
export const useTokenBalance = (token, accountAddress) => {
|
|
8
|
-
const { account
|
|
7
|
+
const { account } = useWallet();
|
|
9
8
|
const queryClient = useQueryClient();
|
|
10
9
|
const walletAddress = accountAddress || account.address;
|
|
11
|
-
const getTokenBalancesWithRetry = useGetTokenBalancesWithRetry(provider);
|
|
10
|
+
const getTokenBalancesWithRetry = useGetTokenBalancesWithRetry(account.signer?.provider);
|
|
12
11
|
const tokenBalanceQueryKey = useMemo(() => ['token-balance', walletAddress, token?.chainId, token?.address], [token?.address, token?.chainId, walletAddress]);
|
|
13
12
|
const { data, isLoading, refetch } = useQuery(tokenBalanceQueryKey, async ({ queryKey: [, accountAddress] }) => {
|
|
14
13
|
const cachedToken = queryClient
|
|
@@ -26,8 +25,8 @@ export const useTokenBalance = (token, accountAddress) => {
|
|
|
26
25
|
throw Error('Could not get tokens balance.');
|
|
27
26
|
}
|
|
28
27
|
const cachedTokenAmount = queryClient.getQueryData(tokenBalanceQueryKey);
|
|
29
|
-
const
|
|
30
|
-
if (cachedTokenAmount?.amount !==
|
|
28
|
+
const tokenAmount = tokenBalances[0].amount;
|
|
29
|
+
if (cachedTokenAmount?.amount !== tokenAmount) {
|
|
31
30
|
queryClient.setQueryDefaults(tokenBalanceQueryKey, {
|
|
32
31
|
refetchInterval: defaultRefetchInterval,
|
|
33
32
|
staleTime: defaultRefetchInterval,
|
|
@@ -39,14 +38,14 @@ export const useTokenBalance = (token, accountAddress) => {
|
|
|
39
38
|
const index = clonedData.findIndex((dataToken) => dataToken.address === token.address);
|
|
40
39
|
clonedData[index] = {
|
|
41
40
|
...clonedData[index],
|
|
42
|
-
amount:
|
|
41
|
+
amount: tokenAmount,
|
|
43
42
|
};
|
|
44
43
|
return clonedData;
|
|
45
44
|
}
|
|
46
45
|
});
|
|
47
46
|
return {
|
|
48
47
|
...tokenBalances[0],
|
|
49
|
-
amount:
|
|
48
|
+
amount: tokenAmount,
|
|
50
49
|
};
|
|
51
50
|
}, {
|
|
52
51
|
enabled: Boolean(walletAddress && token),
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TokenAmount } from '../types';
|
|
2
2
|
export declare const useTokenBalances: (selectedChainId?: number) => {
|
|
3
|
-
tokens:
|
|
4
|
-
tokensWithBalance:
|
|
5
|
-
featuredTokens: import("@lifi/types").
|
|
3
|
+
tokens: TokenAmount[];
|
|
4
|
+
tokensWithBalance: TokenAmount[] | undefined;
|
|
5
|
+
featuredTokens: import("@lifi/types").StaticToken[] | undefined;
|
|
6
6
|
isLoading: boolean;
|
|
7
7
|
isBalanceLoading: boolean;
|
|
8
|
-
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<
|
|
8
|
+
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<TokenAmount[], unknown>>;
|
|
9
9
|
};
|