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);