Skip to content

Commit

Permalink
chore: Add phantom crx downloader
Browse files Browse the repository at this point in the history
  • Loading branch information
maximgeerinck committed Jun 8, 2023
1 parent cf7e85e commit b70022e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 71 deletions.
80 changes: 10 additions & 70 deletions helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
}),
);
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit b70022e

Please sign in to comment.