mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 01:39:44 +01:00
2900fe2c1a
* Move subject type enum to @metamask/controllers * Fix imports
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
import { SubjectType } from '@metamask/subject-metadata-controller';
|
|
import { cloneDeep } from 'lodash';
|
|
|
|
const version = 69;
|
|
|
|
/**
|
|
* Adds the `subjectType` property to all subject metadata.
|
|
*/
|
|
export default {
|
|
version,
|
|
async migrate(originalVersionedData) {
|
|
const versionedData = cloneDeep(originalVersionedData);
|
|
versionedData.meta.version = version;
|
|
const state = versionedData.data;
|
|
const newState = transformState(state);
|
|
versionedData.data = newState;
|
|
return versionedData;
|
|
},
|
|
};
|
|
|
|
function transformState(state) {
|
|
if (typeof state?.SubjectMetadataController?.subjectMetadata === 'object') {
|
|
const {
|
|
SubjectMetadataController: { subjectMetadata },
|
|
} = state;
|
|
|
|
// mutate SubjectMetadataController.subjectMetadata in place
|
|
Object.values(subjectMetadata).forEach((metadata) => {
|
|
if (
|
|
metadata &&
|
|
typeof metadata === 'object' &&
|
|
!Array.isArray(metadata)
|
|
) {
|
|
metadata.subjectType = metadata.extensionId
|
|
? SubjectType.Extension
|
|
: SubjectType.Website;
|
|
}
|
|
});
|
|
}
|
|
return state;
|
|
}
|