-
-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat: Implemented sign_eth method with MetaMask settings page (#1106)
## Motivation and context Implemented MetaMask settings page instance to be able to change advanced settings. Then added `sign_eth` method. ## Quality checklist - [x] I have performed a self-review of my code. - [x] If it is a core feature, I have added thorough e2e tests. **⚠️ 👆 Delete any section you see irrelevant before submitting the pull request 👆⚠️ ** --- <details open="true"><summary>Generated summary</summary> > ## TL;DR > This pull request adds new methods and properties to the MetaMask class, including enabling and disabling the eth_sign feature in advanced settings. It also includes changes to the NotificationPage and SettingsPage classes for interacting with confirmation modals and toggling Ethereum signing. > > ## What changed > - Added new import for SettingsPage and property settingsPage to MetaMask class > - Added confirmSignatureWithRisk method to MetaMask class > - Added enableEthSignUnsafe method to MetaMask class > - Added signMessageWithRisk function to signSimpleMessage.ts > - Added signWithRisk function to signSimpleMessage object > - Added signMessageWithRisk async function to NotificationPage class > - Added new selector for risk modal in NotificationPage > - Added action to disable Ethereum signing in SettingsPage > - Added enableEthSign and disableEthSign functions to SettingsPage > - Added selectors for elements on SettingsPage > - Added confirmation modal object with specific selectors > - Added tests for confirming eth_sign functionality in Metamask > > ## How to test > 1. Enable and disable eth_sign feature in MetaMask advanced settings > 2. Interact with confirmation modals for enabling and disabling Ethereum signing > 3. Confirm signature with risk using the confirmSignatureWithRisk method > 4. Test eth_sign functionality in Metamask with provided test cases > > ## Why make this change > - Enhances MetaMask functionality by adding methods to confirm signatures with risk > - Provides users with the ability to enable and disable eth_sign feature for security purposes > - Improves user experience by adding interaction with confirmation modals > - Ensures proper testing of eth_sign functionality in Metamask for reliability and security </details>
- Loading branch information
Showing
10 changed files
with
146 additions
and
5 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
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
7 changes: 7 additions & 0 deletions
7
wallets/metamask/src/pages/SettingsPage/actions/disableEthSign.ts
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,7 @@ | ||
import type { Page } from '@playwright/test' | ||
import Selectors from '../selectors' | ||
|
||
export default async function disableEthSign(page: Page) { | ||
await page.locator(Selectors.settings.advancedSettings).click() | ||
await page.locator(Selectors.settings.ethSignToggle).click() | ||
} |
18 changes: 18 additions & 0 deletions
18
wallets/metamask/src/pages/SettingsPage/actions/enableEthSign.ts
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,18 @@ | ||
import type { Page } from '@playwright/test' | ||
import Selectors from '../selectors' | ||
|
||
export default async function enableEthSign(page: Page) { | ||
// Settings | ||
await page.locator(Selectors.settings.advancedSettings).click() | ||
await page.locator(Selectors.settings.ethSignToggle).click() | ||
|
||
// Confirmation modal | ||
await page.locator(Selectors.confirmationModal.confirmationCheckbox).click() | ||
await page.locator(Selectors.confirmationModal.continueButton).click() | ||
await page.locator(Selectors.confirmationModal.manualConfirmationInput).focus() | ||
await page.locator(Selectors.confirmationModal.manualConfirmationInput).fill('I only sign what I understand') | ||
await page.locator(Selectors.confirmationModal.enableButton).click() | ||
|
||
// Wait for warning | ||
await page.locator(Selectors.settings.ethSignWarning).isVisible() | ||
} |
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,2 @@ | ||
export { default as enableEthSign } from './enableEthSign' | ||
export { default as disableEthSign } from './disableEthSign' |
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,22 @@ | ||
import type { Page } from '@playwright/test' | ||
import { enableEthSign } from './actions' | ||
import disableEthSign from './actions/disableEthSign' | ||
import Selectors from './selectors' | ||
|
||
export class SettingsPage { | ||
static readonly selectors = Selectors | ||
|
||
readonly page: Page | ||
|
||
constructor(page: Page) { | ||
this.page = page | ||
} | ||
|
||
async enableEthSign() { | ||
await enableEthSign(this.page) | ||
} | ||
|
||
async disableEthSign() { | ||
await disableEthSign(this.page) | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
wallets/metamask/src/pages/SettingsPage/selectors/index.ts
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,23 @@ | ||
import { createDataTestSelector } from '../../../utils/selectors/createDataTestSelector' | ||
|
||
const menuOption = '.settings-page__content__tabs .tab-bar .tab-bar__tab' | ||
|
||
const settings = { | ||
menuOption, | ||
advancedSettings: `${menuOption}:nth-child(2)`, | ||
ethSignToggle: `${createDataTestSelector('advanced-setting-toggle-ethsign')} .eth-sign-toggle`, | ||
ethSignWarning: | ||
'.settings-page__content-row .mm-banner-alert.mm-banner-alert--severity-danger.mm-box--background-color-error-muted' | ||
} | ||
|
||
const confirmationModal = { | ||
confirmationCheckbox: createDataTestSelector('eth-sign__checkbox'), | ||
continueButton: '.modal__content button.mm-button-primary', | ||
manualConfirmationInput: '#enter-eth-sign-text', | ||
enableButton: '.modal__content button.mm-button-primary.mm-button-primary--type-danger' | ||
} | ||
|
||
export default { | ||
settings, | ||
confirmationModal | ||
} |
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