From 026333505f1f8c27e5326de7f4adf70315625843 Mon Sep 17 00:00:00 2001 From: juan-langa Date: Mon, 18 Nov 2024 18:59:05 +0100 Subject: [PATCH] :sparkles: feat: add action for approvingnew RPC provider for Ethereum Mainnet --- docs/api/playwright/classes/MetaMask.md | 18 +++++++++++ wallets/metamask/src/playwright/MetaMask.ts | 30 ++++++++++++++++++- .../NotificationPage/actions/ethereumRpc.ts | 15 ++++++++++ .../pages/NotificationPage/actions/index.ts | 1 + .../playwright/pages/NotificationPage/page.ts | 13 ++++++++ .../pages/NotificationPage/ethereumRpcPage.ts | 4 +++ .../selectors/pages/NotificationPage/index.ts | 4 ++- 7 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 wallets/metamask/src/playwright/pages/NotificationPage/actions/ethereumRpc.ts create mode 100644 wallets/metamask/src/selectors/pages/NotificationPage/ethereumRpcPage.ts diff --git a/docs/api/playwright/classes/MetaMask.md b/docs/api/playwright/classes/MetaMask.md index 5c706026e..5c647731e 100644 --- a/docs/api/playwright/classes/MetaMask.md +++ b/docs/api/playwright/classes/MetaMask.md @@ -132,6 +132,24 @@ If extensionId is not set. *** +### approveNewEthereumRPC() + +```ts +approveNewEthereumRPC(): Promise +``` + +Approves adding a new RPC provider for Ethereum Mainnet. + +#### Returns + +`Promise`\<`void`\> + +#### Throws + +If extensionId is not set. + +*** + ### approveNewNetwork() ```ts diff --git a/wallets/metamask/src/playwright/MetaMask.ts b/wallets/metamask/src/playwright/MetaMask.ts index b3120c7de..8ead578b3 100644 --- a/wallets/metamask/src/playwright/MetaMask.ts +++ b/wallets/metamask/src/playwright/MetaMask.ts @@ -283,13 +283,41 @@ export class MetaMask extends MetaMaskAbstract { await this.notificationPage.rejectSwitchNetwork(this.extensionId) } + /** + * Approves switching to a new network. + * + * @throws {Error} If extensionId is not set. + */ + async approveNewEthereumRPC(): Promise { + if (!this.extensionId) { + throw NO_EXTENSION_ID_ERROR + } + + await this.notificationPage.approveNewEthereumRPC(this.extensionId) + } + + /** + * Rejects switching to a new network. + * + * @throws {Error} If extensionId is not set. + */ + async rejectNewEthereumRPC(): Promise { + if (!this.extensionId) { + throw NO_EXTENSION_ID_ERROR + } + + await this.notificationPage.rejectNewEthereumRPC(this.extensionId) + } + /** * Confirms a transaction. * * @param options - Optional gas settings for the transaction. * @throws {Error} If extensionId is not set. */ - async confirmTransaction(options?: { gasSetting?: GasSettings }): Promise { + async confirmTransaction(options?: { + gasSetting?: GasSettings + }): Promise { if (!this.extensionId) { throw NO_EXTENSION_ID_ERROR } diff --git a/wallets/metamask/src/playwright/pages/NotificationPage/actions/ethereumRpc.ts b/wallets/metamask/src/playwright/pages/NotificationPage/actions/ethereumRpc.ts new file mode 100644 index 000000000..1c3f6d1ca --- /dev/null +++ b/wallets/metamask/src/playwright/pages/NotificationPage/actions/ethereumRpc.ts @@ -0,0 +1,15 @@ +import type { Page } from '@playwright/test' +import Selectors from '../../../../selectors/pages/NotificationPage' + +const approveNewEthereumRPC = async (notificationPage: Page) => { + await notificationPage.locator(Selectors.EthereumRpcPage.approveNewRpc).click() +} + +const rejectNewEthereumRPC = async (notificationPage: Page) => { + await notificationPage.locator(Selectors.EthereumRpcPage.rejectNewRpc).click() +} + +export const ethereumRpc = { + approveNewEthereumRPC, + rejectNewEthereumRPC +} diff --git a/wallets/metamask/src/playwright/pages/NotificationPage/actions/index.ts b/wallets/metamask/src/playwright/pages/NotificationPage/actions/index.ts index 3a2f10500..11a7730c9 100644 --- a/wallets/metamask/src/playwright/pages/NotificationPage/actions/index.ts +++ b/wallets/metamask/src/playwright/pages/NotificationPage/actions/index.ts @@ -6,3 +6,4 @@ export * from './transaction' export * from './network' export * from './token' export * from './encryption' +export * from './ethereumRpc' diff --git a/wallets/metamask/src/playwright/pages/NotificationPage/page.ts b/wallets/metamask/src/playwright/pages/NotificationPage/page.ts index 1052ccd41..12209d598 100644 --- a/wallets/metamask/src/playwright/pages/NotificationPage/page.ts +++ b/wallets/metamask/src/playwright/pages/NotificationPage/page.ts @@ -6,6 +6,7 @@ import { approvePermission, connectToDapp, decryptMessage, + ethereumRpc, network, providePublicEncryptionKey, signSimpleMessage, @@ -99,6 +100,18 @@ export class NotificationPage { await network.rejectSwitchNetwork(notificationPage) } + async approveNewEthereumRPC(extensionId: string) { + const notificationPage = await getNotificationPageAndWaitForLoad(this.page.context(), extensionId) + + await ethereumRpc.approveNewEthereumRPC(notificationPage) + } + + async rejectNewEthereumRPC(extensionId: string) { + const notificationPage = await getNotificationPageAndWaitForLoad(this.page.context(), extensionId) + + await ethereumRpc.rejectNewEthereumRPC(notificationPage) + } + async confirmTransaction(extensionId: string, options?: { gasSetting?: GasSettings }) { const notificationPage = await getNotificationPageAndWaitForLoad(this.page.context(), extensionId) diff --git a/wallets/metamask/src/selectors/pages/NotificationPage/ethereumRpcPage.ts b/wallets/metamask/src/selectors/pages/NotificationPage/ethereumRpcPage.ts new file mode 100644 index 000000000..56e2fe8cd --- /dev/null +++ b/wallets/metamask/src/selectors/pages/NotificationPage/ethereumRpcPage.ts @@ -0,0 +1,4 @@ +export default { + approveNewRpc: '.confirmation-warning-modal__content .mm-button-primary--type-danger', + rejectNewRpc: '.confirmation-warning-modal__content .mm-button-secondary' +} diff --git a/wallets/metamask/src/selectors/pages/NotificationPage/index.ts b/wallets/metamask/src/selectors/pages/NotificationPage/index.ts index 66267cd73..76744ae89 100644 --- a/wallets/metamask/src/selectors/pages/NotificationPage/index.ts +++ b/wallets/metamask/src/selectors/pages/NotificationPage/index.ts @@ -1,5 +1,6 @@ import ActionFooter from './actionFooter' import ConnectPage from './connectPage' +import EthereumRpcPage from './ethereumRpcPage' import NetworkPage from './networkPage' import PermissionPage from './permissionPage' import SignaturePage from './signaturePage' @@ -8,8 +9,9 @@ import TransactionPage from './transactionPage' export default { ActionFooter, ConnectPage, - SignaturePage, + EthereumRpcPage, NetworkPage, PermissionPage, + SignaturePage, TransactionPage }