Skip to content

Commit

Permalink
fix: Allow users to remove linea from networks list (#27512)
Browse files Browse the repository at this point in the history
## **Description**

Users should be allowed to remove Linea from networks list. When Linea
is removed from default network list, it should appear within the
Popular Networks section (be suggested to them). So, we need to also add
it to `FEATURED_RPCS`

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/27512?quickstart=1)

## **Related issues**

Fixes: https://consensyssoftware.atlassian.net/browse/MMASSETS-387

## **Manual testing steps**

1. Go to networks list, ensure that you can remove linea, even though it
is a default network.

## **Screenshots/Recordings**

## **Pre-merge author checklist**

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
gambinish authored Oct 22, 2024
1 parent 80cfcf7 commit 6b94992
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
1 change: 1 addition & 0 deletions shared/constants/network.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('NetworkConstants', () => {
'Polygon Mainnet': CHAIN_IDS.POLYGON,
'zkSync Era Mainnet': CHAIN_IDS.ZKSYNC_ERA,
'Base Mainnet': CHAIN_IDS.BASE,
'Linea Mainnet': CHAIN_IDS.LINEA_MAINNET,
};

FEATURED_RPCS.forEach((rpc) => {
Expand Down
14 changes: 14 additions & 0 deletions shared/constants/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,20 @@ export const UNSUPPORTED_RPC_METHODS = new Set([
export const IPFS_DEFAULT_GATEWAY_URL = 'dweb.link';

export const FEATURED_RPCS: AddNetworkFields[] = [
{
chainId: CHAIN_IDS.LINEA_MAINNET,
name: LINEA_MAINNET_DISPLAY_NAME,
nativeCurrency: CURRENCY_SYMBOLS.ETH,
rpcEndpoints: [
{
url: `https://linea-mainnet.infura.io/v3/${infuraProjectId}`,
type: RpcEndpointType.Custom,
},
],
defaultRpcEndpointIndex: 0,
blockExplorerUrls: ['https://lineascan.build/'],
defaultBlockExplorerUrlIndex: 0,
},
{
chainId: CHAIN_IDS.ARBITRUM,
name: ARBITRUM_DISPLAY_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,7 @@ export const NetworkListMenu = ({ onClose }: { onClose: () => void }) => {
const generateNetworkListItem = (network: NetworkConfiguration) => {
const isCurrentNetwork = network.chainId === currentChainId;
const canDeleteNetwork =
isUnlocked &&
!isCurrentNetwork &&
network.chainId !== CHAIN_IDS.MAINNET &&
network.chainId !== CHAIN_IDS.LINEA_MAINNET;
isUnlocked && !isCurrentNetwork && network.chainId !== CHAIN_IDS.MAINNET;

return (
<NetworkListItem
Expand Down
18 changes: 9 additions & 9 deletions ui/ducks/bridge/selectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Bridge selectors', () => {
{ srcNetworkAllowlist: [CHAIN_IDS.ARBITRUM] },
{ toChainId: '0xe708' },
{},
{ ...mockNetworkState(FEATURED_RPCS[0]) },
{ ...mockNetworkState(FEATURED_RPCS[1]) },
);

const result = getFromChain(state as never);
Expand Down Expand Up @@ -89,7 +89,7 @@ describe('Bridge selectors', () => {
);
const result = getAllBridgeableNetworks(state as never);

expect(result).toHaveLength(7);
expect(result).toHaveLength(8);
expect(result[0]).toStrictEqual(
expect.objectContaining({ chainId: FEATURED_RPCS[0].chainId }),
);
Expand Down Expand Up @@ -190,21 +190,19 @@ describe('Bridge selectors', () => {
},
{},
{},
mockNetworkState(...FEATURED_RPCS, {
chainId: CHAIN_IDS.LINEA_MAINNET,
}),
mockNetworkState(...FEATURED_RPCS),
);
const result = getToChains(state as never);

expect(result).toHaveLength(3);
expect(result[0]).toStrictEqual(
expect.objectContaining({ chainId: CHAIN_IDS.OPTIMISM }),
expect.objectContaining({ chainId: CHAIN_IDS.ARBITRUM }),
);
expect(result[1]).toStrictEqual(
expect.objectContaining({ chainId: CHAIN_IDS.POLYGON }),
expect.objectContaining({ chainId: CHAIN_IDS.OPTIMISM }),
);
expect(result[2]).toStrictEqual(
expect.objectContaining({ chainId: CHAIN_IDS.LINEA_MAINNET }),
expect.objectContaining({ chainId: CHAIN_IDS.POLYGON }),
);
});

Expand Down Expand Up @@ -297,7 +295,9 @@ describe('Bridge selectors', () => {
{
...mockNetworkState(
...Object.values(BUILT_IN_NETWORKS),
...FEATURED_RPCS,
...FEATURED_RPCS.filter(
(network) => network.chainId !== CHAIN_IDS.LINEA_MAINNET, // Linea mainnet is both a built in network, as well as featured RPC
),
),
useExternalServices: true,
},
Expand Down

0 comments on commit 6b94992

Please sign in to comment.