-
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: Enable redesigned transaction confirmations for all users #28321
Merged
+5,385
β2,689
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
821b49d
feat: Enable redesigned transaction confirmations for all users
pedronfigueiredo 16bd2ea
fix: e2e tests
pedronfigueiredo c5528be
fix e2e test
pedronfigueiredo 721e69b
Add tests for redesigned flows
pedronfigueiredo 5fec298
wip
pedronfigueiredo 24b0b3c
wip
pedronfigueiredo 7c90dc2
wip
pedronfigueiredo d2504e3
wip
pedronfigueiredo 47d4b32
Update migration
pedronfigueiredo 1913c38
Rename withRedesignConfirmationFixtures
pedronfigueiredo 4b26411
Migrate snap-account-transfers.spec.ts tests
pedronfigueiredo 0ef5fc8
Revert test spacing
pedronfigueiredo 2d2398f
Revert test run timeout
pedronfigueiredo 4171b58
remove unnecessary test
pedronfigueiredo 23dea5b
fix whitespace
pedronfigueiredo a419656
fix linting errors
pedronfigueiredo e8b230d
Refactor closing the settings panel
pedronfigueiredo d708e8b
fix linting errors
pedronfigueiredo 7b198b9
Add comment on accounts tests
pedronfigueiredo 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,73 @@ | ||
import { migrate, version } from './132'; | ||
|
||
const oldVersion = 131; | ||
|
||
describe('migration #132', () => { | ||
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 no preferences controller state is set', async () => { | ||
const oldState = { | ||
OtherController: {}, | ||
}; | ||
|
||
const transformedState = await migrate({ | ||
meta: { version: oldVersion }, | ||
data: oldState, | ||
}); | ||
|
||
expect(transformedState.data).toEqual(oldState); | ||
}); | ||
|
||
it('adds preferences property to the controller if it is not set and set the preference to true if migration runs', async () => { | ||
const oldState = { PreferencesController: {} }; | ||
|
||
const expectedState = { | ||
PreferencesController: { | ||
preferences: { | ||
redesignedTransactionsEnabled: true, | ||
}, | ||
}, | ||
}; | ||
|
||
const transformedState = await migrate({ | ||
meta: { version: oldVersion }, | ||
data: oldState, | ||
}); | ||
|
||
expect(transformedState.data).toEqual(expectedState); | ||
}); | ||
|
||
it('changes property to true if migration runs', async () => { | ||
const oldState = { | ||
PreferencesController: { | ||
preferences: { | ||
redesignedTransactionsEnabled: false, | ||
}, | ||
}, | ||
}; | ||
|
||
const expectedState = { | ||
PreferencesController: { | ||
preferences: { | ||
redesignedTransactionsEnabled: true, | ||
}, | ||
}, | ||
}; | ||
|
||
const transformedState = await migrate({ | ||
meta: { version: oldVersion }, | ||
data: oldState, | ||
}); | ||
|
||
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,58 @@ | ||
import { isObject } from '@metamask/utils'; | ||
import { cloneDeep } from 'lodash'; | ||
|
||
type VersionedData = { | ||
meta: { version: number }; | ||
data: Record<string, unknown>; | ||
}; | ||
|
||
export const version = 132; | ||
|
||
/** | ||
* This migration sets `redesignedTransactionsEnabled` as true by default in preferences in PreferencesController. | ||
* | ||
* @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 (!isObject(state?.PreferencesController)) { | ||
return state; | ||
} | ||
|
||
if (!isObject(state.PreferencesController?.preferences)) { | ||
state.PreferencesController = { | ||
...state.PreferencesController, | ||
preferences: {}, | ||
}; | ||
} | ||
|
||
const preferencesControllerState = state.PreferencesController as Record< | ||
string, | ||
unknown | ||
>; | ||
|
||
const preferences = preferencesControllerState.preferences as Record< | ||
string, | ||
unknown | ||
>; | ||
|
||
// `redesignedTransactionsEnabled` was previously set to `false` by | ||
// default in `124.ts` | ||
preferences.redesignedTransactionsEnabled = true; | ||
|
||
return state; | ||
} |
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 |
---|---|---|
|
@@ -860,6 +860,46 @@ async function tempToggleSettingRedesignedConfirmations(driver) { | |
); | ||
} | ||
|
||
/** | ||
* Rather than using the FixtureBuilder#withPreferencesController to set the setting | ||
* we need to manually set the setting because the migration #132 overrides this. | ||
* We should be able to remove this when we delete the redesignedTransactionsEnabled setting. | ||
* | ||
* @param driver | ||
*/ | ||
async function tempToggleSettingRedesignedTransactionConfirmations(driver) { | ||
// Ensure we are on the extension window | ||
await driver.switchToWindowWithTitle(WINDOW_TITLES.ExtensionInFullScreenView); | ||
|
||
// Open settings menu button | ||
await driver.clickElement('[data-testid="account-options-menu-button"]'); | ||
|
||
// fix race condition with mmi build | ||
if (process.env.MMI) { | ||
await driver.waitForSelector('[data-testid="global-menu-mmi-portfolio"]'); | ||
} | ||
|
||
// 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 redesigned transactions toggle | ||
await driver.clickElement( | ||
'[data-testid="toggle-redesigned-transactions-container"]', | ||
); | ||
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 think that after clicking the toggle, we should close the settings, so we can proceed with any test normally, without the need of doing any extra step in the test, aside from calling this function (check my comment below) |
||
|
||
// Close settings page | ||
await driver.clickElement( | ||
'.settings-page__header__title-container__close-button', | ||
); | ||
} | ||
|
||
/** | ||
* Opens the account options menu safely, handling potential race conditions | ||
* with the MMI build. | ||
|
@@ -928,6 +968,7 @@ module.exports = { | |
editGasFeeForm, | ||
clickNestedButton, | ||
tempToggleSettingRedesignedConfirmations, | ||
tempToggleSettingRedesignedTransactionConfirmations, | ||
openMenuSafe, | ||
sentryRegEx, | ||
}; |
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.
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.
ππΌ