From 7368e0d0e64319b28445653047d27ee47ca48683 Mon Sep 17 00:00:00 2001 From: Danh Date: Thu, 5 Oct 2023 23:47:23 +0700 Subject: [PATCH] refactor --- src/components/SelectV2.tsx | 2 +- .../MultipleChainSelectV2/index.tsx | 24 +++++++++++++++++-- .../components/TokenFilter/index.tsx | 7 +++++- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/components/SelectV2.tsx b/src/components/SelectV2.tsx index 60e8d4ae92..e3c80c182b 100644 --- a/src/components/SelectV2.tsx +++ b/src/components/SelectV2.tsx @@ -159,7 +159,7 @@ function Select({ }) const updateCallback = useCallback(() => { - update && update() + update?.() }, [update]) useInterval(updateCallback, showMenu ? 100 : null) diff --git a/src/pages/MyEarnings/MultipleChainSelectV2/index.tsx b/src/pages/MyEarnings/MultipleChainSelectV2/index.tsx index 3b9b3f6bc9..49200680b6 100644 --- a/src/pages/MyEarnings/MultipleChainSelectV2/index.tsx +++ b/src/pages/MyEarnings/MultipleChainSelectV2/index.tsx @@ -1,7 +1,7 @@ import { ChainId } from '@kyberswap/ks-sdk-core' import { Trans } from '@lingui/macro' import { rgba } from 'polished' -import { ReactNode, useState } from 'react' +import { ReactNode, useEffect, useRef, useState } from 'react' import { Box, Flex, Text } from 'rebass' import styled, { CSSProperties } from 'styled-components' @@ -78,6 +78,20 @@ const MultipleChainSelect: React.FC = ({ className, st } } + useEffect(() => { + setLocalSelectedChains(selectedChains) + // eslint-disable-next-line + }, [selectedChains.length]) + + const selectAllRef = useRef(null) + useEffect(() => { + if (!selectAllRef.current) { + return + } + selectAllRef.current.indeterminate = + 0 < localSelectedChains.length && localSelectedChains.length < networkList.length + }, [localSelectedChains, networkList.length]) + return (