feat: adds back resetApp

This commit is contained in:
Ben Kremer 2022-02-09 13:01:22 +01:00
parent d33bf9dcd1
commit 1ca7a5cfd1

View File

@ -156,8 +156,15 @@ export function ClientContextProvider({ children }: { children: ReactNode | Reac
} }
}; };
const subscribeToEvents = useCallback( const resetApp = () => {
async (_client: Client) => { setPairings([]);
setSession(undefined);
setBalances({});
setAccounts([]);
setChains([]);
};
const subscribeToEvents = useCallback(async (_client: Client) => {
if (typeof _client === "undefined") { if (typeof _client === "undefined") {
throw new Error("WalletConnect is not initialized"); throw new Error("WalletConnect is not initialized");
} }
@ -177,20 +184,15 @@ export function ClientContextProvider({ children }: { children: ReactNode | Reac
}); });
_client.on(CLIENT_EVENTS.pairing.created, async (proposal: PairingTypes.Settled) => { _client.on(CLIENT_EVENTS.pairing.created, async (proposal: PairingTypes.Settled) => {
if (typeof client === "undefined") return; setPairings(_client.pairing.topics);
setPairings(client.pairing.topics);
}); });
_client.on(CLIENT_EVENTS.session.deleted, (deletedSession: SessionTypes.Settled) => { _client.on(CLIENT_EVENTS.session.deleted, (deletedSession: SessionTypes.Settled) => {
if (deletedSession.topic !== _session?.topic) return; if (deletedSession.topic !== _session?.topic) return;
console.log("EVENT", "session_deleted"); console.log("EVENT", "session_deleted");
// TODO: resetApp();
// this.resetApp();
window.location.reload();
}); });
}, }, []);
[client],
);
const checkPersistedState = useCallback( const checkPersistedState = useCallback(
async (_client: Client) => { async (_client: Client) => {