1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 18:00:18 +01:00
metamask-extension/app/scripts/migrations/049.js

43 lines
1.3 KiB
JavaScript
Raw Normal View History

import { cloneDeep } from 'lodash';
2020-12-02 22:41:30 +01:00
const version = 49;
2020-12-02 22:41:30 +01:00
/**
* Migrate metaMetrics state to the new MetaMetrics controller
*/
export default {
version,
async migrate(originalVersionedData) {
const versionedData = cloneDeep(originalVersionedData);
versionedData.meta.version = version;
const state = versionedData.data;
versionedData.data = transformState(state);
return versionedData;
2020-12-02 22:41:30 +01:00
},
};
2020-12-02 22:41:30 +01:00
function transformState(state = {}) {
if (state.PreferencesController) {
2022-07-31 20:26:40 +02:00
const { metaMetricsId, participateInMetaMetrics, metaMetricsSendCount } =
state.PreferencesController;
state.MetaMetricsController = state.MetaMetricsController ?? {};
2020-12-02 22:41:30 +01:00
if (metaMetricsId !== undefined) {
state.MetaMetricsController.metaMetricsId = metaMetricsId;
delete state.PreferencesController.metaMetricsId;
2020-12-02 22:41:30 +01:00
}
if (participateInMetaMetrics !== undefined) {
2022-07-31 20:26:40 +02:00
state.MetaMetricsController.participateInMetaMetrics =
participateInMetaMetrics;
delete state.PreferencesController.participateInMetaMetrics;
2020-12-02 22:41:30 +01:00
}
if (metaMetricsSendCount !== undefined) {
state.MetaMetricsController.metaMetricsSendCount = metaMetricsSendCount;
delete state.PreferencesController.metaMetricsSendCount;
2020-12-02 22:41:30 +01:00
}
}
return state;
2020-12-02 22:41:30 +01:00
}