Skip to content

Commit

Permalink
Remove deprecated properties warning (#360)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiexi authored Sep 6, 2024
1 parent 9aa39a6 commit 1f047a2
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 58 deletions.
6 changes: 3 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ const baseConfig = {
// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
global: {
branches: 65.43,
branches: 64.95,
functions: 65.65,
lines: 66.74,
statements: 66.81,
lines: 66.04,
statements: 66.13,
},
},

Expand Down
30 changes: 0 additions & 30 deletions src/MetaMaskInpageProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1084,16 +1084,6 @@ describe('MetaMaskInpageProvider: Miscellanea', () => {
).provider;
});

it('should warn the first time chainId is accessed', async () => {
const consoleWarnSpy = jest.spyOn(globalThis.console, 'warn');

expect(provider.chainId).toBe('0x5');
expect(consoleWarnSpy).toHaveBeenCalledWith(
messages.warnings.chainIdDeprecation,
);
expect(consoleWarnSpy).toHaveBeenCalledTimes(1);
});

it('should not allow chainId to be modified', () => {
expect(() => (provider.chainId = '0x539')).toThrow(
'Cannot set property chainId',
Expand All @@ -1115,16 +1105,6 @@ describe('MetaMaskInpageProvider: Miscellanea', () => {
).provider;
});

it('should warn the first time networkVersion is accessed', async () => {
const consoleWarnSpy = jest.spyOn(globalThis.console, 'warn');

expect(provider.networkVersion).toBe('5');
expect(consoleWarnSpy).toHaveBeenCalledWith(
messages.warnings.networkVersionDeprecation,
);
expect(consoleWarnSpy).toHaveBeenCalledTimes(1);
});

it('should not allow networkVersion to be modified', () => {
expect(() => (provider.networkVersion = '1337')).toThrow(
'Cannot set property networkVersion',
Expand All @@ -1146,16 +1126,6 @@ describe('MetaMaskInpageProvider: Miscellanea', () => {
).provider;
});

it('should warn the first time selectedAddress is accessed', async () => {
const consoleWarnSpy = jest.spyOn(globalThis.console, 'warn');

expect(provider.selectedAddress).toBe('0xdeadbeef');
expect(consoleWarnSpy).toHaveBeenCalledWith(
messages.warnings.selectedAddressDeprecation,
);
expect(consoleWarnSpy).toHaveBeenCalledTimes(1);
});

it('should not allow selectedAddress to be modified', () => {
expect(() => (provider.selectedAddress = '0x12345678')).toThrow(
'Cannot set property selectedAddress',
Expand Down
22 changes: 1 addition & 21 deletions src/MetaMaskInpageProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ export type MetaMaskInpageProviderOptions = {
} & Partial<Omit<StreamProviderOptions, 'rpcMiddleware'>>;

type SentWarningsState = {
// properties
chainId: boolean;
networkVersion: boolean;
selectedAddress: boolean;
// methods
enable: boolean;
experimentalMethods: boolean;
Expand All @@ -58,10 +54,6 @@ export const MetaMaskInpageProviderStreamName = 'metamask-provider';

export class MetaMaskInpageProvider extends AbstractStreamProvider {
protected _sentWarnings: SentWarningsState = {
// properties
chainId: false,
networkVersion: false,
selectedAddress: false,
// methods
enable: false,
experimentalMethods: false,
Expand Down Expand Up @@ -167,30 +159,18 @@ export class MetaMaskInpageProvider extends AbstractStreamProvider {
}

//====================
// Deprecated Properties
// Read-only 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;
}

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

Expand Down
4 changes: 0 additions & 4 deletions src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ const messages = {
`MetaMask: Connected to chain with ID "${chainId}".`,
},
warnings: {
// deprecated properties
chainIdDeprecation: `MetaMask: 'ethereum.chainId' is deprecated and may be removed in the future. Please use the 'eth_chainId' RPC method instead.\nFor more information, see: https://github.com/MetaMask/metamask-improvement-proposals/discussions/23`,
networkVersionDeprecation: `MetaMask: 'ethereum.networkVersion' is deprecated and may be removed in the future. Please use the 'net_version' RPC method instead.\nFor more information, see: https://github.com/MetaMask/metamask-improvement-proposals/discussions/23`,
selectedAddressDeprecation: `MetaMask: 'ethereum.selectedAddress' is deprecated and may be removed in the future. Please use the 'eth_accounts' RPC method instead.\nFor more information, see: https://github.com/MetaMask/metamask-improvement-proposals/discussions/23`,
// deprecated methods
enableDeprecation: `MetaMask: 'ethereum.enable()' is deprecated and may be removed in the future. Please use the 'eth_requestAccounts' RPC method instead.\nFor more information, see: https://eips.ethereum.org/EIPS/eip-1102`,
sendDeprecation: `MetaMask: 'ethereum.send(...)' is deprecated and may be removed in the future. Please use 'ethereum.sendAsync(...)' or 'ethereum.request(...)' instead.\nFor more information, see: https://eips.ethereum.org/EIPS/eip-1193`,
Expand Down

0 comments on commit 1f047a2

Please sign in to comment.