fix: update inpage provider chainChanged
, networkChanged
, connect
, and disconnect
events
#29936
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 supportnet_version
. The dapp would instead receive adisconnect
event.Now the inpage provider always emits
chainChanged
andnetworkChanged
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 supportsnet_version
requests. It does this by having the wallet send aloading
fornetworkVersion
when it cannot be resolved (same behavior as before) AND a newisConnected
property in themetamask_getProviderState
request andmetamask_chainChanged
events (these are different from the events emittted by window.ethereum).isConnected
is derived from whether theNetworkController.state.networkMetadata[].status
value is the Available constant.NOTE: this PR still needs the
@metamask/providers
changes linked below before it can be merged. To test manually you will need to manually build and copy the package dist into your local extension build node_modulesRelated issues
Needs: MetaMask/providers#404
See: https://github.com/orgs/MetaMask/projects/146/views/1?filterQuery=label%3A%22team-wallet-api-platform%22+-status%3ABacklog&pane=issue&itemId=95374156&issue=MetaMask%7CMetaMask-planning%7C4039
Manual testing steps
networkChanged
should be emitted by the inpage provider withnull
disconnect
event should be fired ANDchainChanged
andnetworkChanged
should fire as well if those values have changedconnect
event should be fired ANDchainChanged
andnetworkChanged
should fire as well if those values have changeddisconnect
event should be fired andnetworkChanged
should return the previously cached valueScreenshots/Recordings
Before
Screen.Recording.2025-01-27.at.4.13.46.PM.mov
After
Screen.Recording.2025-01-27.at.3.53.39.PM.mov
Pre-merge author checklist
Pre-merge reviewer checklist