mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-12 20:57:12 +01:00
0bc1eeaf37
* 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>
62 lines
1.9 KiB
JavaScript
62 lines
1.9 KiB
JavaScript
import { cloneDeep, mapKeys } from 'lodash';
|
|
import { BUILT_IN_NETWORKS } from '../../../shared/constants/network';
|
|
|
|
const version = 55;
|
|
|
|
/**
|
|
* replace 'incomingTxLastFetchedBlocksByNetwork' with 'incomingTxLastFetchedBlockByChainId'
|
|
*/
|
|
export default {
|
|
version,
|
|
async migrate(originalVersionedData) {
|
|
const versionedData = cloneDeep(originalVersionedData);
|
|
versionedData.meta.version = version;
|
|
const state = versionedData.data;
|
|
versionedData.data = transformState(state);
|
|
return versionedData;
|
|
},
|
|
};
|
|
|
|
const UNKNOWN_CHAIN_ID_KEY = 'UNKNOWN';
|
|
|
|
BUILT_IN_NETWORKS.rinkeby = {
|
|
networkId: '4',
|
|
chainId: '0x4',
|
|
ticker: 'ETH',
|
|
};
|
|
BUILT_IN_NETWORKS.ropsten = {
|
|
networkId: '3',
|
|
chainId: '0x3',
|
|
ticker: 'ETH',
|
|
};
|
|
BUILT_IN_NETWORKS.kovan = {
|
|
networkId: '42',
|
|
chainId: '0x2a',
|
|
ticker: 'ETH',
|
|
};
|
|
|
|
function transformState(state) {
|
|
if (
|
|
state?.IncomingTransactionsController?.incomingTxLastFetchedBlocksByNetwork
|
|
) {
|
|
state.IncomingTransactionsController.incomingTxLastFetchedBlockByChainId =
|
|
mapKeys(
|
|
state.IncomingTransactionsController
|
|
.incomingTxLastFetchedBlocksByNetwork,
|
|
// using optional chaining in case user's state has fetched blocks for
|
|
// RPC network types (which don't map to a single chainId). This should
|
|
// not be possible, but it's safer
|
|
(_, key) => BUILT_IN_NETWORKS[key]?.chainId ?? UNKNOWN_CHAIN_ID_KEY,
|
|
);
|
|
// Now that mainnet and test net last fetched blocks are keyed by their
|
|
// respective chainIds, we can safely delete anything we had for custom
|
|
// networks. Any custom network that shares a chainId with one of the
|
|
// aforementioned networks will use the value stored by chainId.
|
|
delete state.IncomingTransactionsController
|
|
.incomingTxLastFetchedBlockByChainId[UNKNOWN_CHAIN_ID_KEY];
|
|
delete state.IncomingTransactionsController
|
|
.incomingTxLastFetchedBlocksByNetwork;
|
|
}
|
|
return state;
|
|
}
|