[Wallets] Fix switchChain in WCV2 connector (#1214)

This commit is contained in:
iketw
2023-06-21 16:28:16 +00:00
committed by GitHub
parent 3ce5f9a0c3
commit 1ce8558df4
2 changed files with 12 additions and 3 deletions
+7
View File
@@ -0,0 +1,7 @@
---
"@thirdweb-dev/wallets": patch
---
[Wallets] Fix switchChain in WCV2 connector
WCV2 `blockExplorerUrls` field receives an array of urls but we were passing an array of blockExplorer objects, so adding a new chain was failing, hence switching chains was failing
@@ -250,17 +250,18 @@ export class WalletConnectConnector extends WagmiConnector<
const isChainApproved = namespaceChains.includes(chainId);
if (!isChainApproved && namespaceMethods.includes(ADD_ETH_CHAIN_METHOD)) {
const blockExplorerUrls = chain.explorers?.length
? { blockExplorerUrls: [chain.explorers[0].url] }
: {};
await provider.request({
method: ADD_ETH_CHAIN_METHOD,
params: [
{
chainId: utils.hexValue(chain.chainId),
blockExplorerUrls: [
chain.explorers?.length ? chain.explorers[0] : undefined,
],
chainName: chain.name,
nativeCurrency: chain.nativeCurrency,
rpcUrls: [...chain.rpc],
...blockExplorerUrls,
},
],
});
@@ -282,6 +283,7 @@ export class WalletConnectConnector extends WagmiConnector<
if (/user rejected request/i.test(message)) {
throw new UserRejectedRequestError(error);
}
throw new SwitchChainError(error);
}
}