Skip to content

Commit 4f2082f

Browse files
committed
Phantom support
1 parent 11af60d commit 4f2082f

33 files changed

+317
-618
lines changed

wallets/phantom/src/cypress/Phantom.ts

Lines changed: 7 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { type BrowserContext, type Page, expect } from '@playwright/test'
22
import { Phantom as PhantomPlaywright } from '../playwright/Phantom'
33
import { waitFor } from '../playwright/utils/waitFor'
44
import HomePageSelectors from '../selectors/pages/HomePage'
5-
import Selectors from '../selectors/pages/HomePage'
6-
import type { SettingsSidebarMenus } from '../selectors/pages/HomePage/settings'
75
import TransactionPage from '../selectors/pages/NotificationPage/transactionPage'
86
import type { GasSettings } from '../type/GasSettings'
97
import type { Networks } from '../type/Networks'
@@ -137,18 +135,8 @@ export default class Phantom {
137135
* Resets the current account.
138136
* @returns True if the reset was successful
139137
*/
140-
async resetAccount(): Promise<boolean> {
141-
await this.phantomPlaywright.resetAccount()
142-
return true
143-
}
144-
145-
/**
146-
* Adds a new token to Phantom.
147-
* @returns True if the token was added successfully
148-
*/
149-
async addNewToken(): Promise<boolean> {
150-
await this.phantomPlaywright.addNewToken()
151-
await expect(this.phantomExtensionPage.locator(Selectors.portfolio.singleToken).nth(1)).toContainText('TST')
138+
async resetApp(): Promise<boolean> {
139+
await this.phantomPlaywright.resetApp()
152140
return true
153141
}
154142

@@ -200,40 +188,12 @@ export default class Phantom {
200188
*/
201189
async unlock(): Promise<boolean> {
202190
await this.phantomPlaywright.unlock()
203-
await expect(this.phantomExtensionPage.locator(this.phantomPlaywright.homePage.selectors.logo)).toBeVisible()
191+
await expect(
192+
this.phantomExtensionPage.locator(this.phantomPlaywright.homePage.selectors.accountMenu.accountName)
193+
).toBeVisible()
204194
return true
205195
}
206196

207-
/**
208-
* Provides a public encryption key.
209-
* @returns True if the key was provided successfully, false otherwise
210-
*/
211-
async providePublicEncryptionKey(): Promise<boolean> {
212-
return await this.phantomPlaywright
213-
.providePublicEncryptionKey()
214-
.then(() => {
215-
return true
216-
})
217-
.catch(() => {
218-
return false
219-
})
220-
}
221-
222-
/**
223-
* Decrypts a message.
224-
* @returns True if the message was decrypted successfully, false otherwise
225-
*/
226-
async decrypt(): Promise<boolean> {
227-
return await this.phantomPlaywright
228-
.decrypt()
229-
.then(() => {
230-
return true
231-
})
232-
.catch(() => {
233-
return false
234-
})
235-
}
236-
237197
/**
238198
* Confirms a signature request.
239199
* @returns True if the signature was confirmed successfully, false otherwise
@@ -284,72 +244,12 @@ export default class Phantom {
284244
return true
285245
}
286246

287-
/**
288-
* Confirms a transaction and waits for it to be mined.
289-
* @returns True if the transaction was confirmed and mined successfully, false otherwise
290-
*/
291-
async confirmTransactionAndWaitForMining(): Promise<boolean> {
292-
await waitFor(
293-
() => this.phantomExtensionPage.locator(TransactionPage.nftApproveAllConfirmationPopup.approveButton).isVisible(),
294-
5_000,
295-
false
296-
)
297-
return this.phantomPlaywright
298-
.confirmTransactionAndWaitForMining()
299-
.then(() => {
300-
return true
301-
})
302-
.catch(() => {
303-
return false
304-
})
305-
}
306-
307-
/**
308-
* Opens the details of a specific transaction.
309-
* @param txIndex - The index of the transaction to open
310-
* @returns True if the transaction details were opened successfully, false otherwise
311-
*/
312-
async openTransactionDetails(txIndex: number): Promise<boolean> {
313-
return this.phantomPlaywright
314-
.openTransactionDetails(txIndex)
315-
.then(() => {
316-
return true
317-
})
318-
.catch(() => {
319-
return false
320-
})
321-
}
322-
323-
/**
324-
* Closes the transaction details view.
325-
* @returns True if the transaction details were closed successfully, false otherwise
326-
*/
327-
async closeTransactionDetails(): Promise<boolean> {
328-
return this.phantomPlaywright
329-
.closeTransactionDetails()
330-
.then(() => {
331-
return true
332-
})
333-
.catch(() => {
334-
return false
335-
})
336-
}
337-
338247
/**
339248
* Toggles the display of test networks.
340249
* @returns True if the toggle was successful
341250
*/
342-
async toggleShowTestNetworks(): Promise<boolean> {
343-
await this.phantomPlaywright.toggleShowTestNetworks()
344-
return true
345-
}
346-
347-
/**
348-
* Toggles the dismissal of the secret recovery phrase reminder.
349-
* @returns True if the toggle was successful
350-
*/
351-
async toggleDismissSecretRecoveryPhraseReminder(): Promise<boolean> {
352-
await this.phantomPlaywright.toggleDismissSecretRecoveryPhraseReminder()
251+
async toggleTestnetMode(): Promise<boolean> {
252+
await this.phantomPlaywright.toggleTestnetMode()
353253
return true
354254
}
355255

@@ -373,15 +273,4 @@ export default class Phantom {
373273
await this.phantomPlaywright.openSettings()
374274
return true
375275
}
376-
377-
/**
378-
* Opens a specific sidebar menu in the settings.
379-
* @param menu - The menu to open
380-
* @returns True if the menu was opened successfully
381-
*/
382-
async openSidebarMenu(menu: SettingsSidebarMenus): Promise<boolean> {
383-
await this.phantomPlaywright.openSidebarMenu(menu)
384-
await expect(this.phantomExtensionPage.locator(HomePageSelectors.settings.sidebarMenu(menu))).toBeVisible()
385-
return true
386-
}
387276
}

wallets/phantom/src/cypress/configureSynpress.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { BrowserContext, Page } from '@playwright/test'
22
import { ensureRdpPort } from '@synthetixio/synpress-core'
3-
import type { SettingsSidebarMenus } from '../selectors/pages/HomePage/settings'
43
import type { GasSettings } from '../type/GasSettings'
54
import type { Networks } from '../type/Networks'
65
import Phantom from './Phantom'
@@ -124,44 +123,34 @@ export default function configureSynpress(
124123
currentAccountName: string
125124
newAccountName: string
126125
}) => phantom?.renameAccount({ currentAccountName, newAccountName }),
127-
resetAccount: () => phantom?.resetAccount(),
126+
resetApp: () => phantom?.resetApp(),
128127

129128
// Network
130129
getNetwork: () => phantom?.getNetwork(),
131130

132131
// Token
133-
addNewToken: () => phantom?.addNewToken(),
134132
approveTokenPermission: (options?: {
135133
spendLimit?: number | 'max'
136134
gasSetting?: GasSettings
137135
}) => phantom?.approveTokenPermission(options),
138136
rejectTokenPermission: () => phantom?.rejectTokenPermission(),
139137

140-
// Encryption
141-
providePublicEncryptionKey: () => phantom?.providePublicEncryptionKey(),
142-
decrypt: () => phantom?.decrypt(),
143-
144138
// Transactions
145139
confirmSignature: () => phantom?.confirmSignature(),
146140
rejectSignature: () => phantom?.rejectSignature(),
147141
confirmTransaction: (options?: { gasSetting?: GasSettings }) => phantom?.confirmTransaction(options),
148142
rejectTransaction: () => phantom?.rejectTransaction(),
149-
confirmTransactionAndWaitForMining: () => phantom?.confirmTransactionAndWaitForMining(),
150-
openTransactionDetails: (txIndex: number) => phantom?.openTransactionDetails(txIndex),
151-
closeTransactionDetails: () => phantom?.closeTransactionDetails(),
152143

153144
// Lock/Unlock
154145
lock: () => phantom?.lock(),
155146
unlock: () => phantom?.unlock(),
156147

157148
// Toggles
158-
toggleShowTestNetworks: () => phantom?.toggleShowTestNetworks(),
159-
toggleDismissSecretRecoveryPhraseReminder: () => phantom?.toggleDismissSecretRecoveryPhraseReminder(),
149+
toggleTestnetMode: () => phantom?.toggleTestnetMode(),
160150

161151
// Others
162152
goBackToHomePage: () => phantom?.goBackToHomePage(),
163-
openSettings: () => phantom?.openSettings(),
164-
openSidebarMenu: (menu: SettingsSidebarMenus) => phantom?.openSidebarMenu(menu)
153+
openSettings: () => phantom?.openSettings()
165154
})
166155

167156
return {

wallets/phantom/src/cypress/support/importPhantomWallet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { type BrowserContext, type Page, chromium } from '@playwright/test'
2-
import { getExtensionId } from '../../playwright'
2+
import { getExtensionIdPhantom } from '../../playwright'
33
import getPlaywrightPhantom from '../getPlaywrightPhantom'
44

55
const SEED_PHRASE = 'test test test test test test test test test test test junk'
@@ -24,7 +24,7 @@ export default async function importPhantomWallet(port: number, importDefaultWal
2424
const extensionPageIndex = context.pages().findIndex((page) => page.url().includes('chrome-extension://'))
2525
if (extensionPageIndex !== -1) {
2626
extensionPage = context.pages()[extensionPageIndex] as Page
27-
phantomExtensionId = await getExtensionId(context, 'Phantom')
27+
phantomExtensionId = await getExtensionIdPhantom(context, 'Phantom')
2828

2929
const phantom = getPlaywrightPhantom(context, extensionPage, phantomExtensionId)
3030

wallets/phantom/src/cypress/support/synpressCommands.ts

Lines changed: 6 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// https://on.cypress.io/custom-commands
1010
// ***********************************************
1111

12-
import type { SettingsSidebarMenus } from '../../selectors/pages/HomePage/settings'
1312
import type { GasSettings } from '../../type/GasSettings'
1413

1514
declare global {
@@ -27,36 +26,28 @@ declare global {
2726
switchAccount(accountName: string): Chainable<void>
2827
renameAccount(currentAccountName: string, newAccountName: string): Chainable<void>
2928
getAccountAddress(): Chainable<string>
30-
resetAccount(): Chainable<void>
29+
resetApp(): Chainable<void>
3130

32-
addNewToken(): Chainable<void>
3331
approveTokenPermission(options?: {
3432
spendLimit?: number | 'max'
3533
gasSetting?: GasSettings
3634
}): Chainable<void>
3735
rejectTokenPermission(): Chainable<void>
3836

39-
providePublicEncryptionKey(): Chainable<void>
40-
decrypt(): Chainable<void>
4137
confirmSignature(): Chainable<void>
4238
rejectSignature(): Chainable<void>
4339
confirmTransaction(options?: {
4440
gasSetting?: GasSettings
4541
}): Chainable<void>
4642
rejectTransaction(): Chainable<void>
47-
confirmTransactionAndWaitForMining(): Chainable<void>
48-
openTransactionDetails(txIndex: number): Chainable<void>
49-
closeTransactionDetails(): Chainable<void>
5043

5144
lock(): Chainable<void>
5245
unlock(): Chainable<void>
5346

54-
toggleShowTestNetworks(): Chainable<void>
55-
toggleDismissSecretRecoveryPhraseReminder(): Chainable<void>
47+
toggleTestnetMode(): Chainable<void>
5648

5749
goBackToHomePage(): Chainable<void>
5850
openSettings(): Chainable<void>
59-
openSidebarMenu(menu: SettingsSidebarMenus): Chainable<void>
6051
}
6152
}
6253
}
@@ -156,8 +147,8 @@ export default function synpressCommandsForPhantom(): void {
156147
/**
157148
* Resets the current account
158149
*/
159-
Cypress.Commands.add('resetAccount', () => {
160-
return cy.task('resetAccount')
150+
Cypress.Commands.add('resetApp', () => {
151+
return cy.task('resetApp')
161152
})
162153

163154
// Network
@@ -171,13 +162,6 @@ export default function synpressCommandsForPhantom(): void {
171162

172163
// Token
173164

174-
/**
175-
* Adds a new token
176-
*/
177-
Cypress.Commands.add('addNewToken', () => {
178-
return cy.task('addNewToken')
179-
})
180-
181165
/**
182166
* Approves token permission
183167
* @param options - Options for approving token permission
@@ -219,33 +203,12 @@ export default function synpressCommandsForPhantom(): void {
219203
/**
220204
* Toggles showing test networks
221205
*/
222-
Cypress.Commands.add('toggleShowTestNetworks', () => {
223-
return cy.task('toggleShowTestNetworks')
224-
})
225-
226-
/**
227-
* Toggles dismissing the secret recovery phrase reminder
228-
*/
229-
Cypress.Commands.add('toggleDismissSecretRecoveryPhraseReminder', () => {
230-
return cy.task('toggleDismissSecretRecoveryPhraseReminder')
206+
Cypress.Commands.add('toggleTestnetMode', () => {
207+
return cy.task('toggleTestnetMode')
231208
})
232209

233210
// Others
234211

235-
/**
236-
* Provides a public encryption key
237-
*/
238-
Cypress.Commands.add('providePublicEncryptionKey', () => {
239-
return cy.task('providePublicEncryptionKey')
240-
})
241-
242-
/**
243-
* Decrypts a message
244-
*/
245-
Cypress.Commands.add('decrypt', () => {
246-
return cy.task('decrypt')
247-
})
248-
249212
/**
250213
* Confirms a signature
251214
*/
@@ -276,28 +239,6 @@ export default function synpressCommandsForPhantom(): void {
276239
return cy.task('rejectTransaction')
277240
})
278241

279-
/**
280-
* Confirms a transaction and waits for mining
281-
*/
282-
Cypress.Commands.add('confirmTransactionAndWaitForMining', () => {
283-
return cy.task('confirmTransactionAndWaitForMining')
284-
})
285-
286-
/**
287-
* Opens transaction details
288-
* @param txIndex - The index of the transaction to open
289-
*/
290-
Cypress.Commands.add('openTransactionDetails', (txIndex = 0) => {
291-
return cy.task('openTransactionDetails', txIndex)
292-
})
293-
294-
/**
295-
* Closes transaction details
296-
*/
297-
Cypress.Commands.add('closeTransactionDetails', () => {
298-
return cy.task('closeTransactionDetails')
299-
})
300-
301242
/**
302243
* Goes back to the home page
303244
*/
@@ -311,12 +252,4 @@ export default function synpressCommandsForPhantom(): void {
311252
Cypress.Commands.add('openSettings', () => {
312253
return cy.task('openSettings')
313254
})
314-
315-
/**
316-
* Opens a sidebar menu
317-
* @param menu - The menu to open
318-
*/
319-
Cypress.Commands.add('openSidebarMenu', (menu: SettingsSidebarMenus) => {
320-
return cy.task('openSidebarMenu', menu)
321-
})
322255
}

0 commit comments

Comments
 (0)