Skip to content

Commit

Permalink
fix: disconnect wallets on modal close (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
totraev authored Dec 2, 2024
1 parent 214753f commit f8bf66c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/chatty-jeans-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@babylonlabs-io/bbn-wallet-connect": patch
---

disconnect wallets on modal close
8 changes: 5 additions & 3 deletions src/components/WalletProvider/components/WalletDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) => {
Expand All @@ -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?.();
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useWalletConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function useWalletConnect() {
}

reset?.();
}, []);
}, [connectors, reset]);

const selected = useMemo(() => {
const chains = Object.values(chainMap).filter(Boolean);
Expand Down

0 comments on commit f8bf66c

Please sign in to comment.