Skip to content

Commit

Permalink
build cache and unlock wallet from keplr (;
Browse files Browse the repository at this point in the history
  • Loading branch information
Seroxdesign committed Jun 14, 2024
1 parent 68a6094 commit 769344d
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 98 deletions.
6 changes: 3 additions & 3 deletions packages/cache/src/cli/cliEntrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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)
}
Expand Down
22 changes: 19 additions & 3 deletions packages/cache/src/prepareExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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
}
12 changes: 1 addition & 11 deletions wallets/keplr/src/KeplrWallet.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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;
}
}
107 changes: 34 additions & 73 deletions wallets/keplr/src/pages/LockPage/actions/importWallet.ts
Original file line number Diff line number Diff line change
@@ -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();
}
3 changes: 2 additions & 1 deletion wallets/keplr/src/pages/LockPage/selectors/index.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
9 changes: 2 additions & 7 deletions wallets/keplr/test/wallet-setup/connected-keplr.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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})
})

0 comments on commit 769344d

Please sign in to comment.