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: cp-12.10.4 hotfix network version / unresponsive network inpage provider #30111

Merged
merged 5 commits into from
Feb 4, 2025

Conversation

jiexi
Copy link
Contributor

@jiexi jiexi commented Feb 4, 2025

Description

Previously the inpage provider would withhold events for chainChanged events (and property value updates, i.e. window.ethereum.chainId and .networkVersion) when the dapp's network was changed to an rpc endpoint that was unresponsive or did not support net_version. The dapp would instead receive a disconnect event.

Now the inpage provider always emits chainChanged and networkChanged events (and exposes the correct values on window.ethereum.chainId and .networkVersion) when the selected network for the dapp has changed regardless of if the network being changed to is responsive or if it supports net_version requests. It does this by having the wallet send a loading for networkVersion when it cannot be resolved (same behavior as before) AND a new isConnected property in the metamask_getProviderState request and metamask_chainChanged events (these are different from the events emittted by window.ethereum). isConnected is derived from whether the NetworkController.state.networkMetadata[].status value is the Available constant.

Open in GitHub Codespaces

Related issues

See: #29936
Providers patch from commit (d919ab6b): MetaMask/providers#404

Manual testing steps

window.ethereum.on('accountsChanged', (data) => console.log('accountsChanged', data))
window.ethereum.on('chainChanged', (data) => console.log('chainChanged', data))
window.ethereum.on('networkChanged', (data) => console.log('networkChanged', data))
window.ethereum.on('connect', (data) => console.log('connect', data))
window.ethereum.on('disconnect', (data) => console.log('disconnect', data))
  1. Go to a webpage. Enter the following in console
  2. Change to Linea, see that the correct values are emitted for the chainChanged and networkChanged events
  3. Change to Sepolia, see that the correct values are emitted for the chainChanged and networkChanged events
  4. Change to a network that is non-responsive, see that chainChanged emits with the correct chainId, but networkChanged emits with a null value, AND there is a disconnect event emitted
  5. Change back to a working network, see that the correct values are emitted for the chainChanged and networkChanged events, AND there is a connect event emitted with the new chainId
  6. Do the same above with a responsive network that does not have net_version implemented. Se that the correct values are emitted for the chainChanged, that networkChanged emits null, and that there is no disconnect event emitted

Screenshots/Recordings

Before

After

Screenshot 2025-02-04 at 8 34 13 AM

Screenshot 2025-02-04 at 8 39 33 AM

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.

Copy link
Contributor

github-actions bot commented Feb 4, 2025

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.

@jiexi jiexi marked this pull request as ready for review February 4, 2025 17:11
Copy link

socket-security bot commented Feb 4, 2025

Updated dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@metamask/[email protected] 🔁 npm/@metamask/[email protected] None 0 500 kB metamaskbot

View full report↗︎

Copy link
Contributor

@itsyoboieltr itsyoboieltr left a comment

Choose a reason for hiding this comment

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

LGTM!

@metamaskbot
Copy link
Collaborator

Builds ready [ffb5a79]
Page Load Metrics (1759 ± 72 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint15002084175615072
domContentLoaded14892066173014971
load15042089175915072
domInteractive25133452713
backgroundConnect1174342110
firstReactRender1568312010
getState55419199
initialActions01000
loadScripts10521546126812560
setupStore75918189
uiStartup17702383198917685
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 139 Bytes (0.00%)
  • ui: 214 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Copy link
Contributor

@adonesky1 adonesky1 left a comment

Choose a reason for hiding this comment

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

LGTM! Tested and works as expected!

@adonesky1 adonesky1 added this pull request to the merge queue Feb 4, 2025
Merged via the queue into main with commit af80c7b Feb 4, 2025
71 checks passed
@adonesky1 adonesky1 deleted the jl/hotfix-network-version-inpage-provider branch February 4, 2025 19:08
@github-actions github-actions bot locked and limited conversation to collaborators Feb 4, 2025
@metamaskbot metamaskbot added the release-12.13.0 Issue or pull request that will be included in release 12.13.0 label Feb 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.13.0 Issue or pull request that will be included in release 12.13.0 team-wallet-api-platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants