Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: signing with walletConnect not working when switching chains in ethers/ethers5 #3727

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

magiziz
Copy link
Contributor

@magiziz magiziz commented Jan 23, 2025

Description

Fixed an issue where signing was not working when switching chains using WalletConnect with ethers/ethers5 adapters.

The reason is because we never called wallet_switchEthereumChain on the provider when switching chain.

Type of change

  • Chore (non-breaking change that addresses non-functional tasks, maintenance, or code quality improvements)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Associated Issues

For Linear issues: Closes APKT-2102

Showcase (Optional)

Screenshot 2025-01-23 at 14 54 21

Checklist

  • Code in this PR is covered by automated tests (Unit tests, E2E tests)
  • My changes generate no new warnings
  • I have reviewed my own code
  • I have filled out all required sections
  • I have tested my changes on the preview link
  • Approver of this PR confirms that the changes are tested on the preview link

Copy link

linear bot commented Jan 23, 2025

Copy link

changeset-bot bot commented Jan 23, 2025

🦋 Changeset detected

Latest commit: 5c76ab9

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

This PR includes changesets to release 19 packages
Name Type
@reown/appkit-adapter-ethers5 Patch
@reown/appkit-adapter-ethers Patch
@reown/appkit-adapter-bitcoin Patch
@reown/appkit-adapter-solana Patch
@reown/appkit-adapter-wagmi Patch
@reown/appkit Patch
@reown/appkit-utils Patch
@reown/appkit-cdn Patch
@reown/appkit-cli Patch
@reown/appkit-common Patch
@reown/appkit-core Patch
@reown/appkit-experimental Patch
@reown/appkit-polyfills Patch
@reown/appkit-scaffold-ui Patch
@reown/appkit-siwe Patch
@reown/appkit-siwx Patch
@reown/appkit-ui Patch
@reown/appkit-wallet Patch
@reown/appkit-wallet-button 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

Copy link

vercel bot commented Jan 23, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
appkit-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 23, 2025 4:09pm
appkit-laboratory ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 23, 2025 4:09pm
3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
appkit-vue-solana ⬜️ Ignored (Inspect) Jan 23, 2025 4:09pm
appkit-wagmi-cdn-example ⬜️ Ignored (Inspect) Jan 23, 2025 4:09pm
vue-wagmi-example ⬜️ Ignored (Inspect) Jan 23, 2025 4:09pm

providerType: 'WALLET_CONNECT'
})

expect(mockWalletConnectProvider.setDefaultChain).toHaveBeenCalledWith('eip155:1')
Copy link
Contributor Author

@magiziz magiziz Jan 23, 2025

Choose a reason for hiding this comment

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

We don't need to set setDefaultChain because it's done after we switch chain in universal provider. Talked with Gancho about this.

Copy link
Contributor

github-actions bot commented Jan 23, 2025

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 68.25% 19602 / 28720
🔵 Statements 68.25% 19602 / 28720
🔵 Functions 59.5% 1718 / 2887
🔵 Branches 79.9% 3488 / 4365
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/adapters/ethers/src/client.ts 48.47% 55.73% 63.63% 48.47% 43-101, 117-118, 149-150, 163-186, 189-199, 212-249, 254-255, 262-279, 284-291, 294-316, 319-324, 335-336, 343-348, 362-363, 372-373, 389-399, 402-429, 433-434, 447-448, 450, 472-473, 477, 491, 508-510, 517-521, 561-562, 566-571, 580-598, 604-605, 609-614, 623-624, 635-636
packages/adapters/ethers5/src/client.ts 47.58% 56.14% 63.63% 47.58% 44-102, 118-119, 150-151, 164-187, 190-200, 213-249, 254-255, 262-279, 284-291, 294-316, 319-324, 334-335, 342-347, 361-362, 371-372, 388-415, 418-428, 432-433, 446-447, 449, 474-475, 479, 493, 510-512, 519-523, 561-574, 582-600, 606-607, 611-616, 625-626, 637-638
packages/appkit/exports/constants.ts 100% 100% 100% 100%
Generated in workflow #9114 for commit 5c76ab9 by the Vitest Coverage Report Action

@@ -543,7 +543,7 @@ export class EthersAdapter extends AdapterBlueprint {
public override async switchNetwork(params: AdapterBlueprint.SwitchNetworkParams): Promise<void> {
const { caipNetwork, provider, providerType } = params

if (providerType === 'AUTH' || providerType === 'WALLET_CONNECT') {
if (providerType === 'AUTH') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

don't you need to change the parent class implementation too? I remember it handled wc cases as well

Copy link
Contributor Author

@magiziz magiziz Jan 23, 2025

Choose a reason for hiding this comment

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

I want to keep it as is because solana adapter uses it and works fine

@tomiir
Copy link
Collaborator

tomiir commented Jan 23, 2025

can we add an e2e given it's a wc connection ? 🙏
how come tests did not catch this?

@@ -543,7 +543,7 @@ export class EthersAdapter extends AdapterBlueprint {
public override async switchNetwork(params: AdapterBlueprint.SwitchNetworkParams): Promise<void> {
const { caipNetwork, provider, providerType } = params

if (providerType === 'AUTH' || providerType === 'WALLET_CONNECT') {
if (providerType === 'AUTH') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this because we are doing switch network in universal provider adapter for WC option?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah

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.

3 participants