Skip to content

Commit

Permalink
feat: (cherry-pick)(Version v12.2.0) Migration #122 set redesignedCon…
Browse files Browse the repository at this point in the history
…firmationsEnabled to true (#26139)

<!--
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**

Cherry-pick #25769
for Version v12.2.0

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/26043?quickstart=1)

## **Related issues**

Fixes: #24614

## **Manual testing steps**

1. Go to this page...
2.
3.

## **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
digiwand authored Jul 29, 2024
1 parent 582c619 commit 636406d
Show file tree
Hide file tree
Showing 19 changed files with 216 additions and 11 deletions.
1 change: 1 addition & 0 deletions app/scripts/lib/setupSentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ export const SENTRY_BACKGROUND_STATE = {
preferences: {
autoLockTimeLimit: true,
hideZeroBalanceTokens: true,
redesignedConfirmationsEnabled: true,
isRedesignedConfirmationsDeveloperEnabled: false,
showExtensionInFullSizeView: true,
showFiatInTestnets: true,
Expand Down
74 changes: 74 additions & 0 deletions app/scripts/migrations/122.test.ts
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);
},
);
});
});
50 changes: 50 additions & 0 deletions app/scripts/migrations/122.ts
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;
}
1 change: 1 addition & 0 deletions app/scripts/migrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ const migrations = [
require('./119'),
require('./120'),
require('./121'),
require('./122'),
];

export default migrations;
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Suite } from 'mocha';
import FixtureBuilder from '../fixture-builder';
import { withFixtures, multipleGanacheOptions } from '../helpers';
import {
withFixtures,
multipleGanacheOptions,
tempToggleSettingRedesignedConfirmations,
} from '../helpers';
import { Driver } from '../webdriver/driver';
import {
installSnapSimpleKeyring,
Expand All @@ -27,6 +31,8 @@ describe('Snap Account Signatures and Disconnects', function (this: Suite) {

const newPublicKey = await makeNewAccountAndSwitch(driver);

await tempToggleSettingRedesignedConfirmations(driver);

// open the Test Dapp and connect Account 2 to it
await connectAccountToTestDapp(driver);

Expand Down
8 changes: 7 additions & 1 deletion test/e2e/accounts/snap-account-signatures.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { Suite } from 'mocha';
import { openDapp, withFixtures } from '../helpers';
import {
openDapp,
tempToggleSettingRedesignedConfirmations,
withFixtures,
} from '../helpers';
import { Driver } from '../webdriver/driver';
import {
accountSnapFixtures,
Expand Down Expand Up @@ -27,6 +31,8 @@ describe('Snap Account Signatures', function (this: Suite) {

const newPublicKey = await makeNewAccountAndSwitch(driver);

await tempToggleSettingRedesignedConfirmations(driver);

await openDapp(driver);

// Run all 6 signature types
Expand Down
34 changes: 34 additions & 0 deletions test/e2e/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,39 @@ async function initBundler(bundlerServer, ganacheServer, usePaymaster) {
}
}

/**
* Rather than using the FixtureBuilder#withPreferencesController to set the setting
* we need to manually set the setting because the migration #122 overrides this.
* We should be able to remove this when we delete the redesignedConfirmationsEnabled setting.
*
* @param driver
*/
async function tempToggleSettingRedesignedConfirmations(driver) {
// Ensure we are on the extension window
await driver.switchToWindowWithTitle(WINDOW_TITLES.ExtensionInFullScreenView);

// Open settings menu button
const accountOptionsMenuSelector =
'[data-testid="account-options-menu-button"]';
await driver.waitForSelector(accountOptionsMenuSelector);
await driver.clickElement(accountOptionsMenuSelector);

// Click settings from dropdown menu
await driver.clickElement('[data-testid="global-menu-settings"]');

// Click Experimental tab
const experimentalTabRawLocator = {
text: 'Experimental',
tag: 'div',
};
await driver.clickElement(experimentalTabRawLocator);

// Click redesignedConfirmationsEnabled toggle
await driver.clickElement(
'[data-testid="toggle-redesigned-confirmations-container"]',
);
}

module.exports = {
DAPP_HOST_ADDRESS,
DAPP_URL,
Expand Down Expand Up @@ -1207,4 +1240,5 @@ module.exports = {
editGasFeeForm,
clickNestedButton,
defaultGanacheOptionsForType2Transactions,
tempToggleSettingRedesignedConfirmations,
};
2 changes: 2 additions & 0 deletions test/e2e/snaps/test-snap-siginsights.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {
openDapp,
unlockWallet,
switchToNotificationWindow,
tempToggleSettingRedesignedConfirmations,
WINDOW_TITLES,
} = require('../helpers');
const FixtureBuilder = require('../fixture-builder');
Expand All @@ -29,6 +30,7 @@ describe('Test Snap Signature Insights', function () {
},
async ({ driver }) => {
await unlockWallet(driver);
await tempToggleSettingRedesignedConfirmations(driver);

// navigate to test snaps page and connect
await driver.openNewPage(TEST_SNAPS_WEBSITE_URL);
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/tests/dapp-interactions/signin-with-ethereum.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const {
withFixtures,
openDapp,
DAPP_URL,
tempToggleSettingRedesignedConfirmations,
unlockWallet,
WINDOW_TITLES,
} = require('../../helpers');
Expand All @@ -28,6 +29,7 @@ describe('Sign in with ethereum', function () {
},
async ({ driver }) => {
await unlockWallet(driver);
await tempToggleSettingRedesignedConfirmations(driver);

// Create a signin with ethereum request in test dapp
await openDapp(driver);
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/tests/metrics/signature-approved.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {
unlockWallet,
getEventPayloads,
clickSignOnSignatureConfirmation,
tempToggleSettingRedesignedConfirmations,
validateContractDetails,
} = require('../../helpers');
const FixtureBuilder = require('../../fixture-builder');
Expand Down Expand Up @@ -65,6 +66,7 @@ describe('Signature Approved Event @no-mmi', function () {
},
async ({ driver, mockedEndpoint: mockedEndpoints }) => {
await unlockWallet(driver);
await tempToggleSettingRedesignedConfirmations(driver);
await openDapp(driver);

// creates a sign typed data signature request
Expand Down Expand Up @@ -116,6 +118,7 @@ describe('Signature Approved Event @no-mmi', function () {
},
async ({ driver, mockedEndpoint: mockedEndpoints }) => {
await unlockWallet(driver);
await tempToggleSettingRedesignedConfirmations(driver);
await openDapp(driver);

// creates a sign typed data signature request
Expand Down Expand Up @@ -163,6 +166,7 @@ describe('Signature Approved Event @no-mmi', function () {
},
async ({ driver, mockedEndpoint: mockedEndpoints }) => {
await unlockWallet(driver);
await tempToggleSettingRedesignedConfirmations(driver);
await openDapp(driver);

// creates a sign typed data signature request
Expand Down Expand Up @@ -209,6 +213,7 @@ describe('Signature Approved Event @no-mmi', function () {
},
async ({ driver, mockedEndpoint: mockedEndpoints }) => {
await unlockWallet(driver);
await tempToggleSettingRedesignedConfirmations(driver);
await openDapp(driver);

// creates a sign typed data signature request
Expand Down Expand Up @@ -260,6 +265,7 @@ describe('Signature Approved Event @no-mmi', function () {
},
async ({ driver, mockedEndpoint: mockedEndpoints }) => {
await unlockWallet(driver);
await tempToggleSettingRedesignedConfirmations(driver);
await openDapp(driver);

// creates a sign typed data signature request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@
"useNativeCurrencyAsPrimaryCurrency": true,
"petnamesEnabled": true,
"showTokenAutodetectModal": "boolean",
"isRedesignedConfirmationsDeveloperEnabled": "boolean"
"isRedesignedConfirmationsDeveloperEnabled": "boolean",
"redesignedConfirmationsEnabled": true
},
"ipfsGateway": "string",
"isIpfsGatewayEnabled": "boolean",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"useNativeCurrencyAsPrimaryCurrency": true,
"petnamesEnabled": true,
"showTokenAutodetectModal": "boolean",
"isRedesignedConfirmationsDeveloperEnabled": "boolean"
"isRedesignedConfirmationsDeveloperEnabled": "boolean",
"redesignedConfirmationsEnabled": true
},
"firstTimeFlowType": "import",
"completedOnboarding": true,
Expand All @@ -62,11 +63,6 @@
},
"connectedStatusPopoverHasBeenShown": true,
"defaultHomeActiveTabName": null,
"bridgeState": {
"bridgeFeatureFlags": {
"extensionSupport": "boolean"
}
},
"browserEnvironment": { "os": "string", "browser": "string" },
"popupGasPollTokens": "object",
"notificationGasPollTokens": "object",
Expand Down Expand Up @@ -121,8 +117,8 @@
"useRequestQueue": true,
"openSeaEnabled": false,
"securityAlertsEnabled": "boolean",
"addSnapAccountEnabled": "boolean",
"bitcoinSupportEnabled": "boolean",
"addSnapAccountEnabled": "boolean",
"advancedGasFee": {},
"incomingTransactionsPreferences": {},
"identities": "object",
Expand Down Expand Up @@ -255,6 +251,7 @@
"swapsStxGetTransactionsRefreshTime": 10000,
"swapsStxMaxFeeMultiplier": 2
},
"bridgeState": { "bridgeFeatureFlags": { "extensionSupport": "boolean" } },
"ensEntries": "object",
"ensResolutionsByAddress": "object",
"pendingApprovals": "object",
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/tests/petnames/petnames-signatures.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const {
openDapp,
switchToNotificationWindow,
withFixtures,
tempToggleSettingRedesignedConfirmations,
unlockWallet,
defaultGanacheOptions,
} = require('../../helpers');
Expand Down Expand Up @@ -108,6 +109,7 @@ describe('Petnames - Signatures', function () {
},
async ({ driver }) => {
await unlockWallet(driver);
await tempToggleSettingRedesignedConfirmations(driver);
await openDapp(driver);
await createSignatureRequest(driver, SIGNATURE_TYPE.TYPED_V3);
await switchToNotificationWindow(driver, 3);
Expand Down Expand Up @@ -144,6 +146,7 @@ describe('Petnames - Signatures', function () {
},
async ({ driver }) => {
await unlockWallet(driver);
await tempToggleSettingRedesignedConfirmations(driver);
await openDapp(driver);
await createSignatureRequest(driver, SIGNATURE_TYPE.TYPED_V4);
await switchToNotificationWindow(driver, 3);
Expand Down Expand Up @@ -185,6 +188,7 @@ describe('Petnames - Signatures', function () {
},
async ({ driver }) => {
await unlockWallet(driver);
await tempToggleSettingRedesignedConfirmations(driver);
await openDapp(driver);
await openTestSnaps(driver);
await installNameLookupSnap(driver);
Expand Down
Loading

0 comments on commit 636406d

Please sign in to comment.