From 769344d717cc2f9be7d57d6f4b909c6bb9d56ecf Mon Sep 17 00:00:00 2001 From: Sero <69639595+Seroxdesign@users.noreply.github.com> Date: Fri, 14 Jun 2024 10:33:22 -0400 Subject: [PATCH] build cache and unlock wallet from keplr (; --- packages/cache/src/cli/cliEntrypoint.ts | 6 +- packages/cache/src/prepareExtension.ts | 22 +++- wallets/keplr/src/KeplrWallet.ts | 12 +- .../pages/LockPage/actions/importWallet.ts | 107 ++++++------------ .../src/pages/LockPage/selectors/index.ts | 3 +- .../wallet-setup/connected-keplr.setup.ts | 9 +- 6 files changed, 61 insertions(+), 98 deletions(-) diff --git a/packages/cache/src/cli/cliEntrypoint.ts b/packages/cache/src/cli/cliEntrypoint.ts index 9851573f4..a1675ec01 100644 --- a/packages/cache/src/cli/cliEntrypoint.ts +++ b/packages/cache/src/cli/cliEntrypoint.ts @@ -5,7 +5,7 @@ import { Command } from 'commander' import { rimraf } from 'rimraf' import { WALLET_SETUP_DIR_NAME } from '../constants' import { createCache } from '../createCache' -import { prepareExtension } from '../prepareExtension' +import { prepareKeplrExtension, prepareMetamaskExtension } from '../prepareExtension' import { compileWalletSetupFunctions } from './compileWalletSetupFunctions' import { footer } from './footer' @@ -65,8 +65,8 @@ export const cliEntrypoint = async () => { const compiledWalletSetupDirPath = await compileWalletSetupFunctions(walletSetupDir, flags.debug) // TODO: We should be using `prepareExtension` function from the wallet itself! - await createCache(compiledWalletSetupDirPath, prepareExtension, flags.force) - + await createCache(compiledWalletSetupDirPath, prepareKeplrExtension, flags.force) + await createCache(compiledWalletSetupDirPath, prepareMetamaskExtension, flags.force) if (!flags.debug) { await rimraf(compiledWalletSetupDirPath) } diff --git a/packages/cache/src/prepareExtension.ts b/packages/cache/src/prepareExtension.ts index 2cccb0d5c..333ba8d0b 100644 --- a/packages/cache/src/prepareExtension.ts +++ b/packages/cache/src/prepareExtension.ts @@ -3,17 +3,17 @@ import { downloadFile, ensureCacheDirExists, unzipArchive } from '.' export const DEFAULT_METAMASK_VERSION = '11.9.1' export const EXTENSION_DOWNLOAD_URL = `https://github.com/MetaMask/metamask-extension/releases/download/v${DEFAULT_METAMASK_VERSION}/metamask-chrome-${DEFAULT_METAMASK_VERSION}.zip` -export const DEFAULT_KEPLR_VERSION = '0.12.101' +export const DEFAULT_KEPLR_VERSION = '0.12.102' export const EXTENSION_KEPLR_DOWNLOAD_URL = `https://github.com/chainapsis/keplr-wallet/releases/download/v${DEFAULT_KEPLR_VERSION}/keplr-extension-manifest-v2-v${DEFAULT_KEPLR_VERSION}.zip`; // NOTE: This function is copied from `wallets/metamask/src/prepareExtension.ts` only TEMPORARILY! -export async function prepareExtension() { +export async function prepareKeplrExtension() { const cacheDirPath = ensureCacheDirExists() const downloadResult = await downloadFile({ url: EXTENSION_KEPLR_DOWNLOAD_URL, outputDir: cacheDirPath, - fileName: `metamask-chrome-${DEFAULT_KEPLR_VERSION}.zip` + fileName: `keplr-chrome-${DEFAULT_KEPLR_VERSION}.zip` }) const unzipResult = await unzipArchive({ @@ -22,3 +22,19 @@ export async function prepareExtension() { return unzipResult.outputPath } + +export async function prepareMetamaskExtension() { + const cacheDirPath = ensureCacheDirExists() + + const downloadResult = await downloadFile({ + url: EXTENSION_DOWNLOAD_URL, + outputDir: cacheDirPath, + fileName: `metamask-chrome-${DEFAULT_METAMASK_VERSION}.zip` + }) + + const unzipResult = await unzipArchive({ + archivePath: downloadResult.filePath + }) + + return unzipResult.outputPath +} \ No newline at end of file diff --git a/wallets/keplr/src/KeplrWallet.ts b/wallets/keplr/src/KeplrWallet.ts index a9f030d31..260ccb93f 100644 --- a/wallets/keplr/src/KeplrWallet.ts +++ b/wallets/keplr/src/KeplrWallet.ts @@ -1,4 +1,4 @@ -import { chromium, type BrowserContext, type Page } from '@playwright/test' +import { type BrowserContext, type Page } from '@playwright/test' import { playwright } from './playwright-kepler' import { onboardingElements } from './pages/LockPage/selectors/index' import { notificationPageElements } from './pages/NotificationPage/selectors/index' @@ -169,18 +169,8 @@ export class KeplrWallet { page: any, { secretWordsOrPrivateKey, password }: { secretWordsOrPrivateKey: string; password: string }, ) { - console.log('in', 1) - const playwright = chromium - console.log('in', 2) const lockpage = new LockPage(page) - console.log('in', 3, secretWordsOrPrivateKey, password, lockpage) const wallet = await lockpage.unlock(secretWordsOrPrivateKey, password) - console.log('in', 4) - console.log('chromium', playwright,'wallet', wallet) - // await playwright.assignWindows(); - // await playwright.assignActiveTabName('keplr'); - // await this.getExtensionDetails(); - // await this.importWallet(secretWordsOrPrivateKey, password); return wallet; } } diff --git a/wallets/keplr/src/pages/LockPage/actions/importWallet.ts b/wallets/keplr/src/pages/LockPage/actions/importWallet.ts index 8b6ad5f91..b8bc37abb 100644 --- a/wallets/keplr/src/pages/LockPage/actions/importWallet.ts +++ b/wallets/keplr/src/pages/LockPage/actions/importWallet.ts @@ -1,77 +1,38 @@ -// import { playwright } from "../../../playwright-kepler"; -// import { onboardingElements } from "../selectors"; +import { onboardingElements } from "../selectors"; import type { Page } from "@playwright/test"; export async function importWallet(page: Page, secretWords: string, password: string) { - - await page.waitForSelector('button.submit-button'); - console.log(secretWords, password) - // await playwright.waitAndClickByText( - // onboardingElements.createWalletButton, - // await playwright.keplrWindow(), - // ); - // await playwright.waitAndClickByText( - // onboardingElements.importRecoveryPhraseButton, - // await playwright.keplrWindow(), - // ); - // await playwright.waitAndClickByText( - // onboardingElements.useRecoveryPhraseButton, - // await playwright.keplrWindow(), - // ); - // await playwright.waitAndClickByText( - // onboardingElements.phraseCount24, - // await playwright.keplrWindow(), - // ); - - // for (const [index, word] of secretWords.split(' ').entries()) { - // await playwright.waitAndTypeByLocator( - // onboardingElements.textAreaSelector, - // word, - // index, - // ); - // } - - // await playwright.waitAndClick( - // onboardingElements.submitPhraseButton, - // await playwright.keplrWindow(), - // ); - - // await playwright.waitAndType( - // onboardingElements.walletInput, - // onboardingElements.walletName, - // ); - // await playwright.waitAndType(onboardingElements.passwordInput, password); - // await playwright.waitAndType( - // onboardingElements.confirmPasswordInput, - // password, - // ); - - // await playwright.waitAndClick( - // onboardingElements.submitWalletDataButton, - // await playwright.keplrWindow(), - // { number: 1 }, - // ); - - // await playwright.waitForByText( - // onboardingElements.phraseSelectChain, - // await playwright.keplrWindow(), - // ); - - // await playwright.waitAndClick( - // onboardingElements.submitChainButton, - // await playwright.keplrWindow(), - // ); - - // await playwright.waitForByText( - // onboardingElements.phraseAccountCreated, - // await playwright.keplrWindow(), - // ); - - // await playwright.waitAndClick( - // onboardingElements.finishButton, - // await playwright.keplrWindow(), - // { dontWait: true }, - // ); - - // return true; + await page.waitForLoadState('domcontentloaded'); + const importButton = await page.getByText(onboardingElements.importRecoveryPhraseButton); + await importButton.click(); + const useButton = await page.getByText(onboardingElements.useRecoveryPhraseButton); + await useButton.click(); + const phraseCount = await page.getByText(onboardingElements.phraseCount24); + await phraseCount.click(); + const wordsArray = secretWords.split(' '); + const inputFields = page.locator(onboardingElements.phraseInput); + const inputCount = await inputFields.count(); + for (let i = 0; i < inputCount; i++) { + if (!wordsArray[i]) { + return; + } + const inputField = inputFields.nth(i); + await inputField.fill(wordsArray[i]!); + } + const submitPhraseButton = await page.getByText(onboardingElements.submitPhraseButton); + await submitPhraseButton.click(); + const walletInput = await page.locator(onboardingElements.walletInput); + await walletInput.fill(onboardingElements.walletName); + const passwordInput = await page.locator(onboardingElements.passwordInput); + await passwordInput.fill(password); + const confirmPasswordInput = await page.locator(onboardingElements.confirmPasswordInput); + await confirmPasswordInput.fill(password); + const submitWalletDataButton = await page.getByText(onboardingElements.submitWalletDataButton); + await submitWalletDataButton.click(); + const submitChainButton = await page.getByText(onboardingElements.submitChainButton); + await submitChainButton.click(); + const phraseAccountCreated = await page.getByText(onboardingElements.phraseAccountCreated); + await phraseAccountCreated.click(); + const finishButton = await page.getByText(onboardingElements.finishButton); + await finishButton.click(); } diff --git a/wallets/keplr/src/pages/LockPage/selectors/index.ts b/wallets/keplr/src/pages/LockPage/selectors/index.ts index afb49c34e..7de7491ce 100644 --- a/wallets/keplr/src/pages/LockPage/selectors/index.ts +++ b/wallets/keplr/src/pages/LockPage/selectors/index.ts @@ -1,7 +1,8 @@ export const onboardingElements = { createWalletButton: 'Create a new wallet', - importRecoveryPhraseButton: 'Import existing recovery phrase', + importRecoveryPhraseButton: 'Import an existing wallet', useRecoveryPhraseButton: 'Use recovery phrase or private key', + phraseInput: '.sc-iAvgwm.kEpgcC', phraseCount24: '24 words', walletName: 'My wallet', phraseSelectChain: 'Select Chains', diff --git a/wallets/keplr/test/wallet-setup/connected-keplr.setup.ts b/wallets/keplr/test/wallet-setup/connected-keplr.setup.ts index a92ae94b4..6173603b6 100644 --- a/wallets/keplr/test/wallet-setup/connected-keplr.setup.ts +++ b/wallets/keplr/test/wallet-setup/connected-keplr.setup.ts @@ -7,14 +7,9 @@ const PASSWORD = 'Test1234' export default defineWalletSetup(PASSWORD, async (context, lockPage) => { await prepareExtension() - console.log('Extension', context) const extensionId = await getExtensionId(context, 'keplr') const keplr = new KeplrWallet(lockPage, context, PASSWORD, extensionId) - console.log('SEEDP', SEED_PHRASE, PASSWORD) const page = await context.newPage() - await page.goto(`chrome-extension://${extensionId}/home.html`) - const wallet = await keplr.setupWallet(page, { secretWordsOrPrivateKey: SEED_PHRASE, password: PASSWORD}) - console.log('in here2', wallet) - // const page = await context.newPage() - // await page.close() + await page.goto(`chrome-extension://${extensionId}/register.html`) + await keplr.setupWallet(page, { secretWordsOrPrivateKey: SEED_PHRASE, password: PASSWORD}) }) \ No newline at end of file