Skip to content

Commit

Permalink
add import and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Seroxdesign committed Jul 4, 2024
1 parent f9b211e commit c161634
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 3 deletions.
6 changes: 3 additions & 3 deletions wallets/phantom/src/PhantomWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
32 changes: 32 additions & 0 deletions wallets/phantom/src/pages/LockPage/actions/importAccount.ts
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 1 addition & 0 deletions wallets/phantom/src/pages/LockPage/actions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './importAccount'
5 changes: 5 additions & 0 deletions wallets/phantom/src/pages/LockPage/page.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
}
}
12 changes: 12 additions & 0 deletions wallets/phantom/src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const PROVIDER = 'phantom'

Check notice

Code scanning / CodeQL

Semicolon insertion Note

Avoid automated semicolon insertion (90% of all statements in
the enclosing script
have an explicit semicolon).

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`;
Empty file.

0 comments on commit c161634

Please sign in to comment.