1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-26 20:39:08 +01:00
metamask-extension/app/scripts/migrations/052.js
ryanml 0bc1eeaf37
Deprecating the Rinkeby, Ropsten, and Kovan test networks (#15989)
* Deprecating Rinkeby, setting default debug network to Goerli

* Deprecating Ropsten and Kovan

* Conflict fix

* Remove unused localization, test fixes

* Add migration for moving used deprecated testnets to custom networks

* Fix migrator test

* Add more unit tests

* Migration updates provider type to rpc if deprecated network is selected

* Migration fully and correctly updates the provider if selected network is a deprecated testnet

* Continue to show deprecation warning on each of rinkeby, ropsten and kovan

* Add rpcUrl deprecation message to loading screen

* Removing mayBeFauceting prop

Co-authored-by: Dan Miller <danjm.com@gmail.com>
2022-09-28 20:26:01 -07:00

108 lines
3.8 KiB
JavaScript

import { cloneDeep } from 'lodash';
import { CHAIN_IDS, NETWORK_TYPES } from '../../../shared/constants/network';
const version = 52;
/**
* Migrate tokens in Preferences to be keyed by chainId instead of
* providerType. To prevent breaking user's MetaMask and selected
* tokens, this migration copies the RPC entry into *every* custom RPC
* chainId.
*/
export default {
version,
async migrate(originalVersionedData) {
const versionedData = cloneDeep(originalVersionedData);
versionedData.meta.version = version;
const state = versionedData.data;
versionedData.data = transformState(state);
return versionedData;
},
};
function transformState(state = {}) {
if (state.PreferencesController) {
const { accountTokens, accountHiddenTokens, frequentRpcListDetail } =
state.PreferencesController;
const newAccountTokens = {};
const newAccountHiddenTokens = {};
if (accountTokens && Object.keys(accountTokens).length > 0) {
for (const address of Object.keys(accountTokens)) {
newAccountTokens[address] = {};
if (accountTokens[address][NETWORK_TYPES.RPC]) {
frequentRpcListDetail.forEach((detail) => {
newAccountTokens[address][detail.chainId] =
accountTokens[address][NETWORK_TYPES.RPC];
});
}
for (const providerType of Object.keys(accountTokens[address])) {
switch (providerType) {
case NETWORK_TYPES.MAINNET:
newAccountTokens[address][CHAIN_IDS.MAINNET] =
accountTokens[address][NETWORK_TYPES.MAINNET];
break;
case 'ropsten':
newAccountTokens[address]['0x3'] = accountTokens[address].ropsten;
break;
case 'rinkeby':
newAccountTokens[address]['0x4'] = accountTokens[address].rinkeby;
break;
case NETWORK_TYPES.GOERLI:
newAccountTokens[address][CHAIN_IDS.GOERLI] =
accountTokens[address][NETWORK_TYPES.GOERLI];
break;
case 'kovan':
newAccountTokens[address]['0x2a'] = accountTokens[address].kovan;
break;
default:
break;
}
}
}
state.PreferencesController.accountTokens = newAccountTokens;
}
if (accountHiddenTokens && Object.keys(accountHiddenTokens).length > 0) {
for (const address of Object.keys(accountHiddenTokens)) {
newAccountHiddenTokens[address] = {};
if (accountHiddenTokens[address][NETWORK_TYPES.RPC]) {
frequentRpcListDetail.forEach((detail) => {
newAccountHiddenTokens[address][detail.chainId] =
accountHiddenTokens[address][NETWORK_TYPES.RPC];
});
}
for (const providerType of Object.keys(accountHiddenTokens[address])) {
switch (providerType) {
case NETWORK_TYPES.MAINNET:
newAccountHiddenTokens[address][CHAIN_IDS.MAINNET] =
accountHiddenTokens[address][NETWORK_TYPES.MAINNET];
break;
case 'ropsten':
newAccountHiddenTokens[address]['0x3'] =
accountHiddenTokens[address].ropsten;
break;
case 'rinkeby':
newAccountHiddenTokens[address]['0x4'] =
accountHiddenTokens[address].rinkeby;
break;
case NETWORK_TYPES.GOERLI:
newAccountHiddenTokens[address][CHAIN_IDS.GOERLI] =
accountHiddenTokens[address][NETWORK_TYPES.GOERLI];
break;
case 'kovan':
newAccountHiddenTokens[address]['0x2a'] =
accountHiddenTokens[address].kovan;
break;
default:
break;
}
}
}
state.PreferencesController.accountHiddenTokens = newAccountHiddenTokens;
}
}
return state;
}