Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions packages/network-controller/src/NetworkController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1966,8 +1966,22 @@ export class NetworkController extends BaseController<
}
const { EIPS } = metadata;

// may want to include some 'freshness' value - something to make sure we refetch this from time to time
return EIPS[1559];
// If EIP-1559 compatibility is already cached, return it
if (EIPS[1559] !== undefined) {
return EIPS[1559];
}

// Otherwise, determine it now and cache the result
const isEIP1559Compatible = await this.#determineEIP1559Compatibility(
networkClientId,
);
this.update((state) => {
if (isEIP1559Compatible !== undefined) {
state.networksMetadata[networkClientId].EIPS[1559] =
isEIP1559Compatible;
}
});
return isEIP1559Compatible;
}

/**
Expand Down
78 changes: 78 additions & 0 deletions packages/network-controller/tests/NetworkController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3602,6 +3602,84 @@ describe('NetworkController', () => {
},
);
});

it('determines EIP-1559 compatibility if metadata exists but EIPS[1559] is undefined', async () => {
await withController(
{
state: {
networksMetadata: {
'linea-mainnet': {
EIPS: {},
status: NetworkStatus.Available,
},
},
},
infuraProjectId: 'some-infura-project-id',
},
async ({ controller }) => {
const fakeProvider = buildFakeProvider([
{
request: {
method: 'eth_getBlockByNumber',
params: ['latest', false],
},
response: {
result: POST_1559_BLOCK,
},
},
]);
const fakeNetworkClient = buildFakeClient(fakeProvider);
mockCreateNetworkClient().mockReturnValue(fakeNetworkClient);

const isEIP1559Compatible =
await controller.getEIP1559Compatibility('linea-mainnet');

expect(isEIP1559Compatible).toBe(true);
expect(
controller.state.networksMetadata['linea-mainnet'].EIPS[1559],
).toBe(true);
},
);
});

it('returns false if network does not support EIP-1559 when EIPS[1559] is undefined', async () => {
await withController(
{
state: {
networksMetadata: {
'linea-mainnet': {
EIPS: {},
status: NetworkStatus.Available,
},
},
},
infuraProjectId: 'some-infura-project-id',
},
async ({ controller }) => {
const fakeProvider = buildFakeProvider([
{
request: {
method: 'eth_getBlockByNumber',
params: ['latest', false],
},
response: {
result: PRE_1559_BLOCK,
},
},
]);
const fakeNetworkClient = buildFakeClient(fakeProvider);
mockCreateNetworkClient().mockReturnValue(fakeNetworkClient);

const isEIP1559Compatible =
await controller.getEIP1559Compatibility('linea-mainnet');

expect(isEIP1559Compatible).toBe(false);
expect(
controller.state.networksMetadata['linea-mainnet'].EIPS[1559],
).toBe(false);
},
);
});
});

describe('if a provider has been set but networksMetadata[selectedNetworkClientId].EIPS in state already has a "1559" property', () => {
Expand Down
Loading