Skip to content

Commit

Permalink
fixed dapp disconnect (#1866)
Browse files Browse the repository at this point in the history
  • Loading branch information
seeden committed Jun 23, 2023
1 parent caea07f commit 907b921
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions packages/gui/src/util/walletConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,31 @@ export async function disconnectPair(client: Client, pairs: Pairs, topic: string
const sessions = pairs.getPair(topic)?.sessions ?? [];
await Promise.all(
sessions.map(async (session) => {
await client.disconnect({ topic: session.topic, reason: getSdkError('USER_DISCONNECTED') });
try {
await client.disconnect({ topic: session.topic, reason: getSdkError('USER_DISCONNECTED') });
} catch (e) {
if (e instanceof Error && e.message.includes('No matching key')) {
log(`Session was already disconnected ${session.topic}`);
// we can ignore this error because it means that session was already disconnected
return;
}

throw e;
}
})
);

// then disconnect pairing
await client.core.pairing.disconnect({ topic });
try {
await client.core.pairing.disconnect({ topic });
} catch (e) {
if (e instanceof Error && e.message.includes('No matching key')) {
log(`Pairing was already disconnected ${topic}`);
// we can ignore this error because it means that session was already disconnected
return;
}
throw e;
}
}

pairs.removePair(topic);
Expand Down

0 comments on commit 907b921

Please sign in to comment.