From c16163481b680b482b1de3ed67c0fa5bceeb9709 Mon Sep 17 00:00:00 2001 From: Sero <69639595+Seroxdesign@users.noreply.github.com> Date: Thu, 4 Jul 2024 10:44:38 -0400 Subject: [PATCH] add import and clean up --- wallets/phantom/src/PhantomWallet.ts | 6 ++-- .../pages/LockPage/actions/importAccount.ts | 32 +++++++++++++++++++ .../src/pages/LockPage/actions/index.ts | 1 + wallets/phantom/src/pages/LockPage/page.ts | 5 +++ wallets/phantom/src/utils/constants.ts | 12 +++++++ .../phantom/test/wallet-setup/import.setup.ts | 0 6 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 wallets/phantom/src/pages/LockPage/actions/importAccount.ts create mode 100644 wallets/phantom/test/wallet-setup/import.setup.ts diff --git a/wallets/phantom/src/PhantomWallet.ts b/wallets/phantom/src/PhantomWallet.ts index 7836620db..0095863ec 100644 --- a/wallets/phantom/src/PhantomWallet.ts +++ b/wallets/phantom/src/PhantomWallet.ts @@ -28,11 +28,11 @@ export class PhantomWallet { * Does initial setup for the wallet. * * @param playwrightInstance. The playwright instance to use. - * @param secretWordsOrPrivateKey. The secret words or private key to import. + * @param secretWords. The secret words or private key to import. * @param password. The password to set. */ - async setupWallet({ secretWordsOrPrivateKey, password }: { secretWordsOrPrivateKey: string; password: string }) { - console.log(secretWordsOrPrivateKey, password) + async importWallet({ secretWords, password }: { secretWords: string; password: string }) { + this.lockPage.importWallet(secretWords, password) } async createWallet(password: string) { diff --git a/wallets/phantom/src/pages/LockPage/actions/importAccount.ts b/wallets/phantom/src/pages/LockPage/actions/importAccount.ts new file mode 100644 index 000000000..de4622f64 --- /dev/null +++ b/wallets/phantom/src/pages/LockPage/actions/importAccount.ts @@ -0,0 +1,32 @@ +import type { Page } from '@playwright/test' +import { lockPageElements } from "../selectors"; + +export const importWallet = async (page: Page, secretWords: string, password: string) => { + await page.click(lockPageElements.firstTimeFlowPageElements.importWalletButton) + await page.click(lockPageElements.firstTimeFlowPageElements.importRecoveryPhraseButton) + + for (const [index, word] of secretWords.split(' ').entries()) { + const inputField = await page.selectors(lockPageElements.firstTimeFlowImportPageElements.secretWordsInput(index)) + await inputField.fill(word) + } + await page.click(lockPageElements.firstTimeFlowImportPageElements.confirmWordsButton) + + await page.waitForLoadState('domcontentloaded') + + await page.click(lockPageElements.firstTimeFlowImportPageElements.confirmWordsButton) + + const walletInput = await page.locator(lockPageElements.firstTimeFlowImportPageElements.passwordInput) + await walletInput.fill(password) + + const confirmWalletInput = await page.locator(lockPageElements.firstTimeFlowImportPageElements.confirmPasswordInput) + await confirmWalletInput.fill(password) + + const checkbox = await page.locator(lockPageElements.firstTimeFlowImportPageElements.termsCheckbox) + await checkbox.click() + + await page.click(lockPageElements.firstTimeFlowImportPageElements.continueAfterPasswordButton) + + await page.click(lockPageElements.firstTimeFlowImportPageElements.getStartedButton); + + return true; +} \ No newline at end of file diff --git a/wallets/phantom/src/pages/LockPage/actions/index.ts b/wallets/phantom/src/pages/LockPage/actions/index.ts index e69de29bb..4aaa3d5e9 100644 --- a/wallets/phantom/src/pages/LockPage/actions/index.ts +++ b/wallets/phantom/src/pages/LockPage/actions/index.ts @@ -0,0 +1 @@ +export * from './importAccount' \ 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 79c072879..829a0adfc 100644 --- a/wallets/phantom/src/pages/LockPage/page.ts +++ b/wallets/phantom/src/pages/LockPage/page.ts @@ -1,5 +1,6 @@ import type { Page } from '@playwright/test' import { lockPageElements } from './selectors' +import { importWallet } from './actions' export class LockPage { static readonly selectors = lockPageElements @@ -10,4 +11,8 @@ export class LockPage { constructor(page: Page) { this.page = page } + + async importWallet(secretWords: string, password: string) { + await importWallet(this.page, secretWords, password) + } } diff --git a/wallets/phantom/src/utils/constants.ts b/wallets/phantom/src/utils/constants.ts index e69de29bb..2bd168758 100644 --- a/wallets/phantom/src/utils/constants.ts +++ b/wallets/phantom/src/utils/constants.ts @@ -0,0 +1,12 @@ +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/test/wallet-setup/import.setup.ts b/wallets/phantom/test/wallet-setup/import.setup.ts new file mode 100644 index 000000000..e69de29bb