Skip to content

Commit

Permalink
✨ feat(metamask): Add resetAccount method (#1080)
Browse files Browse the repository at this point in the history
  • Loading branch information
duckception authored Jan 24, 2024
1 parent ea4b0e8 commit a38fcd9
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 0 deletions.
19 changes: 19 additions & 0 deletions docs/api/classes/MetaMask.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ This class is the heart of Synpress's MetaMask API.
- [rejectSignature()](MetaMask.md#rejectsignature)
- [rejectSwitchNetwork()](MetaMask.md#rejectswitchnetwork)
- [rejectTransaction()](MetaMask.md#rejecttransaction)
- [resetAccount()](MetaMask.md#resetaccount)
- [switchAccount()](MetaMask.md#switchaccount)
- [switchNetwork()](MetaMask.md#switchnetwork)
- [toggleDismissSecretRecoveryPhraseReminder()](MetaMask.md#toggledismisssecretrecoveryphrasereminder)
Expand Down Expand Up @@ -402,6 +403,24 @@ Rejects a transaction request.
***
### resetAccount()
```ts
resetAccount(): Promise<void>
```
Resets the account.
::: warning
This function requires the correct menu to be already opened.
:::
#### Returns
`Promise`\<`void`\>
***
### switchAccount()
```ts
Expand Down
11 changes: 11 additions & 0 deletions wallets/metamask/src/metamask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,17 @@ export class MetaMask {
await this.homePage.toggleDismissSecretRecoveryPhraseReminder()
}

/**
* Resets the account.
*
* ::: warning
* This function requires the correct menu to be already opened.
* :::
*/
async resetAccount() {
await this.homePage.resetAccount()
}

/// -------------------------------------------
/// ---------- EXPERIMENTAL FEATURES ----------
/// -------------------------------------------
Expand Down
9 changes: 9 additions & 0 deletions wallets/metamask/src/pages/HomePage/actions/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,21 @@ async function openSidebarMenu(page: Page, menu: SettingsSidebarMenus) {
await page.locator(Selectors.settings.sidebarMenu(menu)).click()
}

async function resetAccount(page: Page) {
const buttonSelector = `[data-testid="advanced-setting-reset-account"] button`
const confirmButtonSelector = '.modal .modal-container__footer button.btn-danger-primary'

await page.locator(buttonSelector).click()
await page.locator(confirmButtonSelector).click()
}

async function toggleDismissSecretRecoveryPhraseReminder(page: Page) {
const toggleLocator = page.locator(Selectors.settings.advanced.dismissSecretRecoveryPhraseReminderToggle)
await toggle(toggleLocator)
}

const advanced = {
resetAccount,
toggleDismissSecretRecoveryPhraseReminder
}

Expand Down
4 changes: 4 additions & 0 deletions wallets/metamask/src/pages/HomePage/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export class HomePage {
await toggleShowTestNetworks(this.page)
}

async resetAccount() {
await settings.advanced.resetAccount(this.page)
}

async toggleDismissSecretRecoveryPhraseReminder() {
await settings.advanced.toggleDismissSecretRecoveryPhraseReminder(this.page)
}
Expand Down
6 changes: 6 additions & 0 deletions wallets/metamask/src/pages/HomePage/selectors/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ export enum SettingsSidebarMenus {
const sidebarMenu = (menu: SettingsSidebarMenus) =>
`.settings-page__content__tabs .tab-bar__tab.pointer:nth-of-type(${menu})`

const resetAccount = {
button: `${createDataTestSelector('advanced-setting-reset-account')} button`,
confirmButton: '.modal .modal-container__footer button.btn-danger-primary'
}

const advanced = {
// locator(showTestNetworksToggle).nth(0) -> Show conversion on test networks
// locator(showTestNetworksToggle).nth(1) -> Show test networks
resetAccount,
showTestNetworksToggle: `${createDataTestSelector('advanced-setting-show-testnet-conversion')} .toggle-button`,
dismissSecretRecoveryPhraseReminderToggle: '.settings-page__content-row:nth-of-type(11) .toggle-button'
}
Expand Down
19 changes: 19 additions & 0 deletions wallets/metamask/test/e2e/metamask/resetAccount.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { testWithSynpress } from '@synthetixio/synpress-fixtures'
import { MetaMask, unlockForFixture } from '../../../src'

import basicSetup from '../wallet-setup/basic.setup'

const test = testWithSynpress(basicSetup, unlockForFixture)

test('reset the account', async ({ context, metamaskPage }) => {
const metamask = new MetaMask(context, metamaskPage, basicSetup.walletPassword)

await metamask.openSettings()

const SidebarMenus = metamask.homePage.selectors.settings.SettingsSidebarMenus
await metamask.openSidebarMenu(SidebarMenus.Advanced)

await metamask.resetAccount()

await metamask.goBackToHomePage()
})

0 comments on commit a38fcd9

Please sign in to comment.