2021-03-19 22:54:30 +01:00
|
|
|
import { cloneDeep, mapKeys } from 'lodash';
|
2022-09-14 16:55:31 +02:00
|
|
|
import { BUILT_IN_NETWORKS } from '../../../shared/constants/network';
|
2021-03-19 22:54:30 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-03-22 16:21:52 +01:00
|
|
|
const UNKNOWN_CHAIN_ID_KEY = 'UNKNOWN';
|
|
|
|
|
2022-09-29 05:26:01 +02:00
|
|
|
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',
|
|
|
|
};
|
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
function transformState(state) {
|
|
|
|
if (
|
|
|
|
state?.IncomingTransactionsController?.incomingTxLastFetchedBlocksByNetwork
|
|
|
|
) {
|
2022-07-31 20:26:40 +02:00
|
|
|
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
|
2022-09-14 16:55:31 +02:00
|
|
|
(_, key) => BUILT_IN_NETWORKS[key]?.chainId ?? UNKNOWN_CHAIN_ID_KEY,
|
2022-07-31 20:26:40 +02:00
|
|
|
);
|
2021-03-22 16:21:52 +01:00
|
|
|
// 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];
|
2021-03-19 22:54:30 +01:00
|
|
|
delete state.IncomingTransactionsController
|
|
|
|
.incomingTxLastFetchedBlocksByNetwork;
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|