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

feat: Pre-emptively educate about eviction #242

Merged
merged 3 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
69 changes: 67 additions & 2 deletions frontend/components/Main/MainOlasBalance.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { InfoCircleOutlined } from '@ant-design/icons';
import { Flex, Skeleton, Tooltip, Typography } from 'antd';
import { Button, Flex, Skeleton, Tooltip, Typography } from 'antd';
import { useMemo } from 'react';
import styled from 'styled-components';

import { Alert } from '@/components/Alert';
import { COLOR } from '@/constants/colors';
import { UNICODE_SYMBOLS } from '@/constants/symbols';
import { useBalance } from '@/hooks/useBalance';
import { useElectronApi } from '@/hooks/useElectronApi';
import { useReward } from '@/hooks/useReward';
import { useStore } from '@/hooks/useStore';
import { balanceFormat } from '@/utils/numberFormatters';

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

const { Text } = Typography;
const { Text, Title } = Typography;
const Balance = styled.span`
letter-spacing: -2px;
margin-right: 4px;
Expand Down Expand Up @@ -103,16 +106,78 @@ const CurrentBalance = () => {
);
};

const AvoidSuspensionAlertContainer = styled.div`
.ant-alert-info {
margin-bottom: 8px;
.anticon.ant-alert-icon {
height: 20px;
width: 20px;
svg {
width: 100%;
height: 100%;
}
}
}
`;

const AvoidSuspensionAlert = () => {
const { store } = useElectronApi();

return (
<AvoidSuspensionAlertContainer>
<Alert
fullWidth
type="info"
showIcon
message={
<Flex vertical gap={8} align="flex-start">
<Title level={5} style={{ margin: 0 }}>
Avoid suspension!
</Title>
<Text>
Run your agent for at least half an hour a day to make sure it
hits its targets. If it misses its targets 2 days in a row, it’ll
be suspended. You won’t be able to run it or earn rewards for
several days.
</Text>
<Button
type="primary"
ghost
onClick={() => store?.set?.('agentEvictionAlertShown', true)}
style={{ marginTop: 4 }}
>
Understood
</Button>
</Flex>
}
/>
</AvoidSuspensionAlertContainer>
);
};

export const MainOlasBalance = () => {
const { storeState } = useStore();
const { isBalanceLoaded, totalOlasBalance } = useBalance();

// If first reward notification is shown BUT
// agent eviction alert is NOT yet shown, show this alert.
const canShowAvoidSuspensionAlert = useMemo(() => {
if (!storeState) return false;

return (
storeState.firstRewardNotificationShown &&
!storeState.agentEvictionAlertShown
);
}, [storeState]);

const balance = useMemo(() => {
if (totalOlasBalance === undefined) return '--';
return balanceFormat(totalOlasBalance, 2);
}, [totalOlasBalance]);

return (
<CardSection vertical gap={8} bordertop="true" borderbottom="true">
{canShowAvoidSuspensionAlert ? <AvoidSuspensionAlert /> : null}
{isBalanceLoaded ? (
<>
<CurrentBalance />
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/Main/MainRewards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const DisplayRewards = () => {
const SHARE_TEXT = `I just earned my first reward through the Operate app powered by #olas!\n\nDownload the Pearl app:`;
const OPERATE_URL = 'https://olas.network/operate?pearl=first-reward';

const NotifyRewards = () => {
const NotifyRewardsModal = () => {
const { isEligibleForRewards, availableRewardsForEpochEth } = useReward();
const { totalOlasBalance } = useBalance();
const { showNotification, store } = useElectronApi();
Expand Down Expand Up @@ -179,6 +179,6 @@ const NotifyRewards = () => {
export const MainRewards = () => (
<>
<DisplayRewards />
<NotifyRewards />
<NotifyRewardsModal />
</>
);
1 change: 1 addition & 0 deletions frontend/types/ElectronApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export type ElectronStore = {
isInitialFunded?: boolean;
firstStakingRewardAchieved?: boolean;
firstRewardNotificationShown?: boolean;
agentEvictionAlertShown?: boolean;
};

export type ElectronTrayIconStatus = 'low-gas' | 'running' | 'paused';
Loading