-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: deprecate goerli network (#22995)
## **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
Showing
39 changed files
with
468 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.