@lifi/widget 1.18.1 → 1.18.3

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 (74) hide show
  1. package/AppRoutes.js +7 -3
  2. package/cjs/AppRoutes.js +7 -3
  3. package/cjs/components/BottomSheet/BottomSheet.js +2 -0
  4. package/cjs/components/ChainSelect/ChainSelect.js +1 -1
  5. package/cjs/components/Header/WalletHeader.js +1 -3
  6. package/cjs/components/SendToWallet/SendToWallet.js +1 -1
  7. package/cjs/components/SendToWallet/SendToWalletButton.js +9 -1
  8. package/cjs/components/SwapInput/FormPriceHelperText.js +1 -1
  9. package/cjs/components/SwapInput/SwapInputAdornment.js +1 -1
  10. package/cjs/components/SwapRouteCard/SwapRouteCard.js +4 -4
  11. package/cjs/components/SwapRouteCard/SwapRouteCardSkeleton.js +1 -1
  12. package/cjs/components/SwapRouteCard/types.d.ts +3 -2
  13. package/cjs/components/SwapRoutes/SwapRoutesExpanded.js +9 -5
  14. package/cjs/config/version.d.ts +1 -1
  15. package/cjs/config/version.js +1 -1
  16. package/cjs/hooks/index.d.ts +1 -1
  17. package/cjs/hooks/index.js +1 -1
  18. package/cjs/hooks/useGasSufficiency.js +10 -11
  19. package/cjs/hooks/useScrollableContainer.d.ts +0 -1
  20. package/cjs/hooks/useScrollableContainer.js +1 -15
  21. package/cjs/hooks/useTokenAddressBalance.d.ts +5 -0
  22. package/cjs/hooks/useTokenAddressBalance.js +19 -0
  23. package/cjs/hooks/useTokenBalance.d.ts +7 -3
  24. package/cjs/hooks/useTokenBalance.js +87 -9
  25. package/cjs/hooks/useTokenBalances.d.ts +1 -1
  26. package/cjs/hooks/useTokenBalances.js +1 -4
  27. package/cjs/i18n/en/translation.json +1 -1
  28. package/cjs/pages/SelectTokenPage/SelectTokenPage.js +1 -11
  29. package/cjs/pages/SwapPage/StatusBottomSheet.js +19 -6
  30. package/cjs/utils/index.d.ts +1 -0
  31. package/cjs/utils/index.js +1 -0
  32. package/cjs/utils/wallet.d.ts +1 -0
  33. package/cjs/utils/wallet.js +7 -0
  34. package/components/BottomSheet/BottomSheet.js +2 -0
  35. package/components/ChainSelect/ChainSelect.js +2 -2
  36. package/components/Header/WalletHeader.js +2 -4
  37. package/components/SendToWallet/SendToWallet.js +1 -1
  38. package/components/SendToWallet/SendToWalletButton.js +10 -2
  39. package/components/SwapInput/FormPriceHelperText.js +2 -2
  40. package/components/SwapInput/SwapInputAdornment.js +2 -2
  41. package/components/SwapRouteCard/SwapRouteCard.js +4 -4
  42. package/components/SwapRouteCard/SwapRouteCardSkeleton.js +1 -1
  43. package/components/SwapRouteCard/types.d.ts +3 -2
  44. package/components/SwapRoutes/SwapRoutesExpanded.js +9 -5
  45. package/config/version.d.ts +1 -1
  46. package/config/version.js +1 -1
  47. package/hooks/index.d.ts +1 -1
  48. package/hooks/index.js +1 -1
  49. package/hooks/useGasSufficiency.js +11 -12
  50. package/hooks/useScrollableContainer.d.ts +0 -1
  51. package/hooks/useScrollableContainer.js +0 -13
  52. package/hooks/useTokenAddressBalance.d.ts +5 -0
  53. package/hooks/useTokenAddressBalance.js +15 -0
  54. package/hooks/useTokenBalance.d.ts +7 -3
  55. package/hooks/useTokenBalance.js +88 -10
  56. package/hooks/useTokenBalances.d.ts +1 -1
  57. package/hooks/useTokenBalances.js +1 -4
  58. package/i18n/en/translation.json +1 -1
  59. package/package.json +5 -5
  60. package/pages/SelectTokenPage/SelectTokenPage.js +2 -12
  61. package/pages/SwapPage/StatusBottomSheet.js +19 -6
  62. package/tsconfig.cjs.tsbuildinfo +1 -1
  63. package/utils/index.d.ts +1 -0
  64. package/utils/index.js +1 -0
  65. package/utils/wallet.d.ts +1 -0
  66. package/utils/wallet.js +3 -0
  67. package/cjs/components/SwapButton/ButtonTooltip.d.ts +0 -5
  68. package/cjs/components/SwapButton/ButtonTooltip.js +0 -7
  69. package/cjs/hooks/useContentHeight.d.ts +0 -1
  70. package/cjs/hooks/useContentHeight.js +0 -27
  71. package/components/SwapButton/ButtonTooltip.d.ts +0 -5
  72. package/components/SwapButton/ButtonTooltip.js +0 -3
  73. package/hooks/useContentHeight.d.ts +0 -1
  74. package/hooks/useContentHeight.js +0 -23
package/AppRoutes.js CHANGED
@@ -56,10 +56,14 @@ export const AppRoutes = () => {
56
56
  path: navigationRoutes.swapHistory,
57
57
  element: _jsx(SwapHistoryPage, {}),
58
58
  },
59
- {
60
- path: `${navigationRoutes.swapHistory}/${navigationRoutes.swapDetails}`,
59
+ ...[
60
+ `${navigationRoutes.swapHistory}/${navigationRoutes.swapDetails}`,
61
+ `${navigationRoutes.swapExecution}/${navigationRoutes.swapDetails}`,
62
+ `${navigationRoutes.swapRoutes}/${navigationRoutes.swapExecution}/${navigationRoutes.swapDetails}`,
63
+ ].map((path) => ({
64
+ path,
61
65
  element: _jsx(SwapDetailsPage, {}),
62
- },
66
+ })),
63
67
  ...[
64
68
  navigationRoutes.selectWallet,
65
69
  `${navigationRoutes.swapExecution}/${navigationRoutes.selectWallet}`,
package/cjs/AppRoutes.js CHANGED
@@ -59,10 +59,14 @@ const AppRoutes = () => {
59
59
  path: utils_1.navigationRoutes.swapHistory,
60
60
  element: (0, jsx_runtime_1.jsx)(SwapHistoryPage_1.SwapHistoryPage, {}),
61
61
  },
62
- {
63
- path: `${utils_1.navigationRoutes.swapHistory}/${utils_1.navigationRoutes.swapDetails}`,
62
+ ...[
63
+ `${utils_1.navigationRoutes.swapHistory}/${utils_1.navigationRoutes.swapDetails}`,
64
+ `${utils_1.navigationRoutes.swapExecution}/${utils_1.navigationRoutes.swapDetails}`,
65
+ `${utils_1.navigationRoutes.swapRoutes}/${utils_1.navigationRoutes.swapExecution}/${utils_1.navigationRoutes.swapDetails}`,
66
+ ].map((path) => ({
67
+ path,
64
68
  element: (0, jsx_runtime_1.jsx)(SwapDetailsPage_1.SwapDetailsPage, {}),
65
- },
69
+ })),
66
70
  ...[
67
71
  utils_1.navigationRoutes.selectWallet,
68
72
  `${utils_1.navigationRoutes.swapExecution}/${utils_1.navigationRoutes.selectWallet}`,
@@ -11,9 +11,11 @@ exports.BottomSheet = (0, react_1.forwardRef)(({ elementRef, children, open }, r
11
11
  const containerElement = (0, hooks_1.useScrollableContainer)();
12
12
  const openDrawer = (0, react_1.useCallback)(() => {
13
13
  setDrawerOpen(true);
14
+ openRef.current = true;
14
15
  }, []);
15
16
  const closeDrawer = (0, react_1.useCallback)(() => {
16
17
  setDrawerOpen(false);
18
+ openRef.current = false;
17
19
  }, []);
18
20
  (0, react_1.useImperativeHandle)(ref, () => ({
19
21
  isOpen: () => openRef.current,
@@ -25,7 +25,7 @@ const ChainSelect = ({ formType }) => {
25
25
  const chainsToHide = ((_a = chains === null || chains === void 0 ? void 0 : chains.length) !== null && _a !== void 0 ? _a : 0) - stores_1.maxChainToOrder;
26
26
  return ((0, jsx_runtime_1.jsxs)(ChainSelect_style_1.ChainContainer, { children: [isLoading
27
27
  ? Array.from({ length: stores_1.maxChainToOrder + 1 }).map((_, index) => ((0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "rectangular", width: 56, height: 56, sx: { borderRadius: 1 } }, index)))
28
- : getChains().map((chain) => ((0, jsx_runtime_1.jsx)(ChainSelect_style_1.ChainCard, Object.assign({ onClick: () => setCurrentChain(chain.id), variant: chainId === chain.id ? 'selected' : 'default' }, { children: (0, jsx_runtime_1.jsx)(material_1.Avatar, Object.assign({ src: chain.logoURI, alt: chain.key, sx: { width: 40, height: 40 } }, { children: chain.name[0] })) }), chain.id))), chainsToHide > 0 ? ((0, jsx_runtime_1.jsx)(ChainSelect_style_1.ChainCard, Object.assign({ onClick: showAllChains }, { children: (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ sx: {
28
+ : getChains().map((chain) => ((0, jsx_runtime_1.jsx)(material_1.Tooltip, Object.assign({ title: chain.name, placement: "top", enterDelay: 500, enterNextDelay: 500, arrow: true }, { children: (0, jsx_runtime_1.jsx)(ChainSelect_style_1.ChainCard, Object.assign({ onClick: () => setCurrentChain(chain.id), variant: chainId === chain.id ? 'selected' : 'default' }, { children: (0, jsx_runtime_1.jsx)(material_1.Avatar, Object.assign({ src: chain.logoURI, alt: chain.key, sx: { width: 40, height: 40 } }, { children: chain.name[0] })) })) }), chain.id))), chainsToHide > 0 ? ((0, jsx_runtime_1.jsx)(ChainSelect_style_1.ChainCard, Object.assign({ onClick: showAllChains }, { children: (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ sx: {
29
29
  width: 40,
30
30
  height: 40,
31
31
  display: 'grid',
@@ -21,9 +21,7 @@ const Header_style_1 = require("./Header.style");
21
21
  const WalletHeader = () => {
22
22
  const { t } = (0, react_i18next_1.useTranslation)();
23
23
  const { account, disconnect } = (0, providers_1.useWallet)();
24
- const walletAddress = account.address
25
- ? `${account.address.substring(0, 7)}...${account.address.substring(account.address.length - 7)}`
26
- : null;
24
+ const walletAddress = (0, utils_1.shortenWalletAddress)(account.address);
27
25
  return ((0, jsx_runtime_1.jsx)(Header_style_1.HeaderAppBar, Object.assign({ elevation: 0 }, { children: walletAddress ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ sx: {
28
26
  display: 'flex',
29
27
  flex: 1,
@@ -45,5 +45,5 @@ exports.SendToWallet = (0, react_1.forwardRef)((props, ref) => {
45
45
  }),
46
46
  onBlur: () => trigger(providers_1.SwapFormKey.ToAddress),
47
47
  });
48
- return ((0, jsx_runtime_1.jsx)(material_1.Collapse, Object.assign({ timeout: 225, in: showSendToWallet }, { children: (0, jsx_runtime_1.jsxs)(Card_1.Card, Object.assign({}, props, { ref: ref }, { children: [(0, jsx_runtime_1.jsx)(Card_1.CardTitle, { children: t('swap.sendToWallet') }), (0, jsx_runtime_1.jsxs)(SendToWallet_style_1.FormControl, Object.assign({ fullWidth: true, sx: { paddingTop: '6px', paddingBottom: '5px' } }, { children: [(0, jsx_runtime_1.jsx)(SendToWallet_style_1.Input, { ref: inputRef, size: "small", autoComplete: "off", autoCorrect: "off", autoCapitalize: "off", spellCheck: "false", onChange: onChange, onBlur: onBlur, name: name, placeholder: t('swap.walletAddressOrEns') }), (0, jsx_runtime_1.jsx)(material_1.FormHelperText, Object.assign({ error: !!errors.toAddress }, { children: (_a = errors.toAddress) === null || _a === void 0 ? void 0 : _a.message }))] }))] })) })));
48
+ return ((0, jsx_runtime_1.jsx)(material_1.Collapse, Object.assign({ timeout: 225, unmountOnExit: true, mountOnEnter: true, in: showSendToWallet }, { children: (0, jsx_runtime_1.jsxs)(Card_1.Card, Object.assign({}, props, { ref: ref }, { children: [(0, jsx_runtime_1.jsx)(Card_1.CardTitle, { children: t('swap.sendToWallet') }), (0, jsx_runtime_1.jsxs)(SendToWallet_style_1.FormControl, Object.assign({ fullWidth: true, sx: { paddingTop: '6px', paddingBottom: '5px' } }, { children: [(0, jsx_runtime_1.jsx)(SendToWallet_style_1.Input, { ref: inputRef, size: "small", autoComplete: "off", autoCorrect: "off", autoCapitalize: "off", spellCheck: "false", onChange: onChange, onBlur: onBlur, name: name, placeholder: t('swap.walletAddressOrEns'), autoFocus: true }), (0, jsx_runtime_1.jsx)(material_1.FormHelperText, Object.assign({ error: !!errors.toAddress }, { children: (_a = errors.toAddress) === null || _a === void 0 ? void 0 : _a.message }))] }))] })) })));
49
49
  });
@@ -4,6 +4,7 @@ exports.SendToWalletButton = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const icons_material_1 = require("@mui/icons-material");
6
6
  const material_1 = require("@mui/material");
7
+ const react_hook_form_1 = require("react-hook-form");
7
8
  const react_i18next_1 = require("react-i18next");
8
9
  const providers_1 = require("../../providers");
9
10
  const stores_1 = require("../../stores");
@@ -11,12 +12,19 @@ const store_1 = require("./store");
11
12
  const SendToWalletButton = () => {
12
13
  const { t } = (0, react_i18next_1.useTranslation)();
13
14
  const { account } = (0, providers_1.useWallet)();
15
+ const { setValue } = (0, react_hook_form_1.useFormContext)();
14
16
  const { showDestinationWallet } = (0, stores_1.useSettings)(['showDestinationWallet']);
15
17
  const { showSendToWallet, toggleSendToWallet } = (0, store_1.useSendToWalletStore)();
16
18
  if (!showDestinationWallet || !account.isActive) {
17
19
  return null;
18
20
  }
19
- return ((0, jsx_runtime_1.jsx)(material_1.Tooltip, Object.assign({ title: t('swap.sendToWallet'), placement: "bottom-end", enterDelay: 500, enterNextDelay: 500, arrow: true }, { children: (0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ variant: showSendToWallet ? 'contained' : 'text', onClick: toggleSendToWallet, sx: {
21
+ const handleClick = () => {
22
+ if (showSendToWallet) {
23
+ setValue(providers_1.SwapFormKey.ToAddress, '');
24
+ }
25
+ toggleSendToWallet();
26
+ };
27
+ return ((0, jsx_runtime_1.jsx)(material_1.Tooltip, Object.assign({ title: t('swap.sendToWallet'), placement: "bottom-end", enterDelay: 500, enterNextDelay: 500, arrow: true }, { children: (0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ variant: showSendToWallet ? 'contained' : 'text', onClick: handleClick, sx: {
20
28
  minWidth: 48,
21
29
  marginLeft: 1,
22
30
  } }, { children: (0, jsx_runtime_1.jsx)(icons_material_1.WalletOutlined, {}) })) })));
@@ -17,7 +17,7 @@ const FormPriceHelperText = ({ formType, selected }) => {
17
17
  providers_1.SwapFormKeyHelper.getTokenKey(formType),
18
18
  ],
19
19
  });
20
- const { token, isLoading } = (0, hooks_1.useTokenBalance)(chainId, tokenAddress);
20
+ const { token, isLoading } = (0, hooks_1.useTokenAddressBalance)(chainId, tokenAddress);
21
21
  const fromAmountTokenPrice = (0, utils_1.formatTokenPrice)(amount, token === null || token === void 0 ? void 0 : token.priceUSD);
22
22
  return ((0, jsx_runtime_1.jsxs)(material_1.FormHelperText, Object.assign({ component: "div", sx: { display: 'flex', justifyContent: 'space-between', margin: 0 } }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ color: fromAmountTokenPrice ? 'text.secondary' : 'grey.600', fontWeight: 400, fontSize: 12, marginLeft: selected ? 8 : 2, lineHeight: 1.3334, flex: 1, sx: {
23
23
  wordBreak: 'break-word',
@@ -17,7 +17,7 @@ const SwapInputAdornment = ({ formType }) => {
17
17
  providers_1.SwapFormKeyHelper.getTokenKey(formType),
18
18
  ],
19
19
  });
20
- const { token, isLoading } = (0, hooks_1.useTokenBalance)(chainId, tokenAddress);
20
+ const { token, isLoading } = (0, hooks_1.useTokenAddressBalance)(chainId, tokenAddress);
21
21
  const handleMax = () => {
22
22
  var _a;
23
23
  setValue(providers_1.SwapFormKeyHelper.getAmountKey(formType), (_a = token === null || token === void 0 ? void 0 : token.amount) !== null && _a !== void 0 ? _a : '');
@@ -23,18 +23,18 @@ const Token_1 = require("../Token");
23
23
  const SwapRouteCard_style_1 = require("./SwapRouteCard.style");
24
24
  const SwapRouteCard = (_a) => {
25
25
  var _b;
26
- var { route, active, variant = 'default' } = _a, other = __rest(_a, ["route", "active", "variant"]);
26
+ var { route, active, variant = 'default', expanded } = _a, other = __rest(_a, ["route", "active", "variant", "expanded"]);
27
27
  const { t } = (0, react_i18next_1.useTranslation)();
28
- const [expanded, setExpanded] = (0, react_1.useState)(variant === 'default');
28
+ const [cardExpanded, setCardExpanded] = (0, react_1.useState)(variant === 'default' || expanded);
29
29
  const alternativeTag = t(`swap.tags.ALTERNATIVE`);
30
30
  const label = ((_b = route.tags) === null || _b === void 0 ? void 0 : _b.length)
31
31
  ? t(`swap.tags.${route.tags[0]}`)
32
32
  : alternativeTag;
33
33
  const handleExpand = (e) => {
34
34
  e.stopPropagation();
35
- setExpanded((expanded) => !expanded);
35
+ setCardExpanded((expanded) => !expanded);
36
36
  };
37
- return ((0, jsx_runtime_1.jsxs)(Card_1.Card, Object.assign({ dense: variant === 'dense', variant: active ? 'selected' : 'default', selectionColor: "secondary", indented: true }, other, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", justifyContent: "space-between", alignItems: "center", mb: 2 }, { children: [(0, jsx_runtime_1.jsx)(SwapRouteCard_style_1.Label, Object.assign({ active: active !== null && active !== void 0 ? active : label !== alternativeTag }, { children: label })), variant === 'extended' ? ((0, jsx_runtime_1.jsx)(exports.SwapRouteCardEssentials, { route: route })) : null] })), (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", justifyContent: "space-between", alignItems: "center" }, { children: [(0, jsx_runtime_1.jsx)(Token_1.Token, { token: Object.assign(Object.assign({}, route.toToken), { amount: route.toAmount }), step: variant === 'extended' ? route.steps[0] : undefined }), variant === 'extended' ? ((0, jsx_runtime_1.jsx)(SwapRouteCard_style_1.IconButton, Object.assign({ onClick: handleExpand, size: "small" }, { children: expanded ? (0, jsx_runtime_1.jsx)(icons_material_1.ExpandLess, {}) : (0, jsx_runtime_1.jsx)(icons_material_1.ExpandMore, {}) }))) : null] })), (0, jsx_runtime_1.jsx)(material_1.Collapse, Object.assign({ mountOnEnter: true, unmountOnExit: true, in: expanded }, { children: route.steps.map((step) => ((0, jsx_runtime_1.jsx)(StepActions_1.StepActions, { step: step, mt: 2 }, step.id))) })), variant !== 'extended' ? ((0, jsx_runtime_1.jsx)(exports.SwapRouteCardEssentials, { route: route, dense: true })) : null] })));
37
+ return ((0, jsx_runtime_1.jsxs)(Card_1.Card, Object.assign({ dense: variant === 'dense', variant: active ? 'selected' : 'default', selectionColor: "secondary", indented: true }, other, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", justifyContent: "space-between", alignItems: "center", mb: 2 }, { children: [(0, jsx_runtime_1.jsx)(SwapRouteCard_style_1.Label, Object.assign({ active: active !== null && active !== void 0 ? active : label !== alternativeTag }, { children: label })), variant === 'stretched' ? ((0, jsx_runtime_1.jsx)(exports.SwapRouteCardEssentials, { route: route })) : null] })), (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", justifyContent: "space-between", alignItems: "center" }, { children: [(0, jsx_runtime_1.jsx)(Token_1.Token, { token: Object.assign(Object.assign({}, route.toToken), { amount: route.toAmount }), step: variant === 'stretched' ? route.steps[0] : undefined }), variant === 'stretched' && !expanded ? ((0, jsx_runtime_1.jsx)(SwapRouteCard_style_1.IconButton, Object.assign({ onClick: handleExpand, size: "small" }, { children: cardExpanded ? (0, jsx_runtime_1.jsx)(icons_material_1.ExpandLess, {}) : (0, jsx_runtime_1.jsx)(icons_material_1.ExpandMore, {}) }))) : null] })), (0, jsx_runtime_1.jsx)(material_1.Collapse, Object.assign({ mountOnEnter: true, unmountOnExit: true, in: cardExpanded }, { children: route.steps.map((step) => ((0, jsx_runtime_1.jsx)(StepActions_1.StepActions, { step: step, mt: 2 }, step.id))) })), variant !== 'stretched' ? ((0, jsx_runtime_1.jsx)(exports.SwapRouteCardEssentials, { route: route, dense: true })) : null] })));
38
38
  };
39
39
  exports.SwapRouteCard = SwapRouteCard;
40
40
  const SwapRouteCardEssentials = ({ route, dense }) => {
@@ -17,6 +17,6 @@ const material_1 = require("@mui/material");
17
17
  const Card_1 = require("../Card");
18
18
  const SwapRouteCardSkeleton = (_a) => {
19
19
  var { variant } = _a, other = __rest(_a, ["variant"]);
20
- return ((0, jsx_runtime_1.jsxs)(Card_1.Card, Object.assign({ dense: variant === 'dense', indented: true }, other, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", justifyContent: "space-between", alignItems: "center" }, { children: [(0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "rectangular", width: 118, height: 24, sx: { borderRadius: 0.5 } }), variant === 'extended' ? ((0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex" }, { children: [(0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "text", width: 52, height: 24, sx: { marginRight: 2 } }), (0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "text", width: 44, height: 24, sx: { marginRight: 2 } }), (0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "text", width: 32, height: 24 })] }))) : null] })), (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ mt: 2 }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", alignItems: "center" }, { children: [(0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ mr: 2 }, { children: (0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "circular", width: 32, height: 32 }) })), (0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "text", width: 96, height: 32 })] })), (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ ml: 6, display: "flex", alignItems: "center" }, { children: [(0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "text", width: 102, height: 16, sx: { borderRadius: 0.5 } }), variant === 'extended' ? ((0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "text", width: 72, height: 16, sx: { marginLeft: 1 } })) : null] }))] })), variant !== 'extended' ? ((0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ mt: 2, display: "flex", justifyContent: "space-between" }, { children: [(0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "text", width: 48, height: 24 }), (0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "text", width: 48, height: 24 })] }))) : null] })));
20
+ return ((0, jsx_runtime_1.jsxs)(Card_1.Card, Object.assign({ dense: variant === 'dense', indented: true }, other, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", justifyContent: "space-between", alignItems: "center" }, { children: [(0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "rectangular", width: 118, height: 24, sx: { borderRadius: 0.5 } }), variant === 'stretched' ? ((0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex" }, { children: [(0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "text", width: 52, height: 24, sx: { marginRight: 2 } }), (0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "text", width: 44, height: 24, sx: { marginRight: 2 } }), (0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "text", width: 32, height: 24 })] }))) : null] })), (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ mt: 2 }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", alignItems: "center" }, { children: [(0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ mr: 2 }, { children: (0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "circular", width: 32, height: 32 }) })), (0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "text", width: 96, height: 32 })] })), (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ ml: 6, display: "flex", alignItems: "center" }, { children: [(0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "text", width: 102, height: 16, sx: { borderRadius: 0.5 } }), variant === 'stretched' ? ((0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "text", width: 72, height: 16, sx: { marginLeft: 1 } })) : null] }))] })), variant !== 'stretched' ? ((0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ mt: 2, display: "flex", justifyContent: "space-between" }, { children: [(0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "text", width: 48, height: 24 }), (0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "text", width: 48, height: 24 })] }))) : null] })));
21
21
  };
22
22
  exports.SwapRouteCardSkeleton = SwapRouteCardSkeleton;
@@ -1,13 +1,14 @@
1
1
  import type { Route } from '@lifi/sdk';
2
2
  export interface SwapRouteCardProps {
3
3
  route: Route;
4
- variant?: 'default' | 'extended' | 'dense';
4
+ variant?: 'default' | 'stretched' | 'dense';
5
5
  active?: boolean;
6
+ expanded?: boolean;
6
7
  }
7
8
  export interface SwapRouteCardEssentialsProps {
8
9
  route: Route;
9
10
  dense?: boolean;
10
11
  }
11
12
  export interface SwapRouteCardSkeletonProps {
12
- variant?: 'default' | 'extended' | 'dense';
13
+ variant?: 'default' | 'stretched' | 'dense';
13
14
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SwapRoutesExpanded = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const material_1 = require("@mui/material");
6
+ const react_hook_form_1 = require("react-hook-form");
6
7
  const react_i18next_1 = require("react-i18next");
7
8
  const react_router_dom_1 = require("react-router-dom");
8
9
  const hooks_1 = require("../../hooks");
@@ -17,6 +18,7 @@ const SwapRoutesExpanded = () => {
17
18
  const { containerStyle } = (0, providers_1.useWidgetConfig)();
18
19
  const navigate = (0, react_router_dom_1.useNavigate)();
19
20
  const { routes, isLoading, isFetching, isFetched, dataUpdatedAt, refetchTime, refetch, } = (0, hooks_1.useSwapRoutes)();
21
+ const { isValid, isValidating } = (0, react_hook_form_1.useFormState)();
20
22
  const setExecutableRoute = (0, stores_1.useSetExecutableRoute)();
21
23
  const { pathname } = (0, react_router_dom_1.useLocation)();
22
24
  const cleanedPathname = pathname.endsWith('/')
@@ -25,14 +27,16 @@ const SwapRoutesExpanded = () => {
25
27
  const path = cleanedPathname.substring(cleanedPathname.lastIndexOf('/') + 1);
26
28
  const hasPath = utils_1.navigationRoutesValues.includes(path);
27
29
  const handleRouteClick = (route) => {
28
- setExecutableRoute(route);
29
- navigate(utils_1.navigationRoutes.swapExecution, {
30
- state: { routeId: route.id },
31
- });
30
+ if (isValid && !isValidating) {
31
+ setExecutableRoute(route);
32
+ navigate(utils_1.navigationRoutes.swapExecution, {
33
+ state: { routeId: route.id },
34
+ });
35
+ }
32
36
  };
33
37
  const currentRoute = routes === null || routes === void 0 ? void 0 : routes[0];
34
38
  const expanded = Boolean(currentRoute || isLoading || isFetching || isFetched) && !hasPath;
35
39
  const routeNotFound = !currentRoute && !isLoading && !isFetching && expanded;
36
- return ((0, jsx_runtime_1.jsx)(SwapRoutes_style_1.CollapseContainer, { children: (0, jsx_runtime_1.jsx)(material_1.Collapse, Object.assign({ appear: true, timeout: 225, in: expanded, orientation: "horizontal" }, { children: (0, jsx_runtime_1.jsx)(material_1.Grow, Object.assign({ appear: true, timeout: 225, in: expanded }, { children: (0, jsx_runtime_1.jsx)(SwapRoutes_style_1.Container, Object.assign({ sx: containerStyle }, { children: (0, jsx_runtime_1.jsxs)(SwapRoutes_style_1.ScrollableContainer, { children: [(0, jsx_runtime_1.jsxs)(SwapRoutes_style_1.Header, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ fontSize: 18, fontWeight: "700", flex: 1, noWrap: true }, { children: t('swap.routes') })), (0, jsx_runtime_1.jsx)(ProgressToNextUpdate_1.ProgressToNextUpdate, { updatedAt: dataUpdatedAt || new Date().getTime(), timeToUpdate: refetchTime, isLoading: isFetching, onClick: () => refetch(), sx: { marginRight: -1 } })] }), (0, jsx_runtime_1.jsx)(material_1.Stack, Object.assign({ direction: "column", spacing: 2, flex: 1, paddingX: 3, paddingBottom: 3 }, { children: routeNotFound ? ((0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteNotFoundCard, {})) : isLoading || isFetching ? (Array.from({ length: 3 }).map((_, index) => ((0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteCardSkeleton, { variant: "extended" }, index)))) : (routes === null || routes === void 0 ? void 0 : routes.map((route, index) => ((0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteCard, { route: route, onClick: () => handleRouteClick(route), active: index === 0, variant: "extended" }, route.id)))) }))] }) })) })) })) }));
40
+ return ((0, jsx_runtime_1.jsx)(SwapRoutes_style_1.CollapseContainer, { children: (0, jsx_runtime_1.jsx)(material_1.Collapse, Object.assign({ appear: true, timeout: 225, in: expanded, orientation: "horizontal" }, { children: (0, jsx_runtime_1.jsx)(material_1.Grow, Object.assign({ appear: true, timeout: 225, in: expanded }, { children: (0, jsx_runtime_1.jsx)(SwapRoutes_style_1.Container, Object.assign({ sx: containerStyle }, { children: (0, jsx_runtime_1.jsxs)(SwapRoutes_style_1.ScrollableContainer, { children: [(0, jsx_runtime_1.jsxs)(SwapRoutes_style_1.Header, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ fontSize: 18, fontWeight: "700", flex: 1, noWrap: true }, { children: t('swap.routes') })), (0, jsx_runtime_1.jsx)(ProgressToNextUpdate_1.ProgressToNextUpdate, { updatedAt: dataUpdatedAt || new Date().getTime(), timeToUpdate: refetchTime, isLoading: isFetching, onClick: () => refetch(), sx: { marginRight: -1 } })] }), (0, jsx_runtime_1.jsx)(material_1.Stack, Object.assign({ direction: "column", spacing: 2, flex: 1, paddingX: 3, paddingBottom: 3 }, { children: routeNotFound ? ((0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteNotFoundCard, {})) : isLoading || isFetching ? (Array.from({ length: 3 }).map((_, index) => ((0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteCardSkeleton, { variant: "stretched" }, index)))) : (routes === null || routes === void 0 ? void 0 : routes.map((route, index) => ((0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteCard, { route: route, onClick: () => handleRouteClick(route), active: index === 0, variant: "stretched", expanded: (routes === null || routes === void 0 ? void 0 : routes.length) <= 2 }, route.id)))) }))] }) })) })) })) }));
37
41
  };
38
42
  exports.SwapRoutesExpanded = SwapRoutesExpanded;
@@ -1,2 +1,2 @@
1
1
  export declare const name = "@lifi/widget";
2
- export declare const version = "1.18.1";
2
+ export declare const version = "1.18.3";
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = exports.name = void 0;
4
4
  exports.name = '@lifi/widget';
5
- exports.version = '1.18.1';
5
+ exports.version = '1.18.3';
@@ -1,6 +1,5 @@
1
1
  export * from './useChain';
2
2
  export * from './useChains';
3
- export * from './useContentHeight';
4
3
  export * from './useDebouncedWatch';
5
4
  export * from './useFeaturedTokens';
6
5
  export * from './useGasSufficiency';
@@ -12,6 +11,7 @@ export * from './useScrollableContainer';
12
11
  export * from './useSwapRoutes';
13
12
  export * from './useTelemetry';
14
13
  export * from './useToken';
14
+ export * from './useTokenAddressBalance';
15
15
  export * from './useTokenBalance';
16
16
  export * from './useTokenBalances';
17
17
  export * from './useTokens';
@@ -16,7 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./useChain"), exports);
18
18
  __exportStar(require("./useChains"), exports);
19
- __exportStar(require("./useContentHeight"), exports);
20
19
  __exportStar(require("./useDebouncedWatch"), exports);
21
20
  __exportStar(require("./useFeaturedTokens"), exports);
22
21
  __exportStar(require("./useGasSufficiency"), exports);
@@ -28,6 +27,7 @@ __exportStar(require("./useScrollableContainer"), exports);
28
27
  __exportStar(require("./useSwapRoutes"), exports);
29
28
  __exportStar(require("./useTelemetry"), exports);
30
29
  __exportStar(require("./useToken"), exports);
30
+ __exportStar(require("./useTokenAddressBalance"), exports);
31
31
  __exportStar(require("./useTokenBalance"), exports);
32
32
  __exportStar(require("./useTokenBalances"), exports);
33
33
  __exportStar(require("./useTokens"), exports);
@@ -14,16 +14,15 @@ const big_js_1 = require("big.js");
14
14
  const react_1 = require("react");
15
15
  const _1 = require(".");
16
16
  const providers_1 = require("../providers");
17
- const useTokenBalances_1 = require("./useTokenBalances");
17
+ const useTokenBalance_1 = require("./useTokenBalance");
18
18
  const useGasSufficiency = (route) => {
19
- const lifi = (0, providers_1.useLiFi)();
20
19
  const { account } = (0, providers_1.useWallet)();
21
20
  const { getChainById } = (0, _1.useChains)();
22
- const { tokensWithBalance: fromChainTokenBalances } = (0, useTokenBalances_1.useTokenBalances)(route === null || route === void 0 ? void 0 : route.fromChainId);
21
+ const { token: fromToken, getTokenBalancesWithRetry } = (0, useTokenBalance_1.useTokenBalance)(route === null || route === void 0 ? void 0 : route.fromToken);
23
22
  const [insufficientGas, setInsufficientGas] = (0, react_1.useState)();
24
23
  const checkInsufficientGas = (0, react_1.useCallback)(() => __awaiter(void 0, void 0, void 0, function* () {
25
24
  var _a, _b;
26
- if (!account.isActive || !route) {
25
+ if (!account.address || !route) {
27
26
  setInsufficientGas(undefined);
28
27
  return;
29
28
  }
@@ -50,7 +49,7 @@ const useGasSufficiency = (route) => {
50
49
  if (route.fromToken.address === ((_a = gasCosts[route.fromChainId]) === null || _a === void 0 ? void 0 : _a.token.address)) {
51
50
  gasCosts[route.fromChainId].tokenAmount = (_b = gasCosts[route.fromChainId]) === null || _b === void 0 ? void 0 : _b.gasAmount.plus((0, big_js_1.default)(route.fromAmount).div(Math.pow(10, route.fromToken.decimals)));
52
51
  }
53
- const tokenBalances = yield lifi.getTokenBalances(account.address, Object.values(gasCosts).map((item) => item.token));
52
+ const tokenBalances = yield getTokenBalancesWithRetry(account.address, Object.values(gasCosts).map((item) => item.token));
54
53
  if (!(tokenBalances === null || tokenBalances === void 0 ? void 0 : tokenBalances.length)) {
55
54
  setInsufficientGas(undefined);
56
55
  return;
@@ -66,22 +65,22 @@ const useGasSufficiency = (route) => {
66
65
  const insufficientFromChainGasAmount = insufficientFromChainGas
67
66
  ? (_f = (_e = gasCosts[chainId].tokenAmount) === null || _e === void 0 ? void 0 : _e.minus(gasTokenBalance)) !== null && _f !== void 0 ? _f : gasCosts[chainId].gasAmount.minus(gasTokenBalance)
68
67
  : undefined;
69
- gasCosts[chainId] = Object.assign(Object.assign({}, gasCosts[chainId]), { insufficient: insufficientFromChainGas, insufficientAmount: insufficientFromChainGasAmount });
68
+ gasCosts[chainId] = Object.assign(Object.assign({}, gasCosts[chainId]), { insufficient: insufficientFromChainGas, insufficientAmount: insufficientFromChainGasAmount === null || insufficientFromChainGasAmount === void 0 ? void 0 : insufficientFromChainGasAmount.round(5, big_js_1.default.roundUp) });
70
69
  }
71
70
  });
72
71
  const gasCostResult = Object.values(gasCosts).filter((gasCost) => gasCost.insufficient);
73
72
  setInsufficientGas(gasCostResult);
74
- }), [account.address, account.isActive, getChainById, lifi, route]);
73
+ }), [account.address, getChainById, getTokenBalancesWithRetry, route]);
75
74
  const insufficientFunds = (0, react_1.useMemo)(() => {
76
- var _a, _b;
77
- if (!account.isActive || !fromChainTokenBalances || !route) {
75
+ var _a;
76
+ if (!account.isActive || !fromToken || !route) {
78
77
  return false;
79
78
  }
80
- const balance = (0, big_js_1.default)((_b = (_a = fromChainTokenBalances === null || fromChainTokenBalances === void 0 ? void 0 : fromChainTokenBalances.find((t) => t.address === (route === null || route === void 0 ? void 0 : route.fromToken.address))) === null || _a === void 0 ? void 0 : _a.amount) !== null && _b !== void 0 ? _b : 0);
79
+ const balance = (0, big_js_1.default)((_a = fromToken === null || fromToken === void 0 ? void 0 : fromToken.amount) !== null && _a !== void 0 ? _a : 0);
81
80
  return (0, big_js_1.default)(route.fromAmount)
82
81
  .div(Math.pow(10, route.fromToken.decimals))
83
82
  .gt(balance);
84
- }, [account.isActive, fromChainTokenBalances, route]);
83
+ }, [account.isActive, fromToken, route]);
85
84
  (0, react_1.useEffect)(() => {
86
85
  checkInsufficientGas();
87
86
  }, [checkInsufficientGas]);
@@ -1,2 +1 @@
1
1
  export declare const useScrollableContainer: () => HTMLElement | null;
2
- export declare const useScrollableOverflowHidden: () => void;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useScrollableOverflowHidden = exports.useScrollableContainer = void 0;
3
+ exports.useScrollableContainer = void 0;
4
4
  const react_1 = require("react");
5
5
  const utils_1 = require("../utils");
6
6
  const useScrollableContainer = () => {
@@ -13,17 +13,3 @@ const useScrollableContainer = () => {
13
13
  return containerElement;
14
14
  };
15
15
  exports.useScrollableContainer = useScrollableContainer;
16
- const useScrollableOverflowHidden = () => {
17
- (0, react_1.useLayoutEffect)(() => {
18
- const element = document.getElementById(utils_1.ElementId.ScrollableContainer);
19
- if (element) {
20
- element.style.overflowY = 'hidden';
21
- }
22
- return () => {
23
- if (element) {
24
- element.style.overflowY = 'auto';
25
- }
26
- };
27
- }, []);
28
- };
29
- exports.useScrollableOverflowHidden = useScrollableOverflowHidden;
@@ -0,0 +1,5 @@
1
+ export declare const useTokenAddressBalance: (chainId?: number, tokenAddress?: string) => {
2
+ token: import("..").Token | undefined;
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("..").Token[], unknown>>;
5
+ };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useTokenAddressBalance = void 0;
4
+ const react_1 = require("react");
5
+ const useTokenBalances_1 = require("./useTokenBalances");
6
+ const useTokenAddressBalance = (chainId, tokenAddress) => {
7
+ const { tokens, tokensWithBalance, isBalanceLoading, refetch } = (0, useTokenBalances_1.useTokenBalances)(chainId);
8
+ const token = (0, react_1.useMemo)(() => {
9
+ var _a;
10
+ const token = (_a = (tokensWithBalance !== null && tokensWithBalance !== void 0 ? tokensWithBalance : tokens)) === null || _a === void 0 ? void 0 : _a.find((token) => token.address === tokenAddress && token.chainId === chainId);
11
+ return token;
12
+ }, [chainId, tokenAddress, tokens, tokensWithBalance]);
13
+ return {
14
+ token,
15
+ isLoading: isBalanceLoading,
16
+ refetch,
17
+ };
18
+ };
19
+ exports.useTokenAddressBalance = useTokenAddressBalance;
@@ -1,5 +1,9 @@
1
- export declare const useTokenBalance: (chainId: number, tokenAddress: string) => {
2
- token: import("..").Token | undefined;
1
+ import type { Token, TokenAmount } from '@lifi/sdk';
2
+ export declare const useTokenBalance: (token?: Token, accountAddress?: string) => {
3
+ token: TokenAmount | undefined;
3
4
  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("..").Token[] | undefined, unknown>>;
5
+ refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<TokenAmount, unknown>>;
6
+ refetchNewBalance: () => void;
7
+ refetchAllBalances: () => void;
8
+ getTokenBalancesWithRetry: (accountAddress: string, tokens: Token[], depth?: number) => Promise<TokenAmount[] | undefined>;
5
9
  };
@@ -1,19 +1,97 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.useTokenBalance = void 0;
13
+ const react_query_1 = require("@tanstack/react-query");
4
14
  const react_1 = require("react");
5
- const useTokenBalances_1 = require("./useTokenBalances");
6
- const useTokenBalance = (chainId, tokenAddress) => {
7
- const { tokens, tokensWithBalance, isBalanceLoading, refetch } = (0, useTokenBalances_1.useTokenBalances)(chainId);
8
- const token = (0, react_1.useMemo)(() => {
15
+ const providers_1 = require("../providers");
16
+ const utils_1 = require("../utils");
17
+ const defaultRefetchInterval = 60000;
18
+ const useTokenBalance = (token, accountAddress) => {
19
+ const lifi = (0, providers_1.useLiFi)();
20
+ const { account } = (0, providers_1.useWallet)();
21
+ const queryClient = (0, react_query_1.useQueryClient)();
22
+ const walletAddress = accountAddress !== null && accountAddress !== void 0 ? accountAddress : account.address;
23
+ const getTokenBalancesWithRetry = (0, react_1.useCallback)((accountAddress, tokens, depth = 0) => __awaiter(void 0, void 0, void 0, function* () {
24
+ const tokenBalances = yield lifi.getTokenBalances(accountAddress, tokens);
25
+ if (!tokenBalances.every((token) => token.blockNumber)) {
26
+ if (depth > 5) {
27
+ console.warn('Token balance backoff depth exceeded.');
28
+ return undefined;
29
+ }
30
+ yield new Promise((resolve) => {
31
+ setTimeout(resolve, depth * 100);
32
+ });
33
+ return getTokenBalancesWithRetry(accountAddress, tokens, depth + 1);
34
+ }
35
+ return tokenBalances;
36
+ }), [lifi]);
37
+ const tokenBalanceQueryKey = (0, react_1.useMemo)(() => ['token-balance', walletAddress, token === null || token === void 0 ? void 0 : token.chainId, token === null || token === void 0 ? void 0 : token.address], [token === null || token === void 0 ? void 0 : token.address, token === null || token === void 0 ? void 0 : token.chainId, walletAddress]);
38
+ const { data, isLoading, refetch } = (0, react_query_1.useQuery)(tokenBalanceQueryKey, ({ queryKey: [, accountAddress] }) => __awaiter(void 0, void 0, void 0, function* () {
9
39
  var _a;
10
- const token = (_a = (tokensWithBalance !== null && tokensWithBalance !== void 0 ? tokensWithBalance : tokens)) === null || _a === void 0 ? void 0 : _a.find((token) => token.address === tokenAddress && token.chainId === chainId);
11
- return token;
12
- }, [chainId, tokenAddress, tokens, tokensWithBalance]);
40
+ const cachedToken = (_a = queryClient
41
+ .getQueryData([
42
+ 'token-balances',
43
+ accountAddress,
44
+ token.chainId,
45
+ ])) === null || _a === void 0 ? void 0 : _a.find((t) => t.address === token.address);
46
+ if (cachedToken) {
47
+ return cachedToken;
48
+ }
49
+ const tokenBalances = yield getTokenBalancesWithRetry(accountAddress, [token]);
50
+ if (!(tokenBalances === null || tokenBalances === void 0 ? void 0 : tokenBalances.length)) {
51
+ throw Error('Could not get tokens balance.');
52
+ }
53
+ const cachedTokenAmount = queryClient.getQueryData(tokenBalanceQueryKey);
54
+ const formattedAmount = (0, utils_1.formatTokenAmount)(tokenBalances[0].amount);
55
+ if ((cachedTokenAmount === null || cachedTokenAmount === void 0 ? void 0 : cachedTokenAmount.amount) !== formattedAmount) {
56
+ queryClient.setQueryDefaults(tokenBalanceQueryKey, {
57
+ refetchInterval: defaultRefetchInterval,
58
+ staleTime: defaultRefetchInterval,
59
+ });
60
+ }
61
+ queryClient.setQueryData(['token-balances', accountAddress, token.chainId], (data) => {
62
+ if (data) {
63
+ const index = data.findIndex((dataToken) => dataToken.address === token.address);
64
+ data[index] = Object.assign(Object.assign({}, data[index]), { amount: formattedAmount });
65
+ }
66
+ return data;
67
+ });
68
+ return Object.assign(Object.assign({}, tokenBalances[0]), { amount: formattedAmount });
69
+ }), {
70
+ enabled: Boolean(walletAddress && token),
71
+ refetchIntervalInBackground: true,
72
+ refetchInterval: defaultRefetchInterval,
73
+ staleTime: defaultRefetchInterval,
74
+ });
75
+ const refetchAllBalances = () => {
76
+ queryClient.refetchQueries([
77
+ 'token-balances',
78
+ token === null || token === void 0 ? void 0 : token.chainId,
79
+ accountAddress,
80
+ ]);
81
+ };
82
+ const refetchNewBalance = (0, react_1.useCallback)(() => {
83
+ queryClient.setQueryDefaults(tokenBalanceQueryKey, {
84
+ refetchInterval: 500,
85
+ staleTime: 500,
86
+ });
87
+ }, [queryClient, tokenBalanceQueryKey]);
13
88
  return {
14
- token,
15
- isLoading: isBalanceLoading,
89
+ token: data,
90
+ isLoading,
16
91
  refetch,
92
+ refetchNewBalance,
93
+ refetchAllBalances,
94
+ getTokenBalancesWithRetry,
17
95
  };
18
96
  };
19
97
  exports.useTokenBalance = useTokenBalance;
@@ -5,5 +5,5 @@ export declare const useTokenBalances: (selectedChainId?: number) => {
5
5
  featuredTokens: import("@lifi/types").Token[];
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<Token[] | undefined, unknown>>;
8
+ refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<Token[], unknown>>;
9
9
  };
@@ -29,9 +29,6 @@ const useTokenBalances = (selectedChainId) => {
29
29
  Boolean(tokens === null || tokens === void 0 ? void 0 : tokens.length) &&
30
30
  Boolean(selectedChainId);
31
31
  const { data: tokensWithBalance, isLoading: isBalanceLoading, refetch, } = (0, react_query_1.useQuery)(['token-balances', account.address, selectedChainId, tokens === null || tokens === void 0 ? void 0 : tokens.length], ({ queryKey: [, accountAddress] }) => __awaiter(void 0, void 0, void 0, function* () {
32
- if (!accountAddress || !tokens) {
33
- return;
34
- }
35
32
  const tokenBalances = yield lifi.getTokenBalances(accountAddress, tokens);
36
33
  if (!(tokenBalances === null || tokenBalances === void 0 ? void 0 : tokenBalances.length)) {
37
34
  // Sometimes RPCs (e.g. Arbitrum) don't return balances on first call
@@ -39,7 +36,7 @@ const useTokenBalances = (selectedChainId) => {
39
36
  setRefetchInterval((interval) => interval === defaultRefetchInterval
40
37
  ? minRefetchInterval
41
38
  : interval * 2);
42
- return;
39
+ throw Error('Could not get tokens balance.');
43
40
  }
44
41
  const featuredTokenAddresses = new Set(featuredTokens === null || featuredTokens === void 0 ? void 0 : featuredTokens.map((token) => token.address));
45
42
  const sortFn = (a, b) => {
@@ -78,7 +78,7 @@
78
78
  "fundsReceived": "Funds received"
79
79
  },
80
80
  "message": {
81
- "fundsReceived": "You now have {{amount}} {{tokenSymbol}} in your wallet on {{chainName}} chain."
81
+ "fundsReceived": "There are now {{amount}} {{tokenSymbol}} in wallet {{walletAddress}} on {{chainName}} chain."
82
82
  }
83
83
  },
84
84
  "info": {
@@ -3,22 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SelectTokenPage = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const material_1 = require("@mui/material");
6
- const react_1 = require("react");
7
6
  const ChainSelect_1 = require("../../components/ChainSelect");
8
7
  const TokenList_1 = require("../../components/TokenList");
9
8
  const hooks_1 = require("../../hooks");
10
9
  const SearchTokenInput_1 = require("./SearchTokenInput");
11
- const minTokenListHeight = 330;
12
10
  const SelectTokenPage = ({ formType }) => {
13
- (0, hooks_1.useScrollableOverflowHidden)();
14
11
  const { navigateBack } = (0, hooks_1.useNavigateBack)();
15
- const headerRef = (0, react_1.useRef)(null);
16
- const contentHeight = (0, hooks_1.useContentHeight)();
17
- const [tokenListHeight, setTokenListHeight] = (0, react_1.useState)(0);
18
- (0, react_1.useLayoutEffect)(() => {
19
- var _a, _b;
20
- setTokenListHeight(Math.max(contentHeight - ((_b = (_a = headerRef.current) === null || _a === void 0 ? void 0 : _a.offsetHeight) !== null && _b !== void 0 ? _b : 0), minTokenListHeight));
21
- }, [contentHeight]);
22
- return ((0, jsx_runtime_1.jsxs)(material_1.Container, Object.assign({ disableGutters: true }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ pt: 1, pb: 2, px: 3, ref: headerRef }, { children: [(0, jsx_runtime_1.jsx)(ChainSelect_1.ChainSelect, { formType: formType }), (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ mt: 2 }, { children: (0, jsx_runtime_1.jsx)(SearchTokenInput_1.SearchTokenInput, {}) }))] })), (0, jsx_runtime_1.jsx)(TokenList_1.TokenList, { height: tokenListHeight, onClick: navigateBack, formType: formType })] })));
12
+ return ((0, jsx_runtime_1.jsxs)(material_1.Container, Object.assign({ disableGutters: true }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ pt: 1, pb: 2, px: 3 }, { children: [(0, jsx_runtime_1.jsx)(ChainSelect_1.ChainSelect, { formType: formType }), (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ mt: 2 }, { children: (0, jsx_runtime_1.jsx)(SearchTokenInput_1.SearchTokenInput, {}) }))] })), (0, jsx_runtime_1.jsx)(TokenList_1.TokenList, { height: 360, onClick: navigateBack, formType: formType })] })));
23
13
  };
24
14
  exports.SelectTokenPage = SelectTokenPage;