Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat: Add phantom support #1167

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/cache/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,21 @@
"axios": "1.6.7",
"chalk": "5.3.0",
"commander": "12.0.0",
"download": "8.0.0",
"esbuild": "0.20.0",
"fs-extra": "11.2.0",
"glob": "10.3.10",
"gradient-string": "2.0.2",
"progress": "2.0.3",
"tsup": "8.0.2",
"unzip-crx-3": "0.2.0",
"unzipper": "0.10.14",
"zod": "3.22.4"
},
"devDependencies": {
"@synthetixio/synpress-tsconfig": "0.0.1-alpha.7",
"@types/archiver": "6.0.2",
"@types/download": "8.0.5",
"@types/fs-extra": "11.0.4",
"@types/gradient-string": "1.1.5",
"@types/node": "20.11.17",
Expand Down
8 changes: 6 additions & 2 deletions packages/cache/src/cli/cliEntrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { footer } from './footer'
interface CliFlags {
keplr: boolean
metamask: boolean
phantom: boolean
headless: boolean
force: boolean
debug: boolean
Expand All @@ -34,6 +35,7 @@ export const cliEntrypoint = async () => {
.option('-d, --debug', 'If this flag is present, the compilation files are not going to be deleted', false)
.option('-k, --keplr', 'Prepare the Keplr extension', false)
.option('-m, --metamask', 'Prepare the MetaMask extension', false)
.option('-p, --phantom', 'Prepare the Phantom extension', false)
.helpOption(undefined, 'Display help for command')
.addHelpText('afterAll', `\n${footer}\n`)
.parse(process.argv)
Expand All @@ -57,12 +59,15 @@ export const cliEntrypoint = async () => {
if (flags.metamask) {
extensions.push('MetaMask')
}
if (flags.phantom) {
extensions.push('Phantom')
}
return extensions
}
let extensionNames = extensionsToSetup()

if (!extensionNames.length) {
extensionNames = ['Keplr']
extensionNames = ['Metamask']
}

if (os.platform() === 'win32') {
Expand All @@ -81,7 +86,6 @@ export const cliEntrypoint = async () => {
for (const extensionName of extensionNames) {
await createCache(compiledWalletSetupDirPath, () => prepareExtension(extensionName), flags.force) // Pass extensionName
}
// TODO: We should be using `prepareExtension` function from the wallet itself!

if (!flags.debug) {
await rimraf(compiledWalletSetupDirPath)
Expand Down
43 changes: 31 additions & 12 deletions packages/cache/src/prepareExtension.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import download from 'download'
import unzipCrx from 'unzip-crx-3';
import { downloadFile, ensureCacheDirExists, unzipArchive } from '.'

interface ExtensionConfig {
Expand All @@ -20,6 +22,12 @@
version: '0.12.102',
downloadUrl:
'https://github.com/chainapsis/keplr-wallet/releases/download/v0.12.102/keplr-extension-manifest-v2-v0.12.102.zip'
},
{
name: 'Phantom',
version: 'phantom-chrome-latest',
downloadUrl:
'https://crx-backup.phantom.dev/latest.crx'
}
]
}
Expand All @@ -34,16 +42,27 @@
export async function prepareExtension(extensionName: string) {
const cacheDirPath = ensureCacheDirExists()
const extensionConfig = await getExtensionConfig(extensionName) // Get config

const downloadResult = await downloadFile({
url: extensionConfig.downloadUrl,
outputDir: cacheDirPath,
fileName: `${extensionConfig.name.toLowerCase()}-chrome-${extensionConfig.version}.zip`
})

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

return unzipResult.outputPath
let downloadResult
if (extensionConfig.name === 'Phantom') {
const outputPath = `${cacheDirPath}/latest`
downloadResult = await download(extensionConfig.downloadUrl, cacheDirPath, {
headers: {
Accept: 'application/octet-stream',
},
});

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning

The value assigned to downloadResult here is unused.
await unzipCrx('.cache-synpress/latest.crx', outputPath)
return outputPath
}
else {
downloadResult = await downloadFile({
url: extensionConfig.downloadUrl,
outputDir: cacheDirPath,
fileName: `${extensionConfig.name.toLowerCase()}-chrome-${extensionConfig.version}.zip`
})
const unzipResult = await unzipArchive({
archivePath: downloadResult.filePath
})

return unzipResult.outputPath
}
}
1 change: 1 addition & 0 deletions packages/cache/src/unzip.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'unzip-crx-3';
Loading
Loading