From 2f49db2108ff8e016f7fe3be08bc2480fd4c06ea Mon Sep 17 00:00:00 2001 From: lbqds Date: Tue, 9 Jan 2024 19:43:05 +0800 Subject: [PATCH] Fix no matching keychain error --- packages/walletconnect/src/provider.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/walletconnect/src/provider.ts b/packages/walletconnect/src/provider.ts index f5e227821..b888b3fed 100644 --- a/packages/walletconnect/src/provider.ts +++ b/packages/walletconnect/src/provider.ts @@ -163,10 +163,13 @@ export class WalletConnectProvider extends SignerProvider { await this.providerOpts.onDisconnected() - await this.client.disconnect({ - topic: this.session.topic, - reason: getSdkError('USER_DISCONNECTED') - }) + const reason = getSdkError('USER_DISCONNECTED') + try { + await this.client.disconnect({ topic: this.session.topic, reason }) + } catch (error) { + await this.client.session.delete(this.session.topic, reason) + await this.client.core.crypto.deleteSymKey(this.session.topic) + } this.session = undefined this.account = undefined } @@ -331,8 +334,9 @@ export class WalletConnectProvider extends SignerProvider { const sessionKeys = this.client.session.keys for (let i = sessionKeys.length - 1; i >= 0; i--) { const session = this.client.session.get(sessionKeys[`${i}`]) + const hasKeyChain = this.client.core.crypto.keychain.has(session.topic) const chains = getChainsFromNamespaces(session.namespaces, [PROVIDER_NAMESPACE]) - if (this.sameChains(chains, [this.permittedChain])) { + if (this.sameChains(chains, [this.permittedChain]) && hasKeyChain) { this.session = session return }