mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 18:00:18 +01:00
d1cea85f33
* Rename `provider` to `providerConfig` The network controller `provider` state has been renamed to `providerConfig`. This better reflects what this state is, and makes this controller more closely aligned with the core network controller. All references to the provider configuration have been updated to prefer `providerConfig` over `provider`, to make the distinction clear between a provider and provider config. Closes #18902 * Add migration
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
import { hasProperty, isObject } from '@metamask/utils';
|
|
import { cloneDeep } from 'lodash';
|
|
|
|
export const version = 86;
|
|
|
|
/**
|
|
* Rename network controller `provider` state to `providerConfig`.
|
|
*
|
|
* @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, 'NetworkController') &&
|
|
isObject(state.NetworkController) &&
|
|
hasProperty(state.NetworkController, 'provider')
|
|
) {
|
|
const networkControllerState = state.NetworkController;
|
|
networkControllerState.providerConfig = networkControllerState.provider;
|
|
delete networkControllerState.provider;
|
|
|
|
return {
|
|
...state,
|
|
NetworkController: networkControllerState,
|
|
};
|
|
}
|
|
return state;
|
|
}
|