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,41 +156,43 @@ export function ClientContextProvider({ children }: { children: ReactNode | Reac
} }
}; };
const subscribeToEvents = useCallback( const resetApp = () => {
async (_client: Client) => { setPairings([]);
if (typeof _client === "undefined") { setSession(undefined);
throw new Error("WalletConnect is not initialized"); setBalances({});
} setAccounts([]);
setChains([]);
};
let _session = {} as SessionTypes.Settled; const subscribeToEvents = useCallback(async (_client: Client) => {
if (typeof _client === "undefined") {
throw new Error("WalletConnect is not initialized");
}
if (_client.session.topics.length) { let _session = {} as SessionTypes.Settled;
_session = await _client.session.get(_client.session.topics[0]);
}
_client.on(CLIENT_EVENTS.pairing.proposal, async (proposal: PairingTypes.Proposal) => { if (_client.session.topics.length) {
const { uri } = proposal.signal.params; _session = await _client.session.get(_client.session.topics[0]);
console.log("EVENT", "QR Code Modal open"); }
QRCodeModal.open(uri, () => {
console.log("EVENT", "QR Code Modal closed"); _client.on(CLIENT_EVENTS.pairing.proposal, async (proposal: PairingTypes.Proposal) => {
}); const { uri } = proposal.signal.params;
console.log("EVENT", "QR Code Modal open");
QRCodeModal.open(uri, () => {
console.log("EVENT", "QR Code Modal closed");
}); });
});
_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) => {