fix(dapp-v2): ensure dapp always resets on attempted disconnect

This commit is contained in:
Ben Kremer 2022-12-22 11:42:33 +01:00
parent 5c1092b9ef
commit 609a3239c6

View File

@ -182,12 +182,18 @@ export function ClientContextProvider({
if (typeof session === "undefined") {
throw new Error("Session is not connected");
}
await client.disconnect({
topic: session.topic,
reason: getSdkError("USER_DISCONNECTED"),
});
// Reset app state after disconnect.
reset();
try {
await client.disconnect({
topic: session.topic,
reason: getSdkError("USER_DISCONNECTED"),
});
} catch (error) {
console.error("SignClient.disconnect failed:", error);
} finally {
// Reset app state after disconnect.
reset();
}
}, [client, session]);
const _subscribeToEvents = useCallback(