2021-02-04 19:15:23 +01:00
|
|
|
import { cloneDeep } from 'lodash';
|
2020-12-02 22:41:30 +01:00
|
|
|
|
2021-02-04 19:15:23 +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) {
|
2021-02-04 19:15:23 +01:00
|
|
|
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
|
|
|
},
|
2021-02-04 19:15:23 +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;
|
2021-02-04 19:15:23 +01:00
|
|
|
state.MetaMetricsController = state.MetaMetricsController ?? {};
|
2020-12-02 22:41:30 +01:00
|
|
|
|
|
|
|
if (metaMetricsId !== undefined) {
|
2021-02-04 19:15:23 +01:00
|
|
|
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;
|
2021-02-04 19:15:23 +01:00
|
|
|
delete state.PreferencesController.participateInMetaMetrics;
|
2020-12-02 22:41:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (metaMetricsSendCount !== undefined) {
|
2021-02-04 19:15:23 +01:00
|
|
|
state.MetaMetricsController.metaMetricsSendCount = metaMetricsSendCount;
|
|
|
|
delete state.PreferencesController.metaMetricsSendCount;
|
2020-12-02 22:41:30 +01:00
|
|
|
}
|
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
return state;
|
2020-12-02 22:41:30 +01:00
|
|
|
}
|