Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rewards today tooltip #150

Merged
merged 6 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ const createMainWindow = () => {
mainWindow.setSize(width, height);
});

ipcMain.on('show-notification', (title, description) => {
ipcMain.on('show-notification', (_event, title, description) => {
mohandast52 marked this conversation as resolved.
Show resolved Hide resolved
showNotification(title, description || undefined);
});

Expand Down
4 changes: 3 additions & 1 deletion frontend/components/Main/KeepAgentRunning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { CardSection } from '../styled/CardSection';

const { Text } = Typography;

const COVER_BLOCK_BORDERS_STYLE = { marginBottom: '-1px' };

export const KeepAgentRunning = () => {
const { storeState } = useStore();
const { serviceStatus } = useServices();
Expand All @@ -17,7 +19,7 @@ export const KeepAgentRunning = () => {
if (serviceStatus !== DeploymentStatus.DEPLOYED) return null;

return (
<CardSection>
<CardSection style={COVER_BLOCK_BORDERS_STYLE}>
<Alert
type="info"
fullWidth
Expand Down
80 changes: 73 additions & 7 deletions frontend/components/Main/MainHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { InfoCircleOutlined } from '@ant-design/icons';
import { Badge, Button, Flex, Popover, Typography } from 'antd';
import { Badge, Button, Flex, Modal, Popover, Typography } from 'antd';
import { formatUnits } from 'ethers/lib/utils';
import Image from 'next/image';
import { useCallback, useEffect, useMemo, useState } from 'react';
Expand All @@ -8,23 +8,73 @@ import { Chain, DeploymentStatus } from '@/client';
import { COLOR, LOW_BALANCE, SERVICE_TEMPLATES } from '@/constants';
import { useBalance, useServiceTemplates } from '@/hooks';
import { useElectronApi } from '@/hooks/useElectronApi';
import { useReward } from '@/hooks/useReward';
import { useServices } from '@/hooks/useServices';
import { useStore } from '@/hooks/useStore';
import { useWallet } from '@/hooks/useWallet';
import { ServicesService } from '@/service';
import { WalletService } from '@/service/Wallet';

const { Text } = Typography;
const { Text, Title, Paragraph } = Typography;

const LOADING_MESSAGE =
"It may take a while to start your agent, so feel free to close the app. We'll notify you once your agent is running.";

enum ServiceButtonLoadingState {
Starting,
Pausing,
NotLoading,
}

const FirstRunModal = ({
open,
onClose,
}: {
open: boolean;
onClose: () => void;
}) => {
const { minimumStakedAmountRequired } = useReward();

if (!open) return null;
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>
<Title level={5} className="mt-12 text-center">
Your agent is running and you&apos;ve staked{' '}
{minimumStakedAmountRequired} OLAS!
Tanya-atatakai marked this conversation as resolved.
Show resolved Hide resolved
</Title>
<Paragraph>Your agent is working towards earning rewards.</Paragraph>
<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.
</Paragraph>
</Modal>
);
};

export const MainHeader = () => {
const { storeState } = useStore();
const { services, serviceStatus, setServiceStatus } = useServices();
Expand All @@ -39,6 +89,11 @@ export const MainHeader = () => {
setIsPaused: setIsBalancePollingPaused,
} = useBalance();

const [isModalOpen, setIsModalOpen] = useState(false);
const handleModalClose = useCallback(() => setIsModalOpen(false), []);

const { minimumStakedAmountRequired } = useReward();

const safeOlasBalanceWithStaked = useMemo(() => {
if (safeBalance?.OLAS === undefined) return;
if (totalOlasStakedBalance === undefined) return;
Expand Down Expand Up @@ -122,7 +177,14 @@ export const MainHeader = () => {
})
.then(() => {
setServiceStatus(DeploymentStatus.DEPLOYED);
showNotification?.('Your agent is now running!');
if (totalOlasStakedBalance === 0) {
Tanya-atatakai marked this conversation as resolved.
Show resolved Hide resolved
showNotification?.(
`Your agent is running and you've staked ${minimumStakedAmountRequired} OLAS!`,
);
setIsModalOpen(true);
} else {
showNotification?.('Your agent is now running!');
}
})
.finally(() => {
setIsBalancePollingPaused(false);
Expand All @@ -134,11 +196,13 @@ export const MainHeader = () => {
}
}, [
masterSafeAddress,
minimumStakedAmountRequired,
serviceTemplate,
setIsBalancePollingPaused,
setServiceStatus,
wallets,
showNotification,
totalOlasStakedBalance,
wallets,
]);

const handlePause = useCallback(() => {
Expand Down Expand Up @@ -253,14 +317,14 @@ export const MainHeader = () => {
if (!isDeployable) {
return (
<Button type="default" size="large" disabled>
Start agent
Start agent {totalOlasStakedBalance === 0 && '& stake'}
</Button>
);
}

return (
<Button type="primary" size="large" onClick={handleStart}>
Start agent
Start agent {totalOlasStakedBalance === 0 && '& stake'}
</Button>
);
}, [
Expand All @@ -273,12 +337,14 @@ export const MainHeader = () => {
services,
storeState?.isInitialFunded,
totalEthBalance,
totalOlasStakedBalance,
]);

return (
<Flex justify="start" align="center" gap={10}>
{agentHead}
{serviceToggleButton}
<FirstRunModal open={isModalOpen} onClose={handleModalClose} />
</Flex>
);
};
100 changes: 95 additions & 5 deletions frontend/components/Main/MainOlasBalance.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,103 @@
import { Skeleton } from 'antd';
import { InfoCircleOutlined } from '@ant-design/icons';
import { Flex, Skeleton, Tooltip, Typography } from 'antd';
import { useMemo } from 'react';
import styled from 'styled-components';

import { balanceFormat } from '@/common-util/numberFormatters';
import { UNICODE_SYMBOLS } from '@/constants/unicode';
import { useBalance } from '@/hooks';
import { useReward } from '@/hooks/useReward';

import { CardSection } from '../styled/CardSection';

const { Text } = Typography;
const Balance = styled.span`
letter-spacing: -2px;
margin-right: 4px;
`;
const BalanceBreakdown = styled.div`
padding: 4px;
`;
const BalanceBreakdownLine = styled.div`
position: relative;
display: flex;
align-items: center;
justify-content: space-between;
font-size: 14px;
color: #1f2229;

Tanya-atatakai marked this conversation as resolved.
Show resolved Hide resolved
> span {
background: #fff;
z-index: 1;
Tanya-atatakai marked this conversation as resolved.
Show resolved Hide resolved
&:first-child {
padding-right: 6px;
}
&:last-child {
padding-left: 6px;
}
}

&:before {
content: '';
position: absolute;
bottom: 6px;
width: 100%;
border-bottom: 2px dotted #c2cbd7;
}
Tanya-atatakai marked this conversation as resolved.
Show resolved Hide resolved

&:not(:last-child) {
margin-bottom: 8px;
}
`;
const OVERLAY_STYLE = { maxWidth: '300px', width: '300px' };

const CurrentBalance = () => {
const { totalOlasBalance, totalOlasStakedBalance } = useBalance();
const { accruedServiceStakingRewards } = useReward();

const balances = useMemo(() => {
return [
{
title: 'Staked amount',
value: balanceFormat(totalOlasStakedBalance ?? 0, 2),
},
{
title: 'Unclaimed rewards',
value: balanceFormat(accruedServiceStakingRewards ?? 0, 2),
},
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hope this is the correct value for "Unclaimed rewards"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it is, these are the rewards in contract that have not yet been claimed

{
title: 'Unused funds',
value: balanceFormat(
(totalOlasBalance ?? 0) - (totalOlasStakedBalance ?? 0),
2,
),
},
];
}, [accruedServiceStakingRewards, totalOlasBalance, totalOlasStakedBalance]);

return (
<Text type="secondary">
Current balance&nbsp;
<Tooltip
arrow={false}
placement="bottom"
overlayStyle={OVERLAY_STYLE}
title={
<BalanceBreakdown>
{balances.map((item, index) => (
<BalanceBreakdownLine key={index}>
<span>{item.title}</span>
<span className="font-weight-600">{item.value} OLAS</span>
</BalanceBreakdownLine>
Tanya-atatakai marked this conversation as resolved.
Show resolved Hide resolved
))}
</BalanceBreakdown>
}
>
<InfoCircleOutlined />
</Tooltip>
</Text>
);
};

export const MainOlasBalance = () => {
const { isBalanceLoaded, totalOlasBalance } = useBalance();
Expand All @@ -21,12 +108,15 @@ export const MainOlasBalance = () => {
}, [totalOlasBalance]);

return (
<CardSection align="end" gap={5} bordertop="true" borderbottom="true">
<CardSection vertical gap={8} bordertop="true" borderbottom="true">
{isBalanceLoaded ? (
<>
<span className="balance-symbol">{UNICODE_SYMBOLS.OLAS}</span>
<Balance className="balance">{balance}</Balance>
<span className="balance-currency">OLAS</span>
<CurrentBalance />
<Flex align="end">
<span className="balance-symbol">{UNICODE_SYMBOLS.OLAS}</span>
<Balance className="balance">{balance}</Balance>
<span className="balance-currency">OLAS</span>
</Flex>
</>
) : (
<Skeleton.Input active size="large" style={{ margin: '4px 0' }} />
Expand Down
Loading
Loading