-
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
feat: (cherry-pick)(Version v12.2.0) Migration #122 set redesignedConfirmationsEnabled to true #26139
Merged
chloeYue
merged 1 commit into
Version-v12.2.0
from
chore-cherry-pick-feat-migration-122-redesignedConfirmationsEnabled
Jul 29, 2024
Merged
feat: (cherry-pick)(Version v12.2.0) Migration #122 set redesignedConfirmationsEnabled to true #26139
Changes from all 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -203,7 +203,8 @@ | |
"useNativeCurrencyAsPrimaryCurrency": true, | ||
"petnamesEnabled": true, | ||
"showTokenAutodetectModal": "boolean", | ||
"isRedesignedConfirmationsDeveloperEnabled": "boolean" | ||
"isRedesignedConfirmationsDeveloperEnabled": "boolean", | ||
"redesignedConfirmationsEnabled": true | ||
}, | ||
"ipfsGateway": "string", | ||
"isIpfsGatewayEnabled": "boolean", | ||
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. snapshot differences (compare): |
||
|
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 |
---|---|---|
|
@@ -35,7 +35,8 @@ | |
"useNativeCurrencyAsPrimaryCurrency": true, | ||
"petnamesEnabled": true, | ||
"showTokenAutodetectModal": "boolean", | ||
"isRedesignedConfirmationsDeveloperEnabled": "boolean" | ||
"isRedesignedConfirmationsDeveloperEnabled": "boolean", | ||
"redesignedConfirmationsEnabled": true | ||
}, | ||
"firstTimeFlowType": "import", | ||
"completedOnboarding": true, | ||
|
@@ -62,11 +63,6 @@ | |
}, | ||
"connectedStatusPopoverHasBeenShown": true, | ||
"defaultHomeActiveTabName": null, | ||
"bridgeState": { | ||
"bridgeFeatureFlags": { | ||
"extensionSupport": "boolean" | ||
} | ||
}, | ||
"browserEnvironment": { "os": "string", "browser": "string" }, | ||
"popupGasPollTokens": "object", | ||
"notificationGasPollTokens": "object", | ||
|
@@ -121,8 +117,8 @@ | |
"useRequestQueue": true, | ||
"openSeaEnabled": false, | ||
"securityAlertsEnabled": "boolean", | ||
"addSnapAccountEnabled": "boolean", | ||
"bitcoinSupportEnabled": "boolean", | ||
"addSnapAccountEnabled": "boolean", | ||
"advancedGasFee": {}, | ||
"incomingTransactionsPreferences": {}, | ||
"identities": "object", | ||
|
@@ -255,6 +251,7 @@ | |
"swapsStxGetTransactionsRefreshTime": 10000, | ||
"swapsStxMaxFeeMultiplier": 2 | ||
}, | ||
"bridgeState": { "bridgeFeatureFlags": { "extensionSupport": "boolean" } }, | ||
"ensEntries": "object", | ||
"ensResolutionsByAddress": "object", | ||
"pendingApprovals": "object", | ||
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. snapshot differences (compare): |
||
|
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.
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.
1 less -1 line change here (compare)