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: switch chain with walletconnect #10394

Merged
merged 7 commits into from
Aug 14, 2024

Conversation

ignaciosantise
Copy link
Contributor

@ignaciosantise ignaciosantise commented Jul 24, 2024

Description

MetaMask calls updateSession multiple times when the user tries to switch chain from the dapp. This causes the dapp to receive a chainChanged event before receiving the updated session from the wallet.

  • Compare addresses in lowercase
  • Parse chainId correctly
  • Clearing state variables of BackgroundBridge when the session is disconnected
  • Bumped walletconnect sdk versions to latest

Related issues

Fixes:

Manual testing steps

  1. Go to https://lab.web3modal.com/library/ethers/ with an iPhone
  2. Press the "Connect Wallet" button and select "Metamask"
  3. Press "Open" to open MetaMask (if applies)
  4. Accept the session proposal
  5. Go back to the browser
  6. Switch chain to Polygon (chain must be Already added as know network in Metamask)
  7. Go to MetaMask and accept the switch popup
  8. Go back to the browser and see there is a new redirect popup, which causes issues in the Wallet. The popup shouldn't be there

Screenshots/Recordings

Before

RPReplay_Final1721854496.mov

After

mm.solved.mov

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

…ome state variables of BackgroundBridge when disconnecting
Copy link
Contributor

github-actions bot commented Jul 24, 2024

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@ignaciosantise
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

app/core/BackgroundBridge/BackgroundBridge.js Outdated Show resolved Hide resolved
app/core/BackgroundBridge/BackgroundBridge.js Show resolved Hide resolved
@ignaciosantise ignaciosantise marked this pull request as ready for review July 25, 2024 18:30
@ignaciosantise ignaciosantise requested review from a team as code owners July 25, 2024 18:30
@andreahaku andreahaku added team-sdk SDK team WalletConnect WalletConnect related issue or bug labels Aug 1, 2024
@andreahaku andreahaku self-assigned this Aug 1, 2024
andreahaku
andreahaku previously approved these changes Aug 2, 2024
Copy link
Contributor

@andreahaku andreahaku left a comment

Choose a reason for hiding this comment

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

LGTM

@andreahaku andreahaku added needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) needs-qa Any New Features that needs a full manual QA prior to being added to a release. release-7.30.0 Issue or pull request that will be included in release 7.30.0 and removed needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) labels Aug 2, 2024
@enesozturk
Copy link

Hey @andreahaku, what are the next steps to get the PRs merged and published? 🙏

@andreahaku
Copy link
Contributor

Hey @andreahaku, what are the next steps to get the PRs merged and published? 🙏

it needs to be QAd by our engineers. When it's done we can merge it. Thanks

@christopherferreira9
Copy link
Contributor

@ignaciosantise
Is it normal that this only works on the first switching?

Screen.Recording.2024-08-14.at.17.19.48.mov

@ignaciosantise
Copy link
Contributor Author

@christopherferreira9 yes, to receive a new switch event on MM you need to send a request, like Personal Sign.

This is internally handled by the se-sdk.

@ganchoradkov
Copy link

@ignaciosantise Is it normal that this only works on the first switching?

Screen.Recording.2024-08-14.at.17.19.48.mov

Hey @christopherferreira9, this is the expected behaviour. The reason why you get prompt to accept the switch initially is because polygon (in this example) is not approved in the session. The wallet receives the request, updates the session with this new chain (polygon) and emits chainChanged event. The switch to ethereum is done only locally since it is already approved in the session. If you change again to polygon, it will be local change as well so you won't receive request in the wallet. If you change to 3rd chain though, you will again get request so the wallet can update the session.

Hope this context helps!

@christopherferreira9 christopherferreira9 added the Run Smoke E2E Triggers smoke e2e on Bitrise label Aug 14, 2024
@christopherferreira9 christopherferreira9 added QA in Progress QA has started on the feature. and removed needs-qa Any New Features that needs a full manual QA prior to being added to a release. labels Aug 14, 2024
@christopherferreira9
Copy link
Contributor

@ignaciosantise Is it normal that this only works on the first switching?
Screen.Recording.2024-08-14.at.17.19.48.mov

Hey @christopherferreira9, this is the expected behaviour. The reason why you get prompt to accept the switch initially is because polygon (in this example) is not approved in the session. The wallet receives the request, updates the session with this new chain (polygon) and emits chainChanged event. The switch to ethereum is done only locally since it is already approved in the session. If you change again to polygon, it will be local change as well so you won't receive request in the wallet. If you change to 3rd chain though, you will again get request so the wallet can update the session.

Hope this context helps!

Thank you for the reply. iOS and Android look good.
Tested with both deeplink and QR code session for both platforms.

Copy link
Contributor

@andreahaku andreahaku left a comment

Choose a reason for hiding this comment

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

LGTM

@christopherferreira9 christopherferreira9 added QA Passed A successful QA run through has been done and removed QA in Progress QA has started on the feature. labels Aug 14, 2024
Copy link
Contributor

@sethkfman sethkfman left a comment

Choose a reason for hiding this comment

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

LGTM

@sethkfman sethkfman merged commit c317aba into MetaMask:main Aug 14, 2024
35 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Aug 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
external-contributor QA Passed A successful QA run through has been done release-7.30.0 Issue or pull request that will be included in release 7.30.0 Run Smoke E2E Triggers smoke e2e on Bitrise team-sdk SDK team WalletConnect WalletConnect related issue or bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

8 participants