Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tasty-emus-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Fix add chain not triggering for certain wallets
33 changes: 14 additions & 19 deletions packages/thirdweb/src/wallets/injected/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,25 +348,20 @@
method: "wallet_switchEthereumChain",
params: [{ chainId: hexChainId }],
});
// biome-ignore lint/suspicious/noExplicitAny: TODO: fix any
} catch (e: any) {
} catch {
// if chain does not exist, add the chain
if (e?.code === 4902 || e?.data?.originalError?.code === 4902) {
const apiChain = await getChainMetadata(chain);
await provider.request({
method: "wallet_addEthereumChain",
params: [
{
chainId: hexChainId,
chainName: apiChain.name,
nativeCurrency: apiChain.nativeCurrency,
rpcUrls: getValidPublicRPCUrl(apiChain), // no client id on purpose here
blockExplorerUrls: apiChain.explorers?.map((x) => x.url),
},
],
});
} else {
throw e;
}
const apiChain = await getChainMetadata(chain);
await provider.request({
method: "wallet_addEthereumChain",
params: [
{
chainId: hexChainId,
chainName: apiChain.name,
nativeCurrency: apiChain.nativeCurrency,
rpcUrls: getValidPublicRPCUrl(apiChain), // no client id on purpose here
blockExplorerUrls: apiChain.explorers?.map((x) => x.url),
},
],
});

Check warning on line 365 in packages/thirdweb/src/wallets/injected/index.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/wallets/injected/index.ts#L353-L365

Added lines #L353 - L365 were not covered by tests
}
}
Loading