Skip to content

Commit

Permalink
fix: scroll to top after changing chain
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed May 2, 2022
1 parent 167dd4b commit bc772ab
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/widget/src/components/TokenList/TokenList.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TokenAmount } from '@lifinance/sdk';
import { Box, List, Typography } from '@mui/material';
import { FC, useCallback, useMemo, useRef } from 'react';
import { FC, useCallback, useEffect, useMemo, useRef } from 'react';
import { useFormContext, useWatch } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
import { useVirtual } from 'react-virtual';
Expand Down Expand Up @@ -50,7 +50,7 @@ export const TokenList: FC<TokenListProps> = ({

const parentRef = useRef<HTMLUListElement | null>(null);

const { virtualItems, totalSize } = useVirtual({
const { virtualItems, totalSize, scrollToIndex } = useVirtual({
size: chainTokens.length,
parentRef,
overscan: 3,
Expand All @@ -59,6 +59,10 @@ export const TokenList: FC<TokenListProps> = ({
keyExtractor: (index) => chainTokens[index].address ?? index,
});

useEffect(() => {
scrollToIndex(0);
}, [scrollToIndex, selectedChainId]);

const handleTokenClick = useCallback(
(tokenAddress: string) => {
setValue(SwapFormKeyHelper.getTokenKey(formType), tokenAddress);
Expand Down

0 comments on commit bc772ab

Please sign in to comment.