diff --git a/.github/workflows/live-tests.yaml b/.github/workflows/live-tests.yaml index 629372315..edccee326 100644 --- a/.github/workflows/live-tests.yaml +++ b/.github/workflows/live-tests.yaml @@ -7,6 +7,8 @@ jobs: playwright-e2e: timeout-minutes: 60 runs-on: ubuntu-latest + env: + CONNECT_IFRAME_URL: https://connect.pilot.gnosisguild.org if: github.event.deployment_status.state == 'success' defaults: run: diff --git a/.github/workflows/prod-release.yaml b/.github/workflows/prod-release.yaml index 325680626..f4ea607dd 100644 --- a/.github/workflows/prod-release.yaml +++ b/.github/workflows/prod-release.yaml @@ -8,6 +8,8 @@ jobs: build: runs-on: ubuntu-latest name: Build Extension + env: + CONNECT_IFRAME_URL: https://connect.pilot.gnosisguild.org defaults: run: working-directory: ./deployables/extension @@ -26,9 +28,7 @@ jobs: pnpm build - name: Update manifest.json with release tag - env: - RELEASE_TAG: ${{ github.event.release.tag_name }} - run: node ./manifest-util.js ./public/manifest.json + run: pnpm update-manifest -v ${{ github.event.release.tag_name }} - name: Create extension zip file run: pnpm zip diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 8569fd066..8e875cc09 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -9,6 +9,8 @@ on: jobs: extension: runs-on: ubuntu-latest + env: + CONNECT_IFRAME_URL: http://localhost defaults: run: working-directory: ./deployables/extension diff --git a/deployables/app/vite.config.ts b/deployables/app/vite.config.ts index 86f1bf269..37211ea99 100644 --- a/deployables/app/vite.config.ts +++ b/deployables/app/vite.config.ts @@ -13,6 +13,9 @@ export default defineConfig(({ isSsrBuild }) => ({ } : undefined, }, + server: { + port: 3040, + }, css: { postcss: { plugins: [tailwindcss, autoprefixer], diff --git a/deployables/extension/.env.example b/deployables/extension/.env.example index dd1e049c6..50d9933a3 100644 --- a/deployables/extension/.env.example +++ b/deployables/extension/.env.example @@ -1,5 +1,8 @@ # Run `pnpm dev` in /example-app to start the example app locally PLAYWRIGHT_TEST_BASE_URL=http://localhost:3030 +# run `pnpm dev`` in /app to start the connect app locally +CONNECT_IFRAME_URL=http://localhost:3040/ # ... or use the deployed version of the example app #PLAYWRIGHT_TEST_BASE_URL=https://zodiac-pilot-example-app.vercel.app +# CONNECT_IFRAME_URL=https://app.pilot.gnosisguild.org/ diff --git a/deployables/extension/.gitignore b/deployables/extension/.gitignore index 70b490cd5..2bd8ac9d1 100644 --- a/deployables/extension/.gitignore +++ b/deployables/extension/.gitignore @@ -1,4 +1,5 @@ public/_metadata +public/manifest.json zodiac-pilot.zip diff --git a/deployables/extension/e2e/utils/mockWeb3.ts b/deployables/extension/e2e/utils/mockWeb3.ts index 57fb0f4cf..05ec296f4 100644 --- a/deployables/extension/e2e/utils/mockWeb3.ts +++ b/deployables/extension/e2e/utils/mockWeb3.ts @@ -55,7 +55,7 @@ export const mockWeb3 = async ( const getConnectFrame = (page: Page) => { const frame = page.frame({ - url: 'https://connect.pilot.gnosisguild.org/', + url: process.env.CONNECT_IFRAME_URL, }) invariant(frame != null, 'Connect iframe not found') diff --git a/deployables/extension/esbuild.mjs b/deployables/extension/esbuild.mjs index 175ef0f8f..cb7bc841e 100644 --- a/deployables/extension/esbuild.mjs +++ b/deployables/extension/esbuild.mjs @@ -36,8 +36,8 @@ esbuild /** IMPORTANT: For scripts that are injected into other apps, it's crucial we build to IIFE format to avoid global scope clashes. */ format: 'iife', treeShaking: true, - minify: process.env.NODE_ENV === 'production', - sourcemap: process.env.NODE_ENV !== 'production' ? 'inline' : 'linked', + minify: process.env.NODE_ENV !== 'development', + sourcemap: process.env.NODE_ENV === 'development' ? 'inline' : 'linked', loader: { '.svg': 'file', '.woff': 'file', @@ -45,6 +45,7 @@ esbuild '.png': 'file', '.html': 'text', }, + target: ['chrome96'], outdir: './public/build', publicPath: '/build', @@ -59,6 +60,7 @@ esbuild ? `"http://127.0.0.1:${SERVE_PORT}/esbuild"` : 'false', global: 'window', + 'process.env.CONNECT_IFRAME_URL': `"${process.env.CONNECT_IFRAME_URL}"`, }, plugins: [ plugin(stdLibBrowser), diff --git a/deployables/extension/manifest-util.js b/deployables/extension/manifest-util.js index f054ae501..b95b2ce8d 100644 --- a/deployables/extension/manifest-util.js +++ b/deployables/extension/manifest-util.js @@ -1,4 +1,10 @@ +import { invariant } from '@epic-web/invariant' +import chalk from 'chalk' +import { config } from 'dotenv' import fs from 'fs' +import { parseArgs } from 'node:util' + +config() // this script is used to update the release value // in the manifest.json when released through github @@ -6,30 +12,56 @@ import fs from 'fs' // // node manifest-util.js ./public/manifest.json -const main = () => { - const manifestPath = process.argv[2] - const releaseTag = process.env.RELEASE_TAG - if (!manifestPath) { - return console.log('Please provide a path to the manifest file.') - } - if (!releaseTag) { - return console.log('Please provide a RELEASE_TAG env variable.') - } - - updateManifest(manifestPath, releaseTag) -} +const updateManifest = (templateFileName, outFileName, version) => { + const iframeUrl = process.env.CONNECT_IFRAME_URL -const updateManifest = (manifestFilename, releaseTag) => { - const version = releaseTag.replace('v', '') + invariant(iframeUrl != null, 'CONNECT_IFRAME_URL is missing') try { - const data = fs.readFileSync(manifestFilename) + console.log(chalk.white.bold('Manifest template file:')) + console.log(new URL(templateFileName, import.meta.url).pathname) + + const data = fs + .readFileSync(templateFileName) + .toString() + .replaceAll('', iframeUrl) + const manifest = JSON.parse(data) - manifest['version'] = version - fs.writeFileSync(manifestFilename, JSON.stringify(manifest)) + manifest['version'] = version.replace('v', '') + + console.log(chalk.white.bold('\nWriting manifest to:')) + console.log(new URL(outFileName, import.meta.url).pathname) + + fs.writeFileSync(outFileName, JSON.stringify(manifest, undefined, 2)) } catch (error) { console.log(error) } } -main() +const { + values: { template, outFile, version }, +} = parseArgs({ + options: { + template: { + type: 'string', + short: 't', + description: 'Path to the template file', + }, + outFile: { + type: 'string', + short: 'o', + description: 'Path to the output file', + }, + version: { + type: 'string', + short: 'v', + description: 'Version to update the manifest to', + default: 'v0.0.0', + }, + }, +}) + +invariant(template != null, 'Path to template file missing') +invariant(outFile != null, 'Path to output file missing') + +updateManifest(template, outFile, version) diff --git a/deployables/extension/package.json b/deployables/extension/package.json index 23a7fbb03..72efac36a 100644 --- a/deployables/extension/package.json +++ b/deployables/extension/package.json @@ -11,11 +11,12 @@ "sideEffects": false, "scripts": { "clean": "rimraf public/build", - "prebuild": "pnpm clean", - "build": "NODE_ENV=production node esbuild.mjs", + "update-manifest": "node manifest-util.js -t ./src/manifest.template.json -o ./public/manifest.json", + "prebuild": "pnpm clean && pnpm update-manifest", + "build": "node esbuild.mjs", "zip": "mv public zodiac-pilot && zip -vr zodiac-pilot.zip zodiac-pilot/ -x \"*.DS_Store\" && mv zodiac-pilot public", "predev": "pnpm clean", - "dev": "NODE_ENV=development node esbuild.mjs", + "dev": "NODE_ENV=development pnpm build", "test:unit": "vitest", "test:e2e": "PW_CHROMIUM_ATTACH_TO_OTHER=1 playwright test --headed", "test:e2e:ui": "pnpm test:e2e --ui", @@ -56,6 +57,7 @@ "@zodiac/test-utils": "workspace:*", "@zodiac/typescript-config": "workspace:*", "autoprefixer": "^10.4.20", + "chalk": "^5.4.1", "classnames": "^2.3.1", "copy-to-clipboard": "^3.3.1", "dotenv": "^16.0.1", @@ -89,14 +91,14 @@ "dependencies": { "@epic-web/invariant": "^1.0.0", "@headlessui/react": "^2.2.0", + "@zodiac/chains": "workspace:*", + "@zodiac/schema": "workspace:*", + "@zodiac/ui": "workspace:*", "date-fns": "^4.1.0", "lucide-react": "^0.470.0", - "react-toastify": "11.0.2", "react-router": "7.1.1", "react-stick": "^5.0.6", - "zod": "^3.23.8", - "@zodiac/ui": "workspace:*", - "@zodiac/schema": "workspace:*", - "@zodiac/chains": "workspace:*" + "react-toastify": "11.0.2", + "zod": "^3.23.8" } } diff --git a/deployables/extension/src/connect/contentScripts/dApp.ts b/deployables/extension/src/connect/contentScripts/dApp.ts index afcb81941..d0fcbc94a 100644 --- a/deployables/extension/src/connect/contentScripts/dApp.ts +++ b/deployables/extension/src/connect/contentScripts/dApp.ts @@ -4,14 +4,18 @@ import { } from '@/messages' import { invariant } from '@epic-web/invariant' +const CONNECT_IFRAME_URL = process.env.CONNECT_IFRAME_URL + +invariant(CONNECT_IFRAME_URL != null, 'CONNECT_IFRAME_URL is required') + const ensureIframe = () => { let node: HTMLIFrameElement | null = document.querySelector( - 'iframe[src="https://connect.pilot.gnosisguild.org/"]', + `iframe[src="${CONNECT_IFRAME_URL}"]`, ) if (!node) { node = document.createElement('iframe') - node.src = 'https://connect.pilot.gnosisguild.org/' + node.src = CONNECT_IFRAME_URL node.style.display = 'none' const parent = document.body || document.documentElement @@ -37,10 +41,7 @@ chrome.runtime.onConnect.addListener((port) => { 'cannot access connect iframe window', ) - iframe.contentWindow.postMessage( - message, - 'https://connect.pilot.gnosisguild.org/', - ) + iframe.contentWindow.postMessage(message, CONNECT_IFRAME_URL) // wait for response const handleResponse = (event: MessageEvent) => { diff --git a/deployables/extension/public/manifest.json b/deployables/extension/src/manifest.template.json similarity index 79% rename from deployables/extension/public/manifest.json rename to deployables/extension/src/manifest.template.json index 0fcc6d213..2e1d72e2f 100644 --- a/deployables/extension/public/manifest.json +++ b/deployables/extension/src/manifest.template.json @@ -1,7 +1,7 @@ { "name": "Zodiac Pilot", "description": "Simulate dApp interactions and record transactions", - "version": "0.0.0", + "version": "", "manifest_version": 3, "icons": { "16": "zodiac16.png", @@ -34,27 +34,19 @@ "content_scripts": [ { "matches": [""], - "exclude_globs": [ - "https://connect.pilot.gnosisguild.org/", - "about:*", - "chrome:*" - ], + "exclude_globs": ["/", "about:*", "chrome:*"], "run_at": "document_start", "js": ["build/connect/contentScripts/dApp.js"] }, { - "matches": ["https://connect.pilot.gnosisguild.org/"], + "matches": ["/"], "run_at": "document_start", "all_frames": true, "js": ["build/connect/contentScripts/connectIframe.js"] }, { "matches": [""], - "exclude_globs": [ - "https://connect.pilot.gnosisguild.org/", - "about:*", - "chrome:*" - ], + "exclude_globs": ["/", "about:*", "chrome:*"], "run_at": "document_start", "js": ["build/monitor/contentScript/main.js"] } diff --git a/deployables/landing-page/vite.config.ts b/deployables/landing-page/vite.config.ts index 1308bf17c..595ed148d 100644 --- a/deployables/landing-page/vite.config.ts +++ b/deployables/landing-page/vite.config.ts @@ -21,6 +21,9 @@ export default defineConfig({ }, }), ], + server: { + port: 3050, + }, css: { postcss: { plugins: [tailwindcss, autoprefixer], diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 43f7bd2ca..feaf5bd42 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -394,6 +394,9 @@ importers: autoprefixer: specifier: ^10.4.20 version: 10.4.20(postcss@8.4.49) + chalk: + specifier: ^5.4.1 + version: 5.4.1 classnames: specifier: ^2.3.1 version: 2.5.1 @@ -3973,6 +3976,10 @@ packages: resolution: {integrity: sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==} engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} + chalk@5.4.1: + resolution: {integrity: sha512-zgVZuo2WcZgfUEmsn6eO3kINexW8RAE4maiQ8QNs8CtpPCSyMiYsULR3HQYkm3w8FIA3SberyMJMSldGsW+U3w==} + engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} + character-entities-html4@2.1.0: resolution: {integrity: sha512-1v7fgQRj6hnSwFpq1Eu0ynr/CDEw0rXo2B61qXrLNdHZmPKgb7fqS1a2JwF0rISo9q77jDI8VMEHoApn8qDoZA==} @@ -12883,6 +12890,8 @@ snapshots: chalk@5.3.0: {} + chalk@5.4.1: {} + character-entities-html4@2.1.0: {} character-entities-legacy@3.0.0: {}