Skip to content

Commit a07e85c

Browse files
committed
Phantom support - getAccountAddress
1 parent c0018fd commit a07e85c

File tree

10 files changed

+39
-30
lines changed

10 files changed

+39
-30
lines changed

wallets/phantom/src/cypress/Phantom.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Selectors from '../selectors/pages/HomePage'
66
import type { SettingsSidebarMenus } from '../selectors/pages/HomePage/settings'
77
import TransactionPage from '../selectors/pages/NotificationPage/transactionPage'
88
import type { GasSettings } from '../type/GasSettings'
9+
import type { Networks } from '../type/Networks'
910
import getPlaywrightPhantom from './getPlaywrightPhantom'
1011

1112
/**
@@ -42,8 +43,8 @@ export default class Phantom {
4243
* Gets the current account address.
4344
* @returns The current account address
4445
*/
45-
async getAccountAddress(): Promise<string> {
46-
return await this.phantomPlaywright.getAccountAddress()
46+
async getAccountAddress(network: Networks): Promise<string> {
47+
return await this.phantomPlaywright.getAccountAddress(network)
4748
}
4849

4950
/**
@@ -79,11 +80,7 @@ export default class Phantom {
7980
* @param privateKey - The private key to import
8081
* @returns True if the import was successful
8182
*/
82-
async importWalletFromPrivateKey(
83-
network: 'solana' | 'ethereum' | 'base' | 'polygon' | 'bitcoin',
84-
privateKey: string,
85-
walletName?: string
86-
): Promise<boolean> {
83+
async importWalletFromPrivateKey(network: Networks, privateKey: string, walletName?: string): Promise<boolean> {
8784
await this.phantomPlaywright.importWalletFromPrivateKey(network, privateKey, walletName)
8885
return true
8986
}

wallets/phantom/src/cypress/configureSynpress.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { BrowserContext, Page } from '@playwright/test'
22
import { ensureRdpPort } from '@synthetixio/synpress-core'
33
import type { SettingsSidebarMenus } from '../selectors/pages/HomePage/settings'
44
import type { GasSettings } from '../type/GasSettings'
5+
import type { Networks } from '../type/Networks'
56
import Phantom from './Phantom'
67
import importPhantomWallet from './support/importPhantomWallet'
78
import { initPhantom } from './support/initPhantom'
@@ -106,14 +107,14 @@ export default function configureSynpress(
106107
privateKey,
107108
walletName
108109
}: {
109-
network: 'solana' | 'ethereum' | 'base' | 'polygon' | 'bitcoin'
110+
network: Networks
110111
privateKey: string
111112
walletName?: string
112113
}) => phantom?.importWalletFromPrivateKey(network, privateKey, walletName),
113114

114115
// Account
115116
getAccount: () => phantom?.getAccount(),
116-
getAccountAddress: () => phantom?.getAccountAddress(),
117+
getAccountAddress: (network: Networks) => phantom?.getAccountAddress(network),
117118
addNewAccount: (accountName: string) => phantom?.addNewAccount(accountName),
118119
switchAccount: (accountName: string) => phantom?.switchAccount(accountName),
119120
renameAccount: ({

wallets/phantom/src/playwright/Phantom.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { BrowserContext, Page } from '@playwright/test'
22
import { SettingsSidebarMenus } from '../selectors/pages/HomePage/settings'
33
import type { GasSettings } from '../type/GasSettings'
4+
import type { Networks } from '../type/Networks'
45
import { PhantomAbstract } from '../type/PhantomAbstract'
56
import { CrashPage, HomePage, LockPage, NotificationPage, OnboardingPage } from './pages'
67
import { SettingsPage } from './pages/SettingsPage/page'
@@ -144,8 +145,8 @@ export class Phantom extends PhantomAbstract {
144145
*
145146
* @returns The account address.
146147
*/
147-
async getAccountAddress(): Promise<string> {
148-
return await this.homePage.getAccountAddress()
148+
async getAccountAddress(network: Networks): Promise<string> {
149+
return await this.homePage.getAccountAddress(network)
149150
}
150151

151152
/**

wallets/phantom/src/playwright/pages/HomePage/actions/getAccountAddress.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import type { Page } from '@playwright/test'
22
import Selectors from '../../../../selectors/pages/HomePage'
3+
import type { Networks } from '../../../../type/Networks'
34

45
// TODO - .getAccountAddress() to be updated for all networks
5-
export default async function getAccountAddress(page: Page): Promise<string> {
6+
export default async function getAccountAddress(network: Networks, page: Page): Promise<string> {
67
// Copy account address to clipboard
78
await page.locator(Selectors.accountMenu.accountName).hover()
8-
await page.locator(Selectors.ethereumWalletAddress).click()
9+
await page.locator(Selectors[`${network}WalletAddress`]).click()
910

1011
// Get clipboard content
1112
const handle = await page.evaluateHandle(() => navigator.clipboard.readText())

wallets/phantom/src/playwright/pages/HomePage/actions/importWalletFromPrivateKey.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import type { Page } from '@playwright/test'
22
import Selectors from '../../../../selectors/pages/HomePage'
3+
import type { Networks } from '../../../../type/Networks'
34
import { waitFor } from '../../../utils/waitFor'
45

56
export async function importWalletFromPrivateKey(
67
page: Page,
7-
network: 'solana' | 'ethereum' | 'base' | 'polygon' | 'bitcoin',
8+
network: Networks,
89
privateKey: string,
910
walletName?: string
1011
) {

wallets/phantom/src/playwright/pages/HomePage/page.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Page } from '@playwright/test'
22
import Selectors from '../../../selectors/pages/HomePage'
33
import type { SettingsSidebarMenus } from '../../../selectors/pages/HomePage/settings'
4+
import type { Networks } from '../../../type/Networks'
45
import {
56
addNewAccount,
67
getAccountAddress,
@@ -40,8 +41,8 @@ export class HomePage {
4041
await renameAccount(this.page, currentAccountName, newAccountName)
4142
}
4243

43-
async getAccountAddress() {
44-
return await getAccountAddress(this.page)
44+
async getAccountAddress(network: Networks) {
45+
return await getAccountAddress(network, this.page)
4546
}
4647

4748
async importWalletFromPrivateKey(

wallets/phantom/src/selectors/pages/HomePage/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ const activityTab = {
9191
const singleToken = '.multichain-token-list-item'
9292

9393
export default {
94+
solanaWalletAddress: createDataTestSelector('account-header-chain-solana:101'),
9495
ethereumWalletAddress: createDataTestSelector('account-header-chain-eip155:1'),
96+
baseWalletAddress: createDataTestSelector('account-header-chain-eip155:8453'),
97+
polygonWalletAddress: createDataTestSelector('account-header-chain-eip155:137'),
98+
bitcoinWalletAddress: createDataTestSelector('account-header-chain-bip122:000000000019d6689c085ae165831e93'),
9599
logo: `button${createDataTestSelector('app-header-logo')}`,
96100
copyAccountAddressButton: createDataTestSelector('address-copy-button-text'),
97101
currentNetwork: `${createDataTestSelector('network-display')} span:nth-of-type(1)`,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type Networks = 'solana' | 'ethereum' | 'base' | 'polygon' | 'bitcoin'

wallets/phantom/src/type/PhantomAbstract.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { SettingsSidebarMenus } from '../selectors/pages/HomePage/settings'
22
import type { GasSettings } from './GasSettings'
3+
import type { Networks } from './Networks'
34

45
export abstract class PhantomAbstract {
56
/**
@@ -41,11 +42,7 @@ export abstract class PhantomAbstract {
4142
*
4243
* @param privateKey - The private key to import.
4344
*/
44-
abstract importWalletFromPrivateKey(
45-
network: 'solana' | 'ethereum' | 'base' | 'polygon' | 'bitcoin',
46-
privateKey: string,
47-
walletName?: string
48-
): void
45+
abstract importWalletFromPrivateKey(network: Networks, privateKey: string, walletName?: string): void
4946

5047
/**
5148
* Switches to the account with the given name.
@@ -57,7 +54,7 @@ export abstract class PhantomAbstract {
5754
/**
5855
* Retrieves the current account address.
5956
*/
60-
abstract getAccountAddress(): void
57+
abstract getAccountAddress(network: Networks): void
6158

6259
/**
6360
* Switches to the network with the given name.

wallets/phantom/test/playwright/e2e/getAccountAddress.spec.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,21 @@ const test = testWithSynpress(phantomFixtures(basicSetup))
77

88
const { expect } = test
99

10-
// TODO - .getAccountAddress() and Tests to be updated for all networks
11-
test('should get account address', async ({ context, phantomPage }) => {
10+
test('should get account address for all available networks', async ({ context, phantomPage }) => {
1211
const phantom = new Phantom(context, phantomPage, basicSetup.walletPassword)
1312

14-
await phantom.importWalletFromPrivateKey(
15-
'ethereum',
16-
'ea084c575a01e2bbefcca3db101eaeab1d8af15554640a510c73692db24d0a6a'
17-
)
13+
const solanaAccountAddress = await phantom.getAccountAddress('solana')
14+
expect(solanaAccountAddress).toEqual('oeYf6KAJkLYhBuR8CiGc6L4D4Xtfepr85fuDgA9kq96')
1815

19-
const accountAddress = await phantom.getAccountAddress()
16+
const ethereumAccountAddress = await phantom.getAccountAddress('ethereum')
17+
expect(ethereumAccountAddress).toEqual('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266')
2018

21-
expect(accountAddress).toEqual('0xa2ce797cA71d0EaE1be5a7EffD27Fd6C38126801')
19+
const baseAccountAddress = await phantom.getAccountAddress('base')
20+
expect(baseAccountAddress).toEqual('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266')
21+
22+
const polygonAccountAddress = await phantom.getAccountAddress('polygon')
23+
expect(polygonAccountAddress).toEqual('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266')
24+
25+
const bitcoinAccountAddress = await phantom.getAccountAddress('bitcoin')
26+
expect(bitcoinAccountAddress).toEqual('bc1q4qw42stdzjqs59xvlrlxr8526e3nunw7mp73te')
2227
})

0 commit comments

Comments
 (0)