Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove unused usedNetworks state property from AppStateController #28813

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions app/scripts/migrations/134.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { migrate, version } from './134';

const oldVersion = 133;

describe(`migration #${version}`, () => {
it('updates the version metadata', async () => {
const oldStorage = {
meta: { version: oldVersion },
data: {},
};

const newStorage = await migrate(oldStorage);

expect(newStorage.meta).toStrictEqual({ version });
});

it('Does nothing if `usedNetworks` is not in the AppStateController state', async () => {
const oldState = {
AppStateController: {
timeoutMinutes: 0,
},
};

const transformedState = await migrate({
meta: { version: oldVersion },
data: oldState,
cryptodev-2s marked this conversation as resolved.
Show resolved Hide resolved
});

expect(transformedState.data).toStrictEqual(oldState);
});

it('Removes `usedNetworks` from the AppStateController state', async () => {
const oldState: {
AppStateController: {
timeoutMinutes: number;
usedNetworks?: Record<string, boolean>;
};
} = {
AppStateController: {
timeoutMinutes: 0,
usedNetworks: {
'0x1': true,
'0x5': true,
'0x539': true,
},
},
};
const transformedState = await migrate({
meta: { version: oldVersion },
data: oldState,
});

delete oldState.AppStateController.usedNetworks;
cryptodev-2s marked this conversation as resolved.
Show resolved Hide resolved
expect(transformedState.data).toStrictEqual(oldState);
});
});
41 changes: 41 additions & 0 deletions app/scripts/migrations/134.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { hasProperty, isObject } from '@metamask/utils';
import { cloneDeep } from 'lodash';

type VersionedData = {
meta: { version: number };
data: Record<string, unknown>;
};

export const version = 134;

/**
* This migration removes `providerConfig` from the network controller state.
cryptodev-2s marked this conversation as resolved.
Show resolved Hide resolved
*
* @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: VersionedData,
): Promise<VersionedData> {
const versionedData = cloneDeep(originalVersionedData);
versionedData.meta.version = version;
transformState(versionedData.data);
return versionedData;
}

function transformState(
state: Record<string, unknown>,
): Record<string, unknown> {
if (
hasProperty(state, 'AppStateController') &&
isObject(state.AppStateController) &&
hasProperty(state.AppStateController, 'usedNetworks')
) {
console.log('Removing usedNetworks from AppStateController');
delete state.AppStateController.usedNetworks;
}
return state;
}
1 change: 1 addition & 0 deletions app/scripts/migrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ const migrations = [
require('./131'),
require('./132'),
require('./133'),
require('./134'),
];

export default migrations;
Loading