Skip to content

Commit

Permalink
Merge pull request #290 from valory-xyz/staging
Browse files Browse the repository at this point in the history
Staging to Main, for 117 release
  • Loading branch information
truemiller authored Aug 22, 2024
2 parents 8799c67 + c0e4f59 commit aa9235c
Show file tree
Hide file tree
Showing 84 changed files with 3,186 additions and 1,380 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:

- name: Get trader bin
run: |
trader_version=$(poetry run python -c "import yaml; config = yaml.safe_load(open('templates/trader.yaml')); print(config['trader_version'])")
trader_version=$(poetry run python -c "import yaml; config = yaml.safe_load(open('templates/trader.yaml')); print(config['service_version'])")
echo $trader_version
mkdir dist && curl -L -o dist/aea_bin "https://github.com/valory-xyz/trader/releases/download/${trader_version}/trader_bin_${{ env.OS_ARCH }}"
Expand Down
4 changes: 3 additions & 1 deletion .gitleaksignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ d8149e9b5b7bd6a7ed7bc1039900702f1d4f287b:operate/services/manage.py:generic-api-
99c0f139b037da2587708212fcf6d0e20786d0ba:operate/services/manage.py:generic-api-key:406
99c0f139b037da2587708212fcf6d0e20786d0ba:operate/services/manage.py:generic-api-key:454
99c0f139b037da2587708212fcf6d0e20786d0ba:operate/services/manage.py:generic-api-key:455
91ec07457f69e9a29f63693ac8ef887e4b5f49f0:operate/services/manage.py:generic-api-key:454
91ec07457f69e9a29f63693ac8ef887e4b5f49f0:operate/services/manage.py:generic-api-key:454
410bea2bd02ff54da69387fe8f3b58793e09f7b0:operate/services/manage.py:generic-api-key:421
410bea2bd02ff54da69387fe8f3b58793e09f7b0:operate/services/manage.py:generic-api-key:422
2 changes: 1 addition & 1 deletion electron/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const { paths } = require('./constants');
* - 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.0rc111';
const OlasMiddlewareVersion = '0.1.0rc117';

const path = require('path');
const { app } = require('electron');
Expand Down
28 changes: 15 additions & 13 deletions electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ const HEIGHT = 700;
/**
* Creates the main window
*/
const createMainWindow = () => {
const createMainWindow = async () => {
const width = isDev ? 840 : APP_WIDTH;
mainWindow = new BrowserWindow({
title: 'Pearl',
Expand All @@ -216,12 +216,6 @@ const createMainWindow = () => {

mainWindow.setMenuBarVisibility(true);

if (isDev) {
mainWindow.loadURL(`http://localhost:${appConfig.ports.dev.next}`);
} else {
mainWindow.loadURL(`http://localhost:${appConfig.ports.prod.next}`);
}

ipcMain.on('close-app', () => {
mainWindow.close();
});
Expand Down Expand Up @@ -264,15 +258,23 @@ const createMainWindow = () => {
event.preventDefault();
mainWindow.hide();
});

const storeInitialValues = {
environmentName: process.env.IS_STAGING ? 'staging' : '',
};
setupStoreIpc(ipcMain, mainWindow, storeInitialValues);

try {
logger.electron('Setting up store IPC');
await setupStoreIpc(ipcMain, mainWindow);
} catch (e) {
logger.electron('Store IPC failed:', JSON.stringify(e));
}

if (isDev) {
mainWindow.webContents.openDevTools();
}

if (isDev) {
mainWindow.loadURL(`http://localhost:${appConfig.ports.dev.next}`);
} else {
mainWindow.loadURL(`http://localhost:${appConfig.ports.prod.next}`);
}
};

async function launchDaemon() {
Expand Down Expand Up @@ -494,7 +496,7 @@ ipcMain.on('check', async function (event, _argument) {
}

event.sender.send('response', 'Launching App');
createMainWindow();
await createMainWindow();
createTray();
splashWindow.destroy();
} catch (e) {
Expand Down
38 changes: 18 additions & 20 deletions electron/store.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
const Store = require('electron-store');
// set schema to validate store data
const defaultSchema = {
environmentName: { type: 'string', default: '' },
isInitialFunded: { type: 'boolean', default: false },
const schema = {
isInitialFunded: { type: 'boolean', default: false }, // TODO: reconsider this default, can be problematic if user has already funded prior to implementation
firstStakingRewardAchieved: { type: 'boolean', default: false },
firstRewardNotificationShown: { type: 'boolean', default: false },
agentEvictionAlertShown: { type: 'boolean', default: false },
};

const setupStoreIpc = async (ipcChannel, mainWindow, storeInitialValues) => {
const Store = (await import('electron-store')).default;

// set default values for store
const schema = Object.assign({}, defaultSchema);
Object.keys(schema).forEach((key) => {
if (storeInitialValues[key] !== undefined) {
schema[key].default = storeInitialValues[key];
}
});
environmentName: { type: 'string', default: '' },
currentStakingProgram: { type: 'string', default: '' },
};

/** @type import Store from 'electron-store' */
/**
* Sets up the IPC communication and initializes the Electron store with default values and schema.
* @param {Electron.IpcMain} ipcMain - The IPC channel for communication.
* @param {Electron.BrowserWindow} mainWindow - The main Electron browser window.
* @returns {Promise<void>} - A promise that resolves once the store is set up.
*/
const setupStoreIpc = async (ipcMain, mainWindow) => {
const store = new Store({ schema });

store.onDidAnyChange((data) => {
Expand All @@ -27,11 +25,11 @@ const setupStoreIpc = async (ipcChannel, mainWindow, storeInitialValues) => {
});

// exposed to electron browser window
ipcChannel.handle('store', () => store.store);
ipcChannel.handle('store-get', (_, key) => store.get(key));
ipcChannel.handle('store-set', (_, key, value) => store.set(key, value));
ipcChannel.handle('store-delete', (_, key) => store.delete(key));
ipcChannel.handle('store-clear', (_) => store.clear());
ipcMain.handle('store', () => store.store);
ipcMain.handle('store-get', (_, key) => store.get(key));
ipcMain.handle('store-set', (_, key, value) => store.set(key, value));
ipcMain.handle('store-delete', (_, key) => store.delete(key));
ipcMain.handle('store-clear', (_) => store.clear());
};

module.exports = { setupStoreIpc };
32 changes: 25 additions & 7 deletions frontend/client/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { StakingProgram } from '@/enums/StakingProgram';
import { Address } from '@/types/Address';

import { Chain, DeploymentStatus, Ledger } from './enums';
Expand All @@ -20,36 +21,53 @@ export type ChainData = {
instances?: Address[];
token?: number;
multisig?: Address;
on_chain_state: number;
staked: boolean;
user_params: {
cost_of_bond: number;
fund_requirements: {
agent: number;
safe: number;
};
nft: string;
staking_program_id: StakingProgram;
threshold: number;
use_staking: true;
};
};

export type Service = {
name: string;
hash: string;
keys: ServiceKeys[];
readme?: string;
ledger: LedgerConfig;
chain_data: ChainData;
chain_configs: {
[chainId: number]: {
ledger_config: LedgerConfig;
chain_data: ChainData;
};
};
};

export type ServiceTemplate = {
name: string;
hash: string;
image: string;
description: string;
configuration: ConfigurationTemplate;
service_version: string;
home_chain_id: string;
configurations: { [key: string]: ConfigurationTemplate };
deploy?: boolean;
};

export type ConfigurationTemplate = {
rpc?: string; // added on deployment
staking_program_id?: StakingProgram; // added on deployment
nft: string;
trader_version: string;
rpc?: string; // added by user
agent_id: number;
threshold: number;
use_staking: boolean;
cost_of_bond: number;
olas_cost_of_bond: number;
olas_required_to_stake: number;
monthly_gas_estimate: number;
fund_requirements: FundRequirementsTemplate;
};
Expand Down
5 changes: 5 additions & 0 deletions frontend/components/Alert/AlertTitle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Typography } from 'antd';

export const AlertTitle = ({ children }: { children: React.ReactNode }) => (
<Typography.Text className="font-weight-600">{children}</Typography.Text>
);
2 changes: 1 addition & 1 deletion frontend/components/Alert/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const icons = {
error: <ExclamationCircleOutlined />,
};

export const Alert = ({
export const CustomAlert = ({
type,
fullWidth,
...rest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useCallback, useEffect, useState } from 'react';

import { UNICODE_SYMBOLS } from '@/constants/symbols';
import { FAQ_URL, SUPPORT_URL } from '@/constants/urls';
import { PageState } from '@/enums/PageState';
import { Pages } from '@/enums/PageState';
import { useElectronApi } from '@/hooks/useElectronApi';
import { useLogs } from '@/hooks/useLogs';
import { usePageState } from '@/hooks/usePageState';
Expand Down Expand Up @@ -78,7 +78,7 @@ export const HelpAndSupport = () => {
<Button
size="large"
icon={<CloseOutlined />}
onClick={() => goto(PageState.Main)}
onClick={() => goto(Pages.Main)}
/>
}
>
Expand Down
20 changes: 0 additions & 20 deletions frontend/components/Main/MainHeader/constants.ts

This file was deleted.

58 changes: 58 additions & 0 deletions frontend/components/MainPage/MainHeader/FirstRunModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Button, Flex, Modal, Typography } from 'antd';
import Image from 'next/image';
import { FC } from 'react';

import { useServiceTemplates } from '@/hooks/useServiceTemplates';
import { getMinimumStakedAmountRequired } from '@/utils/service';

type FirstRunModalProps = { open: boolean; onClose: () => void };

export const FirstRunModal: FC<FirstRunModalProps> = ({ open, onClose }) => {
const { getServiceTemplates } = useServiceTemplates();

if (!open) return null;

const minimumStakedAmountRequired = getMinimumStakedAmountRequired(
getServiceTemplates()[0],
);

return (
<Modal
open={open}
width={412}
onCancel={onClose}
footer={[
<Button
key="ok"
type="primary"
block
size="large"
className="mt-8"
onClick={onClose}
>
Got it
</Button>,
]}
>
<Flex align="center" justify="center">
<Image
src="/splash-robot-head.png"
width={100}
height={100}
alt="OLAS logo"
/>
</Flex>
<Typography.Title level={5} className="mt-12 text-center">
{`Your agent is running and you've staked ${minimumStakedAmountRequired} OLAS!`}
</Typography.Title>
<Typography.Paragraph>
Your agent is working towards earning rewards.
</Typography.Paragraph>
<Typography.Paragraph>
Pearl is designed to make it easy for you to earn staking rewards every
day. Simply leave the app and agent running in the background for ~1hr a
day.
</Typography.Paragraph>
</Modal>
);
};
Loading

0 comments on commit aa9235c

Please sign in to comment.