Skip to content

Commit

Permalink
feat: deprecate goerli network (#22995)
Browse files Browse the repository at this point in the history
## **Description**

Removes Goerli network from the settings=>Network tab.
Removes Goerli network from network-display picker.
When the user tried to add a network manually and he attempts to add
goerli network, we display a new modal to say that the network is
deprecated.

Designs for the new Modal here:
https://www.figma.com/file/KXgbxFucvk3FM5VULGZmzk/Assets%3A-Bug-Fixes?node-id=442%3A4490&mode=dev

## **Related issues**

Fixes: MetaMask/mobile-planning#1368

## **Manual testing steps**

1. Go to Settings
2. Click on Nework
3. you should not be able to see goerli testnetwork
4. Go back to home page
5. Click on network display picker
6. You should not be able to see goerli testnetwork.
7. Go to home page
8. Click on Add network manually
9. Try adding goerli network
10. You should be able to see a new modal saying that the network is
deprecated and you should not be able to add goerli.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**


https://github.com/MetaMask/metamask-extension/assets/10994169/6b2b0c7b-22c6-4fcd-a04e-0395aec539ad


### **After**


https://github.com/MetaMask/metamask-extension/assets/10994169/7f168355-d011-4bd8-a0c5-b3bca38a4122


## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've clearly explained what problem this PR is solving and how it
is solved.
- [ ] I've linked related issues
- [ ] I've included manual testing steps
- [ ] I've included screenshots/recordings if applicable
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] 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.
- [ ] I’ve properly set the pull request status:
  - [ ] In case it's not yet "ready for review", I've set it to "draft".
- [ ] In case it's "ready for review", I've changed it from "draft" to
"non-draft".

## **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.

---------

Co-authored-by: Antonio Regadas <[email protected]>
  • Loading branch information
2 people authored and dbrans committed Feb 27, 2024
1 parent d8e2901 commit 826d9a1
Show file tree
Hide file tree
Showing 39 changed files with 468 additions and 75 deletions.
8 changes: 4 additions & 4 deletions .storybook/test-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ const state = {
},
],
allDetectedTokens: {
'0x5': {
'0xaa36a7': {
'0x9d0ba4ddac06032527b140912ec808ab9451b788': [
{
address: '0x514910771AF9Ca656af840dff83E8264EcF986CA',
Expand Down Expand Up @@ -673,11 +673,11 @@ const state = {
swapsWelcomeMessageHasBeenShown: true,
defaultHomeActiveTabName: 'Tokens',
providerConfig: {
type: 'goerli',
type: 'sepolia',
ticker: 'ETH',
nickname: 'Goerli',
nickname: 'Sepolia',
rpcUrl: '',
chainId: '0x5',
chainId: '0xaa36a7',
},
network: '5',
accounts: {
Expand Down
9 changes: 9 additions & 0 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/scripts/controllers/mmi-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ export default class MMIController extends EventEmitter {
const networks = [
...networkConfigurations,
{ chainId: CHAIN_IDS.MAINNET },
{ chainId: CHAIN_IDS.GOERLI },
{ chainId: CHAIN_IDS.SEPOLIA },
];

return handleMmiPortfolio({
Expand Down
6 changes: 3 additions & 3 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,9 @@ export default class MetamaskController extends EventEmitter {
) {
initialNetworkControllerState = {
providerConfig: {
type: NETWORK_TYPES.GOERLI,
chainId: CHAIN_IDS.GOERLI,
ticker: TEST_NETWORK_TICKER_MAP[NETWORK_TYPES.GOERLI],
type: NETWORK_TYPES.SEPOLIA,
chainId: CHAIN_IDS.SEPOLIA,
ticker: TEST_NETWORK_TICKER_MAP[NETWORK_TYPES.SEPOLIA],
},
};
}
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/migrations/055.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('migration #55', () => {
[NETWORK_TYPES.MAINNET]: 1,
ropsten: 2,
rinkeby: 3,
[NETWORK_TYPES.GOERLI]: 4,
[NETWORK_TYPES.SEPOLIA]: 4,
kovan: 5,
},
},
Expand All @@ -50,7 +50,7 @@ describe('migration #55', () => {
[CHAIN_IDS.MAINNET]: 1,
'0x3': 2,
'0x4': 3,
[CHAIN_IDS.GOERLI]: 4,
[CHAIN_IDS.SEPOLIA]: 4,
'0x2a': 5,
},
},
Expand Down
195 changes: 195 additions & 0 deletions app/scripts/migrations/110.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
import { NetworkType } from '@metamask/controller-utils';
import {
CHAIN_IDS,
CHAIN_ID_TO_RPC_URL_MAP,
NETWORK_TYPES,
SEPOLIA_DISPLAY_NAME,
TEST_NETWORK_TICKER_MAP,
} from '../../../shared/constants/network';
import { migrate, version } from './110';

const oldVersion = 109;

const ethereumProviderConfig = {
chainId: '0x1',
rpcPrefs: {
blockExplorerUrl: 'https://etherscan.io',
},
ticker: 'ETH',
type: 'mainnet',
};

const ethereumNetworksMetadata = {
mainnet: {
EIPS: {
'1559': true,
},
status: 'available',
},
};
const ethereumOldState = {
CurrencyController: {
currencyRates: {
ETH: {
conversionDate: 1708532473.416,
conversionRate: 2918.02,
usdConversionRate: 2918.02,
},
GoerliETH: {
conversionDate: 1708532466.732,
conversionRate: 2918.02,
usdConversionRate: 2918.02,
},
},
currentCurrency: 'usd',
},
NetworkController: {
networkConfigurations: {},
networksMetadata: ethereumNetworksMetadata,
providerConfig: ethereumProviderConfig,
selectedNetworkClientId: 'mainnet',
},
};

const goerliState = {
NetworkController: {
networkConfigurations: {},
networksMetadata: {
goerli: {
EIPS: {
'1559': true,
},
status: 'available',
},
},
providerConfig: {
chainId: '0x5',
rpcPrefs: {},
ticker: 'goerliETH',
type: 'goerli',
},
selectedNetworkClientId: 'goerli',
},
};

describe('migration #110', () => {
it('updates the version metadata', async () => {
const oldStorage = {
meta: { version: oldVersion },
data: {},
};

const newStorage = await migrate(oldStorage);

expect(newStorage.meta).toStrictEqual({ version });
});

it('does nothing if no preferences state', async () => {
const oldState = {
OtherController: {},
};

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

expect(transformedState.data).toEqual(oldState);
});

it('Should return state if chainId is not goerli', async () => {
const transformedState = await migrate({
meta: { version: oldVersion },
data: ethereumOldState,
});

expect(transformedState.data).toEqual(ethereumOldState);
});

it('Should return state if there is no NetworkController in state', async () => {
const { NetworkController, ...state } = ethereumOldState;
const transformedState = await migrate({
meta: { version: oldVersion },
data: state,
});

expect(transformedState.data).toEqual(state);
});

it('Should return state if there is no provider in NetworkController', async () => {
const state = {
...ethereumOldState,
NetworkController: {},
};
const transformedState = await migrate({
meta: { version: oldVersion },
data: state,
});

expect(transformedState.data).toEqual(state);
});

it('Should return state if there is no chainId in provider in NetworkController', async () => {
const state = {
...ethereumOldState,
NetworkController: {
providerConfig: {},
},
};
const transformedState = await migrate({
meta: { version: oldVersion },
data: state,
});

expect(transformedState.data).toEqual(state);
});

it('Should return state if chainId is not goerli', async () => {
const transformedState = await migrate({
meta: { version: oldVersion },
data: ethereumOldState,
});

expect(transformedState.data).toEqual(ethereumOldState);
});

it('Should update NetworkController to Sepolia if chainId is on goerli', async () => {
const expectedNetworkControllerState = {
networkConfigurations: {},
networksMetadata: {
goerli: {
EIPS: {
'1559': true,
},
status: 'available',
},
sepolia: {
EIPS: {
'1559': true,
},
status: 'available',
},
},
providerConfig: {
type: NetworkType.sepolia,
rpcPrefs: {},
chainId: CHAIN_IDS.SEPOLIA,
nickname: SEPOLIA_DISPLAY_NAME,
rpcUrl: CHAIN_ID_TO_RPC_URL_MAP[CHAIN_IDS.SEPOLIA],
providerType: NETWORK_TYPES.SEPOLIA,
ticker: TEST_NETWORK_TICKER_MAP[NETWORK_TYPES.SEPOLIA],
id: NETWORK_TYPES.SEPOLIA,
removable: false,
},
selectedNetworkClientId: 'sepolia',
};
const transformedState = await migrate({
meta: { version: oldVersion },
data: goerliState,
});

expect(transformedState.data).toEqual({
NetworkController: expectedNetworkControllerState,
});
});
});
81 changes: 81 additions & 0 deletions app/scripts/migrations/110.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { cloneDeep, isObject } from 'lodash';
import { NetworkType } from '@metamask/controller-utils';
import { hasProperty } from '@metamask/utils';
import { NetworkStatus } from '@metamask/network-controller';
import {
CHAIN_IDS,
SEPOLIA_DISPLAY_NAME,
CHAIN_ID_TO_RPC_URL_MAP,
NETWORK_TYPES,
TEST_NETWORK_TICKER_MAP,
} from '../../../shared/constants/network';

type VersionedData = {
meta: { version: number };
data: Record<string, unknown>;
};

export const version = 110;

/**
* Migrates the user network to Sepolia if the user is on Goerli network.
*
* @param originalVersionedData - Versioned MetaMask extension state, exactly what we persist to dist.
* @param originalVersionedData.meta - State metadata.
* @param originalVersionedData.meta.version - The current state version.
* @param originalVersionedData.data - The persisted MetaMask state, keyed by controller.
* @returns Updated versioned MetaMask extension state.
*/
export async function migrate(
originalVersionedData: VersionedData,
): Promise<VersionedData> {
const versionedData = cloneDeep(originalVersionedData);
versionedData.meta.version = version;
transformState(versionedData.data);
return versionedData;
}

function transformState(state: Record<string, any>) {
const NetworkController = state?.NetworkController || {};
const provider = NetworkController?.providerConfig || {};

if (provider?.chainId !== CHAIN_IDS.GOERLI) {
return state;
}
const networkControllerState = state.NetworkController;

if (
hasProperty(state, 'NetworkController') &&
isObject(state.NetworkController) &&
hasProperty(state.NetworkController, 'providerConfig') &&
isObject(state.NetworkController.providerConfig) &&
hasProperty(state.NetworkController.providerConfig, 'chainId') &&
state.NetworkController.providerConfig.chainId === CHAIN_IDS.GOERLI
) {
networkControllerState.providerConfig = {
type: NetworkType.sepolia,
rpcPrefs: {},
chainId: CHAIN_IDS.SEPOLIA,
nickname: SEPOLIA_DISPLAY_NAME,
rpcUrl: CHAIN_ID_TO_RPC_URL_MAP[CHAIN_IDS.SEPOLIA],
providerType: NETWORK_TYPES.SEPOLIA,
ticker: TEST_NETWORK_TICKER_MAP[NETWORK_TYPES.SEPOLIA],
id: NETWORK_TYPES.SEPOLIA,
removable: false,
};
networkControllerState.selectedNetworkClientId = NETWORK_TYPES.SEPOLIA;
networkControllerState.networksMetadata = {
...networkControllerState.networksMetadata,
sepolia: {
EIPS: {
'1559': true,
},
status: NetworkStatus.Available,
},
};
}
return {
...state,
NetworkController: networkControllerState,
};
}
1 change: 1 addition & 0 deletions app/scripts/migrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ const migrations = [
require('./107'),
require('./108'),
require('./109'),
require('./110'),
];

export default migrations;
7 changes: 0 additions & 7 deletions shared/constants/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,14 +411,12 @@ export const ZORA_MAINNET_IMAGE_URL = './images/zora.svg';

export const INFURA_PROVIDER_TYPES = [
NETWORK_TYPES.MAINNET,
NETWORK_TYPES.GOERLI,
NETWORK_TYPES.SEPOLIA,
NETWORK_TYPES.LINEA_GOERLI,
NETWORK_TYPES.LINEA_MAINNET,
] as const;

export const TEST_CHAINS = [
CHAIN_IDS.GOERLI,
CHAIN_IDS.SEPOLIA,
CHAIN_IDS.LINEA_GOERLI,
CHAIN_IDS.LOCALHOST,
Expand Down Expand Up @@ -451,11 +449,6 @@ export const TEST_NETWORK_TICKER_MAP: {
* Map of all build-in Infura networks to their network, ticker and chain IDs.
*/
export const BUILT_IN_NETWORKS = {
[NETWORK_TYPES.GOERLI]: {
chainId: CHAIN_IDS.GOERLI,
ticker: TEST_NETWORK_TICKER_MAP[NETWORK_TYPES.GOERLI],
blockExplorerUrl: `https://${NETWORK_TYPES.GOERLI}.etherscan.io`,
},
[NETWORK_TYPES.SEPOLIA]: {
chainId: CHAIN_IDS.SEPOLIA,
ticker: TEST_NETWORK_TICKER_MAP[NETWORK_TYPES.SEPOLIA],
Expand Down
Loading

0 comments on commit 826d9a1

Please sign in to comment.