Skip to content

Commit

Permalink
keplr extension install
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSero committed Jun 13, 2024
1 parent 60304a3 commit 0ec44d3
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
46 changes: 46 additions & 0 deletions wallets/keplr/src/fixtureActions/getExtensionId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import type { BrowserContext } from '@playwright/test'
import { z } from 'zod'

const Extension = z.object({
id: z.string(),
name: z.string()
})

const Extensions = z.array(Extension)

/**
* Returns the extension ID for the given extension name. The ID is fetched from the `chrome://extensions` page.
*
* ::: tip
* This function soon will be removed to improve the developer experience! 😇
* :::
*
* @param context - The browser context.
* @param extensionName - The name of the extension, e.g., `Keplr`.
*
* @returns The extension ID.
*/
export async function getExtensionId(context: BrowserContext, extensionName: string) {
const page = await context.newPage()
await page.goto('chrome://extensions')

const unparsedExtensions = await page.evaluate('chrome.management.getAll()')

const allExtensions = Extensions.parse(unparsedExtensions)
const targetExtension = allExtensions.find(
(extension) => extension.name.toLowerCase() === extensionName.toLowerCase()
)

if (!targetExtension) {
throw new Error(
[
`[GetExtensionId] Extension with name ${extensionName} not found.`,
`Available extensions: ${allExtensions.map((extension) => extension.name).join(', ')}`
].join('\n')
)
}

await page.close()

return targetExtension.id
}
19 changes: 19 additions & 0 deletions wallets/keplr/src/fixtureActions/prepareExtension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { downloadFile, ensureCacheDirExists, unzipArchive } from '@synthetixio/synpress-cache'

export const DEFAULT_KEPLR_VERSION = '0.12.101'
export const EXTENSION_DOWNLOAD_URL = `https://github.com/chainapsis/keplr-wallet/releases/download/v${DEFAULT_KEPLR_VERSION}/keplr-extension-manifest-v2-v${DEFAULT_KEPLR_VERSION}.zip`;
export async function prepareExtension() {
const cacheDirPath = ensureCacheDirExists()

const downloadResult = await downloadFile({
url: EXTENSION_DOWNLOAD_URL,
outputDir: cacheDirPath,
fileName: `keplr-extension-manifest-v2-v${DEFAULT_KEPLR_VERSION}.zip`
})

const unzipResult = await unzipArchive({
archivePath: downloadResult.filePath
})

return unzipResult.outputPath
}

0 comments on commit 0ec44d3

Please sign in to comment.