-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** This migration sets redesignedConfirmationsEnabled to true. Some users may have explicitly turned off the experimental setting, which this migration will reset to true. This is intentional as we also plan to remove the setting in an upcoming release. I also added the redesigned confirmation prop to the Sentry state log. Needed to add or not add it to support the setting in the tests. I went with adding it. --- Getting the tests to pass were a bit tricky. It turns out the migrations run after the fixtures are set. The withPreferencesController fixture method is no help here. One way we discussed to set the desired test state is to set the previous migration data to the state and setting the fixture migration version to the current version: ``` meta: { version: 122 } ``` This would require opening a live version, extracting the latest migration state, and adding the mock state to the tests. Instead, we manually toggle the setting off for each test that requires the old signature pages. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/25768?quickstart=1) ## **Related issues** Fixes: #24614 ## **Manual testing steps** 1. Turn off the Experimental > Improved signature redesign setting 2. Run newest version with migration 3. Observe setting has been turned on ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
- Loading branch information
Showing
19 changed files
with
218 additions
and
14 deletions.
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
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,74 @@ | ||
import { migrate, version } from './122'; | ||
|
||
const oldVersion = 121; | ||
|
||
describe('migration #122', () => { | ||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it('updates the version metadata', async () => { | ||
const oldStorage = { | ||
meta: { | ||
version: oldVersion, | ||
}, | ||
data: {}, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.meta).toStrictEqual({ version }); | ||
}); | ||
|
||
describe('set redesignedConfirmationsEnabled to true in PreferencesController', () => { | ||
it('sets redesignedConfirmationsEnabled to true', async () => { | ||
const oldStorage = { | ||
PreferencesController: { | ||
preferences: { | ||
redesignedConfirmationsEnabled: false, | ||
}, | ||
}, | ||
}; | ||
|
||
const expectedState = { | ||
PreferencesController: { | ||
preferences: { | ||
redesignedConfirmationsEnabled: true, | ||
}, | ||
}, | ||
}; | ||
|
||
const transformedState = await migrate({ | ||
meta: { version: oldVersion }, | ||
data: oldStorage, | ||
}); | ||
|
||
expect(transformedState.data).toEqual(expectedState); | ||
}); | ||
|
||
it( | ||
'sets redesignedConfirmationsEnabled to true even with original preferences object in the' + | ||
'state', | ||
async () => { | ||
const oldStorage = { | ||
PreferencesController: {}, | ||
}; | ||
|
||
const expectedState = { | ||
PreferencesController: { | ||
preferences: { | ||
redesignedConfirmationsEnabled: true, | ||
}, | ||
}, | ||
}; | ||
|
||
const transformedState = await migrate({ | ||
meta: { version: oldVersion }, | ||
data: oldStorage, | ||
}); | ||
|
||
expect(transformedState.data).toEqual(expectedState); | ||
}, | ||
); | ||
}); | ||
}); |
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,50 @@ | ||
import { cloneDeep } from 'lodash'; | ||
import { hasProperty, isObject } from '@metamask/utils'; | ||
|
||
type VersionedData = { | ||
meta: { version: number }; | ||
data: Record<string, unknown>; | ||
}; | ||
|
||
export const version = 122; | ||
|
||
/** | ||
* This migration sets preference redesignedConfirmationsEnabled to true | ||
* | ||
* @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; | ||
} | ||
|
||
// TODO: Replace `any` with specific type | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
function transformState(state: Record<string, any>) { | ||
if (!hasProperty(state, 'PreferencesController')) { | ||
return; | ||
} | ||
|
||
if (!isObject(state.PreferencesController)) { | ||
const controllerType = typeof state.PreferencesController; | ||
global.sentry?.captureException?.( | ||
new Error(`state.PreferencesController is type: ${controllerType}`), | ||
); | ||
} | ||
|
||
if (!isObject(state.PreferencesController?.preferences)) { | ||
state.PreferencesController = { | ||
preferences: {}, | ||
}; | ||
} | ||
|
||
state.PreferencesController.preferences.redesignedConfirmationsEnabled = true; | ||
} |
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
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
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
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
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
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
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
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
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
Oops, something went wrong.