Skip to content

Commit 52aba0f

Browse files
[SDK] Skip chain switching for Coinbase Wallet if already on correct chain (#8453)
1 parent 9809d5c commit 52aba0f

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

.changeset/vast-nails-wash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Dont attempt chain switching for cb wallet if already connected to the right chain

packages/thirdweb/src/wallets/coinbase/coinbase-web.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,16 @@ async function switchChainCoinbaseWalletSDK(
474474
provider: ProviderInterface,
475475
chain: Chain,
476476
) {
477+
// check if chain is already connected
478+
const connectedChainId = (await provider.request({
479+
method: "eth_chainId",
480+
})) as string | number;
481+
const connectedChain = getCachedChain(normalizeChainId(connectedChainId));
482+
if (connectedChain?.id === chain.id) {
483+
// chain is already connected, no need to switch
484+
return;
485+
}
486+
477487
const chainIdHex = numberToHex(chain.id);
478488

479489
try {

0 commit comments

Comments
 (0)