From 6a1a7b6c6f64d04998cf0de3687213a78fcda51e Mon Sep 17 00:00:00 2001 From: vvava <94397450+vvava@users.noreply.github.com> Date: Fri, 7 Feb 2025 17:00:23 +0100 Subject: [PATCH] feat: scroll to the active account (#131) --- src/pages/Accounts/components/AccountItem.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/pages/Accounts/components/AccountItem.tsx b/src/pages/Accounts/components/AccountItem.tsx index e47c3731e..dbd64ef0e 100644 --- a/src/pages/Accounts/components/AccountItem.tsx +++ b/src/pages/Accounts/components/AccountItem.tsx @@ -13,6 +13,7 @@ import { ForwardedRef, forwardRef, useCallback, + useEffect, useMemo, useRef, useState, @@ -79,6 +80,18 @@ export const AccountItem = forwardRef( const address = network ? getAddressForChain(network.chainId, account) : ''; const [cardHovered, setCardHovered] = useState(false); const itemRef = useRef(null); + const firstPageload = useRef(true); + + useEffect(() => { + if (isActive) { + const behavior = firstPageload.current ? 'instant' : 'smooth'; + itemRef?.current?.scrollIntoView({ + block: 'center', + behavior, + }); + } + firstPageload.current = false; + }, [isActive]); const toggle = useCallback( (accountId: string) => {