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

Jl/version v12 10.4/hotfix network version inpage provider #30109

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 16:48
@jiexi jiexi changed the base branch from Version-v12.10.4 to main February 4, 2025 16:56
@jiexi jiexi requested review from a team as code owners February 4, 2025 16:56
@jiexi jiexi changed the base branch from main to Version-v12.10.4 February 4, 2025 16:59
@jiexi
Copy link
Contributor Author

jiexi commented Feb 4, 2025

closed in favor of #30111

@jiexi jiexi closed this Feb 4, 2025
@jiexi jiexi deleted the jl/Version-v12-10.4/hotfix-network-version-inpage-provider branch February 4, 2025 17:11
@github-actions github-actions bot locked and limited conversation to collaborators Feb 4, 2025
@metamaskbot
Copy link
Collaborator

Builds ready [ef7c966]
Page Load Metrics (1824 ± 56 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint31320321681435209
domContentLoaded15851995179212259
load16282017182411756
domInteractive28117482311
backgroundConnect979282210
firstReactRender16106362512
getState55514147
initialActions01000
loadScripts11591495132710752
setupStore673222211
uiStartup18242576210717684

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants