@lifi/widget 1.10.2 → 1.11.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.
Files changed (203) hide show
  1. package/App.js +6 -10
  2. package/AppDrawer.js +1 -1
  3. package/AppDrawer.style.d.ts +1 -1
  4. package/AppDrawer.style.js +0 -1
  5. package/AppProvider.d.ts +1 -0
  6. package/AppProvider.js +5 -2
  7. package/components/AppContainer.d.ts +10 -0
  8. package/components/AppContainer.js +4 -7
  9. package/components/Card/Card.d.ts +11 -5
  10. package/components/Card/Card.js +29 -5
  11. package/components/Card/index.d.ts +0 -1
  12. package/components/Card/index.js +0 -1
  13. package/components/Dialog.d.ts +3 -0
  14. package/components/Dialog.js +23 -0
  15. package/components/GasSufficiencyMessage/GasSufficiencyMessage.d.ts +6 -0
  16. package/components/GasSufficiencyMessage/GasSufficiencyMessage.js +48 -0
  17. package/components/{InsufficientGasOrFundsMessage/InsufficientGasOrFundsMessage.style.d.ts → GasSufficiencyMessage/GasSufficiencyMessage.style.d.ts} +0 -0
  18. package/components/{InsufficientGasOrFundsMessage/InsufficientGasOrFundsMessage.style.js → GasSufficiencyMessage/GasSufficiencyMessage.style.js} +1 -0
  19. package/components/GasSufficiencyMessage/index.d.ts +1 -0
  20. package/components/GasSufficiencyMessage/index.js +1 -0
  21. package/components/Header/Header.js +5 -6
  22. package/components/Header/Header.style.js +2 -1
  23. package/components/Header/NavigationHeader.js +27 -23
  24. package/components/Header/WalletHeader.js +4 -4
  25. package/components/Header/index.d.ts +1 -0
  26. package/components/Header/index.js +1 -0
  27. package/components/Header/types.d.ts +9 -0
  28. package/components/Header/types.js +1 -0
  29. package/components/Header/useHeaderActionStore.d.ts +6 -0
  30. package/components/Header/useHeaderActionStore.js +21 -0
  31. package/components/PoweredBy/PoweredBy.js +0 -1
  32. package/components/ProgressToNextUpdate/ProgressToNextUpdate.js +14 -2
  33. package/components/ReverseTokensButton/ReverseTokensButton.js +5 -7
  34. package/components/ReverseTokensButton/ReverseTokensButton.style.d.ts +1 -1
  35. package/components/ReverseTokensButton/ReverseTokensButton.style.js +4 -2
  36. package/components/SelectTokenButton/SelectTokenButton.js +9 -7
  37. package/components/SelectTokenButton/SelectTokenButton.style.d.ts +3 -10
  38. package/components/SelectTokenButton/SelectTokenButton.style.js +0 -7
  39. package/components/SmallAvatar.d.ts +16 -0
  40. package/components/SmallAvatar.js +8 -0
  41. package/{pages/SwapPage → components/Step}/CircularProgress.d.ts +0 -0
  42. package/{pages/SwapPage → components/Step}/CircularProgress.js +0 -0
  43. package/{pages/SwapPage → components/Step}/CircularProgress.style.d.ts +0 -0
  44. package/{pages/SwapPage → components/Step}/CircularProgress.style.js +0 -0
  45. package/components/Step/Step.d.ts +7 -0
  46. package/{pages/SwapPage/StepItem.js → components/Step/Step.js} +6 -6
  47. package/{pages/SwapPage/ExecutionItem.d.ts → components/Step/StepProcess.d.ts} +1 -1
  48. package/{pages/SwapPage/ExecutionItem.js → components/Step/StepProcess.js} +2 -2
  49. package/{pages/SwapPage/ExecutionItem.style.d.ts → components/Step/StepProcess.style.d.ts} +1 -1
  50. package/{pages/SwapPage/ExecutionItem.style.js → components/Step/StepProcess.style.js} +0 -0
  51. package/{pages/SwapPage → components/Step}/StepTimer.d.ts +0 -0
  52. package/{pages/SwapPage → components/Step}/StepTimer.js +0 -0
  53. package/components/Step/index.d.ts +1 -0
  54. package/components/Step/index.js +1 -0
  55. package/components/Step/utils.d.ts +6 -0
  56. package/components/Step/utils.js +89 -0
  57. package/components/StepActions/StepActions.js +17 -7
  58. package/components/StepActions/StepActions.style.js +2 -2
  59. package/{pages/SwapPage → components/StepDivider}/StepDivider.d.ts +0 -0
  60. package/{pages/SwapPage → components/StepDivider}/StepDivider.js +0 -0
  61. package/{pages/SwapPage → components/StepDivider}/StepDivider.style.d.ts +0 -0
  62. package/{pages/SwapPage → components/StepDivider}/StepDivider.style.js +0 -0
  63. package/components/StepDivider/index.d.ts +1 -0
  64. package/components/StepDivider/index.js +1 -0
  65. package/components/SwapButton/SwapButton.js +9 -12
  66. package/components/SwapButton/SwapButton.style.d.ts +1 -1
  67. package/components/SwapButton/SwapButton.style.js +1 -5
  68. package/components/SwapButton/types.d.ts +2 -0
  69. package/components/SwapInProgress/SwapInProgress.js +9 -6
  70. package/components/SwapInProgress/SwapInProgress.style.d.ts +9 -21
  71. package/components/SwapInProgress/SwapInProgress.style.js +5 -6
  72. package/components/SwapInput/FormPriceHelperText.js +1 -1
  73. package/components/SwapInput/SwapInput.js +4 -5
  74. package/components/SwapInput/SwapInputAdornment.style.d.ts +1 -1
  75. package/components/SwapInput/SwapInputAdornment.style.js +0 -2
  76. package/components/SwapRouteCard/SwapRouteCard.js +15 -15
  77. package/components/SwapRouteCard/SwapRouteCard.style.d.ts +0 -20
  78. package/components/SwapRouteCard/SwapRouteCard.style.js +7 -54
  79. package/components/SwapRouteCard/SwapRouteCardSkeleton.js +6 -10
  80. package/components/SwapRouteCard/SwapRouteNotFoundCard.js +3 -3
  81. package/components/SwapRouteCard/types.d.ts +0 -3
  82. package/components/{StepToken.d.ts → Token/Token.d.ts} +2 -1
  83. package/components/Token/Token.js +31 -0
  84. package/components/Token/Token.style.d.ts +24 -0
  85. package/components/Token/Token.style.js +31 -0
  86. package/components/Token/index.d.ts +2 -0
  87. package/components/Token/index.js +2 -0
  88. package/components/TokenAvatar/TokenAvatar.d.ts +7 -0
  89. package/components/TokenAvatar/TokenAvatar.js +8 -0
  90. package/components/TokenAvatar/TokenAvatar.style.d.ts +1 -0
  91. package/components/TokenAvatar/TokenAvatar.style.js +16 -0
  92. package/components/TokenAvatar/index.d.ts +2 -0
  93. package/components/TokenAvatar/index.js +2 -0
  94. package/components/TokenList/TokenList.js +2 -2
  95. package/components/TokenList/TokenList.style.js +1 -1
  96. package/components/TokenList/TokenListItem.d.ts +1 -0
  97. package/components/TokenList/TokenListItem.js +13 -7
  98. package/components/TokenList/types.d.ts +1 -0
  99. package/config/queryClient.d.ts +1 -1
  100. package/config/queryClient.js +1 -1
  101. package/config/sentry.js +1 -1
  102. package/config/theme.js +14 -1
  103. package/config/version.d.ts +1 -1
  104. package/config/version.js +1 -1
  105. package/hooks/index.d.ts +1 -1
  106. package/hooks/index.js +1 -1
  107. package/hooks/useChains.d.ts +8 -8
  108. package/hooks/useChains.js +1 -1
  109. package/hooks/useContentHeight.js +1 -1
  110. package/hooks/useGasSufficiency.d.ts +15 -0
  111. package/hooks/useGasSufficiency.js +91 -0
  112. package/hooks/useRouteExecution.d.ts +3 -3
  113. package/hooks/useRouteExecution.js +23 -19
  114. package/hooks/useScrollableContainer.js +1 -1
  115. package/hooks/useSwapRoutes.d.ts +1 -1
  116. package/hooks/useSwapRoutes.js +2 -14
  117. package/hooks/useTelemetry.js +11 -3
  118. package/hooks/useTokenBalance.js +5 -5
  119. package/hooks/useTokenBalances.d.ts +2 -2
  120. package/hooks/useTokenBalances.js +8 -10
  121. package/hooks/useTokens.js +1 -1
  122. package/hooks/useTools.d.ts +10 -1
  123. package/hooks/useTools.js +13 -3
  124. package/i18n/en/translation.json +18 -9
  125. package/i18n/index.d.ts +12 -3
  126. package/icons/LiFiToolLogo.svg +6 -0
  127. package/index.js +0 -2
  128. package/package.json +9 -9
  129. package/pages/MainPage/MainPage.js +2 -3
  130. package/pages/MainPage/MainSwapButton.js +6 -7
  131. package/{components/SwapRoutes → pages/MainPage}/SwapRoutes.d.ts +0 -0
  132. package/pages/MainPage/SwapRoutes.js +36 -0
  133. package/{components/SwapRoutes → pages/MainPage}/SwapRoutes.style.d.ts +0 -0
  134. package/{components/SwapRoutes → pages/MainPage}/SwapRoutes.style.js +4 -0
  135. package/pages/SelectTokenPage/ChainSelect.js +2 -2
  136. package/pages/SelectTokenPage/SearchTokenInput.js +2 -2
  137. package/pages/SelectWalletPage/SelectWalletPage.js +4 -23
  138. package/pages/SelectWalletPage/SelectWalletPage.style.js +1 -1
  139. package/pages/SettingsPage/AdvancedPreferences.js +1 -1
  140. package/pages/SettingsPage/ColorSchemeButtonGroup.style.d.ts +1 -1
  141. package/pages/SettingsPage/EnabledBridgesSelect.js +7 -4
  142. package/pages/SettingsPage/EnabledExchangesSelect.js +7 -4
  143. package/pages/SettingsPage/GasPriceSelect.js +2 -2
  144. package/pages/SettingsPage/RoutePrioritySelect.js +2 -2
  145. package/pages/SettingsPage/SlippageInput.js +3 -3
  146. package/pages/SwapDetailsPage/SwapDetailsPage.d.ts +2 -0
  147. package/pages/SwapDetailsPage/SwapDetailsPage.js +63 -0
  148. package/pages/SwapDetailsPage/SwapDetailsPage.style.d.ts +11 -0
  149. package/pages/SwapDetailsPage/SwapDetailsPage.style.js +5 -0
  150. package/pages/SwapDetailsPage/index.d.ts +1 -0
  151. package/pages/SwapDetailsPage/index.js +1 -0
  152. package/pages/SwapHistoryPage/SwapHistoryEmpty.d.ts +2 -0
  153. package/pages/SwapHistoryPage/SwapHistoryEmpty.js +14 -0
  154. package/pages/SwapHistoryPage/SwapHistoryItem.d.ts +5 -0
  155. package/pages/SwapHistoryPage/SwapHistoryItem.js +23 -0
  156. package/pages/SwapHistoryPage/SwapHistoryPage.d.ts +2 -0
  157. package/pages/SwapHistoryPage/SwapHistoryPage.js +14 -0
  158. package/pages/SwapHistoryPage/index.d.ts +1 -0
  159. package/pages/SwapHistoryPage/index.js +1 -0
  160. package/pages/SwapPage/StatusBottomSheet.js +4 -4
  161. package/pages/SwapPage/SwapPage.js +13 -10
  162. package/pages/SwapPage/SwapPage.style.d.ts +0 -33
  163. package/pages/SwapPage/SwapPage.style.js +2 -9
  164. package/pages/SwapPage/utils.js +1 -1
  165. package/pages/SwapRoutesPage/SwapRoutesPage.js +14 -7
  166. package/pages/SwapRoutesPage/SwapRoutesPage.style.js +1 -1
  167. package/providers/WalletProvider/WalletProvider.js +7 -26
  168. package/providers/WalletProvider/types.d.ts +0 -1
  169. package/providers/WidgetProvider/WidgetProvider.js +1 -1
  170. package/stores/route/index.d.ts +1 -1
  171. package/stores/route/index.js +1 -1
  172. package/stores/route/types.d.ts +2 -4
  173. package/stores/route/useExecutingRoutes.d.ts +2 -1
  174. package/stores/route/useExecutingRoutes.js +4 -2
  175. package/stores/route/useRouteStore.d.ts +4 -1
  176. package/stores/route/useRouteStore.js +23 -24
  177. package/stores/route/useSwapHistory.d.ts +2 -0
  178. package/stores/route/useSwapHistory.js +11 -0
  179. package/stores/settings/useSettingsStore.d.ts +13 -0
  180. package/types/widget.d.ts +3 -4
  181. package/utils/index.d.ts +6 -0
  182. package/utils/index.js +6 -0
  183. package/utils/navigationRoutes.d.ts +13 -0
  184. package/utils/navigationRoutes.js +12 -0
  185. package/components/Card/CardContainer.d.ts +0 -11
  186. package/components/Card/CardContainer.js +0 -16
  187. package/components/InsufficientGasOrFundsMessage/InsufficientGasOrFundsMessage.d.ts +0 -3
  188. package/components/InsufficientGasOrFundsMessage/InsufficientGasOrFundsMessage.js +0 -31
  189. package/components/InsufficientGasOrFundsMessage/index.d.ts +0 -1
  190. package/components/InsufficientGasOrFundsMessage/index.js +0 -1
  191. package/components/StepToken.js +0 -21
  192. package/components/SwapRoutes/SwapRoutes.js +0 -32
  193. package/components/SwapRoutes/SwapRoutesUpdateProgress.d.ts +0 -3
  194. package/components/SwapRoutes/SwapRoutesUpdateProgress.js +0 -24
  195. package/components/SwapRoutes/index.d.ts +0 -1
  196. package/components/SwapRoutes/index.js +0 -1
  197. package/hooks/useHasSufficientBalance.d.ts +0 -5
  198. package/hooks/useHasSufficientBalance.js +0 -72
  199. package/pages/SwapPage/StepItem.d.ts +0 -7
  200. package/stores/route/useCurrentRoute.d.ts +0 -2
  201. package/stores/route/useCurrentRoute.js +0 -5
  202. package/utils/routes.d.ts +0 -11
  203. package/utils/routes.js +0 -10
@@ -2,23 +2,29 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Avatar, Box, ListItemAvatar, ListItemText, Skeleton, Typography, } from '@mui/material';
3
3
  import { memo } from 'react';
4
4
  import { useTranslation } from 'react-i18next';
5
- import { formatTokenPrice } from '../../utils/format';
5
+ import { formatTokenPrice } from '../../utils';
6
6
  import { ListItem, ListItemButton } from './TokenList.style';
7
- export const TokenListItem = memo(({ onClick, size, start, token, showBalance }) => {
8
- var _a;
7
+ export const TokenListItem = memo(({ onClick, size, start, token, showBalance, isBalanceLoading }) => {
9
8
  const { t } = useTranslation();
10
9
  const handleClick = () => onClick === null || onClick === void 0 ? void 0 : onClick(token.address);
11
10
  const tokenPrice = formatTokenPrice(token.amount, token.priceUSD);
12
11
  return (_jsx(ListItem, Object.assign({ disablePadding: true, style: {
13
12
  height: `${size}px`,
14
13
  transform: `translateY(${start}px)`,
15
- } }, { children: _jsxs(ListItemButton, Object.assign({ onClick: handleClick, dense: true, disableRipple: true }, { children: [_jsx(ListItemAvatar, { children: _jsx(Avatar, Object.assign({ src: token.logoURI, alt: token.symbol }, { children: token.symbol[0] })) }), _jsx(ListItemText, { primary: token.symbol, secondary: token.name }), showBalance ? (_jsxs(Box, Object.assign({ sx: { textAlign: 'right' } }, { children: [_jsx(Typography, Object.assign({ variant: "body1", noWrap: true }, { children: (_a = token.amount) !== null && _a !== void 0 ? _a : '0' })), tokenPrice ? (_jsx(Typography, Object.assign({ fontWeight: 400, fontSize: 12, color: "text.secondary", "data-price": token.priceUSD }, { children: t(`swap.currency`, {
14
+ } }, { children: _jsxs(ListItemButton, Object.assign({ onClick: handleClick, dense: true, disableRipple: true }, { children: [_jsx(ListItemAvatar, { children: _jsx(Avatar, Object.assign({ src: token.logoURI, alt: token.symbol }, { children: token.symbol[0] })) }), _jsx(ListItemText, { primary: token.symbol, secondary: token.name }), showBalance ? (isBalanceLoading ? (_jsx(TokenAmountSkeleton, {})) : (_jsxs(Box, Object.assign({ sx: { textAlign: 'right' } }, { children: [Number(token.amount) ? (_jsx(Typography, Object.assign({ variant: "body1", noWrap: true }, { children: token.amount }))) : null, tokenPrice ? (_jsx(Typography, Object.assign({ fontWeight: 400, fontSize: 12, color: "text.secondary", "data-price": token.priceUSD }, { children: t(`swap.currency`, {
16
15
  value: tokenPrice,
17
- }) }))) : null] }))) : null] })) })));
16
+ }) }))) : null] })))) : null] })) })));
18
17
  });
19
18
  export const TokenListItemSkeleton = ({ size, start, }) => {
20
- return (_jsxs(ListItem, Object.assign({ secondaryAction: _jsx(Skeleton, { variant: "text", width: 60, height: 24 }), disablePadding: true, style: {
19
+ return (_jsxs(ListItem, Object.assign({ secondaryAction: _jsx(TokenAmountSkeleton, {}), disablePadding: true, style: {
21
20
  height: `${size}px`,
22
21
  transform: `translateY(${start}px)`,
23
- } }, { children: [_jsx(ListItemAvatar, { children: _jsx(Skeleton, { variant: "circular", width: 32, height: 32, sx: { marginLeft: 2, marginRight: 2 } }) }), _jsx(ListItemText, { primary: _jsx(Skeleton, { variant: "text", width: 48, height: 20 }), secondary: _jsx(Skeleton, { variant: "text", width: 128, height: 20 }) })] })));
22
+ } }, { children: [_jsx(ListItemAvatar, { children: _jsx(Skeleton, { variant: "circular", width: 32, height: 32, sx: { marginLeft: 2, marginRight: 2 } }) }), _jsx(ListItemText, { primary: _jsx(Skeleton, { variant: "text", width: 48, height: 20 }), secondary: _jsx(Skeleton, { variant: "text", width: 96, height: 20 }) })] })));
23
+ };
24
+ export const TokenAmountSkeleton = () => {
25
+ return (_jsxs(Box, Object.assign({ sx: {
26
+ display: 'flex',
27
+ flexDirection: 'column',
28
+ alignItems: 'flex-end',
29
+ } }, { children: [_jsx(Skeleton, { variant: "text", width: 56, height: 24 }), _jsx(Skeleton, { variant: "text", width: 48, height: 18 })] })));
24
30
  };
@@ -13,4 +13,5 @@ export interface TokenListItemBaseProps {
13
13
  export interface TokenListItemProps extends TokenListItemBaseProps {
14
14
  showBalance?: boolean;
15
15
  token: TokenAmount;
16
+ isBalanceLoading?: boolean;
16
17
  }
@@ -1,2 +1,2 @@
1
- import { QueryClient } from 'react-query';
1
+ import { QueryClient } from '@tanstack/react-query';
2
2
  export declare const queryClient: QueryClient;
@@ -1,4 +1,4 @@
1
- import { QueryClient } from 'react-query';
1
+ import { QueryClient } from '@tanstack/react-query';
2
2
  export const queryClient = new QueryClient({
3
3
  defaultOptions: {
4
4
  queries: {
package/config/sentry.js CHANGED
@@ -13,7 +13,7 @@ export const initSentry = (enabled) => {
13
13
  ],
14
14
  sampleRate: 1,
15
15
  tracesSampleRate: 0.2,
16
- enabled: enabled && process.env.NODE_ENV === 'production',
16
+ enabled,
17
17
  environment: process.env.NODE_ENV,
18
18
  release: version,
19
19
  });
package/config/theme.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { dialogActionsClasses } from '@mui/material/DialogActions';
1
2
  import { alpha, createTheme as createMuiTheme, darken, lighten, } from '@mui/material/styles';
2
3
  const palette = {
3
4
  primary: {
@@ -24,7 +25,7 @@ const palette = {
24
25
  },
25
26
  };
26
27
  export const createTheme = (mode, theme = {}) => {
27
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
28
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
28
29
  return createMuiTheme({
29
30
  typography: Object.assign({ fontFamily: 'Inter var, Inter, sans-serif' }, theme.typography),
30
31
  palette: Object.assign(Object.assign(Object.assign({ mode }, palette), { primary: {
@@ -73,6 +74,9 @@ export const createTheme = (mode, theme = {}) => {
73
74
  },
74
75
  },
75
76
  MuiButton: {
77
+ defaultProps: {
78
+ disableElevation: true,
79
+ },
76
80
  styleOverrides: Object.assign(Object.assign({}, (mode === 'dark'
77
81
  ? {
78
82
  outlined: {
@@ -92,10 +96,19 @@ export const createTheme = (mode, theme = {}) => {
92
96
  },
93
97
  }
94
98
  : {})), { root: {
99
+ borderRadius: (_u = theme.shape) === null || _u === void 0 ? void 0 : _u.borderRadiusSecondary,
100
+ textTransform: 'none',
101
+ fontSize: '1rem',
102
+ padding: '10px 16px',
103
+ [`.${dialogActionsClasses.root} &`]: {
104
+ padding: '6px 12px',
105
+ },
95
106
  '&.Mui-disabled': {
96
107
  color: mode === 'light'
97
108
  ? 'rgb(0 0 0 / 70%)'
98
109
  : 'rgb(255 255 255 / 70%)',
110
+ cursor: 'not-allowed',
111
+ pointerEvents: 'auto',
99
112
  },
100
113
  } }),
101
114
  },
@@ -1,2 +1,2 @@
1
1
  export declare const name = "@lifi/widget";
2
- export declare const version = "1.10.2";
2
+ export declare const version = "1.11.0";
package/config/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@lifi/widget';
2
- export const version = '1.10.2';
2
+ export const version = '1.11.0';
package/hooks/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export * from './useChain';
2
2
  export * from './useChains';
3
3
  export * from './useContentHeight';
4
4
  export * from './useDebouncedWatch';
5
- export * from './useHasSufficientBalance';
5
+ export * from './useGasSufficiency';
6
6
  export * from './useRouteExecution';
7
7
  export * from './useScrollableContainer';
8
8
  export * from './useSwapRoutes';
package/hooks/index.js CHANGED
@@ -2,7 +2,7 @@ export * from './useChain';
2
2
  export * from './useChains';
3
3
  export * from './useContentHeight';
4
4
  export * from './useDebouncedWatch';
5
- export * from './useHasSufficientBalance';
5
+ export * from './useGasSufficiency';
6
6
  export * from './useRouteExecution';
7
7
  export * from './useScrollableContainer';
8
8
  export * from './useSwapRoutes';
@@ -18,9 +18,9 @@ export declare const useChains: () => {
18
18
  isPreviousData: boolean;
19
19
  isRefetching: boolean;
20
20
  isStale: boolean;
21
- refetch: <TPageData>(options?: (import("react-query").RefetchOptions & import("react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("react-query").QueryObserverResult<import("@lifi/types").EVMChain[], unknown>>;
21
+ refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<import("@lifi/types").EVMChain[], unknown>>;
22
22
  remove: () => void;
23
- fetchStatus: import("react-query").FetchStatus;
23
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
24
24
  chains: import("@lifi/types").EVMChain[] | undefined;
25
25
  getChainById: (chainId: number) => import("@lifi/types").EVMChain | undefined;
26
26
  } | {
@@ -43,9 +43,9 @@ export declare const useChains: () => {
43
43
  isPreviousData: boolean;
44
44
  isRefetching: boolean;
45
45
  isStale: boolean;
46
- refetch: <TPageData>(options?: (import("react-query").RefetchOptions & import("react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("react-query").QueryObserverResult<import("@lifi/types").EVMChain[], unknown>>;
46
+ refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<import("@lifi/types").EVMChain[], unknown>>;
47
47
  remove: () => void;
48
- fetchStatus: import("react-query").FetchStatus;
48
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
49
49
  chains: import("@lifi/types").EVMChain[] | undefined;
50
50
  getChainById: (chainId: number) => import("@lifi/types").EVMChain | undefined;
51
51
  } | {
@@ -68,9 +68,9 @@ export declare const useChains: () => {
68
68
  isPreviousData: boolean;
69
69
  isRefetching: boolean;
70
70
  isStale: boolean;
71
- refetch: <TPageData>(options?: (import("react-query").RefetchOptions & import("react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("react-query").QueryObserverResult<import("@lifi/types").EVMChain[], unknown>>;
71
+ refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<import("@lifi/types").EVMChain[], unknown>>;
72
72
  remove: () => void;
73
- fetchStatus: import("react-query").FetchStatus;
73
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
74
74
  chains: import("@lifi/types").EVMChain[] | undefined;
75
75
  getChainById: (chainId: number) => import("@lifi/types").EVMChain | undefined;
76
76
  } | {
@@ -93,9 +93,9 @@ export declare const useChains: () => {
93
93
  isPreviousData: boolean;
94
94
  isRefetching: boolean;
95
95
  isStale: boolean;
96
- refetch: <TPageData>(options?: (import("react-query").RefetchOptions & import("react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("react-query").QueryObserverResult<import("@lifi/types").EVMChain[], unknown>>;
96
+ refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<import("@lifi/types").EVMChain[], unknown>>;
97
97
  remove: () => void;
98
- fetchStatus: import("react-query").FetchStatus;
98
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
99
99
  chains: import("@lifi/types").EVMChain[] | undefined;
100
100
  getChainById: (chainId: number) => import("@lifi/types").EVMChain | undefined;
101
101
  };
@@ -18,8 +18,8 @@ var __rest = (this && this.__rest) || function (s, e) {
18
18
  }
19
19
  return t;
20
20
  };
21
+ import { useQuery } from '@tanstack/react-query';
21
22
  import { useCallback } from 'react';
22
- import { useQuery } from 'react-query';
23
23
  import { LiFi } from '../config/lifi';
24
24
  import { useWidgetConfig } from '../providers/WidgetProvider';
25
25
  export const useChains = () => {
@@ -1,5 +1,5 @@
1
1
  import { useLayoutEffect, useState } from 'react';
2
- import { ElementId } from '../utils/elements';
2
+ import { ElementId } from '../utils';
3
3
  const getContentHeight = () => {
4
4
  const headerElement = document.getElementById(ElementId.Header);
5
5
  const containerElement = document.getElementById(ElementId.ScrollableContainer);
@@ -0,0 +1,15 @@
1
+ import { EVMChain, Route, Token } from '@lifi/sdk';
2
+ import Big from 'big.js';
3
+ interface GasSufficiency {
4
+ gasAmount: Big;
5
+ tokenAmount?: Big;
6
+ insufficientAmount?: Big;
7
+ insufficient?: boolean;
8
+ token: Token;
9
+ chain?: EVMChain;
10
+ }
11
+ export declare const useGasSufficiency: (route?: Route) => {
12
+ insufficientGas: GasSufficiency[];
13
+ insufficientFunds: boolean;
14
+ };
15
+ export {};
@@ -0,0 +1,91 @@
1
+ import Big from 'big.js';
2
+ import { useMemo } from 'react';
3
+ import { useWatch } from 'react-hook-form';
4
+ import { useChains, useDebouncedWatch } from '.';
5
+ import { SwapFormKey, SwapFormKeyHelper } from '../providers/SwapFormProvider';
6
+ import { useWallet } from '../providers/WalletProvider';
7
+ import { useTokenBalances } from './useTokenBalances';
8
+ export const useGasSufficiency = (route) => {
9
+ const { account } = useWallet();
10
+ const [fromChainId, toChainId, fromToken] = useWatch({
11
+ name: [
12
+ SwapFormKeyHelper.getChainKey('from'),
13
+ SwapFormKeyHelper.getChainKey('to'),
14
+ SwapFormKey.FromToken,
15
+ ],
16
+ });
17
+ const fromAmount = useDebouncedWatch(SwapFormKey.FromAmount, 250);
18
+ const { tokens: fromChainTokenBalances } = useTokenBalances(fromChainId);
19
+ const { tokens: toChainTokenBalances } = useTokenBalances(toChainId);
20
+ const { getChainById } = useChains();
21
+ const insufficientGas = useMemo(() => {
22
+ var _a;
23
+ if (!account.isActive || !route || !fromAmount) {
24
+ return [];
25
+ }
26
+ const tokenBalancesByChain = {
27
+ [fromChainId]: fromChainTokenBalances,
28
+ [toChainId]: toChainTokenBalances,
29
+ };
30
+ const gasCosts = route.steps.reduce((groupedGasCosts, step) => {
31
+ if (step.estimate.gasCosts) {
32
+ const { token } = step.estimate.gasCosts[0];
33
+ const gasCostAmount = step.estimate.gasCosts
34
+ .reduce((amount, gasCost) => amount.plus(Big(gasCost.amount || 0)), Big(0))
35
+ .div(Math.pow(10, token.decimals));
36
+ const groupedGasCost = groupedGasCosts[token.chainId];
37
+ const gasAmount = groupedGasCost
38
+ ? groupedGasCost.gasAmount.plus(gasCostAmount)
39
+ : gasCostAmount;
40
+ groupedGasCosts[token.chainId] = {
41
+ gasAmount,
42
+ tokenAmount: gasAmount,
43
+ token,
44
+ chain: getChainById(token.chainId),
45
+ };
46
+ return groupedGasCosts;
47
+ }
48
+ return groupedGasCosts;
49
+ }, {});
50
+ if (gasCosts[fromChainId] &&
51
+ route.fromToken.address === gasCosts[fromChainId].token.address) {
52
+ gasCosts[fromChainId].tokenAmount = (_a = gasCosts[fromChainId]) === null || _a === void 0 ? void 0 : _a.gasAmount.plus(Big(fromAmount));
53
+ }
54
+ [fromChainId, toChainId].forEach((chainId) => {
55
+ var _a, _b, _c, _d, _e, _f, _g;
56
+ if (gasCosts[chainId]) {
57
+ const gasTokenBalance = Big((_c = (_b = (_a = tokenBalancesByChain[chainId]) === null || _a === void 0 ? void 0 : _a.find((t) => t.address === gasCosts[chainId].token.address)) === null || _b === void 0 ? void 0 : _b.amount) !== null && _c !== void 0 ? _c : 0);
58
+ const insufficientFromChainGas = gasTokenBalance.lte(0) ||
59
+ gasTokenBalance.lt((_d = gasCosts[chainId].gasAmount) !== null && _d !== void 0 ? _d : Big(0)) ||
60
+ gasTokenBalance.lt((_e = gasCosts[chainId].tokenAmount) !== null && _e !== void 0 ? _e : Big(0));
61
+ const insufficientFromChainGasAmount = insufficientFromChainGas
62
+ ? (_g = (_f = gasCosts[chainId].tokenAmount) === null || _f === void 0 ? void 0 : _f.minus(gasTokenBalance)) !== null && _g !== void 0 ? _g : gasCosts[chainId].gasAmount.minus(gasTokenBalance)
63
+ : undefined;
64
+ gasCosts[chainId] = Object.assign(Object.assign({}, gasCosts[chainId]), { insufficient: insufficientFromChainGas, insufficientAmount: insufficientFromChainGasAmount });
65
+ }
66
+ });
67
+ const gasCostResult = Object.values(gasCosts).filter((gasCost) => gasCost.insufficient);
68
+ return gasCostResult;
69
+ }, [
70
+ account.isActive,
71
+ fromAmount,
72
+ fromChainId,
73
+ fromChainTokenBalances,
74
+ getChainById,
75
+ route,
76
+ toChainId,
77
+ toChainTokenBalances,
78
+ ]);
79
+ const insufficientFunds = useMemo(() => {
80
+ var _a, _b;
81
+ if (!account.isActive || !fromToken || !fromAmount) {
82
+ return false;
83
+ }
84
+ const balance = Big((_b = (_a = fromChainTokenBalances === null || fromChainTokenBalances === void 0 ? void 0 : fromChainTokenBalances.find((t) => t.address === fromToken)) === null || _a === void 0 ? void 0 : _a.amount) !== null && _b !== void 0 ? _b : 0);
85
+ return Big(fromAmount).gte(balance);
86
+ }, [account.isActive, fromAmount, fromChainTokenBalances, fromToken]);
87
+ return {
88
+ insufficientGas,
89
+ insufficientFunds,
90
+ };
91
+ };
@@ -2,7 +2,7 @@ import { Route } from '@lifi/sdk';
2
2
  export declare const useRouteExecution: (routeId: string) => {
3
3
  executeRoute: () => void;
4
4
  restartRoute: () => void;
5
- removeRoute: () => void;
6
- route: Route;
7
- status: import("../stores").RouteExecutionStatus;
5
+ deleteRoute: () => void;
6
+ route: Route | undefined;
7
+ status: import("../stores").RouteExecutionStatus | undefined;
8
8
  };
@@ -7,18 +7,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ import { useMutation } from '@tanstack/react-query';
10
11
  import { useCallback, useEffect, useRef } from 'react';
11
- import { useMutation } from 'react-query';
12
12
  import shallow from 'zustand/shallow';
13
13
  import { LiFi } from '../config/lifi';
14
14
  import { useWallet } from '../providers/WalletProvider';
15
15
  import { useRouteStore } from '../stores';
16
- import { deepClone } from '../utils/deepClone';
16
+ import { deepClone } from '../utils';
17
17
  export const useRouteExecution = (routeId) => {
18
18
  const { account, switchChain } = useWallet();
19
19
  const resumedAfterMount = useRef(false);
20
- const { route, status } = useRouteStore((state) => { var _a; return (_a = state.routes[routeId]) !== null && _a !== void 0 ? _a : {}; });
21
- const [updateRoute, restartRoute, removeRoute] = useRouteStore((state) => [state.updateRoute, state.restartRoute, state.removeRoute], shallow);
20
+ const routeExecution = useRouteStore((state) => state.routes[routeId]);
21
+ const [updateRoute, restartRoute, deleteRoute] = useRouteStore((state) => [state.updateRoute, state.restartRoute, state.deleteRoute], shallow);
22
22
  const updateCallback = (updatedRoute) => {
23
23
  console.log('Route updated.', updatedRoute);
24
24
  updateRoute(deepClone(updatedRoute));
@@ -39,10 +39,10 @@ export const useRouteExecution = (routeId) => {
39
39
  if (!account.signer) {
40
40
  throw Error('Account signer not found.');
41
41
  }
42
- if (!route) {
42
+ if (!(routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route)) {
43
43
  throw Error('Execution route not found.');
44
44
  }
45
- return LiFi.executeRoute(account.signer, route, {
45
+ return LiFi.executeRoute(account.signer, routeExecution.route, {
46
46
  updateCallback,
47
47
  switchChainHook,
48
48
  infiniteApproval: false,
@@ -62,10 +62,10 @@ export const useRouteExecution = (routeId) => {
62
62
  if (!account.signer) {
63
63
  throw Error('Account signer not found.');
64
64
  }
65
- if (!route) {
65
+ if (!(routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route)) {
66
66
  throw Error('Execution route not found.');
67
67
  }
68
- return LiFi.resumeRoute(account.signer, resumedRoute !== null && resumedRoute !== void 0 ? resumedRoute : route, {
68
+ return LiFi.resumeRoute(account.signer, resumedRoute !== null && resumedRoute !== void 0 ? resumedRoute : routeExecution.route, {
69
69
  updateCallback,
70
70
  switchChainHook,
71
71
  infiniteApproval: false,
@@ -105,18 +105,18 @@ export const useRouteExecution = (routeId) => {
105
105
  }, [resumeRouteMutation, routeId]);
106
106
  const restartRouteMutation = useCallback(() => {
107
107
  restartRoute(routeId);
108
- resumeRoute(route);
108
+ resumeRoute(routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route);
109
109
  // eslint-disable-next-line react-hooks/exhaustive-deps
110
- }, [resumeRoute, route, routeId]);
111
- const removeRouteMutation = useCallback(() => {
112
- removeRoute(routeId);
110
+ }, [resumeRoute, routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route, routeId]);
111
+ const deleteRouteMutation = useCallback(() => {
112
+ deleteRoute(routeId);
113
113
  // eslint-disable-next-line react-hooks/exhaustive-deps
114
114
  }, [routeId]);
115
115
  useEffect(() => {
116
116
  // check if route is eligible for automatic resuming
117
- const isDone = route.steps.every((step) => { var _a; return ((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'DONE'; });
118
- const isFailed = route.steps.some((step) => { var _a; return ((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'FAILED'; });
119
- const alreadyStarted = route.steps.some((step) => step.execution);
117
+ const isDone = routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route.steps.every((step) => { var _a; return ((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'DONE'; });
118
+ const isFailed = routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route.steps.some((step) => { var _a; return ((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'FAILED'; });
119
+ const alreadyStarted = routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route.steps.some((step) => step.execution);
120
120
  if (!isDone &&
121
121
  !isFailed &&
122
122
  alreadyStarted &&
@@ -125,14 +125,18 @@ export const useRouteExecution = (routeId) => {
125
125
  resumedAfterMount.current = true;
126
126
  resumeRoute();
127
127
  }
128
- return () => LiFi.moveExecutionToBackground(route);
128
+ return () => {
129
+ if (routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route) {
130
+ LiFi.moveExecutionToBackground(routeExecution.route);
131
+ }
132
+ };
129
133
  // eslint-disable-next-line react-hooks/exhaustive-deps
130
134
  }, [account.signer]);
131
135
  return {
132
136
  executeRoute,
133
137
  restartRoute: restartRouteMutation,
134
- removeRoute: removeRouteMutation,
135
- route,
136
- status,
138
+ deleteRoute: deleteRouteMutation,
139
+ route: routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route,
140
+ status: routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.status,
137
141
  };
138
142
  };
@@ -1,5 +1,5 @@
1
1
  import { useLayoutEffect, useState } from 'react';
2
- import { ElementId } from '../utils/elements';
2
+ import { ElementId } from '../utils';
3
3
  export const useScrollableContainer = () => {
4
4
  const [containerElement, setContainerElement] = useState(() => document.getElementById(ElementId.ScrollableContainer));
5
5
  useLayoutEffect(() => {
@@ -5,5 +5,5 @@ export declare const useSwapRoutes: () => {
5
5
  isFetched: boolean;
6
6
  dataUpdatedAt: number;
7
7
  refetchTime: number;
8
- refetch: <TPageData>(options?: (import("react-query").RefetchOptions & import("react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("react-query").QueryObserverResult<import("@lifi/types").RoutesResponse, unknown>>;
8
+ refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<import("@lifi/types").RoutesResponse, unknown>>;
9
9
  };
@@ -7,21 +7,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ import { useQuery, useQueryClient } from '@tanstack/react-query';
10
11
  import Big from 'big.js';
11
- import { useEffect } from 'react';
12
12
  import { useWatch } from 'react-hook-form';
13
- import { useQuery, useQueryClient } from 'react-query';
14
13
  import { useDebouncedWatch, useToken } from '.';
15
14
  import { LiFi } from '../config/lifi';
16
15
  import { SwapFormKey } from '../providers/SwapFormProvider';
17
16
  import { useWallet } from '../providers/WalletProvider';
18
- import { useCurrentRoute, useSettings } from '../stores';
17
+ import { useSettings } from '../stores';
19
18
  const refetchTime = 60000;
20
19
  export const useSwapRoutes = () => {
21
20
  var _a;
22
21
  const { account } = useWallet();
23
22
  const queryClient = useQueryClient();
24
- const [currentRoute, setCurrentRoute] = useCurrentRoute();
25
23
  const { slippage, enabledBridges, enabledExchanges, routePriority } = useSettings([
26
24
  'slippage',
27
25
  'routePriority',
@@ -92,16 +90,6 @@ export const useSwapRoutes = () => {
92
90
  staleTime: refetchTime,
93
91
  cacheTime: refetchTime,
94
92
  });
95
- useEffect(() => {
96
- // check that the current route is selected from existing routes
97
- const isCurrentRouteInSet = data === null || data === void 0 ? void 0 : data.routes.some((route) => route.id === (currentRoute === null || currentRoute === void 0 ? void 0 : currentRoute.id));
98
- const recommendedRoute = data === null || data === void 0 ? void 0 : data.routes[0];
99
- // we don't want to set the current route again on mount if it's already selected from existing routes
100
- if (!isCurrentRouteInSet) {
101
- setCurrentRoute(recommendedRoute);
102
- }
103
- // eslint-disable-next-line react-hooks/exhaustive-deps
104
- }, [data === null || data === void 0 ? void 0 : data.routes, setCurrentRoute]);
105
93
  return {
106
94
  routes: data === null || data === void 0 ? void 0 : data.routes,
107
95
  isLoading: isEnabled && isLoading,
@@ -1,10 +1,18 @@
1
+ /* eslint-disable consistent-return */
1
2
  import { useEffect } from 'react';
2
3
  import { initSentry } from '../config/sentry';
3
4
  export const useTelemetry = (disabled) => {
4
5
  useEffect(() => {
5
- if (process.env.NODE_ENV === 'production' && disabled) {
6
- console.warn('Enable crash reports and diagnostic data to be collected. This helps us to better understand how the widget is performing and where improvements need to be made.');
7
- initSentry(false);
6
+ if (disabled) {
7
+ if (process.env.NODE_ENV === 'production') {
8
+ console.warn('Enable crash reports and diagnostic data to be collected. This helps us to better understand how the widget is performing and where improvements need to be made.');
9
+ }
10
+ }
11
+ else {
12
+ initSentry(true);
13
+ return () => {
14
+ initSentry(false);
15
+ };
8
16
  }
9
17
  }, [disabled]);
10
18
  };
@@ -7,11 +7,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ import { useQuery, useQueryClient } from '@tanstack/react-query';
10
11
  import { useCallback } from 'react';
11
- import { useQuery, useQueryClient } from 'react-query';
12
12
  import { LiFi } from '../config/lifi';
13
13
  import { useWallet } from '../providers/WalletProvider';
14
- import { formatTokenAmount } from '../utils/format';
14
+ import { formatTokenAmount } from '../utils';
15
15
  import { useToken } from './useToken';
16
16
  export const useTokenBalance = (chainId, tokenAddress) => {
17
17
  const { account } = useWallet();
@@ -26,9 +26,9 @@ export const useTokenBalance = (chainId, tokenAddress) => {
26
26
  }), {
27
27
  enabled: Boolean(account.address) && Boolean(token),
28
28
  refetchIntervalInBackground: true,
29
- refetchInterval: 60000,
30
- staleTime: 60000,
31
- cacheTime: 60000,
29
+ refetchInterval: 30000,
30
+ staleTime: 30000,
31
+ cacheTime: 30000,
32
32
  });
33
33
  const refetchBalance = useCallback((chainId, tokenAddress) => __awaiter(void 0, void 0, void 0, function* () {
34
34
  if (!chainId && !tokenAddress) {
@@ -2,6 +2,6 @@ import { TokenAmount } from '@lifi/sdk';
2
2
  export declare const useTokenBalances: (selectedChainId: number) => {
3
3
  tokens: TokenAmount[] | undefined;
4
4
  isLoading: boolean;
5
- isFetching: boolean;
6
- updateBalances: <TPageData>(options?: (import("react-query").RefetchOptions & import("react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("react-query").QueryObserverResult<TokenAmount[], unknown>>;
5
+ isBalanceLoading: boolean;
6
+ updateBalances: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<TokenAmount[], unknown>>;
7
7
  };
@@ -7,18 +7,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { useQuery } from 'react-query';
10
+ import { useQuery } from '@tanstack/react-query';
11
11
  import { LiFi } from '../config/lifi';
12
12
  import { useWallet } from '../providers/WalletProvider';
13
- import { formatTokenAmount } from '../utils/format';
13
+ import { formatTokenAmount } from '../utils';
14
14
  import { useChains } from './useChains';
15
15
  import { useTokens } from './useTokens';
16
16
  export const useTokenBalances = (selectedChainId) => {
17
17
  const { account } = useWallet();
18
18
  const { chains, isLoading: isChainsLoading } = useChains();
19
- const { tokens, isLoading, isFetching } = useTokens(selectedChainId);
20
- const isBalancesLoadingEnabled = Boolean(account.address) && Boolean(tokens) && Boolean(chains);
21
- const { data: tokensWithBalance, isLoading: isBalancesLoading, isFetching: isBalancesFetching, refetch, } = useQuery(['token-balances', selectedChainId, account.address], ({ queryKey: [_, chainId, account] }) => __awaiter(void 0, void 0, void 0, function* () {
19
+ const { tokens, isLoading } = useTokens(selectedChainId);
20
+ const isBalanceLoadingEnabled = Boolean(account.address) && Boolean(tokens) && Boolean(chains);
21
+ const { data: tokensWithBalance, isLoading: isBalanceLoading, refetch, } = useQuery(['token-balances', selectedChainId, account.address], ({ queryKey: [_, chainId, account] }) => __awaiter(void 0, void 0, void 0, function* () {
22
22
  if (!account || !tokens) {
23
23
  return [];
24
24
  }
@@ -38,17 +38,15 @@ export const useTokenBalances = (selectedChainId) => {
38
38
  ...formatedTokens.filter((token) => token.amount === '0'),
39
39
  ];
40
40
  }), {
41
- enabled: isBalancesLoadingEnabled,
41
+ enabled: isBalanceLoadingEnabled,
42
42
  refetchIntervalInBackground: true,
43
43
  refetchInterval: 60000,
44
44
  staleTime: 60000,
45
45
  });
46
46
  return {
47
47
  tokens: tokensWithBalance !== null && tokensWithBalance !== void 0 ? tokensWithBalance : tokens,
48
- isLoading: (isBalancesLoading && isBalancesLoadingEnabled) ||
49
- (isLoading && isFetching) ||
50
- isChainsLoading,
51
- isFetching: isBalancesFetching,
48
+ isLoading: isLoading || isChainsLoading,
49
+ isBalanceLoading: isBalanceLoading && isBalanceLoadingEnabled,
52
50
  updateBalances: refetch,
53
51
  };
54
52
  };
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { useQuery } from 'react-query';
10
+ import { useQuery } from '@tanstack/react-query';
11
11
  import { LiFi } from '../config/lifi';
12
12
  export const useTokens = (selectedChainId) => {
13
13
  const { data: tokens, isLoading, isFetching, } = useQuery(['tokens', selectedChainId], () => __awaiter(void 0, void 0, void 0, function* () {
@@ -1 +1,10 @@
1
- export declare const useTools: () => import("@lifi/types").ToolsResponse | undefined;
1
+ import { Bridge, Exchange } from '@lifi/sdk';
2
+ declare type FormattedTool<T, K extends keyof T> = Record<string, Pick<T, K>>;
3
+ export declare const useTools: () => {
4
+ tools: import("@lifi/sdk").ToolsResponse | undefined;
5
+ formattedTools: {
6
+ bridges: FormattedTool<Bridge, "key" | "name" | "logoURI"> | undefined;
7
+ exchanges: FormattedTool<Exchange, "key" | "name" | "logoURI"> | undefined;
8
+ };
9
+ };
10
+ export {};