Skip to content

Commit

Permalink
Merge pull request #54 from IntersectMBO/wallet-bug-fix
Browse files Browse the repository at this point in the history
Multiple app windows wallet fixes
  • Loading branch information
JanJaroszczak authored Dec 29, 2023
2 parents 5d3e614 + ee922dd commit 9d2469b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/vva-fe/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@ import {
WALLET_LS_KEY,
removeItemFromLocalStorage,
} from "@utils";

import { SetupInterceptors } from "./services";
import { useGetDRepInfo } from "./hooks";
import { useGetDRepInfo, useWalletConnectionListener } from "./hooks";

export default function App() {
const { enable, setDRep, setIsDrepLoading } = useCardano();
const navigate = useNavigate();
const { data } = useGetDRepInfo();

useWalletConnectionListener();

useEffect(() => {
SetupInterceptors(navigate);
}, []);
Expand Down
1 change: 1 addition & 0 deletions src/vva-fe/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from "./useScreenDimension";
export * from "./useSlider";
export * from "./useSaveScrollPosition";
export * from "./useFetchNextPageDetector";
export * from "./useWalletConnectionListener";

export * from "./forms";
export * from "./mutations";
Expand Down
21 changes: 21 additions & 0 deletions src/vva-fe/src/hooks/useWalletConnectionListener.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { useEffect } from "react";
import { useCardano } from "@context";
import { WALLET_LS_KEY } from "@utils";

export const useWalletConnectionListener = () => {
const { disconnectWallet } = useCardano();

useEffect(() => {
const handleStorageChange = (event: StorageEvent) => {
if (event.key === `${WALLET_LS_KEY}_name` && event.newValue === null) {
disconnectWallet();
}
};

window.addEventListener("storage", handleStorageChange);

return () => {
window.removeEventListener("storage", handleStorageChange);
};
}, []);
};

0 comments on commit 9d2469b

Please sign in to comment.