Skip to content
Open
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
7 changes: 7 additions & 0 deletions .changeset/olive-moons-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@thirdweb-dev/wagmi-adapter": patch
---

Fix `getProvider` reading the last active chain from storage

`switchChain` persists the active chain under `thirdweb:active-chain` as a JSON-serialized `Chain` object, and `connect` reads it back with `JSON.parse(...)`. `getProvider` instead parsed the same value with `Number(...)`, which produces `NaN` for the stored object. Because `NaN` is falsy, `getProvider` silently fell back to chain `1` instead of the user's last active chain when auto-connecting. It now parses the value the same way `connect` does.
5 changes: 4 additions & 1 deletion packages/wagmi-adapter/src/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,10 @@ export function inAppWalletConnector(
},
getProvider: async (params) => {
const lastChainIdStr = await rawStorage?.getItem(activeChainIdKey);
const lastChainId = lastChainIdStr ? Number(lastChainIdStr) : undefined;
const lastChain = lastChainIdStr
? (JSON.parse(lastChainIdStr) as Chain)
: undefined;
const lastChainId = lastChain ? lastChain.id : undefined;
const chain = defineChain(
params?.chainId || args.smartAccount?.chain?.id || lastChainId || 1,
);
Expand Down
Loading