diff --git a/.env.example b/.env.example index 5f8e07890..f6a88375f 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,5 @@ FORK_URL= NODE_ENV= +DEV_RPC= STAKING_TEST_KEYS_PATH= -DEV_RPC= \ No newline at end of file +IS_STAGING= diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9737db6c3..0deab94b3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -63,6 +63,7 @@ jobs: env: NODE_ENV: production DEV_RPC: https://rpc-gate.autonolas.tech/gnosis-rpc/ + IS_STAGING: ${{ contains(github.ref, 'staging') }} FORK_URL: https://rpc-gate.autonolas.tech/gnosis-rpc/ - run: rm -rf /dist - name: "Build, notarize, publish" diff --git a/build.js b/build.js index 29e953fc4..a5059c953 100644 --- a/build.js +++ b/build.js @@ -1,6 +1,6 @@ const dotenv = require('dotenv'); const build = require('electron-builder').build; -const {publishOptions} = require('./electron/constants/publishOptions'); +const { publishOptions } = require('./electron/constants/publishOptions'); dotenv.config(); @@ -24,7 +24,7 @@ const main = async () => { target: [ { target: 'default', - arch: ['x64','arm64'], + arch: ['x64', 'arm64'], }, ], publish: publishOptions, @@ -35,11 +35,11 @@ const main = async () => { entitlements: 'electron/entitlements.mac.plist', entitlementsInherit: 'electron/entitlements.mac.plist', notarize: { - teamId: process.env.APPLETEAMID + teamId: process.env.APPLETEAMID, }, }, }, }); }; -main().then((response) => { console.log('Build & Notarize complete'); }).catch((e) => console.error(e)); \ No newline at end of file +main().then((response) => { console.log('Build & Notarize complete'); }).catch((e) => console.error(e)); diff --git a/electron/install.js b/electron/install.js index 944ceac50..d59a08215 100644 --- a/electron/install.js +++ b/electron/install.js @@ -11,7 +11,12 @@ const axios = require("axios") const Docker = require('dockerode'); const { spawnSync } = require('child_process'); -const Version = '0.1.0rc34'; +/** + * current version of the pearl release + * - use "" (nothing as a suffix) for latest release candidate, for example "0.1.0rc26" + * - use "alpha" for alpha release, for example "0.1.0rc26-alpha" + */ +const OlasMiddlewareVersion = '0.1.0rc34'; const OperateDirectory = `${os.homedir()}/.operate`; const VenvDir = `${OperateDirectory}/venv`; const TempDir = `${OperateDirectory}/temp`; @@ -65,7 +70,7 @@ function appendLog(log) { function runCmdUnix(command, options) { fs.appendFileSync( OperateInstallationLog, - `Runninng ${command} with options ${JSON.stringify(options)}`, + `Running ${command} with options ${JSON.stringify(options)}`, { encoding: 'utf-8' }, ); let bin = getBinPath(command); @@ -97,7 +102,7 @@ function runSudoUnix(command, options) { if (!bin) { throw new Error(`Command ${command} not found`); } - return new Promise(function (resolve, reject) { + return new Promise(function (resolve, _reject) { sudo.exec( `${bin} ${options}`, SudoOptions, @@ -216,7 +221,7 @@ function installOperatePackageUnix(path) { '-m', 'pip', 'install', - `olas-operate-middleware==${Version}`, + `olas-operate-middleware==${OlasMiddlewareVersion}`, ]); } @@ -226,7 +231,7 @@ function reInstallOperatePackageUnix(path) { '-m', 'pip', 'install', - `olas-operate-middleware==${Version}`, + `olas-operate-middleware==${OlasMiddlewareVersion}`, '--force-reinstall', ]); } @@ -236,11 +241,11 @@ function installOperateCli(path) { if (fs.existsSync(installPath)) { fs.rmSync(installPath); } - return new Promise((resolve, reject) => { + return new Promise((resolve, _reject) => { fs.copyFile( `${OperateDirectory}/venv/bin/operate`, installPath, - function (error, stdout, stderr) { + function (error, _stdout, _stderr) { resolve(!error); }, ); @@ -251,7 +256,7 @@ function createDirectory(path) { if (fs.existsSync(path)) { return; } - return new Promise((resolve, reject) => { + return new Promise((resolve, _reject) => { fs.mkdir(path, { recursive: true }, (error) => { resolve(!error); }); @@ -259,15 +264,15 @@ function createDirectory(path) { } function writeVersion() { - fs.writeFileSync(VersionFile, Version); + fs.writeFileSync(VersionFile, OlasMiddlewareVersion); } function versionBumpRequired() { if (!fs.existsSync(VersionFile)) { return true; } - const version = fs.readFileSync(VersionFile).toString(); - return version != Version; + const olasMiddlewareVersionInFile = fs.readFileSync(VersionFile).toString(); + return olasMiddlewareVersionInFile != OlasMiddlewareVersion; } function removeLogFile() { @@ -324,7 +329,9 @@ async function setupDarwin(ipcChannel) { console.log(appendLog('Checking if upgrade is required')); if (versionBumpRequired()) { - console.log(appendLog(`Upgrading pearl daemon to ${Version}`)); + console.log( + appendLog(`Upgrading pearl daemon to ${OlasMiddlewareVersion}`), + ); reInstallOperatePackageUnix(OperateDirectory); writeVersion(); removeLogFile(); @@ -378,7 +385,9 @@ async function setupUbuntu(ipcChannel) { console.log(appendLog('Checking if upgrade is required')); if (versionBumpRequired()) { - console.log(appendLog(`Upgrading pearl daemon to ${Version}`)); + console.log( + appendLog(`Upgrading pearl daemon to ${OlasMiddlewareVersion}`), + ); reInstallOperatePackageUnix(OperateDirectory); writeVersion(); removeLogFile(); diff --git a/electron/main.js b/electron/main.js index c820346d6..25db772ff 100644 --- a/electron/main.js +++ b/electron/main.js @@ -259,7 +259,10 @@ const createMainWindow = () => { mainWindow.hide(); }); - setupStoreIpc(ipcMain, mainWindow); + const storeInitialValues = { + environmentName: process.env.IS_STAGING ? 'staging' : '', + }; + setupStoreIpc(ipcMain, mainWindow, storeInitialValues); if (isDev) { mainWindow.webContents.openDevTools(); diff --git a/electron/store.js b/electron/store.js index 91cde5bef..5577decff 100644 --- a/electron/store.js +++ b/electron/store.js @@ -1,27 +1,25 @@ // set schema to validate store data -const schema = { - isInitialFunded: { - type: 'boolean', - default: false, - }, - firstStakingRewardAchieved: { - type: 'boolean', - default: false, - }, - firstRewardNotificationShown: { - type: 'boolean', - default: false, - }, +const defaultSchema = { + environmentName: { type: 'string', default: '' }, + isInitialFunded: { type: 'boolean', default: false }, + firstStakingRewardAchieved: { type: 'boolean', default: false }, + firstRewardNotificationShown: { type: 'boolean', default: false }, }; -const setupStoreIpc = async (ipcChannel, mainWindow) => { +const setupStoreIpc = async (ipcChannel, mainWindow, storeInitialValues) => { const Store = (await import('electron-store')).default; - /** @type import Store from 'electron-store' */ - const store = new Store({ - schema, + // set default values for store + const schema = Object.assign({}, defaultSchema); + Object.keys(schema).forEach((key) => { + if (storeInitialValues[key] !== undefined) { + schema[key].default = storeInitialValues[key]; + } }); + /** @type import Store from 'electron-store' */ + const store = new Store({ schema }); + store.onDidAnyChange((data) => { if (mainWindow?.webContents) mainWindow.webContents.send('store-changed', data); diff --git a/electron/update.js b/electron/update.js index d31153f25..b975e5ee6 100644 --- a/electron/update.js +++ b/electron/update.js @@ -4,14 +4,12 @@ const electronLogger = require('electron-log'); const macUpdater = new electronUpdater.MacUpdater({ ...publishOptions, - private: false, + channels: ['latest', 'beta', 'alpha'], // automatically update to all channels }); macUpdater.logger = electronLogger; -macUpdater.setFeedURL({ - ...publishOptions, -}); +macUpdater.setFeedURL({ ...publishOptions }); macUpdater.autoDownload = true; macUpdater.autoInstallOnAppQuit = true; diff --git a/frontend/components/Layout/TopBar.tsx b/frontend/components/Layout/TopBar.tsx index a98b26363..c36f3054f 100644 --- a/frontend/components/Layout/TopBar.tsx +++ b/frontend/components/Layout/TopBar.tsx @@ -3,6 +3,7 @@ import styled from 'styled-components'; import { COLOR } from '@/constants'; import { useElectronApi } from '@/hooks/useElectronApi'; +import { useStore } from '@/hooks/useStore'; const { Text } = Typography; @@ -48,6 +49,9 @@ const TopBarContainer = styled.div` export const TopBar = () => { const electronApi = useElectronApi(); + const store = useStore(); + const envName = store?.storeState?.environmentName; + return ( @@ -56,7 +60,7 @@ export const TopBar = () => { - Pearl (alpha) + {`Pearl (alpha) ${envName ? `(${envName})` : ''}`.trim()} ); }; diff --git a/frontend/types/ElectronApi.ts b/frontend/types/ElectronApi.ts index 221b00000..2f586a0d9 100644 --- a/frontend/types/ElectronApi.ts +++ b/frontend/types/ElectronApi.ts @@ -1,4 +1,5 @@ export type ElectronStore = { + environmentName?: string; isInitialFunded?: boolean; firstStakingRewardAchieved?: boolean; firstRewardNotificationShown?: boolean; diff --git a/package.json b/package.json index d866e9081..bc7c5f1e3 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,9 @@ { "author": "Valory AG", + "main": "electron/main.js", + "name": "olas-operate-app", + "productName": "Pearl", + "version": "0.1.0-rc34", "dependencies": { "@ant-design/cssinjs": "^1.18.4", "@ant-design/icons": "^5.3.0", @@ -38,9 +42,6 @@ "net": "^1.0.2", "prettier": "^3.2.5" }, - "main": "electron/main.js", - "name": "olas-operate-app", - "productName": "Pearl", "scripts": { "build:frontend": "cd frontend && yarn build && rm -rf ../electron/.next && cp -r .next ../electron/.next && rm -rf ../electron/public && cp -r public ../electron/public", "dev:backend": "poetry run python operate/cli.py", @@ -54,6 +55,5 @@ "test:frontend": "cd frontend && yarn test", "start": "electron .", "build": "rm -rf dist/ && electron-builder build" - }, - "version": "0.1.0-rc34" + } }