mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 18:00:18 +01:00
b76875ac69
* Update phishing controller to v4.0.0 * Move phishing e2e test utilities into its own helper.js * Update phishing detection e2e test * Update MetaMask Controller test mocks * Update mv3 phishing tests * Fix test for 500 error on warning page * Allow for directories in test folder * Update migration number * Linting fixes * Remove fail on console error * Separate mocks from helpers * Have migration delete PhishingController state entirely * Remove phishing detection directory * Only delete the listState in migration * Bump migration version
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import { cloneDeep } from 'lodash';
|
|
import { hasProperty, isObject } from '@metamask/utils';
|
|
|
|
export const version = 90;
|
|
|
|
/**
|
|
* Explain the purpose of the migration here.
|
|
*
|
|
* @param originalVersionedData - Versioned MetaMask extension state, exactly what we persist to dist.
|
|
* @param originalVersionedData.meta - State metadata.
|
|
* @param originalVersionedData.meta.version - The current state version.
|
|
* @param originalVersionedData.data - The persisted MetaMask state, keyed by controller.
|
|
* @returns Updated versioned MetaMask extension state.
|
|
*/
|
|
export async function migrate(originalVersionedData: {
|
|
meta: { version: number };
|
|
data: Record<string, unknown>;
|
|
}) {
|
|
const versionedData = cloneDeep(originalVersionedData);
|
|
versionedData.meta.version = version;
|
|
versionedData.data = transformState(versionedData.data);
|
|
return versionedData;
|
|
}
|
|
|
|
function transformState(state: Record<string, unknown>) {
|
|
if (
|
|
!hasProperty(state, 'PhishingController') ||
|
|
!isObject(state.PhishingController) ||
|
|
!hasProperty(state.PhishingController, 'listState')
|
|
) {
|
|
return state;
|
|
}
|
|
|
|
delete state.PhishingController.listState;
|
|
|
|
return state;
|
|
}
|