-
Notifications
You must be signed in to change notification settings - Fork 5k
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
fix: Remove old properties from state #29792
Merged
+395
−0
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,305 @@ | ||
import { omit } from 'lodash'; | ||
import { migrate, version } from './139'; | ||
|
||
const oldVersion = 138; | ||
|
||
const dataWithAllControllerProperties = { | ||
AppStateController: {}, | ||
NetworkController: {}, | ||
PreferencesController: {}, | ||
}; | ||
|
||
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 state has no AppStateController property, even if it has other relevant properties', async () => { | ||
const data = omit(dataWithAllControllerProperties, 'AppStateController'); | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual(data); | ||
}); | ||
|
||
it('deletes AppStateController.collectiblesDropdownState from state', async () => { | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data: { | ||
AppStateController: { | ||
collectiblesDropdownState: 'test', | ||
}, | ||
}, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual({ | ||
AppStateController: {}, | ||
}); | ||
}); | ||
|
||
it('deletes AppStateController.serviceWorkerLastActiveTime from state', async () => { | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data: { | ||
AppStateController: { | ||
serviceWorkerLastActiveTime: 5, | ||
}, | ||
}, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual({ | ||
AppStateController: {}, | ||
}); | ||
}); | ||
|
||
it('deletes AppStateController.showPortfolioTooltip from state', async () => { | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data: { | ||
AppStateController: { | ||
showPortfolioTooltip: true, | ||
}, | ||
}, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual({ | ||
AppStateController: {}, | ||
}); | ||
}); | ||
|
||
it('does nothing if state has no NetworkController property, even if it has other relevant properties', async () => { | ||
const data = omit(dataWithAllControllerProperties, 'NetworkController'); | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual(data); | ||
}); | ||
|
||
it('deletes NetworkController.networkConfigurations from state', async () => { | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data: { | ||
NetworkController: { | ||
networkConfigurations: { | ||
'AAAA-AAAA-AAAA-AAAA': { | ||
doesnt: 'matter', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual({ | ||
NetworkController: {}, | ||
}); | ||
}); | ||
|
||
it('deletes NetworkController.providerConfig from state', async () => { | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data: { | ||
NetworkController: { | ||
providerConfig: { | ||
doesnt: 'matter', | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual({ | ||
NetworkController: {}, | ||
}); | ||
}); | ||
|
||
it('does nothing if state has no PreferencesController property, even if it has other relevant properties', async () => { | ||
const data = omit(dataWithAllControllerProperties, 'PreferencesController'); | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual(data); | ||
}); | ||
|
||
it('deletes PreferencesController.customNetworkListEnabled from state', async () => { | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data: { | ||
PreferencesController: { | ||
customNetworkListEnabled: true, | ||
}, | ||
}, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual({ | ||
PreferencesController: {}, | ||
}); | ||
}); | ||
|
||
it('deletes PreferencesController.disabledRpcMethodPreferences from state', async () => { | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data: { | ||
PreferencesController: { | ||
disabledRpcMethodPreferences: { | ||
doesnt: 'matter', | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual({ | ||
PreferencesController: {}, | ||
}); | ||
}); | ||
|
||
it('deletes PreferencesController.eip1559V2Enabled from state', async () => { | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data: { | ||
PreferencesController: { | ||
eip1559V2Enabled: true, | ||
}, | ||
}, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual({ | ||
PreferencesController: {}, | ||
}); | ||
}); | ||
|
||
it('deletes PreferencesController.hasDismissedOpenSeaToBlockaidBanner from state', async () => { | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data: { | ||
PreferencesController: { | ||
hasDismissedOpenSeaToBlockaidBanner: true, | ||
}, | ||
}, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual({ | ||
PreferencesController: {}, | ||
}); | ||
}); | ||
|
||
it('deletes PreferencesController.hasMigratedFromOpenSeaToBlockaid from state', async () => { | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data: { | ||
PreferencesController: { | ||
hasMigratedFromOpenSeaToBlockaid: true, | ||
}, | ||
}, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual({ | ||
PreferencesController: {}, | ||
}); | ||
}); | ||
|
||
it('deletes PreferencesController.improvedTokenAllowanceEnabled from state', async () => { | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data: { | ||
PreferencesController: { | ||
improvedTokenAllowanceEnabled: true, | ||
}, | ||
}, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual({ | ||
PreferencesController: {}, | ||
}); | ||
}); | ||
|
||
it('deletes PreferencesController.infuraBlocked from state', async () => { | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data: { | ||
PreferencesController: { | ||
infuraBlocked: true, | ||
}, | ||
}, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual({ | ||
PreferencesController: {}, | ||
}); | ||
}); | ||
|
||
it('deletes PreferencesController.useCollectibleDetection from state', async () => { | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data: { | ||
PreferencesController: { | ||
useCollectibleDetection: true, | ||
}, | ||
}, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual({ | ||
PreferencesController: {}, | ||
}); | ||
}); | ||
|
||
it('deletes PreferencesController.useStaticTokenList from state', async () => { | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data: { | ||
PreferencesController: { | ||
useStaticTokenList: true, | ||
}, | ||
}, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual({ | ||
PreferencesController: {}, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { hasProperty, isObject } from '@metamask/utils'; | ||
import { cloneDeep } from 'lodash'; | ||
|
||
type VersionedData = { | ||
meta: { version: number }; | ||
data: Record<string, unknown>; | ||
}; | ||
|
||
export const version = 139; | ||
|
||
/** | ||
* This migration deletes properties from state which have been removed in | ||
* previous commits. | ||
* | ||
* @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>) { | ||
if ( | ||
hasProperty(state, 'AppStateController') && | ||
isObject(state.AppStateController) | ||
) { | ||
// Removed in 33cc8d587aad05c0b41871ba3676676a3ce5680e with a migration, but | ||
// still persists for some people for some reason | ||
// See https://metamask.sentry.io/issues/6223008336/events/723c5195130e4c5584b53a6656a85595/ | ||
delete state.AppStateController.collectiblesDropdownState; | ||
// Removed in 4ea52511eb7934bf0ce6b9b7d570a525120229ce | ||
delete state.AppStateController.serviceWorkerLastActiveTime; | ||
// Removed in 24e0a9030b1a715a008e0c5dfaf9c552bcdb304e with a migration, but | ||
// still persists for some people for some reason | ||
// See https://metamask.sentry.io/issues/6223008336/events/a2cc42d6ed79485a8b2e9072d8033720/ | ||
delete state.AppStateController.showPortfolioTooltip; | ||
} | ||
|
||
if ( | ||
hasProperty(state, 'NetworkController') && | ||
isObject(state.NetworkController) | ||
) { | ||
// Removed in 555d42b9ead0f4919356ff16e11c663c5e38639e | ||
delete state.NetworkController.networkConfigurations; | ||
// Removed in 800a9d3a177446ff2d05e3e95ec06b3658474207 with a migration, but | ||
// still persists for some people for some reason | ||
// See: https://metamask.sentry.io/issues/6011869130/events/039861ddb07f4b39b947edba3bbd710e/ | ||
delete state.NetworkController.providerConfig; | ||
} | ||
|
||
if ( | ||
hasProperty(state, 'PreferencesController') && | ||
isObject(state.PreferencesController) | ||
) { | ||
// Removed in 6c84e9604c7160dd91c685f301f3c8bd128ad3e3 | ||
delete state.PreferencesController.customNetworkListEnabled; | ||
// Removed in e6ecd956b054a29481071e4eded2f8cd17d137d2 | ||
delete state.PreferencesController.disabledRpcMethodPreferences; | ||
// Removed in 8125473dc53476b6685c5e85918f89bce87e3006 | ||
delete state.PreferencesController.eip1559V2Enabled; | ||
// Removed in 699ddccc76302df6130835dc6655077806bf6335 | ||
delete state.PreferencesController.hasDismissedOpenSeaToBlockaidBanner; | ||
// I could find references to this in the commit history, but don't know | ||
// where it was removed | ||
delete state.PreferencesController.hasMigratedFromOpenSeaToBlockaid; | ||
// Removed in f988dc1c5ef98ec72212d1f58e736556273b68f7 | ||
delete state.PreferencesController.improvedTokenAllowanceEnabled; | ||
// Removed in 315c043785cd5d7a4b0f7e974097ccac18a6b241 | ||
delete state.PreferencesController.infuraBlocked; | ||
// Removed in 4f66dc948fee54b8491227414342ab0d373475f1 with a migration, but | ||
// still persists for some people for some reason | ||
// See: https://metamask.sentry.io/issues/6042074159/events/5711f95785d741739e5d0fa5ad19e7c0/ | ||
delete state.PreferencesController.useCollectibleDetection; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found this error in Sentry here: https://metamask.sentry.io/issues/6042074159/events/5711f95785d741739e5d0fa5ad19e7c0/. Again we already have a migration that should be removing this property, so I'm not sure if this is needed? |
||
// Removed in eb987a47b51ce410de0047ec883bb4549ce80c85 | ||
delete state.PreferencesController.useStaticTokenList; | ||
} | ||
|
||
return state; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found this error in Sentry: https://metamask.sentry.io/issues/6011869130/events/039861ddb07f4b39b947edba3bbd710e/. I am not sure why it is occurring. We already have a migration that removes this property. So do we need this here? Kind of strange that some people still have this property.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It must be due to some migration failure that we have not yet understood. I think it is good to attempt to delete again here, but we should investigate further if it continues to persist after this