Skip to content

Commit

Permalink
✨ feat: add action for approvingnew RPC provider for Ethereum Mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
zgz2020 committed Nov 19, 2024
1 parent 4199721 commit 0263335
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 2 deletions.
18 changes: 18 additions & 0 deletions docs/api/playwright/classes/MetaMask.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,24 @@ If extensionId is not set.
***
### approveNewEthereumRPC()
```ts
approveNewEthereumRPC(): Promise<void>
```
Approves adding a new RPC provider for Ethereum Mainnet.
#### Returns
`Promise`\<`void`\>
#### Throws
If extensionId is not set.
***
### approveNewNetwork()
```ts
Expand Down
30 changes: 29 additions & 1 deletion wallets/metamask/src/playwright/MetaMask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
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<void> {
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<void> {
async confirmTransaction(options?: {
gasSetting?: GasSettings
}): Promise<void> {
if (!this.extensionId) {
throw NO_EXTENSION_ID_ERROR
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from './transaction'
export * from './network'
export * from './token'
export * from './encryption'
export * from './ethereumRpc'
13 changes: 13 additions & 0 deletions wallets/metamask/src/playwright/pages/NotificationPage/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
approvePermission,
connectToDapp,
decryptMessage,
ethereumRpc,
network,
providePublicEncryptionKey,
signSimpleMessage,
Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default {
approveNewRpc: '.confirmation-warning-modal__content .mm-button-primary--type-danger',
rejectNewRpc: '.confirmation-warning-modal__content .mm-button-secondary'
}
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -8,8 +9,9 @@ import TransactionPage from './transactionPage'
export default {
ActionFooter,
ConnectPage,
SignaturePage,
EthereumRpcPage,
NetworkPage,
PermissionPage,
SignaturePage,
TransactionPage
}

0 comments on commit 0263335

Please sign in to comment.