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 May 8, 2023
1 parent 817519d commit fe136c6
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 72 deletions.
80 changes: 10 additions & 70 deletions helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const path = require('path');
const { ethers } = require('ethers');
const download = require('download');
const packageJson = require('./package.json');
const unzipCrx = require('unzip-crx-3');

const PRESET_NETWORKS = Object.freeze({
mainnet: {
Expand Down Expand Up @@ -150,69 +151,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 @@ -221,7 +167,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 @@ -275,14 +226,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);
}),
);
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@phantom/synpress",
"version": "4.0.0-alpha.18",
"version": "4.0.0-alpha.19",
"description": "Synpress is e2e testing framework based around Cypress.io & playwright with included MetaMask support. Test your dapps with ease.",
"keywords": [
"Synpress",
Expand Down Expand Up @@ -91,7 +91,8 @@
"prettier": "^2.8.4",
"serve": "^14.2.0",
"start-server-and-test": "^2.0.0",
"synthetix-js": "^2.74.1"
"synthetix-js": "^2.74.1",
"unzip-crx-3": "^0.2.0"
},
"devDependencies": {
"@metamask/test-dapp": "^5.6.0",
Expand Down
41 changes: 41 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7587,6 +7587,11 @@ immediate@^3.2.3:
resolved "https://registry.yarnpkg.com/immediate/-/immediate-3.3.0.tgz#1aef225517836bcdf7f2a2de2600c79ff0269266"
integrity sha512-HR7EVodfFUdQCTIeySw+WDRFJlPcLOJbXfwwZ7Oom6tjsvZ3bOkCDJHehQC3nxJrv7+f9XecwazynjU8e4Vw3Q==

immediate@~3.0.5:
version "3.0.6"
resolved "https://registry.yarnpkg.com/immediate/-/immediate-3.0.6.tgz#9db1dbd0faf8de6fbe0f5dd5e56bb606280de69b"
integrity sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ==

import-fresh@^3.0.0, import-fresh@^3.2.1:
version "3.3.0"
resolved "https://registry.yarnpkg.com/import-fresh/-/import-fresh-3.3.0.tgz#37162c25fcb9ebaa2e6e53d5b4d88ce17d9e0c2b"
Expand Down Expand Up @@ -8524,6 +8529,16 @@ jsprim@^2.0.2:
json-schema "0.4.0"
verror "1.10.0"

jszip@^3.1.0:
version "3.10.1"
resolved "https://registry.yarnpkg.com/jszip/-/jszip-3.10.1.tgz#34aee70eb18ea1faec2f589208a157d1feb091c2"
integrity sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==
dependencies:
lie "~3.3.0"
pako "~1.0.2"
readable-stream "~2.3.6"
setimmediate "^1.0.5"

keccak@^1.0.2:
version "1.4.0"
resolved "https://registry.yarnpkg.com/keccak/-/keccak-1.4.0.tgz#572f8a6dbee8e7b3aa421550f9e6408ca2186f80"
Expand Down Expand Up @@ -8664,6 +8679,13 @@ levn@~0.3.0:
prelude-ls "~1.1.2"
type-check "~0.3.2"

lie@~3.3.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/lie/-/lie-3.3.0.tgz#dcf82dee545f46074daf200c7c1c5a08e0f40f6a"
integrity sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==
dependencies:
immediate "~3.0.5"

lines-and-columns@^1.1.6:
version "1.2.4"
resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.2.4.tgz#eca284f75d2965079309dc0ad9255abb2ebc1632"
Expand Down Expand Up @@ -10098,6 +10120,11 @@ pacote@15.1.1:
ssri "^10.0.0"
tar "^6.1.11"

pako@~1.0.2:
version "1.0.11"
resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.11.tgz#6c9599d340d54dfd3946380252a35705a6b992bf"
integrity sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==

param-case@^2.1.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/param-case/-/param-case-2.1.1.tgz#df94fd8cf6531ecf75e6bef9a0858fbc72be2247"
Expand Down Expand Up @@ -12726,6 +12753,15 @@ untildify@^4.0.0:
resolved "https://registry.yarnpkg.com/untildify/-/untildify-4.0.0.tgz#2bc947b953652487e4600949fb091e3ae8cd919b"
integrity sha512-KK8xQ1mkzZeg9inewmFVDNkg3l5LUhoq9kN6iWYB/CC9YMG8HA+c1Q8HwDe6dEX7kErrEVNVBO3fWsVq5iDgtw==

unzip-crx-3@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/unzip-crx-3/-/unzip-crx-3-0.2.0.tgz#d5324147b104a8aed9ae8639c95521f6f7cda292"
integrity sha512-0+JiUq/z7faJ6oifVB5nSwt589v1KCduqIJupNVDoWSXZtWDmjDGO3RAEOvwJ07w90aoXoP4enKsR7ecMrJtWQ==
dependencies:
jszip "^3.1.0"
mkdirp "^0.5.1"
yaku "^0.16.6"

update-browserslist-db@^1.0.10:
version "1.0.10"
resolved "https://registry.yarnpkg.com/update-browserslist-db/-/update-browserslist-db-1.0.10.tgz#0f54b876545726f17d00cd9a2561e6dade943ff3"
Expand Down Expand Up @@ -13624,6 +13660,11 @@ yaeti@^0.0.6:
resolved "https://registry.yarnpkg.com/yaeti/-/yaeti-0.0.6.tgz#f26f484d72684cf42bedfb76970aa1608fbf9577"
integrity sha512-MvQa//+KcZCUkBTIC9blM+CU9J2GzuTytsOUwf2lidtvkx/6gnEp1QvJv34t9vdjhFmha/mUiNDbN0D0mJWdug==

yaku@^0.16.6:
version "0.16.7"
resolved "https://registry.yarnpkg.com/yaku/-/yaku-0.16.7.tgz#1d195c78aa9b5bf8479c895b9504fd4f0847984e"
integrity sha512-Syu3IB3rZvKvYk7yTiyl1bo/jiEFaaStrgv1V2TIJTqYPStSMQVO8EQjg/z+DRzLq/4LIIharNT3iH1hylEIRw==

yallist@^3.0.0, yallist@^3.0.2, yallist@^3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.1.1.tgz#dbb7daf9bfd8bac9ab45ebf602b8cbad0d5d08fd"
Expand Down

0 comments on commit fe136c6

Please sign in to comment.