@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
@@ -26,9 +26,6 @@ export const useTokenBalances = (selectedChainId) => {
26
26
  Boolean(tokens === null || tokens === void 0 ? void 0 : tokens.length) &&
27
27
  Boolean(selectedChainId);
28
28
  const { data: tokensWithBalance, isLoading: isBalanceLoading, refetch, } = 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* () {
29
- if (!accountAddress || !tokens) {
30
- return;
31
- }
32
29
  const tokenBalances = yield lifi.getTokenBalances(accountAddress, tokens);
33
30
  if (!(tokenBalances === null || tokenBalances === void 0 ? void 0 : tokenBalances.length)) {
34
31
  // Sometimes RPCs (e.g. Arbitrum) don't return balances on first call
@@ -36,7 +33,7 @@ export const useTokenBalances = (selectedChainId) => {
36
33
  setRefetchInterval((interval) => interval === defaultRefetchInterval
37
34
  ? minRefetchInterval
38
35
  : interval * 2);
39
- return;
36
+ throw Error('Could not get tokens balance.');
40
37
  }
41
38
  const featuredTokenAddresses = new Set(featuredTokens === null || featuredTokens === void 0 ? void 0 : featuredTokens.map((token) => token.address));
42
39
  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": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/widget",
3
- "version": "1.18.1",
3
+ "version": "1.18.3",
4
4
  "description": "LI.FI Widget for cross-chain bridging and swapping. It will drive your multi-chain strategy and attract new users from everywhere.",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./index.js",
@@ -45,12 +45,12 @@
45
45
  "@lifi/sdk": "^1.6.0",
46
46
  "@lifi/wallet-management": "^1.1.10",
47
47
  "@mui/icons-material": "^5.10.6",
48
- "@mui/lab": "^5.0.0-alpha.100",
49
- "@mui/material": "^5.10.6",
48
+ "@mui/lab": "^5.0.0-alpha.101",
49
+ "@mui/material": "^5.10.7",
50
50
  "@sentry/integrations": "^7.13.0",
51
51
  "@sentry/react": "^7.13.0",
52
52
  "@sentry/tracing": "^7.13.0",
53
- "@tanstack/react-query": "^4.3.9",
53
+ "@tanstack/react-query": "^4.6.1",
54
54
  "@tanstack/react-virtual": "^3.0.0-beta.18",
55
55
  "big.js": "^6.2.1",
56
56
  "i18next": "^21.9.2",
@@ -59,7 +59,7 @@
59
59
  "mitt": "^3.0.0",
60
60
  "react": "^18.2.0",
61
61
  "react-dom": "^18.2.0",
62
- "react-hook-form": "^7.36.0",
62
+ "react-hook-form": "^7.36.1",
63
63
  "react-i18next": "^11.18.6",
64
64
  "react-router-dom": "^6.4.1",
65
65
  "react-timer-hook": "^3.0.5",
@@ -1,20 +1,10 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Box, Container } from '@mui/material';
3
- import { useLayoutEffect, useRef, useState } from 'react';
4
3
  import { ChainSelect } from '../../components/ChainSelect';
5
4
  import { TokenList } from '../../components/TokenList';
6
- import { useContentHeight, useNavigateBack, useScrollableOverflowHidden, } from '../../hooks';
5
+ import { useNavigateBack } from '../../hooks';
7
6
  import { SearchTokenInput } from './SearchTokenInput';
8
- const minTokenListHeight = 330;
9
7
  export const SelectTokenPage = ({ formType }) => {
10
- useScrollableOverflowHidden();
11
8
  const { navigateBack } = useNavigateBack();
12
- const headerRef = useRef(null);
13
- const contentHeight = useContentHeight();
14
- const [tokenListHeight, setTokenListHeight] = useState(0);
15
- useLayoutEffect(() => {
16
- var _a, _b;
17
- setTokenListHeight(Math.max(contentHeight - ((_b = (_a = headerRef.current) === null || _a === void 0 ? void 0 : _a.offsetHeight) !== null && _b !== void 0 ? _b : 0), minTokenListHeight));
18
- }, [contentHeight]);
19
- return (_jsxs(Container, Object.assign({ disableGutters: true }, { children: [_jsxs(Box, Object.assign({ pt: 1, pb: 2, px: 3, ref: headerRef }, { children: [_jsx(ChainSelect, { formType: formType }), _jsx(Box, Object.assign({ mt: 2 }, { children: _jsx(SearchTokenInput, {}) }))] })), _jsx(TokenList, { height: tokenListHeight, onClick: navigateBack, formType: formType })] })));
9
+ return (_jsxs(Container, Object.assign({ disableGutters: true }, { children: [_jsxs(Box, Object.assign({ pt: 1, pb: 2, px: 3 }, { children: [_jsx(ChainSelect, { formType: formType }), _jsx(Box, Object.assign({ mt: 2 }, { children: _jsx(SearchTokenInput, {}) }))] })), _jsx(TokenList, { height: 360, onClick: navigateBack, formType: formType })] })));
20
10
  };
@@ -1,4 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /* eslint-disable consistent-return */
2
3
  import { Done as DoneIcon, Info as InfoIcon, Warning as WarningIcon, } from '@mui/icons-material';
3
4
  import { Box, Button, Typography } from '@mui/material';
4
5
  import { useEffect, useRef } from 'react';
@@ -8,17 +9,18 @@ import { BottomSheet } from '../../components/BottomSheet';
8
9
  import { Token } from '../../components/Token';
9
10
  import { getProcessMessage, useChains, useNavigateBack, useTokenBalance, } from '../../hooks';
10
11
  import { SwapFormKey } from '../../providers';
12
+ import { navigationRoutes, shortenWalletAddress } from '../../utils';
11
13
  import { IconCircle, IconContainer, iconStyles, } from './StatusBottomSheet.style';
12
14
  export const StatusBottomSheet = ({ status, route, }) => {
13
15
  var _a, _b, _c, _d, _e, _f, _g;
14
16
  const { t } = useTranslation();
15
- const { navigateBack } = useNavigateBack();
17
+ const { navigateBack, navigate } = useNavigateBack();
16
18
  const ref = useRef(null);
17
19
  const { getChainById } = useChains();
18
- const { token, refetch: refetchBalance } = useTokenBalance(route.toChainId, route.toToken.address);
20
+ const { token, refetch, refetchNewBalance, refetchAllBalances } = useTokenBalance(route.toToken, route.toAddress);
19
21
  const { setValue } = useFormContext();
20
22
  const clearFromAmount = () => {
21
- refetchBalance();
23
+ refetchAllBalances();
22
24
  setValue(SwapFormKey.FromAmount, '');
23
25
  };
24
26
  const handleDone = () => {
@@ -30,6 +32,13 @@ export const StatusBottomSheet = ({ status, route, }) => {
30
32
  clearFromAmount();
31
33
  (_a = ref.current) === null || _a === void 0 ? void 0 : _a.closeDrawer();
32
34
  };
35
+ const handleSeeDetails = () => {
36
+ handleClose();
37
+ navigate(navigationRoutes.swapDetails, {
38
+ state: { routeId: route.id },
39
+ replace: true,
40
+ });
41
+ };
33
42
  let title;
34
43
  let message;
35
44
  switch (status) {
@@ -39,6 +48,7 @@ export const StatusBottomSheet = ({ status, route, }) => {
39
48
  amount: token === null || token === void 0 ? void 0 : token.amount,
40
49
  tokenSymbol: token === null || token === void 0 ? void 0 : token.symbol,
41
50
  chainName: (_a = getChainById(route.toChainId)) === null || _a === void 0 ? void 0 : _a.name,
51
+ walletAddress: shortenWalletAddress(route.toAddress),
42
52
  });
43
53
  break;
44
54
  case 'error': {
@@ -59,9 +69,12 @@ export const StatusBottomSheet = ({ status, route, }) => {
59
69
  var _a, _b;
60
70
  if ((status === 'success' || status === 'error') &&
61
71
  !((_a = ref.current) === null || _a === void 0 ? void 0 : _a.isOpen())) {
62
- refetchBalance();
72
+ if (status === 'success') {
73
+ refetchNewBalance();
74
+ refetch();
75
+ }
63
76
  (_b = ref.current) === null || _b === void 0 ? void 0 : _b.openDrawer();
64
77
  }
65
- }, [refetchBalance, status]);
66
- return (_jsx(BottomSheet, Object.assign({ ref: ref }, { children: _jsxs(Box, Object.assign({ p: 3 }, { children: [_jsxs(IconContainer, { children: [_jsxs(IconCircle, Object.assign({ status: status, mb: 1 }, { children: [status === 'idle' ? (_jsx(InfoIcon, { color: "primary", sx: iconStyles })) : null, status === 'success' ? (_jsx(DoneIcon, { color: "success", sx: iconStyles })) : null, status === 'error' ? (_jsx(WarningIcon, { color: "error", sx: iconStyles })) : null] })), _jsx(Typography, Object.assign({ py: 1, fontSize: 18, fontWeight: 700 }, { children: title })), status === 'success' ? (_jsx(Token, { token: Object.assign(Object.assign({}, route.toToken), { amount: (_g = (_e = (_d = (_c = route.steps.at(-1)) === null || _c === void 0 ? void 0 : _c.execution) === null || _d === void 0 ? void 0 : _d.toAmount) !== null && _e !== void 0 ? _e : (_f = route.steps.at(-1)) === null || _f === void 0 ? void 0 : _f.estimate.toAmount) !== null && _g !== void 0 ? _g : route.toAmount }), py: 1 })) : null] }), _jsx(Typography, Object.assign({ pt: 2, pb: 1 }, { children: message })), _jsx(Box, Object.assign({ mt: 2 }, { children: _jsxs(Button, Object.assign({ variant: "contained", fullWidth: true, onClick: status === 'success' ? handleDone : handleClose }, { children: [status === 'idle' ? t('button.okay') : null, status === 'success' ? t('button.done') : null, status === 'error' ? t('button.tryAgain') : null] })) })), status === 'success' ? (_jsx(Box, Object.assign({ mt: 2 }, { children: _jsx(Button, Object.assign({ variant: "outlined", fullWidth: true, onClick: handleClose }, { children: t('button.seeDetails') })) }))) : null] })) })));
78
+ }, [refetch, refetchNewBalance, status]);
79
+ return (_jsx(BottomSheet, Object.assign({ ref: ref }, { children: _jsxs(Box, Object.assign({ p: 3 }, { children: [_jsxs(IconContainer, { children: [_jsxs(IconCircle, Object.assign({ status: status, mb: 1 }, { children: [status === 'idle' ? (_jsx(InfoIcon, { color: "primary", sx: iconStyles })) : null, status === 'success' ? (_jsx(DoneIcon, { color: "success", sx: iconStyles })) : null, status === 'error' ? (_jsx(WarningIcon, { color: "error", sx: iconStyles })) : null] })), _jsx(Typography, Object.assign({ py: 1, fontSize: 18, fontWeight: 700 }, { children: title })), status === 'success' ? (_jsx(Token, { token: Object.assign(Object.assign({}, route.toToken), { amount: (_g = (_e = (_d = (_c = route.steps.at(-1)) === null || _c === void 0 ? void 0 : _c.execution) === null || _d === void 0 ? void 0 : _d.toAmount) !== null && _e !== void 0 ? _e : (_f = route.steps.at(-1)) === null || _f === void 0 ? void 0 : _f.estimate.toAmount) !== null && _g !== void 0 ? _g : route.toAmount }), py: 1 })) : null] }), _jsx(Typography, Object.assign({ pt: 2, pb: 1 }, { children: message })), _jsx(Box, Object.assign({ mt: 2 }, { children: _jsxs(Button, Object.assign({ variant: "contained", fullWidth: true, onClick: status === 'success' ? handleDone : handleClose }, { children: [status === 'idle' ? t('button.okay') : null, status === 'success' ? t('button.done') : null, status === 'error' ? t('button.tryAgain') : null] })) })), status === 'success' ? (_jsx(Box, Object.assign({ mt: 2 }, { children: _jsx(Button, Object.assign({ variant: "outlined", fullWidth: true, onClick: handleSeeDetails }, { children: t('button.seeDetails') })) }))) : null] })) })));
67
80
  };