From 769d933d7dbb56ec0c3b417270a19681bf0b06c9 Mon Sep 17 00:00:00 2001 From: Sero <69639595+Seroxdesign@users.noreply.github.com> Date: Tue, 9 Jul 2024 09:58:14 -0400 Subject: [PATCH] organise pages --- wallets/phantom/src/PhantomWallet.ts | 48 +++++++++++++++---- .../phantom/src/fixtures/phantomFixtures.ts | 2 +- .../HomePage/actions/disconnectFromApp.ts | 28 +++++++++++ .../src/pages/HomePage/actions/index.ts | 4 ++ wallets/phantom/src/pages/HomePage/page.ts | 17 +++++++ .../pages/LockPage/actions/createAccount.ts | 4 +- .../src/pages/LockPage/actions/index.ts | 3 +- wallets/phantom/src/pages/LockPage/page.ts | 9 +++- .../src/pages/NotificationPage/page.ts | 33 +++++++++++++ wallets/phantom/src/utils/constants.ts | 12 ----- wallets/phantom/src/utils/index.ts | 3 +- wallets/phantom/test/synpress.ts | 2 +- .../{import2.setup.ts => create.setup.ts} | 8 ++-- 13 files changed, 138 insertions(+), 35 deletions(-) create mode 100644 wallets/phantom/src/pages/HomePage/actions/disconnectFromApp.ts delete mode 100644 wallets/phantom/src/utils/constants.ts rename wallets/phantom/test/wallet-setup/{import2.setup.ts => create.setup.ts} (63%) diff --git a/wallets/phantom/src/PhantomWallet.ts b/wallets/phantom/src/PhantomWallet.ts index 0095863ec..5eb5a190a 100644 --- a/wallets/phantom/src/PhantomWallet.ts +++ b/wallets/phantom/src/PhantomWallet.ts @@ -32,30 +32,58 @@ export class PhantomWallet { * @param password. The password to set. */ async importWallet({ secretWords, password }: { secretWords: string; password: string }) { - this.lockPage.importWallet(secretWords, password) + await this.lockPage.importWallet(secretWords, password) } async createWallet(password: string) { - console.log(password) + await this.lockPage.createWallet(password) } async getWalletAddress(wallet: string) { - console.log(wallet) + await this.homePage.getWalletAddress(this.extensionId!, wallet) } - async addNewTokensFound() { - console.log('') + async changeAccount(accountIndex: number) { + await this.homePage.changeAccount(accountIndex) } - async disconnectWalletFromDapps() { - console.log('') + async closePopupAndTooltips() { + await this.homePage.closePopupAndTooltips(this.extensionId!) + } + + async disconnectFromApp() { + await this.homePage.disconnectFromApp(this.extensionId!) + } + + async selectWallet(wallet: string) { + await this.notificationPage.selectWallet(this.extensionId!, wallet) + } + + async lock() { + await this.notificationPage.lock(this.extensionId!) } async acceptAccess() { - console.log('') + await this.notificationPage.acceptAccess(this.extensionId!) + } + + async confirmIncorrectNetwork() { + await this.notificationPage.confirmIncorrectNetwork(this.extensionId!) + } + + async confirmSignature() { + await this.notificationPage.confirmSignatureRequest(this.extensionId!) + } + + async confirmTransaction() { + await this.notificationPage.confirmTransaction(this.extensionId!) + } + + async rejectSignature() { + await this.notificationPage.rejectSignatureRequest(this.extensionId!) } - async rejectAccess() { - console.log('') + async rejectTransaction() { + await this.notificationPage.rejectTransaction(this.extensionId!) } } diff --git a/wallets/phantom/src/fixtures/phantomFixtures.ts b/wallets/phantom/src/fixtures/phantomFixtures.ts index 3df589fb9..cbd9dc121 100644 --- a/wallets/phantom/src/fixtures/phantomFixtures.ts +++ b/wallets/phantom/src/fixtures/phantomFixtures.ts @@ -62,7 +62,7 @@ export const phantomFixtures = (walletSetup: ReturnType { + const notificationPage = await getNotificationPageAndWaitForLoad(page.context(), extensionId) + + await notificationPage.click(homePageElements.settingsMenu.settingsMenuButton) + await notificationPage.click(homePageElements.settingsMenu.settingsSidebarButton) + await notificationPage.click(homePageElements.settingsMenu.trustedAppsRow) + + const rowButtonLocator = await notificationPage.locator(homePageElements.connectedSites.rowButton) + const hasConnectedSite = await rowButtonLocator.isVisible(); + + let isDisconnected = false; + if (hasConnectedSite) { + await rowButtonLocator.click() + await notificationPage.click(homePageElements.connectedSites.trustedAppsRevokeButton) + isDisconnected = true + } + else { + console.log( + '[disconnectWalletFromDapp] Wallet is not connected to a dapp, skipping...', + ); + } + + return isDisconnected; +} \ No newline at end of file diff --git a/wallets/phantom/src/pages/HomePage/actions/index.ts b/wallets/phantom/src/pages/HomePage/actions/index.ts index e69de29bb..fbc6bf642 100644 --- a/wallets/phantom/src/pages/HomePage/actions/index.ts +++ b/wallets/phantom/src/pages/HomePage/actions/index.ts @@ -0,0 +1,4 @@ +export * from './changeAccount' +export * from './closePopupAndTooltips' +export * from './getWalletAddress' +export * from './disconnectFromApp' \ No newline at end of file diff --git a/wallets/phantom/src/pages/HomePage/page.ts b/wallets/phantom/src/pages/HomePage/page.ts index 8b2424843..f44be3ce8 100644 --- a/wallets/phantom/src/pages/HomePage/page.ts +++ b/wallets/phantom/src/pages/HomePage/page.ts @@ -1,5 +1,6 @@ import type { Page } from '@playwright/test' import { homePageElements } from './selectors' +import { changeAccount, getWalletAddress, closePopupAndTooltips, disconnectFromApp } from './actions' export class HomePage { static readonly selectors = homePageElements @@ -10,4 +11,20 @@ export class HomePage { constructor(page: Page) { this.page = page } + + async changeAccount(accountIndex?: number) { + return await changeAccount(this.page, accountIndex) + } + + async getWalletAddress(extensionId: string, chainId: string){ + return await getWalletAddress(this.page, extensionId, chainId) + } + + async closePopupAndTooltips(extensionId: string) { + await closePopupAndTooltips(this.page, extensionId) + } + + async disconnectFromApp(extensionId: string) { + await disconnectFromApp(this.page, extensionId) + } } diff --git a/wallets/phantom/src/pages/LockPage/actions/createAccount.ts b/wallets/phantom/src/pages/LockPage/actions/createAccount.ts index 55cfc8fef..9274c33ea 100644 --- a/wallets/phantom/src/pages/LockPage/actions/createAccount.ts +++ b/wallets/phantom/src/pages/LockPage/actions/createAccount.ts @@ -1,8 +1,8 @@ import type { Page } from '@playwright/test' import { lockPageElements } from "../selectors"; -export const createAccount = async (page: Page, secretWords: string, password: string) => { - console.log(lockPageElements, page, secretWords, password) +export const createAccount = async (page: Page, password: string) => { + console.log(lockPageElements, page, password) // await page.click(lockPageElements.firstTimeFlowPageElements.importWalletButton) // await page.click(lockPageElements.firstTimeFlowPageElements.importRecoveryPhraseButton) diff --git a/wallets/phantom/src/pages/LockPage/actions/index.ts b/wallets/phantom/src/pages/LockPage/actions/index.ts index 5fa3aef98..1110a77a7 100644 --- a/wallets/phantom/src/pages/LockPage/actions/index.ts +++ b/wallets/phantom/src/pages/LockPage/actions/index.ts @@ -1,2 +1,3 @@ export * from './importAccount' -export * from './createAccount' \ No newline at end of file +export * from './createAccount' +export * from './unlock' \ No newline at end of file diff --git a/wallets/phantom/src/pages/LockPage/page.ts b/wallets/phantom/src/pages/LockPage/page.ts index a2e5cfc16..da7326aec 100644 --- a/wallets/phantom/src/pages/LockPage/page.ts +++ b/wallets/phantom/src/pages/LockPage/page.ts @@ -1,6 +1,6 @@ import type { Page } from '@playwright/test' import { lockPageElements } from './selectors' -import { importWallet, createAccount } from './actions' +import { importWallet, createAccount, unlock } from './actions' export class LockPage { static readonly selectors = lockPageElements @@ -16,7 +16,12 @@ export class LockPage { await importWallet(this.page, secretWords, password) } + //@todo: get this written async createWallet(password: string) { await createAccount(this.page, password) - } + } + + async unlock(extensionId: string, password: string) { + await unlock(this.page, extensionId, password, true) + } } diff --git a/wallets/phantom/src/pages/NotificationPage/page.ts b/wallets/phantom/src/pages/NotificationPage/page.ts index c34847eb3..7259d54d9 100644 --- a/wallets/phantom/src/pages/NotificationPage/page.ts +++ b/wallets/phantom/src/pages/NotificationPage/page.ts @@ -1,5 +1,6 @@ import type { Page } from '@playwright/test' import { notificationPageElements } from './selectors' +import { acceptAccess, confirmIncorrectNetwork, confirmSignatureRequest, confirmTransaction, rejectSignatureRequest, rejectTransaction, lock, selectWallet } from './actions' export class NotificationPage { static readonly selectors = notificationPageElements @@ -10,4 +11,36 @@ export class NotificationPage { constructor(page: Page) { this.page = page } + + async lock(extensionId: string) { + await lock(this.page, extensionId) + } + + async acceptAccess(extensionId: string) { + await acceptAccess(this.page, extensionId) + } + + async selectWallet(extensionId: string, wallet: string) { + await selectWallet(this.page, extensionId, wallet) + } + + async confirmIncorrectNetwork(extensionId: string) { + await confirmIncorrectNetwork(this.page, extensionId) + } + + async confirmSignatureRequest(extensionId: string) { + await confirmSignatureRequest(this.page, extensionId) + } + + async confirmTransaction(extensionId: string) { + await confirmTransaction(this.page, extensionId) + } + + async rejectTransaction(extensionId: string) { + await rejectTransaction(this.page, extensionId) + } + + async rejectSignatureRequest(extensionId: string) { + await rejectSignatureRequest(this.page, extensionId) + } } diff --git a/wallets/phantom/src/utils/constants.ts b/wallets/phantom/src/utils/constants.ts deleted file mode 100644 index c3fb26259..000000000 --- a/wallets/phantom/src/utils/constants.ts +++ /dev/null @@ -1,12 +0,0 @@ -// const PROVIDER = 'phantom' - -// const extensionInitialUrl = await playwright.windows(PROVIDER).url(); -// const extensionId = extensionInitialUrl.match('//(.*?)/')[1]; -// const extensionHomeUrl = `chrome-extension://${extensionId}/notification.html`; -// const extensionSettingsUrl = `${extensionHomeUrl}#settings`; -// const extensionAdvancedSettingsUrl = `${extensionSettingsUrl}/advanced`; -// const extensionExperimentalSettingsUrl = `${extensionSettingsUrl}/experimental`; -// const extensionAddNetworkUrl = `${extensionSettingsUrl}/networks/add-network`; -// const extensionNewAccountUrl = `${extensionHomeUrl}#new-account`; -// const extensionImportAccountUrl = `${extensionNewAccountUrl}/import`; -// const extensionImportTokenUrl = `${extensionHomeUrl}#import-token`; \ No newline at end of file diff --git a/wallets/phantom/src/utils/index.ts b/wallets/phantom/src/utils/index.ts index ee4cdabba..d6f677629 100644 --- a/wallets/phantom/src/utils/index.ts +++ b/wallets/phantom/src/utils/index.ts @@ -1,2 +1 @@ -export * from './selectors/loading' -export * from './constants' \ No newline at end of file +export * from './selectors/loading' \ No newline at end of file diff --git a/wallets/phantom/test/synpress.ts b/wallets/phantom/test/synpress.ts index 4fffc0e54..54693c56f 100644 --- a/wallets/phantom/test/synpress.ts +++ b/wallets/phantom/test/synpress.ts @@ -1,5 +1,5 @@ import { testWithSynpress } from '@synthetixio/synpress-core' import { phantomFixtures } from '../src' -import importPhantom from './wallet-setup/import-wallet.setup' +import importPhantom from './wallet-setup/import.setup' export default testWithSynpress(phantomFixtures(importPhantom)) diff --git a/wallets/phantom/test/wallet-setup/import2.setup.ts b/wallets/phantom/test/wallet-setup/create.setup.ts similarity index 63% rename from wallets/phantom/test/wallet-setup/import2.setup.ts rename to wallets/phantom/test/wallet-setup/create.setup.ts index adfae4e5c..28e887a8d 100644 --- a/wallets/phantom/test/wallet-setup/import2.setup.ts +++ b/wallets/phantom/test/wallet-setup/create.setup.ts @@ -5,15 +5,15 @@ import { getExtensionId } from '../../src/fixtureActions' const PASSWORD = 'Test1234' -const importPhantomWallet = defineWalletSetup(PASSWORD, async (context: BrowserContext, phantomPage: Page) => { +const createPhantomWallet = defineWalletSetup(PASSWORD, async (context: BrowserContext, phantomPage: Page) => { const extensionId = await getExtensionId(context, 'phantom') - const phantom2 = new PhantomWallet(phantomPage, context, PASSWORD, extensionId) + const phantom = new PhantomWallet(phantomPage, context, PASSWORD, extensionId) try { - await phantom2.importWallet({ secretWords: '', password: PASSWORD }) + await phantom.createWallet(PASSWORD) } catch (e) { console.log('Error creating Keplr wallet:', e) } }) -export default importPhantomWallet +export default createPhantomWallet