diff --git a/packages/network-controller/CHANGELOG.md b/packages/network-controller/CHANGELOG.md index 208ad01dcdf..bdf1e8fa101 100644 --- a/packages/network-controller/CHANGELOG.md +++ b/packages/network-controller/CHANGELOG.md @@ -17,6 +17,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Bump `@metamask/eth-json-rpc-middleware` from `^22.0.0` to `^22.0.1` ([#7330](https://github.com/MetaMask/core/pull/7330)) +### Fixed + +- Ensure `get1559CompatibilityWithNetworkClientId` updates network metadata with EIP-1559 compatibility data missing ([#7532](https://github.com/MetaMask/core/pull/7532)) + ## [27.0.0] ### Added diff --git a/packages/network-controller/src/NetworkController.ts b/packages/network-controller/src/NetworkController.ts index 8f80a241540..f095a4fb65d 100644 --- a/packages/network-controller/src/NetworkController.ts +++ b/packages/network-controller/src/NetworkController.ts @@ -2132,7 +2132,7 @@ export class NetworkController extends BaseController< networkClientId: NetworkClientId, ): Promise { let metadata = this.state.networksMetadata[networkClientId]; - if (metadata === undefined) { + if (metadata?.EIPS[1559] === undefined) { await this.lookupNetwork(networkClientId); metadata = this.state.networksMetadata[networkClientId]; } diff --git a/packages/network-controller/tests/NetworkController.test.ts b/packages/network-controller/tests/NetworkController.test.ts index 1f051aeb3e2..f585e7a806f 100644 --- a/packages/network-controller/tests/NetworkController.test.ts +++ b/packages/network-controller/tests/NetworkController.test.ts @@ -3590,7 +3590,7 @@ describe('NetworkController', () => { }, ); }); - it('calls provider of the networkClientId and returns true', async () => { + it('updates network metadata if undefined', async () => { await withController( { infuraProjectId: 'some-infura-project-id', @@ -3624,6 +3624,48 @@ describe('NetworkController', () => { }, ); }); + it('updates network metadata if EIP-1559 compatibility is missing', async () => { + await withController( + { + infuraProjectId: 'some-infura-project-id', + state: { + networksMetadata: { + 'linea-mainnet': { + EIPS: {}, + status: NetworkStatus.Unknown, + }, + }, + }, + }, + async ({ controller }) => { + await setFakeProvider(controller, { + stubs: [ + { + request: { + method: 'eth_getBlockByNumber', + params: ['latest', false], + }, + response: { + result: POST_1559_BLOCK, + }, + }, + { + request: { + method: 'eth_getBlockByNumber', + params: ['latest', false], + }, + response: { + result: POST_1559_BLOCK, + }, + }, + ], + }); + const isEIP1559Compatible = + await controller.getEIP1559Compatibility('linea-mainnet'); + expect(isEIP1559Compatible).toBe(true); + }, + ); + }); }); describe('if a provider has been set but networksMetadata[selectedNetworkClientId].EIPS in state already has a "1559" property', () => {