diff --git a/src/web3/connectors/ledgerLive.ts b/src/web3/connectors/ledgerLive.ts index 9e0e5ece6..4b411b4ce 100644 --- a/src/web3/connectors/ledgerLive.ts +++ b/src/web3/connectors/ledgerLive.ts @@ -61,6 +61,12 @@ export class LedgerLiveConnector extends AbstractConnector { if (!this.supportedChainIds) { throw new Error("Supported chain ids are not defined.") } + // Removes all local storage entries that starts with "wc@2" + // This is a workaround for "Cannot convert undefined or null to object" + // error that sometime occur with WalletConnect + Object.keys(localStorage) + .filter((x) => x.startsWith("wc@2")) + .forEach((x) => localStorage.removeItem(x)) let account = "" const connectKit = await this.connectKitPromise const chainId = this.supportedChainIds[0] diff --git a/src/web3/connectors/walletConnect.ts b/src/web3/connectors/walletConnect.ts index b8c0ed45c..4ecf19ae4 100644 --- a/src/web3/connectors/walletConnect.ts +++ b/src/web3/connectors/walletConnect.ts @@ -82,6 +82,12 @@ export class WalletConnectConnector extends AbstractConnector { } public async activate(): Promise { + // Removes all local storage entries that starts with "wc@2" + // This is a workaround for "Cannot convert undefined or null to object" + // error that sometime occur with WalletConnect + Object.keys(localStorage) + .filter((x) => x.startsWith("wc@2")) + .forEach((x) => localStorage.removeItem(x)) if (!this.provider) { const chains = getSupportedChains(this.config) if (chains.length === 0) throw new Error("Chains not specified!")