From f0a60ce8767514872d496efea420bc492431c6e6 Mon Sep 17 00:00:00 2001 From: Kheops <26880866+0xKheops@users.noreply.github.com> Date: Wed, 18 Oct 2023 15:29:58 +0900 Subject: [PATCH] fix: virtualized rows --- .../dashboard/routes/Networks/ChainsList.tsx | 32 +++++++++---------- .../routes/Networks/EvmNetworksList.tsx | 32 +++++++++---------- .../dashboard/routes/Tokens/TokensPage.tsx | 20 ++++++++++-- 3 files changed, 49 insertions(+), 35 deletions(-) diff --git a/apps/extension/src/ui/apps/dashboard/routes/Networks/ChainsList.tsx b/apps/extension/src/ui/apps/dashboard/routes/Networks/ChainsList.tsx index ec1f172361..2fe4e8b3da 100644 --- a/apps/extension/src/ui/apps/dashboard/routes/Networks/ChainsList.tsx +++ b/apps/extension/src/ui/apps/dashboard/routes/Networks/ChainsList.tsx @@ -103,8 +103,8 @@ const ChainsListItem = ({ }, [navigate, chain.id]) // there are lots of chains so we should only render visible rows to prevent performance issues - const refButton = useRef(null) - const intersection = useIntersection(refButton, { + const refContainer = useRef(null) + const intersection = useIntersection(refContainer, { root: null, rootMargin: "1000px", }) @@ -116,27 +116,27 @@ const ChainsListItem = ({ [onEnableChanged] ) - const buttonContent = intersection?.isIntersecting ? ( + const rowContent = intersection?.isIntersecting ? ( <> - -
{chain.name}
- {chain.isTestnet && } - {isCustomChain(chain) && } -
- - - ) : null - - return ( -
- - {buttonContent} + + +
{chain.name}
+ {chain.isTestnet && } + {isCustomChain(chain) && } +
+
+ + ) : null + + return ( +
+ {rowContent}
) } diff --git a/apps/extension/src/ui/apps/dashboard/routes/Networks/EvmNetworksList.tsx b/apps/extension/src/ui/apps/dashboard/routes/Networks/EvmNetworksList.tsx index 3f9c85856e..2c2a94d5f4 100644 --- a/apps/extension/src/ui/apps/dashboard/routes/Networks/EvmNetworksList.tsx +++ b/apps/extension/src/ui/apps/dashboard/routes/Networks/EvmNetworksList.tsx @@ -116,8 +116,8 @@ const EvmNetworksListItem = ({ }, [navigate, network.id]) // there are lots of networks so we should only render visible rows to prevent performance issues - const refButton = useRef(null) - const intersection = useIntersection(refButton, { + const refContainer = useRef(null) + const intersection = useIntersection(refContainer, { root: null, rootMargin: "1000px", }) @@ -129,27 +129,27 @@ const EvmNetworksListItem = ({ [onEnableChanged] ) - const buttonContent = intersection?.isIntersecting ? ( + const rowContent = intersection?.isIntersecting ? ( <> - -
{network.name}
- {network.isTestnet && } - {isCustomEvmNetwork(network) && } -
- - - ) : null - - return ( -
- - {buttonContent} + + +
{network.name}
+ {network.isTestnet && } + {isCustomEvmNetwork(network) && } +
+
+ + ) : null + + return ( +
+ {rowContent}
) } diff --git a/apps/extension/src/ui/apps/dashboard/routes/Tokens/TokensPage.tsx b/apps/extension/src/ui/apps/dashboard/routes/Tokens/TokensPage.tsx index 0483747066..dd09b0d7ac 100644 --- a/apps/extension/src/ui/apps/dashboard/routes/Tokens/TokensPage.tsx +++ b/apps/extension/src/ui/apps/dashboard/routes/Tokens/TokensPage.tsx @@ -17,9 +17,10 @@ import { useTokensEnabledState } from "@ui/hooks/useTokensEnabledState" import { isCustomErc20Token } from "@ui/util/isCustomErc20Token" import { isErc20Token } from "@ui/util/isErc20Token" import sortBy from "lodash/sortBy" -import { ChangeEventHandler, FC, useCallback, useMemo, useState } from "react" +import { ChangeEventHandler, FC, useCallback, useMemo, useRef, useState } from "react" import { useTranslation } from "react-i18next" import { useNavigate } from "react-router-dom" +import { useIntersection } from "react-use" import { ListButton, PillButton, Toggle } from "talisman-ui" import { DashboardLayout } from "../../layout/DashboardLayout" @@ -48,8 +49,15 @@ const TokenRow = ({ token }: { token: Erc20Token }) => { [token.id] ) - return ( -
+ // there are lots of tokens so we should only render visible rows to prevent performance issues + const refContainer = useRef(null) + const intersection = useIntersection(refContainer, { + root: null, + rootMargin: "1000px", + }) + + const rowContent = intersection?.isIntersecting ? ( + <> navigate(`./${token.id}`)}>
@@ -65,6 +73,12 @@ const TokenRow = ({ token }: { token: Erc20Token }) => { checked={isEnabled} onChange={handleEnableChanged} /> + + ) : null + + return ( +
+ {rowContent}
) }