From 609a3239c677a2f5cef52ff3757a022196fa0d64 Mon Sep 17 00:00:00 2001 From: Ben Kremer Date: Thu, 22 Dec 2022 11:42:33 +0100 Subject: [PATCH] fix(dapp-v2): ensure dapp always resets on attempted disconnect --- .../src/contexts/ClientContext.tsx | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/dapps/react-dapp-v2/src/contexts/ClientContext.tsx b/dapps/react-dapp-v2/src/contexts/ClientContext.tsx index 67c8be5..7b15a97 100644 --- a/dapps/react-dapp-v2/src/contexts/ClientContext.tsx +++ b/dapps/react-dapp-v2/src/contexts/ClientContext.tsx @@ -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(