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/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
Loading