From b70022e70515155878a041deb5895a8dffa4a57a Mon Sep 17 00:00:00 2001 From: Maxim Geerinck Date: Mon, 8 May 2023 10:46:35 +0200 Subject: [PATCH] chore: Add phantom crx downloader --- helpers.js | 80 +++++++--------------------------------------------- package.json | 3 +- 2 files changed, 12 insertions(+), 71 deletions(-) diff --git a/helpers.js b/helpers.js index f164feddb..b56fcb722 100644 --- a/helpers.js +++ b/helpers.js @@ -8,6 +8,7 @@ const packageJson = require('./package.json'); const chains = require('viem/chains'); const appRoot = require('app-root-path'); const os = require('os'); +const unzipCrx = require('unzip-crx-3'); let currentNetwork = chains.mainnet; // list of added networks to metamask @@ -200,69 +201,14 @@ module.exports = { ); } }, - getPhantomReleases: async version => { - log(`Trying to find phantom version ${version} in GitHub releases..`); - let filename; - let downloadUrl; - let tagName; - let response; + getPhantomReleases: async () => { + const PHANTOM_URL = 'https://crx-backup.phantom.dev/latest.crx'; - /** - * We don't have github releases public for now. Hardcode values until we have - */ return { filename: 'phantom-chrome-latest', - downloadUrl: 'chrome-dist.zip', + downloadUrl: PHANTOM_URL, tagName: 'phantom-chrome-latest', }; - // try { - // if (version === 'latest' || !version) { - // if (process.env.GH_USERNAME && process.env.GH_PAT) { - // response = await axios.get( - // 'https://api.github.com/repos/phantom/wallet/releases', - // { - // auth: { - // username: process.env.GH_USERNAME, - // password: process.env.GH_PAT, - // }, - // }, - // ); - // } else { - // response = await axios.get( - // 'https://api.github.com/repos/phantom/wallet/releases', - // ); - // } - // console.log(response.data[0]) - // filename = response.data[0].assets[0].name; - // downloadUrl = response.data[0].assets[0].url; - // tagName = 'phantom-chrome-latest'; - // log( - // `Phantom version found! Filename: ${filename}; Download url: ${downloadUrl}; Tag name: ${tagName}`, - // ); - // } else if (version) { - // filename = `chrome-dist.zip`; - // downloadUrl = `https://github.com/phantom-labs/wallet/releases/download/v${version}/chrome-dist.zip`; - // tagName = `phantom-chrome-${version}`; - // log( - // `Phantom version found! Filename: ${filename}; Download url: ${downloadUrl}; Tag name: ${tagName}`, - // ); - // } - // return { - // filename, - // downloadUrl, - // tagName, - // }; - // } catch (e) { - // if (e.response && e.response.status === 403) { - // throw new Error( - // `[getPhantomReleases] Unable to fetch phantom releases from GitHub because you've been rate limited! Please set GH_USERNAME and GH_PAT environment variables to avoid this issue or retry again.`, - // ); - // } else { - // throw new Error( - // `[getPhantomReleases] Unable to fetch phantom releases from GitHub with following error:\n${e}`, - // ); - // } - // } }, download: async (provider, url, destination) => { try { @@ -271,7 +217,12 @@ module.exports = { ); if (provider === 'phantom') { - // phantom doesnt support downloading yet. + await download(url, destination, { + headers: { + Accept: 'application/octet-stream', + }, + }); + await unzipCrx(`${destination}/latest.crx`, destination); return; } @@ -330,14 +281,3 @@ module.exports = { return providerDirectory; }, }; - -async function moveFiles(srcDir, destDir) { - const files = await fs.readdir(srcDir); - - return Promise.all( - files.map(function (file) { - var destFile = path.join(destDir, file); - return fs.rename(path.join(srcDir, file), destFile); - }), - ); -} diff --git a/package.json b/package.json index 9f0e9d375..ffb5e62dd 100644 --- a/package.json +++ b/package.json @@ -106,7 +106,8 @@ "release-it": "^15.10.2", "serve": "^14.2.0", "start-server-and-test": "^2.0.0", - "turbo": "^1.9.4-canary.7" + "turbo": "^1.9.4-canary.7", + "unzip-crx-3": "^0.2.0" }, "resolutions": { "gh-pages": "5.0.0",