Skip to content

Commit

Permalink
fix: exclude linea mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
salimtb committed Dec 5, 2024
1 parent 7d3f428 commit 919d18b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
49 changes: 49 additions & 0 deletions app/scripts/migrations/135.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,54 @@ describe('migration #135', () => {
.defaultRpcEndpointIndex,
).toEqual(0);
});

it('does nothing if Linea mainnet is excluded', async () => {
const oldState = {
NetworkController: {
networkConfigurationsByChainId: {
[BASE_CHAIN_ID]: {
rpcEndpoints: [
{
url: 'https://mainnet.base.org',
type: 'custom',
},
],
defaultRpcEndpointIndex: 0,
},
'0x1': {
rpcEndpoints: [
{
url: `https://mainnet.infura.io/v3/${infuraProjectId}`,
type: 'infura',
},
],
defaultRpcEndpointIndex: 0,
},
'0x13881': {
rpcEndpoints: [
{
url: 'https://rpc.goerli.linea.io',
type: 'custom',
},
],
defaultRpcEndpointIndex: 0,
},
},
},
};

const transformedState = await migrate({
meta: { version: oldVersion },
data: cloneDeep(oldState),
});

const updatedNetworkController = transformedState.data
.NetworkController as NetworkState;

expect(
updatedNetworkController.networkConfigurationsByChainId['0x13881']
.rpcEndpoints[0].url,
).toEqual('https://rpc.goerli.linea.io');
});
});
});
8 changes: 7 additions & 1 deletion app/scripts/migrations/135.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { RpcEndpointType } from '@metamask/network-controller';
import { cloneDeep } from 'lodash';
import {
allowedInfuraHosts,
CHAIN_IDS,
infuraChainIdsTestNets,
infuraProjectId,
} from '../../../shared/constants/network';
Expand Down Expand Up @@ -44,7 +45,12 @@ function transformState(state: Record<string, unknown>) {

// Check if at least one network uses an Infura RPC endpoint, excluding testnets
const usesInfura = Object.entries(networkConfigurationsByChainId)
.filter(([chainId]) => !infuraChainIdsTestNets.includes(chainId))
.filter(
([chainId]) =>
![...infuraChainIdsTestNets, CHAIN_IDS.LINEA_MAINNET].includes(
chainId,
),
)
.some(([, networkConfig]) => {
if (
!isObject(networkConfig) ||
Expand Down

0 comments on commit 919d18b

Please sign in to comment.