I am using this code given below in my react application to listen an account change event but facing issue as no response or error i am getting on changing account form phantom wallet .i have followed the documentation and tried the method using public key as well but still i didn't get any solution the code for the account change listener is given below .
useEffect(() => { const provider = (window as any)?.phantom?.solana;
if (provider !== undefined) {
provider.on("accountChanged", async () => {
try {
dispatch(setOverlapLoader(true));
await wallet.disconnect();
dispatch(logoutUser());
} catch (error) {
console.log("error", error);
} finally {
dispatch(setOverlapLoader(false));
}
});
}
}, [dispatch, wallet]);