Skip to content

Commit

Permalink
organise pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Seroxdesign committed Jul 9, 2024
1 parent 00eddf5 commit 769d933
Show file tree
Hide file tree
Showing 13 changed files with 138 additions and 35 deletions.
48 changes: 38 additions & 10 deletions wallets/phantom/src/PhantomWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!)
}
}
2 changes: 1 addition & 1 deletion wallets/phantom/src/fixtures/phantomFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const phantomFixtures = (walletSetup: ReturnType<typeof defineWalletSetup
const context = await chromium.launchPersistentContext(_contextPath, {
headless: false,
args: browserArgs,
slowMo: process.env.HEADLESS ? 0 : slowMo
slowMo: process.env.HEADLESS ? 0 : 2000
})

const { cookies, origins } = await currentContext.storageState()
Expand Down
28 changes: 28 additions & 0 deletions wallets/phantom/src/pages/HomePage/actions/disconnectFromApp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { Page } from "@playwright/test";
import { getNotificationPageAndWaitForLoad } from "../../../utils/getNotificationAndWaitForLoads";
import { homePageElements } from "../selectors";

export const disconnectFromApp = async (page: Page, extensionId: string) => {
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;
}
4 changes: 4 additions & 0 deletions wallets/phantom/src/pages/HomePage/actions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './changeAccount'
export * from './closePopupAndTooltips'
export * from './getWalletAddress'
export * from './disconnectFromApp'
17 changes: 17 additions & 0 deletions wallets/phantom/src/pages/HomePage/page.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
}
}
4 changes: 2 additions & 2 deletions wallets/phantom/src/pages/LockPage/actions/createAccount.ts
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
3 changes: 2 additions & 1 deletion wallets/phantom/src/pages/LockPage/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './importAccount'
export * from './createAccount'
export * from './createAccount'
export * from './unlock'
9 changes: 7 additions & 2 deletions wallets/phantom/src/pages/LockPage/page.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
}
}
33 changes: 33 additions & 0 deletions wallets/phantom/src/pages/NotificationPage/page.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
}
}
12 changes: 0 additions & 12 deletions wallets/phantom/src/utils/constants.ts

This file was deleted.

3 changes: 1 addition & 2 deletions wallets/phantom/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './selectors/loading'
export * from './constants'
export * from './selectors/loading'
2 changes: 1 addition & 1 deletion wallets/phantom/test/synpress.ts
Original file line number Diff line number Diff line change
@@ -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))
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 769d933

Please sign in to comment.