From f8bf66c17e0f4f6779b11c2ab5ae98e8b4e89d51 Mon Sep 17 00:00:00 2001 From: David Totrashvili <8580261+totraev@users.noreply.github.com> Date: Mon, 2 Dec 2024 11:44:25 +0500 Subject: [PATCH] fix: disconnect wallets on modal close (#82) --- .changeset/chatty-jeans-carry.md | 5 +++++ src/components/WalletProvider/components/WalletDialog.tsx | 8 +++++--- src/hooks/useWalletConnect.ts | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 .changeset/chatty-jeans-carry.md diff --git a/.changeset/chatty-jeans-carry.md b/.changeset/chatty-jeans-carry.md new file mode 100644 index 0000000..1cfd79c --- /dev/null +++ b/.changeset/chatty-jeans-carry.md @@ -0,0 +1,5 @@ +--- +"@babylonlabs-io/bbn-wallet-connect": patch +--- + +disconnect wallets on modal close diff --git a/src/components/WalletProvider/components/WalletDialog.tsx b/src/components/WalletProvider/components/WalletDialog.tsx index 361ae6a..98ed664 100644 --- a/src/components/WalletProvider/components/WalletDialog.tsx +++ b/src/components/WalletProvider/components/WalletDialog.tsx @@ -8,6 +8,7 @@ import { useInscriptionProvider } from "@/context/Inscriptions.context"; import { Screen } from "./Screen"; import { useWalletConnectors } from "@/hooks/useWalletConnectors"; +import { useWalletConnect } from "@/hooks/useWalletConnect"; interface WalletDialogProps { onError?: (e: Error) => void; @@ -17,11 +18,12 @@ interface WalletDialogProps { const ANIMATION_DELAY = 1000; export function WalletDialog({ config, onError }: WalletDialogProps) { - const { visible, screen, close, reset = () => {}, confirm, displayChains } = useWidgetState(); + const { visible, screen, close, confirm, displayChains } = useWidgetState(); const { toggleShowAgain, toggleLockInscriptions } = useInscriptionProvider(); const connectors = useChainProviders(); const walletWidgets = useWalletWidgets(connectors, config); const { connect, disconnect } = useWalletConnectors(onError); + const { disconnect: disconnectAll } = useWalletConnect(); const handleToggleInscriptions = useCallback( (lockInscriptions: boolean, showAgain: boolean) => { @@ -34,8 +36,8 @@ export function WalletDialog({ config, onError }: WalletDialogProps) { const handleClose = useCallback(() => { close?.(); - setTimeout(reset, ANIMATION_DELAY); - }, [close, reset]); + setTimeout(disconnectAll, ANIMATION_DELAY); + }, [close, disconnectAll]); const handleConfirm = useCallback(() => { confirm?.(); diff --git a/src/hooks/useWalletConnect.ts b/src/hooks/useWalletConnect.ts index 15c18d1..661dd88 100644 --- a/src/hooks/useWalletConnect.ts +++ b/src/hooks/useWalletConnect.ts @@ -20,7 +20,7 @@ export function useWalletConnect() { } reset?.(); - }, []); + }, [connectors, reset]); const selected = useMemo(() => { const chains = Object.values(chainMap).filter(Boolean);