@lifi/widget 1.12.1 → 1.13.2

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 (68) hide show
  1. package/components/Initializer.js +1 -1
  2. package/components/LiFiLogo.js +1 -2
  3. package/components/PoweredBy/PoweredBy.js +3 -2
  4. package/components/StepActions/StepActions.js +1 -1
  5. package/components/SwapInput/FormPriceHelperText.js +2 -2
  6. package/components/SwapInput/SwapInputAdornment.js +2 -2
  7. package/components/SwapRouteCard/SwapRouteCard.style.js +1 -1
  8. package/components/TokenAvatar/TokenAvatar.js +3 -2
  9. package/components/TokenList/TokenList.js +25 -43
  10. package/components/TokenList/TokenList.style.js +5 -2
  11. package/components/TokenList/TokenListItem.d.ts +2 -2
  12. package/components/TokenList/TokenListItem.js +7 -10
  13. package/components/TokenList/TokenNotFound.d.ts +2 -0
  14. package/components/TokenList/TokenNotFound.js +15 -0
  15. package/components/TokenList/VirtualizedTokenList.d.ts +3 -0
  16. package/components/TokenList/VirtualizedTokenList.js +53 -0
  17. package/components/TokenList/types.d.ts +16 -1
  18. package/config/sentry.d.ts +1 -1
  19. package/config/sentry.js +36 -18
  20. package/config/version.d.ts +1 -1
  21. package/config/version.js +1 -1
  22. package/hooks/index.d.ts +3 -0
  23. package/hooks/index.js +3 -0
  24. package/hooks/useChains.d.ts +10 -10
  25. package/hooks/useFeaturedTokens.d.ts +1 -0
  26. package/hooks/useFeaturedTokens.js +6 -0
  27. package/hooks/useToken.d.ts +2 -1
  28. package/hooks/useToken.js +2 -1
  29. package/hooks/useTokenBalance.d.ts +2 -4
  30. package/hooks/useTokenBalance.js +11 -42
  31. package/hooks/useTokenBalances.d.ts +5 -4
  32. package/hooks/useTokenBalances.js +25 -13
  33. package/hooks/useTokenSearch.d.ts +7 -0
  34. package/hooks/useTokenSearch.js +37 -0
  35. package/hooks/useTokens.d.ts +2 -1
  36. package/hooks/useTokens.js +12 -4
  37. package/i18n/en/translation.json +2 -0
  38. package/i18n/index.d.ts +2 -0
  39. package/icons/LiFiFullLogo.d.ts +2 -0
  40. package/icons/LiFiFullLogo.js +2 -0
  41. package/icons/LiFiLogo.d.ts +2 -0
  42. package/icons/LiFiLogo.js +2 -0
  43. package/icons/LiFiToolLogo.d.ts +2 -0
  44. package/icons/LiFiToolLogo.js +2 -0
  45. package/icons/index.d.ts +3 -0
  46. package/icons/index.js +3 -0
  47. package/package.json +12 -13
  48. package/pages/SelectTokenPage/ChainSelect.js +8 -5
  49. package/pages/SelectTokenPage/SearchTokenInput.js +2 -2
  50. package/pages/SelectWalletPage/SelectWalletPage.js +1 -1
  51. package/pages/SwapPage/StatusBottomSheet.js +2 -2
  52. package/providers/SwapFormProvider/SwapFormProvider.d.ts +1 -1
  53. package/providers/SwapFormProvider/SwapFormProvider.js +28 -5
  54. package/providers/SwapFormProvider/types.d.ts +2 -3
  55. package/providers/SwapFormProvider/types.js +1 -2
  56. package/providers/WalletProvider/WalletProvider.d.ts +5 -0
  57. package/providers/WalletProvider/WalletProvider.js +12 -6
  58. package/providers/WidgetProvider/WidgetProvider.js +24 -15
  59. package/types/index.d.ts +1 -0
  60. package/types/index.js +1 -0
  61. package/types/token.d.ts +4 -0
  62. package/types/token.js +1 -0
  63. package/types/widget.d.ts +3 -2
  64. package/components/TokenList/utils.d.ts +0 -15
  65. package/components/TokenList/utils.js +0 -10
  66. package/icons/LiFiFullLogo.svg +0 -10
  67. package/icons/LiFiLogo.svg +0 -5
  68. package/icons/LiFiToolLogo.svg +0 -6
@@ -1,4 +1,4 @@
1
- import { useInitializer } from '../hooks/useInitializer';
1
+ import { useInitializer } from '../hooks';
2
2
  export const Initializer = () => {
3
3
  useInitializer();
4
4
  return null;
@@ -1,6 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { ReactComponent as LiFiFullLogo } from '../icons/LiFiFullLogo.svg';
3
- import { ReactComponent as LiFiIconLogo } from '../icons/LiFiLogo.svg';
2
+ import { LiFiFullLogo, LiFiLogo as LiFiIconLogo } from '../icons';
4
3
  export const LiFiLogo = ({ variant = 'icon', style }) => {
5
4
  const Component = variant === 'icon' ? LiFiIconLogo : LiFiFullLogo;
6
5
  return _jsx(Component, { style: style, fill: "currentColor", color: "currentColor" });
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Box, Typography } from '@mui/material';
2
+ import { Box, Tooltip, Typography } from '@mui/material';
3
+ import { version } from '../../config/version';
3
4
  import { LiFiLogo } from '../LiFiLogo';
4
5
  import { Link } from './PoweredBy.style';
5
6
  export const PoweredBy = () => {
@@ -7,5 +8,5 @@ export const PoweredBy = () => {
7
8
  display: 'flex',
8
9
  alignItems: 'flex-end',
9
10
  justifyContent: 'flex-end',
10
- } }, { children: _jsxs(Link, Object.assign({ href: "https://li.fi", target: "_blank", underline: "none", color: "text.primary" }, { children: [_jsx(Typography, Object.assign({ color: "text.secondary", fontSize: 12, px: 0.5 }, { children: "Powered by" })), _jsx(LiFiLogo, { variant: "full", style: { height: 16, width: 42 } })] })) })));
11
+ } }, { children: _jsx(Tooltip, Object.assign({ title: `v${version}`, placement: "top", enterDelay: 5000, arrow: true }, { children: _jsxs(Link, Object.assign({ href: "https://li.fi", target: "_blank", underline: "none", color: "text.primary" }, { children: [_jsx(Typography, Object.assign({ color: "text.secondary", fontSize: 12, px: 0.5 }, { children: "Powered by" })), _jsx(LiFiLogo, { variant: "full", style: { height: 16, width: 42 } })] })) })) })));
11
12
  };
@@ -14,7 +14,7 @@ import { ArrowForward as ArrowForwardIcon } from '@mui/icons-material';
14
14
  import { Box, Step as MuiStep, Stepper, Typography, } from '@mui/material';
15
15
  import { useTranslation } from 'react-i18next';
16
16
  import { useChains } from '../../hooks';
17
- import { ReactComponent as LiFiToolLogo } from '../../icons/LiFiToolLogo.svg';
17
+ import { LiFiToolLogo } from '../../icons';
18
18
  import { formatTokenAmount } from '../../utils';
19
19
  import { SmallAvatar } from '../SmallAvatar';
20
20
  import { StepAvatar, StepConnector, StepContent, StepLabel, } from './StepActions.style';
@@ -14,14 +14,14 @@ export const FormPriceHelperText = ({ formType, selected }) => {
14
14
  SwapFormKeyHelper.getTokenKey(formType),
15
15
  ],
16
16
  });
17
- const { token, isLoading, isFetching } = useTokenBalance(chainId, tokenAddress);
17
+ const { token, isLoading } = useTokenBalance(chainId, tokenAddress);
18
18
  const fromAmountTokenPrice = formatTokenPrice(amount, token === null || token === void 0 ? void 0 : token.priceUSD);
19
19
  return (_jsxs(FormHelperText, Object.assign({ component: "div", sx: { display: 'flex', justifyContent: 'space-between', margin: 0 } }, { children: [_jsx(Typography, Object.assign({ color: fromAmountTokenPrice ? 'text.secondary' : 'grey.600', fontWeight: 400, fontSize: 12, marginLeft: selected ? 8 : 2, lineHeight: 1.3334, flex: 1, sx: {
20
20
  wordBreak: 'break-word',
21
21
  overflowWrap: 'break-word',
22
22
  } }, { children: t(`swap.currency`, {
23
23
  value: fromAmountTokenPrice,
24
- }) })), isLoading && isFetching ? (_jsx(Skeleton, { variant: "text", width: 48, height: 16, sx: { borderRadius: 0.25 } })) : (token === null || token === void 0 ? void 0 : token.amount) ? (_jsx(Typography, Object.assign({ fontWeight: 400, fontSize: 12, color: "text.secondary", lineHeight: 1.3334, pl: 0.25 }, { children: t(`swap.maxAmount`, {
24
+ }) })), isLoading && tokenAddress ? (_jsx(Skeleton, { variant: "text", width: 48, height: 16, sx: { borderRadius: 0.25 } })) : (token === null || token === void 0 ? void 0 : token.amount) ? (_jsx(Typography, Object.assign({ fontWeight: 400, fontSize: 12, color: "text.secondary", lineHeight: 1.3334, pl: 0.25 }, { children: t(`swap.maxAmount`, {
25
25
  amount: token === null || token === void 0 ? void 0 : token.amount,
26
26
  }) }))) : null] })));
27
27
  };
@@ -14,10 +14,10 @@ export const SwapInputAdornment = ({ formType }) => {
14
14
  SwapFormKeyHelper.getTokenKey(formType),
15
15
  ],
16
16
  });
17
- const { token, isLoading, isFetching } = useTokenBalance(chainId, tokenAddress);
17
+ const { token, isLoading } = useTokenBalance(chainId, tokenAddress);
18
18
  const handleMax = () => {
19
19
  var _a;
20
20
  setValue(SwapFormKeyHelper.getAmountKey(formType), (_a = token === null || token === void 0 ? void 0 : token.amount) !== null && _a !== void 0 ? _a : '');
21
21
  };
22
- return (_jsx(InputAdornment, Object.assign({ position: "end" }, { children: isLoading && isFetching ? (_jsx(Skeleton, { variant: "rectangular", width: 46, height: 20, sx: { borderRadius: 0.5 } })) : formType === 'from' && (token === null || token === void 0 ? void 0 : token.amount) ? (_jsx(Button, Object.assign({ onClick: handleMax, variant: "outlined" }, { children: t('button.max') }))) : null })));
22
+ return (_jsx(InputAdornment, Object.assign({ position: "end" }, { children: isLoading && tokenAddress ? (_jsx(Skeleton, { variant: "rectangular", width: 46, height: 20, sx: { borderRadius: 0.5 } })) : formType === 'from' && (token === null || token === void 0 ? void 0 : token.amount) ? (_jsx(Button, Object.assign({ onClick: handleMax, variant: "outlined" }, { children: t('button.max') }))) : null })));
23
23
  };
@@ -1,6 +1,6 @@
1
- import { getContrastTextColor } from '@lifi/widget/utils';
2
1
  import { Typography } from '@mui/material';
3
2
  import { styled } from '@mui/material/styles';
3
+ import { getContrastTextColor } from '../../utils';
4
4
  export const Label = styled(Typography, {
5
5
  shouldForwardProp: (prop) => prop !== 'active',
6
6
  })(({ theme, active }) => ({
@@ -1,8 +1,9 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Avatar, Badge } from '@mui/material';
3
- import { useChain } from '../../hooks';
3
+ import { useChain, useToken } from '../../hooks';
4
4
  import { SmallAvatar } from '../SmallAvatar';
5
5
  export const TokenAvatar = ({ token, sx }) => {
6
6
  const { chain } = useChain(token.chainId);
7
- return (_jsx(Badge, Object.assign({ overlap: "circular", anchorOrigin: { vertical: 'bottom', horizontal: 'right' }, badgeContent: chain ? (_jsx(SmallAvatar, Object.assign({ src: chain.logoURI, alt: chain.name }, { children: chain.name[0] }))) : null, sx: sx }, { children: _jsx(Avatar, Object.assign({ src: token.logoURI, alt: token.symbol }, { children: token.symbol[0] })) })));
7
+ const { token: chainToken } = useToken(token.chainId, token.address);
8
+ return (_jsx(Badge, Object.assign({ overlap: "circular", anchorOrigin: { vertical: 'bottom', horizontal: 'right' }, badgeContent: chain ? (_jsx(SmallAvatar, Object.assign({ src: chain.logoURI, alt: chain.name }, { children: chain.name[0] }))) : null, sx: sx }, { children: _jsx(Avatar, Object.assign({ src: token.logoURI || (chainToken === null || chainToken === void 0 ? void 0 : chainToken.logoURI), alt: token.symbol }, { children: token.symbol[0] })) })));
8
9
  };
@@ -1,49 +1,37 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Box, List, Typography } from '@mui/material';
3
- import { useCallback, useEffect, useMemo, useRef } from 'react';
2
+ import { Box } from '@mui/material';
3
+ import { useCallback, useRef } from 'react';
4
4
  import { useFormContext, useWatch } from 'react-hook-form';
5
- import { useTranslation } from 'react-i18next';
6
- import { useVirtual } from 'react-virtual';
7
- import { useDebouncedWatch, useTokenBalances } from '../../hooks';
5
+ import { useDebouncedWatch, useTokenBalances, useTokenSearch, } from '../../hooks';
8
6
  import { SwapFormKey, SwapFormKeyHelper, } from '../../providers/SwapFormProvider';
9
7
  import { useWallet } from '../../providers/WalletProvider';
10
- import { TokenListItem, TokenListItemSkeleton } from './TokenListItem';
11
- import { createTokenAmountSkeletons, skeletonKey } from './utils';
8
+ import { TokenNotFound } from './TokenNotFound';
9
+ import { VirtualizedTokenList } from './VirtualizedTokenList';
12
10
  export const TokenList = ({ formType, height, onClick, }) => {
13
- const { t } = useTranslation();
11
+ var _a, _b;
12
+ const parentRef = useRef(null);
14
13
  const { account } = useWallet();
15
14
  const { setValue, getValues } = useFormContext();
16
15
  const [selectedChainId] = useWatch({
17
16
  name: [SwapFormKeyHelper.getChainKey(formType)],
18
17
  });
19
- const [searchTokensFilter] = useDebouncedWatch([SwapFormKey.SearchTokensFilter], 250);
20
- const { tokens: tokensWithoutBalance, tokensWithBalance, isLoading, isBalanceLoading, } = useTokenBalances(selectedChainId);
21
- const tokens = tokensWithBalance !== null && tokensWithBalance !== void 0 ? tokensWithBalance : tokensWithoutBalance;
22
- const chainTokens = useMemo(() => {
23
- var _a;
24
- let chainTokens = tokens !== null && tokens !== void 0 ? tokens : [];
25
- const searchFilter = (_a = searchTokensFilter === null || searchTokensFilter === void 0 ? void 0 : searchTokensFilter.toUpperCase()) !== null && _a !== void 0 ? _a : '';
26
- chainTokens = isLoading
27
- ? createTokenAmountSkeletons()
28
- : searchTokensFilter
29
- ? chainTokens.filter((token) => token.name.toUpperCase().includes(searchFilter) ||
30
- token.symbol.toUpperCase().includes(searchFilter) ||
31
- token.address.toUpperCase().includes(searchFilter))
32
- : chainTokens;
33
- return chainTokens;
34
- }, [isLoading, searchTokensFilter, tokens]);
35
- const parentRef = useRef(null);
36
- const { virtualItems, totalSize, scrollToIndex } = useVirtual({
37
- size: chainTokens.length,
38
- parentRef,
39
- overscan: 3,
40
- paddingEnd: 12,
41
- estimateSize: useCallback(() => 64, []),
42
- keyExtractor: (index) => { var _a; return (_a = chainTokens[index].address) !== null && _a !== void 0 ? _a : index; },
43
- });
44
- useEffect(() => {
45
- scrollToIndex(0);
46
- }, [scrollToIndex, selectedChainId]);
18
+ const [tokenSearchFilter] = useDebouncedWatch([SwapFormKey.TokenSearchFilter], 250);
19
+ const { tokens: chainTokens, tokensWithBalance, isLoading: isTokensLoading, isBalanceLoading, featuredTokens, } = useTokenBalances(selectedChainId);
20
+ let filteredTokens = ((_a = tokensWithBalance !== null && tokensWithBalance !== void 0 ? tokensWithBalance : chainTokens) !== null && _a !== void 0 ? _a : []);
21
+ const searchFilter = (_b = tokenSearchFilter === null || tokenSearchFilter === void 0 ? void 0 : tokenSearchFilter.toUpperCase()) !== null && _b !== void 0 ? _b : '';
22
+ filteredTokens = tokenSearchFilter
23
+ ? filteredTokens.filter((token) => token.name.toUpperCase().includes(searchFilter) ||
24
+ token.symbol.toUpperCase().includes(searchFilter) ||
25
+ token.address.toUpperCase().includes(searchFilter))
26
+ : filteredTokens;
27
+ const tokenSearchEnabled = !filteredTokens.length && !isTokensLoading;
28
+ const { token: searchedToken, isLoading: isSearchedTokenLoading } = useTokenSearch(tokenSearchFilter, selectedChainId, tokenSearchEnabled);
29
+ const isLoading = isTokensLoading || (tokenSearchEnabled && isSearchedTokenLoading);
30
+ const tokens = filteredTokens.length
31
+ ? filteredTokens
32
+ : searchedToken
33
+ ? [searchedToken]
34
+ : filteredTokens;
47
35
  const handleTokenClick = useCallback((tokenAddress) => {
48
36
  setValue(SwapFormKeyHelper.getTokenKey(formType), tokenAddress);
49
37
  setValue(SwapFormKeyHelper.getAmountKey(formType), '');
@@ -59,11 +47,5 @@ export const TokenList = ({ formType, height, onClick, }) => {
59
47
  }
60
48
  onClick === null || onClick === void 0 ? void 0 : onClick();
61
49
  }, [formType, getValues, onClick, setValue]);
62
- return (_jsxs(Box, Object.assign({ ref: parentRef, style: { height, overflow: 'auto' } }, { children: [!virtualItems.length ? (_jsx(Typography, Object.assign({ variant: "body1", align: "center", py: 2, px: 3 }, { children: t('swap.couldntFindTokens') }))) : null, _jsx(List, Object.assign({ style: { height: totalSize }, disablePadding: true }, { children: virtualItems.map((item) => {
63
- const token = chainTokens[item.index];
64
- if (token.name.includes(skeletonKey)) {
65
- return (_jsx(TokenListItemSkeleton, { size: item.size, start: item.start }, item.key));
66
- }
67
- return (_jsx(TokenListItem, { onClick: handleTokenClick, size: item.size, start: item.start, token: token, isBalanceLoading: isBalanceLoading, showBalance: account.isActive }, item.key));
68
- }) }))] })));
50
+ return (_jsxs(Box, Object.assign({ ref: parentRef, style: { height, overflow: 'auto' } }, { children: [!tokens.length && !isLoading ? _jsx(TokenNotFound, {}) : null, _jsx(VirtualizedTokenList, { tokens: tokens, featuredTokensLength: featuredTokens === null || featuredTokens === void 0 ? void 0 : featuredTokens.length, scrollElementRef: parentRef, chainId: selectedChainId, isLoading: isLoading, isBalanceLoading: isBalanceLoading, showBalance: account.isActive, showFeatured: !tokenSearchFilter, onClick: handleTokenClick })] })));
69
51
  };
@@ -6,6 +6,7 @@ export const ListItemButton = styled(MuiListItemButton)(({ theme }) => ({
6
6
  borderRadius: theme.shape.borderRadiusSecondary,
7
7
  paddingLeft: theme.spacing(2),
8
8
  height: 64,
9
+ width: '100%',
9
10
  '&:hover': {
10
11
  backgroundColor: getContrastAlphaColor(theme, '4%'),
11
12
  },
@@ -14,8 +15,10 @@ export const ListItem = styled(MuiListItem)(({ theme }) => ({
14
15
  position: 'absolute',
15
16
  top: 0,
16
17
  left: 0,
17
- width: '100%',
18
- padding: theme.spacing(0.5, 3),
18
+ height: 64,
19
+ flexDirection: 'column',
20
+ alignItems: 'flex-start',
21
+ padding: theme.spacing(0, 3),
19
22
  [`.${listItemSecondaryActionClasses.root}`]: {
20
23
  right: theme.spacing(5),
21
24
  },
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { TokenListItemBaseProps, TokenListItemProps } from './types';
2
+ import { TokenListItemProps } from './types';
3
3
  export declare const TokenListItem: React.FC<TokenListItemProps>;
4
- export declare const TokenListItemSkeleton: React.FC<TokenListItemBaseProps>;
4
+ export declare const TokenListItemSkeleton: () => JSX.Element;
5
5
  export declare const TokenAmountSkeleton: React.FC;
@@ -4,22 +4,19 @@ import { memo } from 'react';
4
4
  import { useTranslation } from 'react-i18next';
5
5
  import { formatTokenPrice } from '../../utils';
6
6
  import { ListItem, ListItemButton } from './TokenList.style';
7
- export const TokenListItem = memo(({ onClick, size, start, token, showBalance, isBalanceLoading }) => {
7
+ export const TokenListItem = memo(({ onClick, size, start, token, showBalance, isBalanceLoading, startAdornment, endAdornment, }) => {
8
8
  const { t } = useTranslation();
9
9
  const handleClick = () => onClick === null || onClick === void 0 ? void 0 : onClick(token.address);
10
10
  const tokenPrice = formatTokenPrice(token.amount, token.priceUSD);
11
- return (_jsx(ListItem, Object.assign({ disablePadding: true, style: {
11
+ return (_jsxs(ListItem, Object.assign({ disablePadding: true, style: {
12
12
  height: `${size}px`,
13
13
  transform: `translateY(${start}px)`,
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`, {
15
- value: tokenPrice,
16
- }) }))) : null] })))) : null] })) })));
14
+ } }, { children: [startAdornment, _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`, {
15
+ value: tokenPrice,
16
+ }) }))) : null] })))) : null] })), endAdornment] })));
17
17
  });
18
- export const TokenListItemSkeleton = ({ size, start, }) => {
19
- return (_jsxs(ListItem, Object.assign({ secondaryAction: _jsx(TokenAmountSkeleton, {}), disablePadding: true, style: {
20
- height: `${size}px`,
21
- transform: `translateY(${start}px)`,
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 }) })] })));
18
+ export const TokenListItemSkeleton = () => {
19
+ return (_jsxs(ListItem, Object.assign({ secondaryAction: _jsx(TokenAmountSkeleton, {}), disablePadding: true, sx: { position: 'relative', flexDirection: 'row', alignItems: 'center' } }, { 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
20
  };
24
21
  export const TokenAmountSkeleton = () => {
25
22
  return (_jsxs(Box, Object.assign({ sx: {
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const TokenNotFound: React.FC;
@@ -0,0 +1,15 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { SearchOff as SearchOffIcon } from '@mui/icons-material';
3
+ import { Box, Typography } from '@mui/material';
4
+ import { useTranslation } from 'react-i18next';
5
+ export const TokenNotFound = () => {
6
+ const { t } = useTranslation();
7
+ return (_jsxs(Box, Object.assign({ sx: {
8
+ display: 'flex',
9
+ justifyContent: 'center',
10
+ alignItems: 'center',
11
+ flexDirection: 'column',
12
+ flex: 1,
13
+ padding: 3,
14
+ } }, { children: [_jsx(Typography, Object.assign({ fontSize: 48, lineHeight: 1 }, { children: _jsx(SearchOffIcon, { fontSize: "inherit" }) })), _jsx(Typography, Object.assign({ fontSize: 14, color: "text.secondary", textAlign: "center", mt: 2, px: 2 }, { children: t('swap.couldntFindTokens') }))] })));
15
+ };
@@ -0,0 +1,3 @@
1
+ import { FC } from 'react';
2
+ import { VirtualizedTokenListProps } from './types';
3
+ export declare const VirtualizedTokenList: FC<VirtualizedTokenListProps>;
@@ -0,0 +1,53 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { List, Typography } from '@mui/material';
3
+ import { useVirtualizer } from '@tanstack/react-virtual';
4
+ import { useEffect } from 'react';
5
+ import { useTranslation } from 'react-i18next';
6
+ import { TokenListItem, TokenListItemSkeleton } from './TokenListItem';
7
+ export const VirtualizedTokenList = ({ tokens, featuredTokensLength, scrollElementRef, chainId, isLoading, isBalanceLoading, showBalance, showFeatured, onClick, }) => {
8
+ const { t } = useTranslation();
9
+ const hasFeaturedTokens = !!featuredTokensLength && showFeatured;
10
+ const featuredTokensLastIndex = (featuredTokensLength !== null && featuredTokensLength !== void 0 ? featuredTokensLength : 0) - 1;
11
+ const tokensLastIndex = tokens.length - 1;
12
+ const { getVirtualItems, getTotalSize, scrollToIndex } = useVirtualizer({
13
+ count: tokens.length,
14
+ getScrollElement: () => scrollElementRef.current,
15
+ overscan: 5,
16
+ paddingEnd: 12,
17
+ estimateSize: (index) => {
18
+ var _a, _b;
19
+ // heigth of TokenListItem
20
+ let size = 64;
21
+ if (!hasFeaturedTokens) {
22
+ return size;
23
+ }
24
+ if (index === 0 && ((_a = tokens[index]) === null || _a === void 0 ? void 0 : _a.featured)) {
25
+ // height of startAdornment
26
+ size += 24;
27
+ }
28
+ if (index === featuredTokensLastIndex &&
29
+ index !== tokensLastIndex &&
30
+ ((_b = tokens[index]) === null || _b === void 0 ? void 0 : _b.featured)) {
31
+ // height of endAdornment
32
+ size += 32;
33
+ }
34
+ return size;
35
+ },
36
+ getItemKey: (index) => { var _a; return (_a = tokens[index].address) !== null && _a !== void 0 ? _a : index; },
37
+ });
38
+ useEffect(() => {
39
+ scrollToIndex(0, { align: 'start', smoothScroll: false });
40
+ }, [scrollToIndex, chainId]);
41
+ if (isLoading) {
42
+ return (_jsx(List, Object.assign({ disablePadding: true }, { children: Array.from({ length: 3 }).map((_, index) => (
43
+ // eslint-disable-next-line react/no-array-index-key
44
+ _jsx(TokenListItemSkeleton, {}, index))) })));
45
+ }
46
+ return (_jsx(List, Object.assign({ style: { height: getTotalSize() }, disablePadding: true }, { children: getVirtualItems().map((item) => {
47
+ const token = tokens[item.index];
48
+ return (_jsx(TokenListItem, { onClick: onClick, size: item.size, start: item.start, token: token, isBalanceLoading: isBalanceLoading, showBalance: showBalance, startAdornment: hasFeaturedTokens && token.featured && item.index === 0 ? (_jsx(Typography, Object.assign({ fontSize: 14, fontWeight: 600, lineHeight: 1, px: 2, pb: 1.25 }, { children: t('swap.featuredTokens') }))) : null, endAdornment: hasFeaturedTokens &&
49
+ token.featured &&
50
+ item.index === featuredTokensLastIndex &&
51
+ item.index !== tokensLastIndex ? (_jsx(Typography, Object.assign({ fontSize: 14, fontWeight: 600, lineHeight: 1, px: 2, py: 1.25 }, { children: t('swap.otherTokens') }))) : null }, item.key));
52
+ }) })));
53
+ };
@@ -1,12 +1,25 @@
1
1
  import { TokenAmount } from '@lifi/sdk';
2
+ import { MutableRefObject } from 'react';
2
3
  import { SwapFormDirection } from '../../providers/SwapFormProvider';
4
+ import { Token } from '../../types';
3
5
  export interface TokenListProps {
4
6
  formType: SwapFormDirection;
5
7
  height: number;
6
8
  onClick?(): void;
7
9
  }
10
+ export interface VirtualizedTokenListProps {
11
+ tokens: Token[];
12
+ featuredTokensLength?: number;
13
+ scrollElementRef: MutableRefObject<HTMLElement | null>;
14
+ isLoading: boolean;
15
+ isBalanceLoading: boolean;
16
+ chainId: number;
17
+ showBalance?: boolean;
18
+ showFeatured?: boolean;
19
+ onClick(tokenAddress: string): void;
20
+ }
8
21
  export interface TokenListItemBaseProps {
9
- onClick?(token: string): void;
22
+ onClick?(tokenAddress: string): void;
10
23
  size: number;
11
24
  start: number;
12
25
  }
@@ -14,4 +27,6 @@ export interface TokenListItemProps extends TokenListItemBaseProps {
14
27
  showBalance?: boolean;
15
28
  token: TokenAmount;
16
29
  isBalanceLoading?: boolean;
30
+ startAdornment?: React.ReactNode;
31
+ endAdornment?: React.ReactNode;
17
32
  }
@@ -1 +1 @@
1
- export declare const initSentry: (enabled?: boolean) => void;
1
+ export declare const initSentry: (enabled?: boolean) => Promise<void>;
package/config/sentry.js CHANGED
@@ -1,20 +1,38 @@
1
- import { CaptureConsole } from '@sentry/integrations';
2
- import * as Sentry from '@sentry/react';
3
- import { BrowserTracing } from '@sentry/tracing';
4
- import { version } from './version';
5
- export const initSentry = (enabled) => {
6
- Sentry.init({
7
- dsn: 'https://bc1312161bf948db9b9c82618035ec22@o1302189.ingest.sentry.io/6539228',
8
- integrations: [
9
- new BrowserTracing(),
10
- new CaptureConsole({
11
- levels: ['error'],
12
- }),
13
- ],
14
- sampleRate: 1,
15
- tracesSampleRate: 0.2,
16
- enabled,
17
- environment: process.env.NODE_ENV,
18
- release: version,
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
8
  });
20
9
  };
10
+ import { version } from './version';
11
+ let sentryLoaded = false;
12
+ export const initSentry = (enabled) => __awaiter(void 0, void 0, void 0, function* () {
13
+ if (process.env.NODE_ENV === 'development') {
14
+ return;
15
+ }
16
+ if (enabled || sentryLoaded) {
17
+ const [Sentry, { CaptureConsole }, { BrowserTracing }] = yield Promise.all([
18
+ import('@sentry/react'),
19
+ import('@sentry/integrations'),
20
+ import('@sentry/tracing'),
21
+ ]);
22
+ Sentry.init({
23
+ dsn: 'https://bc1312161bf948db9b9c82618035ec22@o1302189.ingest.sentry.io/6539228',
24
+ integrations: [
25
+ new BrowserTracing(),
26
+ new CaptureConsole({
27
+ levels: ['error'],
28
+ }),
29
+ ],
30
+ sampleRate: 1,
31
+ tracesSampleRate: 0.2,
32
+ enabled,
33
+ environment: process.env.NODE_ENV,
34
+ release: version,
35
+ });
36
+ sentryLoaded = true;
37
+ }
38
+ });
@@ -1,2 +1,2 @@
1
1
  export declare const name = "@lifi/widget";
2
- export declare const version = "1.12.1";
2
+ export declare const version = "1.13.2";
package/config/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@lifi/widget';
2
- export const version = '1.12.1';
2
+ export const version = '1.13.2';
package/hooks/index.d.ts CHANGED
@@ -2,7 +2,9 @@ export * from './useChain';
2
2
  export * from './useChains';
3
3
  export * from './useContentHeight';
4
4
  export * from './useDebouncedWatch';
5
+ export * from './useFeaturedTokens';
5
6
  export * from './useGasSufficiency';
7
+ export * from './useInitializer';
6
8
  export * from './useRouteExecution';
7
9
  export * from './useScrollableContainer';
8
10
  export * from './useSwapRoutes';
@@ -11,4 +13,5 @@ export * from './useToken';
11
13
  export * from './useTokenBalance';
12
14
  export * from './useTokenBalances';
13
15
  export * from './useTokens';
16
+ export * from './useTokenSearch';
14
17
  export * from './useTools';
package/hooks/index.js CHANGED
@@ -2,7 +2,9 @@ export * from './useChain';
2
2
  export * from './useChains';
3
3
  export * from './useContentHeight';
4
4
  export * from './useDebouncedWatch';
5
+ export * from './useFeaturedTokens';
5
6
  export * from './useGasSufficiency';
7
+ export * from './useInitializer';
6
8
  export * from './useRouteExecution';
7
9
  export * from './useScrollableContainer';
8
10
  export * from './useSwapRoutes';
@@ -11,4 +13,5 @@ export * from './useToken';
11
13
  export * from './useTokenBalance';
12
14
  export * from './useTokenBalances';
13
15
  export * from './useTokens';
16
+ export * from './useTokenSearch';
14
17
  export * from './useTools';
@@ -2,8 +2,8 @@ export declare const useChains: () => {
2
2
  error: unknown;
3
3
  isError: true;
4
4
  isLoading: false;
5
- isLoadingError: true;
6
- isRefetchError: false;
5
+ isLoadingError: false;
6
+ isRefetchError: true;
7
7
  isSuccess: false;
8
8
  status: "error";
9
9
  dataUpdatedAt: number;
@@ -26,11 +26,11 @@ export declare const useChains: () => {
26
26
  } | {
27
27
  error: null;
28
28
  isError: false;
29
- isLoading: true;
29
+ isLoading: false;
30
30
  isLoadingError: false;
31
31
  isRefetchError: false;
32
- isSuccess: false;
33
- status: "loading";
32
+ isSuccess: true;
33
+ status: "success";
34
34
  dataUpdatedAt: number;
35
35
  errorUpdatedAt: number;
36
36
  failureCount: number;
@@ -52,8 +52,8 @@ export declare const useChains: () => {
52
52
  error: unknown;
53
53
  isError: true;
54
54
  isLoading: false;
55
- isLoadingError: false;
56
- isRefetchError: true;
55
+ isLoadingError: true;
56
+ isRefetchError: false;
57
57
  isSuccess: false;
58
58
  status: "error";
59
59
  dataUpdatedAt: number;
@@ -76,11 +76,11 @@ export declare const useChains: () => {
76
76
  } | {
77
77
  error: null;
78
78
  isError: false;
79
- isLoading: false;
79
+ isLoading: true;
80
80
  isLoadingError: false;
81
81
  isRefetchError: false;
82
- isSuccess: true;
83
- status: "success";
82
+ isSuccess: false;
83
+ status: "loading";
84
84
  dataUpdatedAt: number;
85
85
  errorUpdatedAt: number;
86
86
  failureCount: number;
@@ -0,0 +1 @@
1
+ export declare const useFeaturedTokens: (selectedChainId: number) => import("@lifi/types").Token[] | undefined;
@@ -0,0 +1,6 @@
1
+ import { useMemo } from 'react';
2
+ import { useWidgetConfig } from '../providers/WidgetProvider';
3
+ export const useFeaturedTokens = (selectedChainId) => {
4
+ const { featuredTokens } = useWidgetConfig();
5
+ return useMemo(() => featuredTokens === null || featuredTokens === void 0 ? void 0 : featuredTokens.filter((token) => token.chainId === selectedChainId), [featuredTokens, selectedChainId]);
6
+ };
@@ -1,4 +1,5 @@
1
1
  export declare const useToken: (chainId: number, tokenAddress: string) => {
2
- token: import("@lifi/types").Token | undefined;
2
+ token: import("..").Token | undefined;
3
3
  isLoading: boolean;
4
+ isFetching: boolean;
4
5
  };
package/hooks/useToken.js CHANGED
@@ -8,6 +8,7 @@ export const useToken = (chainId, tokenAddress) => {
8
8
  }, [chainId, tokenAddress, tokens]);
9
9
  return {
10
10
  token,
11
- isLoading: isLoading && isFetching,
11
+ isLoading,
12
+ isFetching,
12
13
  };
13
14
  };
@@ -1,7 +1,5 @@
1
- import { TokenAmount } from '@lifi/sdk';
2
1
  export declare const useTokenBalance: (chainId: number, tokenAddress: string) => {
3
- token: TokenAmount | undefined;
2
+ token: import("..").Token | undefined;
4
3
  isLoading: boolean;
5
- isFetching: boolean;
6
- refetchBalance: (chainId?: number, tokenAddress?: string) => Promise<void>;
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>>;
7
5
  };