Skip to content

fix(ethers,ethers5): resolve walletProvider after account switch in modal#5663

Open
Khizr97 wants to merge 3 commits into
chore/khizr-fixes-2from
chore/khizr-fixes-2-REOWN-4657
Open

fix(ethers,ethers5): resolve walletProvider after account switch in modal#5663
Khizr97 wants to merge 3 commits into
chore/khizr-fixes-2from
chore/khizr-fixes-2-REOWN-4657

Conversation

@Khizr97
Copy link
Copy Markdown
Contributor

@Khizr97 Khizr97 commented May 11, 2026

Summary

  • In connect()'s early-return path (used when switching accounts in the modal), connector.provider was never initialised for connectors backed by ethersProviders (injected, coinbaseWallet, baseAccount, safe)
  • This caused the base-client's accountChanged handler to skip syncProvider() — leaving useAppKitProvider returning a stale provider
  • Fix resolves connector.provider from ethersProviders before emitting accountChanged, when it is not already set
  • Applies to both @reown/appkit-adapter-ethers and @reown/appkit-adapter-ethers5

Root Cause

appkit-base-client.ts only calls syncProvider() in the accountChanged handler when connector?.provider is truthy. The early-return path in connect() emits the event before initialising the provider, so the guard is never satisfied.

Test plan

  • New unit test: provider resolved from ethersProviders when connector.provider is undefined in early-return path
  • New unit test: existing connector.provider is preserved (no re-initialisation) when already set
  • All 72 Ethers adapter tests pass
  • All 46 Ethers5 adapter tests pass

Fixes: REOWN-4657

🤖 Generated with Claude Code

Khizr97 and others added 3 commits May 11, 2026 21:38
…in connect early-return path

When switching accounts in the modal, connect() takes an early-return path for
existing connections but never initialised connector.provider. This caused the
base-client's accountChanged handler to skip syncProvider() (which guards on
connector?.provider), leaving useAppKitProvider stale.

Fix: resolve connector.provider from ethersProviders before emitting the event
when it is not yet set. Applies to both ethers and ethers5 adapters.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…tch fix

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@linear
Copy link
Copy Markdown

linear Bot commented May 11, 2026

REOWN-4657

@vercel
Copy link
Copy Markdown

vercel Bot commented May 11, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
appkit-demo Ready Ready Preview, Comment May 11, 2026 4:43pm
appkit-gallery Ready Ready Preview, Comment May 11, 2026 4:43pm
appkit-headless-sample-app Ready Ready Preview, Comment May 11, 2026 4:43pm
appkit-laboratory Ready Ready Preview, Comment May 11, 2026 4:43pm
9 Skipped Deployments
Project Deployment Actions Updated (UTC)
appkit-basic-example Ignored Ignored May 11, 2026 4:43pm
appkit-basic-sign-client-example Ignored Ignored May 11, 2026 4:43pm
appkit-basic-up-example Ignored Ignored May 11, 2026 4:43pm
appkit-ethers5-bera Ignored Ignored May 11, 2026 4:43pm
appkit-nansen-demo Ignored Ignored May 11, 2026 4:43pm
appkit-wagmi-cdn-example Ignored Ignored May 11, 2026 4:43pm
ethereum-provider-wagmi-example Ignored Ignored May 11, 2026 4:43pm
next-wagmi-solana-bitcoin-example Ignored Ignored May 11, 2026 4:43pm
vue-wagmi-example Ignored Ignored May 11, 2026 4:43pm

Request Review

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 11, 2026

🦋 Changeset detected

Latest commit: 3301083

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 26 packages
Name Type
@reown/appkit-adapter-ethers Patch
@reown/appkit-adapter-ethers5 Patch
@reown/appkit-cdn Patch
@reown/appkit Patch
@reown/appkit-adapter-bitcoin Patch
@reown/appkit-adapter-solana Patch
@reown/appkit-adapter-ton Patch
@reown/appkit-adapter-tron Patch
@reown/appkit-adapter-wagmi Patch
@reown/appkit-common Patch
@reown/appkit-universal-connector Patch
@reown/appkit-ui Patch
@reown/appkit-controllers Patch
@reown/appkit-core Patch
@reown/appkit-utils Patch
@reown/appkit-scaffold-ui Patch
@reown/appkit-polyfills Patch
@reown/appkit-wallet Patch
@reown/appkit-siwe Patch
@reown/appkit-siwx Patch
@reown/appkit-wallet-button Patch
@reown/appkit-experimental Patch
@reown/appkit-testing Patch
@reown/appkit-cli Patch
@reown/appkit-pay Patch
@reown/appkit-codemod Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment on lines +465 to +467
if (ethersProvider) {
await ethersProvider.initialize()
connector.provider = (await ethersProvider.getProvider()) as Provider | undefined
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the initialize returns the provider? If so it could be like:

Suggested change
if (ethersProvider) {
await ethersProvider.initialize()
connector.provider = (await ethersProvider.getProvider()) as Provider | undefined
if (ethersProvider) {
connector.provider = await ethersProvider.initialize()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants