Skip to content

Commit

Permalink
add networkVersion error
Browse files Browse the repository at this point in the history
  • Loading branch information
jiexi committed Mar 12, 2024
1 parent 85335f4 commit 10ee3a3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
6 changes: 3 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ const baseConfig = {
coverageThreshold: {
global: {
branches: 61.45,
functions: 63.15,
lines: 63.41,
statements: 63.48,
functions: 63.91,
lines: 63.59,
statements: 63.65,
},
},

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

describe('networkVersion', () => {
let provider: any | MetaMaskInpageProvider;

beforeEach(async () => {
provider = (await getInitializedProvider()).provider;
});

it('should throw an error when accessing networkVersion', () => {
expect(() => provider.networkVersion).toThrow(
`'ethereum.networkVersion' has been removed`,
);
});
});

describe('selectedAddress', () => {
let provider: any | MetaMaskInpageProvider;

Expand Down
4 changes: 4 additions & 0 deletions src/MetaMaskInpageProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ export class MetaMaskInpageProvider extends AbstractStreamProvider {
throw new Error(messages.errors.invalidPropertyChainId());
}

get networkVersion(): string | null {
throw new Error(messages.errors.invalidPropertyNetworkVersion());
}

get selectedAddress(): string | null {
throw new Error(messages.errors.invalidPropertySelectedAddress());
}
Expand Down
2 changes: 2 additions & 0 deletions src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const messages = {
`'args.logger' must include required method '${method}'.`,
invalidPropertyChainId: () =>
`MetaMask: 'ethereum.chainId' has been removed. Please use the 'eth_chainId' RPC method instead.\nFor more information, see: https://github.com/MetaMask/metamask-improvement-proposals/discussions/23`,
invalidPropertyNetworkVersion: () =>
`MetaMask: 'ethereum.networkVersion' has been removed. Please use the 'net_version' RPC method instead.\nFor more information, see: https://github.com/MetaMask/metamask-improvement-proposals/discussions/23`,
invalidPropertySelectedAddress: () =>
`MetaMask: 'ethereum.selectedAddress' has been removed. Please use the 'eth_accounts' RPC method instead.\nFor more information, see: https://github.com/MetaMask/metamask-improvement-proposals/discussions/23`,
},
Expand Down

0 comments on commit 10ee3a3

Please sign in to comment.