Skip to content

Commit

Permalink
fix: format
Browse files Browse the repository at this point in the history
  • Loading branch information
matstyler committed Feb 15, 2024
1 parent 09efd7f commit 3eec073
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 103 deletions.
135 changes: 76 additions & 59 deletions wallets/metamask/src/metamask.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import type { BrowserContext, Page } from '@playwright/test'
import { CrashPage, HomePage, LockPage, NotificationPage, OnboardingPage } from './pages'
import type { Network } from './pages/HomePage/actions'
import { SettingsSidebarMenus } from './pages/HomePage/selectors/settings'
import type { GasSetting } from './pages/NotificationPage/actions'

const NO_EXTENSION_ID_ERROR = new Error('MetaMask extensionId is not set')
import type { BrowserContext, Page } from "@playwright/test";
import {
CrashPage,
HomePage,
LockPage,
NotificationPage,
OnboardingPage,
} from "./pages";
import type { Network } from "./pages/HomePage/actions";
import { SettingsSidebarMenus } from "./pages/HomePage/selectors/settings";
import type { GasSetting } from "./pages/NotificationPage/actions";

const NO_EXTENSION_ID_ERROR = new Error("MetaMask extensionId is not set");

/**
* This class is the heart of Synpress's MetaMask API.
Expand All @@ -15,31 +21,31 @@ export class MetaMask {
*
* @group Selectors
*/
readonly crashPage: CrashPage
readonly crashPage: CrashPage;
/**
* This property can be used to access selectors for a given page.
*
* @group Selectors
*/
readonly onboardingPage: OnboardingPage
readonly onboardingPage: OnboardingPage;
/**
* This property can be used to access selectors for a given page.
*
* @group Selectors
*/
readonly lockPage: LockPage
readonly lockPage: LockPage;
/**
* This property can be used to access selectors for a given page.
*
* @group Selectors
*/
readonly homePage: HomePage
readonly homePage: HomePage;
/**
* This property can be used to access selectors for a given page.
*
* @group Selectors
*/
readonly notificationPage: NotificationPage
readonly notificationPage: NotificationPage;

/**
* Class constructor.
Expand Down Expand Up @@ -69,12 +75,12 @@ export class MetaMask {
*/
readonly extensionId?: string
) {
this.crashPage = new CrashPage()
this.crashPage = new CrashPage();

this.onboardingPage = new OnboardingPage(page)
this.lockPage = new LockPage(page)
this.homePage = new HomePage(page)
this.notificationPage = new NotificationPage(page)
this.onboardingPage = new OnboardingPage(page);
this.lockPage = new LockPage(page);
this.homePage = new HomePage(page);
this.notificationPage = new NotificationPage(page);
}

/**
Expand All @@ -83,7 +89,7 @@ export class MetaMask {
* @param seedPhrase - The seed phrase to import.
*/
async importWallet(seedPhrase: string) {
await this.onboardingPage.importWallet(seedPhrase, this.password)
await this.onboardingPage.importWallet(seedPhrase, this.password);
}

/**
Expand All @@ -92,7 +98,7 @@ export class MetaMask {
* @param accountName - The name of the new account.
*/
async addNewAccount(accountName: string) {
await this.homePage.addNewAccount(accountName)
await this.homePage.addNewAccount(accountName);
}

/**
Expand All @@ -101,7 +107,7 @@ export class MetaMask {
* @param privateKey - The private key to import.
*/
async importWalletFromPrivateKey(privateKey: string) {
await this.homePage.importWalletFromPrivateKey(privateKey)
await this.homePage.importWalletFromPrivateKey(privateKey);
}

/**
Expand All @@ -110,7 +116,7 @@ export class MetaMask {
* @param accountName - The name of the account to switch to.
*/
async switchAccount(accountName: string) {
await this.homePage.switchAccount(accountName)
await this.homePage.switchAccount(accountName);
}

/**
Expand All @@ -124,7 +130,7 @@ export class MetaMask {
* @param network.blockExplorerUrl - The block explorer URL of the network.
*/
async addNetwork(network: Network) {
await this.homePage.addNetwork(network)
await this.homePage.addNetwork(network);
}

/**
Expand All @@ -134,98 +140,98 @@ export class MetaMask {
* @param isTestnet - If switch to a test network.
*/
async switchNetwork(networkName: string, isTestnet: boolean = false) {
await this.homePage.switchNetwork(networkName, isTestnet)
await this.homePage.switchNetwork(networkName, isTestnet);
}

/**
* Connects to the dapp using the currently selected account.
*/
async connectToDapp(accounts?: string[]) {
if (!this.extensionId) {
throw NO_EXTENSION_ID_ERROR
throw NO_EXTENSION_ID_ERROR;
}

await this.notificationPage.connectToDapp(this.extensionId, accounts)
await this.notificationPage.connectToDapp(this.extensionId, accounts);
}

/**
* Locks MetaMask.
*/
async lock() {
await this.homePage.lock()
await this.homePage.lock();
}

/**
* Unlocks MetaMask.
*/
async unlock() {
await this.lockPage.unlock(this.password)
await this.lockPage.unlock(this.password);
}

/**
* Confirms a signature request. This function supports all types of commonly used signatures.
*/
async confirmSignature() {
if (!this.extensionId) {
throw NO_EXTENSION_ID_ERROR
throw NO_EXTENSION_ID_ERROR;
}

await this.notificationPage.signMessage(this.extensionId)
await this.notificationPage.signMessage(this.extensionId);
}

/**
* Rejects a signature request. This function supports all types of commonly used signatures.
*/
async rejectSignature() {
if (!this.extensionId) {
throw NO_EXTENSION_ID_ERROR
throw NO_EXTENSION_ID_ERROR;
}

await this.notificationPage.rejectMessage(this.extensionId)
await this.notificationPage.rejectMessage(this.extensionId);
}

/**
* Approves a new network request.
*/
async approveNewNetwork() {
if (!this.extensionId) {
throw NO_EXTENSION_ID_ERROR
throw NO_EXTENSION_ID_ERROR;
}

await this.notificationPage.approveNewNetwork(this.extensionId)
await this.notificationPage.approveNewNetwork(this.extensionId);
}

/**
* Rejects a new network request.
*/
async rejectNewNetwork() {
if (!this.extensionId) {
throw NO_EXTENSION_ID_ERROR
throw NO_EXTENSION_ID_ERROR;
}

await this.notificationPage.rejectNewNetwork(this.extensionId)
await this.notificationPage.rejectNewNetwork(this.extensionId);
}

/**
* Approves a switch network request.
*/
async approveSwitchNetwork() {
if (!this.extensionId) {
throw NO_EXTENSION_ID_ERROR
throw NO_EXTENSION_ID_ERROR;
}

await this.notificationPage.approveSwitchNetwork(this.extensionId)
await this.notificationPage.approveSwitchNetwork(this.extensionId);
}

/**
* Rejects a switch network request.
*/
async rejectSwitchNetwork() {
if (!this.extensionId) {
throw NO_EXTENSION_ID_ERROR
throw NO_EXTENSION_ID_ERROR;
}

await this.notificationPage.rejectSwitchNetwork(this.extensionId)
await this.notificationPage.rejectSwitchNetwork(this.extensionId);
}

/**
Expand All @@ -236,21 +242,21 @@ export class MetaMask {
*/
async confirmTransaction(options?: { gasSetting?: GasSetting }) {
if (!this.extensionId) {
throw NO_EXTENSION_ID_ERROR
throw NO_EXTENSION_ID_ERROR;
}

await this.notificationPage.confirmTransaction(this.extensionId, options)
await this.notificationPage.confirmTransaction(this.extensionId, options);
}

/**
* Rejects a transaction request.
*/
async rejectTransaction() {
if (!this.extensionId) {
throw NO_EXTENSION_ID_ERROR
throw NO_EXTENSION_ID_ERROR;
}

await this.notificationPage.rejectTransaction(this.extensionId)
await this.notificationPage.rejectTransaction(this.extensionId);
}

/**
Expand All @@ -264,12 +270,18 @@ export class MetaMask {
* @param options.spendLimit - The spend limit to use for the permission.
* @param options.gasSetting - The gas setting to use for the approval transaction.
*/
async approveTokenPermission(options?: { spendLimit?: 'max' | number; gasSetting?: GasSetting }) {
async approveTokenPermission(options?: {
spendLimit?: "max" | number;
gasSetting?: GasSetting;
}) {
if (!this.extensionId) {
throw NO_EXTENSION_ID_ERROR
throw NO_EXTENSION_ID_ERROR;
}

await this.notificationPage.approveTokenPermission(this.extensionId, options)
await this.notificationPage.approveTokenPermission(
this.extensionId,
options
);
}

/**
Expand All @@ -281,24 +293,24 @@ export class MetaMask {
*/
async rejectTokenPermission() {
if (!this.extensionId) {
throw NO_EXTENSION_ID_ERROR
throw NO_EXTENSION_ID_ERROR;
}

await this.notificationPage.rejectTokenPermission(this.extensionId)
await this.notificationPage.rejectTokenPermission(this.extensionId);
}

/**
* Goes back to the home page of MetaMask tab.
*/
async goBackToHomePage() {
await this.homePage.goBackToHomePage()
await this.homePage.goBackToHomePage();
}

/**
* Opens the settings page.
*/
async openSettings() {
await this.homePage.openSettings()
await this.homePage.openSettings();
}

/**
Expand All @@ -307,7 +319,7 @@ export class MetaMask {
* @param menu - The menu to open.
*/
async openSidebarMenu(menu: SettingsSidebarMenus) {
await this.homePage.openSidebarMenu(menu)
await this.homePage.openSidebarMenu(menu);
}

/**
Expand All @@ -318,7 +330,7 @@ export class MetaMask {
* :::
*/
async toggleShowTestNetworks() {
await this.homePage.toggleShowTestNetworks()
await this.homePage.toggleShowTestNetworks();
}

/**
Expand All @@ -329,7 +341,7 @@ export class MetaMask {
* :::
*/
async toggleDismissSecretRecoveryPhraseReminder() {
await this.homePage.toggleDismissSecretRecoveryPhraseReminder()
await this.homePage.toggleDismissSecretRecoveryPhraseReminder();
}

/**
Expand All @@ -340,7 +352,7 @@ export class MetaMask {
* :::
*/
async resetAccount() {
await this.homePage.resetAccount()
await this.homePage.resetAccount();
}

/// -------------------------------------------
Expand All @@ -357,12 +369,17 @@ export class MetaMask {
* @experimental
* @group Experimental Methods
*/
async confirmTransactionAndWaitForMining(options?: { gasSetting?: GasSetting }) {
async confirmTransactionAndWaitForMining(options?: {
gasSetting?: GasSetting;
}) {
if (!this.extensionId) {
throw NO_EXTENSION_ID_ERROR
throw NO_EXTENSION_ID_ERROR;
}

await this.notificationPage.confirmTransactionAndWaitForMining(this.extensionId, options)
await this.notificationPage.confirmTransactionAndWaitForMining(
this.extensionId,
options
);
}

/**
Expand All @@ -374,7 +391,7 @@ export class MetaMask {
* @group Experimental Methods
*/
async openTransactionDetails(txIndex: number) {
await this.homePage.openTransactionDetails(txIndex)
await this.homePage.openTransactionDetails(txIndex);
}

/**
Expand All @@ -384,6 +401,6 @@ export class MetaMask {
* @group Experimental Methods
*/
async closeTransactionDetails() {
await this.homePage.closeTransactionDetails()
await this.homePage.closeTransactionDetails();
}
}
Loading

0 comments on commit 3eec073

Please sign in to comment.