Skip to content

Commit

Permalink
[SDK] Fix: Undefined chain ID on eip1193 provider input (#5871)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregfromstl authored Jan 5, 2025
1 parent a3f59e5 commit 1e8ddcb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/yellow-experts-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

SDK: Gracefully ignore chain with no chain ID in `fromEip1193Provider`
18 changes: 18 additions & 0 deletions packages/thirdweb/src/adapters/eip1193/from-eip1193.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,24 @@ describe("fromProvider", () => {
expect(chain).toBe(ANVIL_CHAIN);
});

test("should handle connection with no chainId", async () => {
const wallet = fromProvider({
provider: {
...mockProvider,
request: () => Promise.resolve([mockAccount.address]),
},
});

await wallet.connect({
client: TEST_CLIENT,
chain: {
...ANVIL_CHAIN,
id: undefined,
// biome-ignore lint/suspicious/noExplicitAny: Testing unexpected input data
} as any,
});
});

test("should reset state on disconnect", async () => {
const wallet = fromProvider({
provider: {
Expand Down
3 changes: 2 additions & 1 deletion packages/thirdweb/src/wallets/injected/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ export async function connectEip1193Wallet({
chain && chain.id === chainId ? chain : getCachedChain(chainId);

// if we want a specific chainId and it is not the same as the provider chainId, trigger switchChain
if (chain && chain.id !== chainId) {
// we check for undefined chain ID since some chain-specific wallets like Abstract will not send a chain ID on connection
if (chain && typeof chain.id !== "undefined" && chain.id !== chainId) {
await switchChain(provider, chain);
connectedChain = chain;
}
Expand Down

0 comments on commit 1e8ddcb

Please sign in to comment.