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

Remove deprecated properties, networkChanged event, and offline send() net_version support #306

Merged
merged 12 commits into from
Mar 12, 2024

Conversation

jiexi
Copy link
Contributor

@jiexi jiexi commented Mar 6, 2024

This PR removes properties that are not officially documented and should not have been exposed in the first place. It also removes support for the networkChange event and offline net_version resolution which will allow us to remove the last remaining chunk of networkId usage in Extension. These have all been properly deprecated, the most recent deprecations being 180 days old now.

Removes the following:

  • window.ethereum.chainId
  • window.ethereum.networkVersion
  • window.ethereum.selectedAddress
  • networkChanged event
  • offline net_version support in window.ethereum.send()

See: https://github.com/MetaMask/MetaMask-planning/issues/2195
See: MetaMask/metamask-improvement-proposals#23
See: https://github.com/MetaMask/MetaMask-planning/issues/2176
See: MetaMask/metamask-extension#23375

Before

Screenshot 2024-03-07 at 10 16 08 AM

After

Screenshot 2024-03-07 at 10 23 54 AM

Comment on lines 170 to 161
// Deprecated Properties
// Private Properties
//====================

get chainId(): string | null {
if (!this._sentWarnings.chainId) {
this._log.warn(messages.warnings.chainIdDeprecation);
this._sentWarnings.chainId = true;
}
return super.chainId;
}

get networkVersion(): string | null {
if (!this._sentWarnings.networkVersion) {
this._log.warn(messages.warnings.networkVersionDeprecation);
this._sentWarnings.networkVersion = true;
}
return this.#networkVersion;
throw new Error(messages.errors.invalidPropertyChainId());
}

get selectedAddress(): string | null {
if (!this._sentWarnings.selectedAddress) {
this._log.warn(messages.warnings.selectedAddressDeprecation);
this._sentWarnings.selectedAddress = true;
}
return super.selectedAddress;
throw new Error(messages.errors.invalidPropertySelectedAddress());
Copy link
Contributor Author

@jiexi jiexi Mar 6, 2024

Choose a reason for hiding this comment

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

These getter overrides must exist in order to prevent publicly exposing them via inheritance from the BaseProvider. We cannot just make those properties private in the BaseProvider themselves because the subclasses still need access to them.

Copy link
Contributor

@legobeat legobeat Mar 7, 2024

Choose a reason for hiding this comment

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

Could they be made protected, if anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried making the BaseProvider getters protected and removing the overrides in MetaMaskInpageProvider, but the properties are still accessible. If i add protected to the MetaMaskInpageProvider getters, it does nothing and the properties are also still accessible

});
});
});

it('handles chain changes with intermittent disconnection', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we don't have networkId anymore, nor the notion of temporary disconnection/switching when networkId is set to loading

Comment on lines -198 to -202
if (networkVersion === 'loading') {
this._handleDisconnect(true);
} else {
super._handleChainChanged({ chainId });
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we don't have networkId anymore, nor the notion of temporary disconnection/switching when networkId is set to loading

@jiexi jiexi marked this pull request as ready for review March 7, 2024 00:29
@jiexi jiexi requested a review from a team as a code owner March 7, 2024 00:29
@shanejonas
Copy link
Contributor

shanejonas commented Mar 7, 2024

Total sidebar here but

Screenshot 2024-03-06 at 3 43 05 PM

null {id: undefined, jsonrpe: '2.0', result: '100'}

Wow looks like send doesnt generate an ID like how we have request set up. I do like that send leaves it up to the client to deal with the ID.

shanejonas
shanejonas previously approved these changes Mar 7, 2024
@jiexi jiexi changed the title Remove deprecated properties, networkChanged event, and send() net_version support Remove deprecated properties, networkChanged event, and offline send() net_version support Mar 7, 2024
return super.chainId;
}

get networkVersion(): string | null {
Copy link
Contributor

Choose a reason for hiding this comment

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

any reason we're not throwing a new Error(messages.errors.invalidPropertyNetworkVersion()) for this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mostly because networkVersion doesn't require a getter override, so it's possible to remove it completely without issue unlike the chainId and selectedAddress getters. I am also not throwing when networkChanged are listened to.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I agree. If we only throw for some of the things we've removed but not others, then couldn't it possibly be surprising?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Throwing error for networkVersion here 10ee3a3

@@ -62,11 +62,6 @@ export function initializeProvider({
const proxiedProvider = new Proxy(provider, {
Copy link

Choose a reason for hiding this comment

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

its not clear to me why this is a proxy, nor what the deleteProperty problem is.

When we use this in extension, the return value is never used, and I dont see anywhere that we are setting a new target, but maybe Im missing something. Heres the extension place im referring to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe it's a proxy to override deleteProperty: () => true,

BelfordZ
BelfordZ previously approved these changes Mar 9, 2024
mcmire
mcmire previously approved these changes Mar 12, 2024
Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

One comment, but this change makes sense to me regardless.

…operties-events' into jl/mmp-2195/remove-deprecated-properties-events
@jiexi jiexi dismissed stale reviews from BelfordZ and shanejonas via 7477e62 March 12, 2024 21:24
@jiexi jiexi merged commit 25b7e4b into main Mar 12, 2024
18 checks passed
@jiexi jiexi deleted the jl/mmp-2195/remove-deprecated-properties-events branch March 12, 2024 21:47
jiexi added a commit that referenced this pull request Mar 18, 2024
…ne send() net_version support (#306)"

This reverts commit 25b7e4b.
jiexi added a commit that referenced this pull request Mar 19, 2024
#312)

Revert "Remove deprecated properties, networkChanged event, and offline send() net_version support (#306)"

This reverts commit 25b7e4b.
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.

6 participants