From 47e9edc4486815c07f12ccccbcb0d3934a36af70 Mon Sep 17 00:00:00 2001 From: Don Kackman Date: Wed, 25 Mar 2026 17:02:47 -0500 Subject: [PATCH 1/2] debounce wallet drop down on hover fix https://github.com/xch-dev/sage/issues/769 --- src/components/WalletSwitcher.tsx | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/components/WalletSwitcher.tsx b/src/components/WalletSwitcher.tsx index da1add4b4..91dacac08 100644 --- a/src/components/WalletSwitcher.tsx +++ b/src/components/WalletSwitcher.tsx @@ -14,13 +14,14 @@ import { } from '@/components/ui/tooltip'; import { CustomError } from '@/contexts/ErrorContext'; import { useWallet } from '@/contexts/WalletContext'; +import { useDebounce } from '@/hooks/useDebounce'; import { useErrors } from '@/hooks/useErrors'; import { clearState, loginAndUpdateState, logoutAndUpdateState } from '@/state'; import { t } from '@lingui/core/macro'; import { Trans } from '@lingui/react/macro'; import { platform } from '@tauri-apps/plugin-os'; import { ChevronDown, WalletIcon } from 'lucide-react'; -import { useEffect, useRef, useState } from 'react'; +import { useEffect, useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { useTheme } from 'theme-o-rama'; import iconDark from '@/icon-dark.png'; @@ -40,9 +41,9 @@ export function WalletSwitcher({ isCollapsed, wallet }: WalletSwitcherProps) { const [loading, setLoading] = useState(true); const [isOpen, setIsOpen] = useState(false); const [isHovering, setIsHovering] = useState(false); + const debouncedIsHovering = useDebounce(isHovering, 300); const [isMigrationDialogOpen, setIsMigrationDialogOpen] = useState(false); const [migrationWallet, setMigrationWallet] = useState(null); - const timeoutRef = useRef(null); const isMobile = platform() === 'ios' || platform() === 'android'; useEffect(() => { @@ -61,12 +62,12 @@ export function WalletSwitcher({ isCollapsed, wallet }: WalletSwitcherProps) { }, [addError]); useEffect(() => { - return () => { - if (timeoutRef.current) { - clearTimeout(timeoutRef.current); - } - }; - }, []); + if (debouncedIsHovering) { + setIsOpen(true); + } else if (!isHovering) { + setIsOpen(false); + } + }, [debouncedIsHovering, isHovering]); const handleSwitchWallet = async (fingerprint: number) => { if (isSwitching) { @@ -122,20 +123,12 @@ export function WalletSwitcher({ isCollapsed, wallet }: WalletSwitcherProps) { const handleMouseEnter = () => { if (isMobile) return; - if (timeoutRef.current) { - clearTimeout(timeoutRef.current); - timeoutRef.current = null; - } setIsHovering(true); - setIsOpen(true); }; const handleMouseLeave = () => { if (isMobile) return; setIsHovering(false); - timeoutRef.current = setTimeout(() => { - setIsOpen(false); - }, 150); }; // Filter out current wallet from the list From bd4db324db1a5cbe84a5aaa32d61c9f7eac71ccb Mon Sep 17 00:00:00 2001 From: Don Kackman Date: Wed, 25 Mar 2026 17:07:14 -0500 Subject: [PATCH 2/2] review fix --- src/components/WalletSwitcher.tsx | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/components/WalletSwitcher.tsx b/src/components/WalletSwitcher.tsx index 91dacac08..5c7ffdf5a 100644 --- a/src/components/WalletSwitcher.tsx +++ b/src/components/WalletSwitcher.tsx @@ -62,12 +62,8 @@ export function WalletSwitcher({ isCollapsed, wallet }: WalletSwitcherProps) { }, [addError]); useEffect(() => { - if (debouncedIsHovering) { - setIsOpen(true); - } else if (!isHovering) { - setIsOpen(false); - } - }, [debouncedIsHovering, isHovering]); + setIsOpen(debouncedIsHovering); + }, [debouncedIsHovering]); const handleSwitchWallet = async (fingerprint: number) => { if (isSwitching) {