From 1717074700617f13e32f65a2379e61667685041c Mon Sep 17 00:00:00 2001 From: David Totrashvili <8580261+totraev@users.noreply.github.com> Date: Mon, 2 Dec 2024 00:05:54 +0500 Subject: [PATCH] fix: update disconnect method (#76) --- .changeset/lovely-hotels-lay.md | 5 +++++ src/hooks/useWalletConnect.ts | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 .changeset/lovely-hotels-lay.md diff --git a/.changeset/lovely-hotels-lay.md b/.changeset/lovely-hotels-lay.md new file mode 100644 index 0000000..5c40db2 --- /dev/null +++ b/.changeset/lovely-hotels-lay.md @@ -0,0 +1,5 @@ +--- +"@babylonlabs-io/bbn-wallet-connect": patch +--- + +update disconnect method diff --git a/src/hooks/useWalletConnect.ts b/src/hooks/useWalletConnect.ts index e5c5d1e..15c18d1 100644 --- a/src/hooks/useWalletConnect.ts +++ b/src/hooks/useWalletConnect.ts @@ -1,17 +1,26 @@ import { useCallback, useMemo } from "react"; + +import { useChainProviders } from "@/context/Chain.context"; import { useWidgetState } from "./useWidgetState"; export function useWalletConnect() { - const { confirmed, chains: chainMap, selectedWallets, open: openModal, close, reset } = useWidgetState(); + const { confirmed, chains: chainMap, selectedWallets, open: openModal, reset } = useWidgetState(); + const connectors = useChainProviders(); const open = useCallback(() => { reset?.(); openModal?.(); }, [openModal, reset]); - const disconnect = useCallback(() => { + const disconnect = useCallback(async () => { + for (const connector of Object.values(connectors)) { + if (!connector) continue; + + await connector.disconnect(); + } + reset?.(); - }, [close]); + }, []); const selected = useMemo(() => { const chains = Object.values(chainMap).filter(Boolean);