-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #162 from valory-xyz/mohan/checks-against-contract…
…-no-funds feat: Add checks against contract no funds and full slots cases
- Loading branch information
Showing
11 changed files
with
354 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { InfoCircleOutlined } from '@ant-design/icons'; | ||
import { Popover, PopoverProps, Typography } from 'antd'; | ||
|
||
import { COLOR, SUPPORT_URL } from '@/constants'; | ||
import { UNICODE_SYMBOLS } from '@/constants/unicode'; | ||
import { useStakingContractInfo } from '@/hooks/useStakingContractInfo'; | ||
|
||
const { Paragraph, Text } = Typography; | ||
|
||
const cannotStartAgentText = ( | ||
<Text style={{ color: COLOR.RED }}> | ||
Cannot start agent | ||
<InfoCircleOutlined /> | ||
</Text> | ||
); | ||
|
||
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 = () => ( | ||
<Popover | ||
{...otherPopoverProps} | ||
title="Your agent was evicted" | ||
content={<div style={{ maxWidth: 340 }}>{evictedDescription}</div>} | ||
> | ||
{cannotStartAgentText} | ||
</Popover> | ||
); | ||
|
||
const otherPopoverProps: PopoverProps = { | ||
arrow: false, | ||
placement: 'bottomRight', | ||
}; | ||
|
||
const JoinOlasCommunity = () => ( | ||
<div style={{ maxWidth: 340 }}> | ||
<Paragraph> | ||
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> | ||
); | ||
|
||
const NoRewardsAvailablePopover = () => ( | ||
<Popover | ||
{...otherPopoverProps} | ||
title="No rewards available" | ||
content={<JoinOlasCommunity />} | ||
> | ||
{cannotStartAgentText} | ||
</Popover> | ||
); | ||
|
||
const NoJobsAvailablePopover = () => ( | ||
<Popover | ||
{...otherPopoverProps} | ||
title="No jobs available" | ||
content={<JoinOlasCommunity />} | ||
> | ||
{cannotStartAgentText} | ||
</Popover> | ||
); | ||
|
||
export const CannotStartAgent = () => { | ||
const { | ||
canStartAgent, | ||
hasEnoughServiceSlots, | ||
isRewardsAvailable, | ||
isAgentEvicted, | ||
} = useStakingContractInfo(); | ||
|
||
if (canStartAgent) return null; | ||
if (!hasEnoughServiceSlots) return <NoJobsAvailablePopover />; | ||
if (!isRewardsAvailable) return <NoRewardsAvailablePopover />; | ||
if (isAgentEvicted) return <AgentEvictedPopover />; | ||
throw new Error('Cannot start agent, please contact support'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Button, Flex, Modal, Typography } from 'antd'; | ||
import Image from 'next/image'; | ||
import { FC } from 'react'; | ||
|
||
import { useReward } from '@/hooks/useReward'; | ||
|
||
const { Title, Paragraph } = Typography; | ||
|
||
type FirstRunModalProps = { open: boolean; onClose: () => void }; | ||
|
||
export const FirstRunModal: FC<FirstRunModalProps> = ({ open, onClose }) => { | ||
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've staked ${minimumStakedAmountRequired} OLAS!`} | ||
</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> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.