Skip to content

Commit

Permalink
Merge pull request #253 from valory-xyz/staging
Browse files Browse the repository at this point in the history
feat: staging to main
  • Loading branch information
mohandast52 authored Aug 13, 2024
2 parents be324d7 + d917f72 commit 8799c67
Show file tree
Hide file tree
Showing 22 changed files with 371 additions and 77 deletions.
26 changes: 24 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:
- run: yarn install-deps
- name: "Build frontend with env vars"
run: yarn build:frontend
env:
env:
NODE_ENV: production
DEV_RPC: https://rpc-gate.autonolas.tech/gnosis-rpc/
IS_STAGING: ${{ github.ref != 'refs/heads/main' && 'true' || 'false' }}
Expand All @@ -110,4 +110,26 @@ jobs:
NODE_ENV: production
DEV_RPC: https://rpc-gate.autonolas.tech/gnosis-rpc/
FORK_URL: https://rpc-gate.autonolas.tech/gnosis-rpc/
run: node build.js
run: node build.js
- name: "Build frontend with dev env vars"
run: yarn build:frontend
env:
NODE_ENV: development
DEV_RPC: https://virtual.gnosis.rpc.tenderly.co/78ca845d-2b24-44a6-9ce2-869a979e8b5b
IS_STAGING: ${{ github.ref != 'refs/heads/main' && 'true' || 'false' }}
FORK_URL: https://virtual.gnosis.rpc.tenderly.co/78ca845d-2b24-44a6-9ce2-869a979e8b5b
- name: "Build, notarize, publish dev build"
env:
APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLEIDPASS }}
APPLE_ID: ${{ secrets.APPLEID }}
APPLETEAMID: ${{ secrets.APPLETEAMID }}
CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }}
CSC_LINK: ${{ secrets.CSC_LINK }}
GH_TOKEN: ${{ secrets.github_token}}
NODE_ENV: development
DEV_RPC: https://virtual.gnosis.rpc.tenderly.co/78ca845d-2b24-44a6-9ce2-869a979e8b5b
FORK_URL: https://virtual.gnosis.rpc.tenderly.co/78ca845d-2b24-44a6-9ce2-869a979e8b5b
run: |
echo "DEV_RPC=https://virtual.gnosis.rpc.tenderly.co/78ca845d-2b24-44a6-9ce2-869a979e8b5b" >> .env
echo -e "FORK_URL=https://virtual.gnosis.rpc.tenderly.co/78ca845d-2b24-44a6-9ce2-869a979e8b5b" >> .env
node build.js
16 changes: 15 additions & 1 deletion build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ const build = require('electron-builder').build;

const { publishOptions } = require('./electron/constants');

/**
* Get the artifact name for the build based on the environment.
* @returns {string}
*/
function artifactName() {
const env = process.env.NODE_ENV;
const prefix = env === 'production' ? '' : 'dev-';
return prefix + '${productName}-${version}-${platform}-${arch}.${ext}';
}

const main = async () => {
console.log('Building...');

Expand All @@ -14,7 +24,7 @@ const main = async () => {
publish: 'onTag',
config: {
appId: 'xyz.valory.olas-operate-app',
artifactName: '${productName}-${version}-${platform}-${arch}.${ext}',
artifactName: artifactName(),
productName: 'Pearl',
files: ['electron/**/*', 'package.json'],
directories: {
Expand All @@ -26,6 +36,10 @@ const main = async () => {
to: 'bins',
filter: ['**/*'],
},
{
from: '.env',
to: '.env'
},
],
cscKeyPassword: process.env.CSC_KEY_PASSWORD,
cscLink: process.env.CSC_LINK,
Expand Down
47 changes: 47 additions & 0 deletions build_pearl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

# ------------------------------------------------------------------------------
#
# Copyright 2023-2024 Valory AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ------------------------------------------------------------------------------

cd "$(dirname "$0")"

BIN_DIR="electron/bins/"
mkdir -p $BIN_DIR

poetry install

poetry run pyinstaller operate/services/utils/tendermint.py --onefile --distpath $BIN_DIR

poetry run pyinstaller \
--collect-data eth_account \
--collect-all aea \
--collect-all autonomy \
--collect-all operate \
--collect-all aea_ledger_ethereum \
--collect-all aea_ledger_cosmos \
--collect-all aea_ledger_ethereum_flashbots \
--hidden-import aea_ledger_ethereum \
--hidden-import aea_ledger_cosmos \
--hidden-import aea_ledger_ethereum_flashbots \
operate/pearl.py \
--add-binary ${BIN_DIR}/aea_bin_x64:. \
--add-binary ${BIN_DIR}/aea_bin_arm64:. \
--onefile \
--distpath $BIN_DIR \
--name pearl_$(uname -m)

10 changes: 10 additions & 0 deletions download_binaries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

BIN_DIR="electron/bins/"
mkdir -p $BIN_DIR

trader_version=$(poetry run python -c "import yaml; config = yaml.safe_load(open('templates/trader.yaml')); print(config['configuration']['trader_version'])")

curl -L -o "${BIN_DIR}aea_bin_x64" "https://github.com/valory-xyz/trader/releases/download/${trader_version}/trader_bin_x64"

curl -L -o "${BIN_DIR}aea_bin_arm64" "https://github.com/valory-xyz/trader/releases/download/${trader_version}/trader_bin_arm64"
12 changes: 11 additions & 1 deletion electron/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,17 @@ 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.0rc110';
const OlasMiddlewareVersion = '0.1.0rc111';

const path = require('path');
const { app } = require('electron');

// load env vars
require('dotenv').config({
path: app.isPackaged
? path.join(process.resourcesPath, '.env')
: path.resolve(process.cwd(), '.env'),
});

const Env = {
...process.env,
Expand Down
14 changes: 11 additions & 3 deletions electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,25 +131,33 @@ const createTray = () => {
tray.setContextMenu(contextMenu);

ipcMain.on('tray', (_event, status) => {
const isSupportedOS = isWindows || isMac;
switch (status) {
case 'low-gas': {
const icon = getUpdatedTrayIcon(
isWindows || isMac ? TRAY_ICONS.LOW_GAS : TRAY_ICONS_PATHS.LOW_GAS,
isSupportedOS ? TRAY_ICONS.LOW_GAS : TRAY_ICONS_PATHS.LOW_GAS,
);
tray.setImage(icon);
break;
}
case 'running': {
const icon = getUpdatedTrayIcon(
isWindows || isMac ? TRAY_ICONS.RUNNING : TRAY_ICONS_PATHS.RUNNING,
isSupportedOS ? TRAY_ICONS.RUNNING : TRAY_ICONS_PATHS.RUNNING,
);
tray.setImage(icon);

break;
}
case 'paused': {
const icon = getUpdatedTrayIcon(
isWindows || isMac ? TRAY_ICONS.PAUSED : TRAY_ICONS_PATHS.PAUSED,
isSupportedOS ? TRAY_ICONS.PAUSED : TRAY_ICONS_PATHS.PAUSED,
);
tray.setImage(icon);
break;
}
case 'logged-out': {
const icon = getUpdatedTrayIcon(
isSupportedOS ? TRAY_ICONS.LOGGED_OUT : TRAY_ICONS_PATHS.LOGGED_OUT,
);
tray.setImage(icon);
break;
Expand Down
1 change: 1 addition & 0 deletions electron/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const defaultSchema = {
isInitialFunded: { type: 'boolean', default: false },
firstStakingRewardAchieved: { type: 'boolean', default: false },
firstRewardNotificationShown: { type: 'boolean', default: false },
agentEvictionAlertShown: { type: 'boolean', default: false },
};

const setupStoreIpc = async (ipcChannel, mainWindow, storeInitialValues) => {
Expand Down
45 changes: 35 additions & 10 deletions frontend/components/Main/MainGasBalance.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { ArrowUpOutlined, InfoCircleOutlined } from '@ant-design/icons';
import { Skeleton, Tooltip, Typography } from 'antd';
import { useMemo } from 'react';
import { useEffect, useMemo, useState } from 'react';
import styled from 'styled-components';

import { COLOR } from '@/constants/colors';
import { LOW_BALANCE } from '@/constants/thresholds';
import { useBalance } from '@/hooks/useBalance';
import { useElectronApi } from '@/hooks/useElectronApi';
import { useStore } from '@/hooks/useStore';
import { useWallet } from '@/hooks/useWallet';

import { CardSection } from '../styled/CardSection';
Expand All @@ -30,20 +32,43 @@ const EmptyDot = styled(Dot)`
const FineDot = styled(Dot)`
background-color: ${COLOR.GREEN_2};
`;
const LowDot = styled(Dot)`
background-color: ${COLOR.ORANGE};
`;

const BalanceStatus = () => {
const { safeBalance } = useBalance();
const { isBalanceLoaded, safeBalance } = useBalance();
const { storeState } = useStore();
const { showNotification } = useElectronApi();

const status = useMemo(() => {
if (!safeBalance || safeBalance.ETH === 0) {
return { statusName: 'Empty', StatusComponent: EmptyDot };
const [isLowBalanceNotificationShown, setIsLowBalanceNotificationShown] =
useState(false);

// show notification if balance is too low
useEffect(() => {
if (!isBalanceLoaded) return;
if (!safeBalance) return;
if (!showNotification) return;
if (!storeState?.isInitialFunded) return;

if (safeBalance.ETH < LOW_BALANCE && !isLowBalanceNotificationShown) {
showNotification('Trading balance is too low.');
setIsLowBalanceNotificationShown(true);
}

if (safeBalance.ETH < LOW_BALANCE) {
return { statusName: 'Low', StatusComponent: LowDot };
// If it has already been shown and the balance has increased,
// should show the notification again if it goes below the threshold.
if (safeBalance.ETH >= LOW_BALANCE && isLowBalanceNotificationShown) {
setIsLowBalanceNotificationShown(false);
}
}, [
isBalanceLoaded,
isLowBalanceNotificationShown,
safeBalance,
showNotification,
storeState?.isInitialFunded,
]);

const status = useMemo(() => {
if (!safeBalance || safeBalance.ETH < LOW_BALANCE) {
return { statusName: 'Too low', StatusComponent: EmptyDot };
}

return { statusName: 'Fine', StatusComponent: FineDot };
Expand Down
22 changes: 16 additions & 6 deletions frontend/components/Main/MainHeader/AgentButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useCallback, useMemo } from 'react';

import { Chain, DeploymentStatus } from '@/client';
import { COLOR } from '@/constants/colors';
import { LOW_BALANCE } from '@/constants/thresholds';
import { useBalance } from '@/hooks/useBalance';
import { useElectronApi } from '@/hooks/useElectronApi';
import { useServices } from '@/hooks/useServices';
Expand All @@ -15,7 +16,10 @@ import { ServicesService } from '@/service/Services';
import { WalletService } from '@/service/Wallet';
import { getMinimumStakedAmountRequired } from '@/utils/service';

import { CannotStartAgent } from '../CannotStartAgent';
import {
CannotStartAgent,
CannotStartAgentDueToUnexpectedError,
} from '../CannotStartAgent';
import { requiredGas, requiredOlas } from '../constants';

const { Text } = Typography;
Expand Down Expand Up @@ -185,6 +189,15 @@ const AgentNotRunningButton = () => {
]);

const isDeployable = useMemo(() => {
// if the agent is NOT running and the balance is too low,
// user should not be able to start the agent
const isServiceInactive =
serviceStatus === DeploymentStatus.BUILT ||
serviceStatus === DeploymentStatus.STOPPED;
if (isServiceInactive && safeBalance && safeBalance.ETH < LOW_BALANCE) {
return false;
}

if (serviceStatus === DeploymentStatus.DEPLOYED) return false;
if (serviceStatus === DeploymentStatus.DEPLOYING) return false;
if (serviceStatus === DeploymentStatus.STOPPING) return false;
Expand All @@ -211,6 +224,7 @@ const AgentNotRunningButton = () => {
serviceStatus,
storeState?.isInitialFunded,
totalEthBalance,
safeBalance,
]);

const buttonProps: ButtonProps = {
Expand Down Expand Up @@ -258,11 +272,7 @@ export const AgentButton = () => {
return <AgentNotRunningButton />;
}

return (
<Button type="primary" size="large" disabled>
Error, contact us!
</Button>
);
return <CannotStartAgentDueToUnexpectedError />;
}, [
hasInitialLoaded,
serviceStatus,
Expand Down
31 changes: 26 additions & 5 deletions frontend/components/Main/MainHeader/CannotStartAgent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,32 @@ const cannotStartAgentText = (
</Text>
);

const otherPopoverProps: PopoverProps = {
arrow: false,
placement: 'bottomRight',
};

export const CannotStartAgentDueToUnexpectedError = () => (
<Popover
{...otherPopoverProps}
title="Unexpected error"
content={
<div style={{ maxWidth: 340 }}>
<Paragraph>
Try to restart the app. If the issue persists, join the Olas community
Discord server to report or stay up to date on the issue.
</Paragraph>

<a href={SUPPORT_URL} target="_blank" rel="noreferrer">
Olas community Discord server {UNICODE_SYMBOLS.EXTERNAL_LINK}
</a>
</div>
}
>
{cannotStartAgentText}
</Popover>
);

const evictedDescription =
"You didn't run your agent enough and it missed its targets multiple times. Please wait a few days and try to run your agent again.";
const AgentEvictedPopover = () => (
Expand All @@ -27,11 +53,6 @@ const AgentEvictedPopover = () => (
</Popover>
);

const otherPopoverProps: PopoverProps = {
arrow: false,
placement: 'bottomRight',
};

const JoinOlasCommunity = () => (
<div style={{ maxWidth: 340 }}>
<Paragraph>
Expand Down
2 changes: 2 additions & 0 deletions frontend/components/Main/MainHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const useSetupTrayIcon = () => {
setTrayIcon?.('running');
} else if (serviceStatus === DeploymentStatus.STOPPED) {
setTrayIcon?.('paused');
} else if (serviceStatus === DeploymentStatus.BUILT) {
setTrayIcon?.('logged-out');
}
}, [safeBalance, serviceStatus, setTrayIcon]);

Expand Down
Loading

0 comments on commit 8799c67

Please sign in to comment.