Skip to content

Commit

Permalink
fix: make token selection smoother
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed Apr 5, 2022
1 parent d74140b commit 51ef8ed
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/widget/src/components/TokenList/TokenList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Box, List, Typography } from '@mui/material';
import { useCallback, useMemo, useRef } from 'react';
import { useCallback, useMemo, useRef, useTransition } from 'react';
import { useFormContext, useWatch } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
import { defaultRangeExtractor, useVirtual } from 'react-virtual';
Expand Down Expand Up @@ -30,6 +30,7 @@ export const TokenList: React.FC<TokenListProps> = ({
onClick,
}) => {
const { t } = useTranslation();
const [, startTransition] = useTransition();
const { account } = useWalletInterface();
const { setValue } = useFormContext();
const [selectedChainId, myTokensFilter] = useWatch({
Expand Down Expand Up @@ -102,8 +103,10 @@ export const TokenList: React.FC<TokenListProps> = ({

const handleTokenClick = useCallback(
(tokenAddress: string) => {
setValue(SwapFormKeyHelper.getTokenKey(formType), tokenAddress);
onClick?.();
startTransition(() => {
setValue(SwapFormKeyHelper.getTokenKey(formType), tokenAddress);
});
},
[formType, onClick, setValue],
);
Expand Down

0 comments on commit 51ef8ed

Please sign in to comment.