Skip to content

Commit

Permalink
chore: add dummy components for Eviction cases
Browse files Browse the repository at this point in the history
  • Loading branch information
mohandast52 committed Jul 15, 2024
1 parent b410379 commit 48ee3d0
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 2 deletions.
6 changes: 6 additions & 0 deletions frontend/components/Main/MainHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { WalletService } from '@/service/Wallet';

import { requiredGas, requiredOlas } from './constants';
import { FirstRunModal } from './FirstRunModal';
import { useEviction } from './useEviction';

const { Text } = Typography;

Expand Down Expand Up @@ -81,6 +82,7 @@ export const MainHeader = () => {
isBalanceLoaded,
setIsPaused: setIsBalancePollingPaused,
} = useBalance();
const { isEvicted, component } = useEviction();

const [isModalOpen, setIsModalOpen] = useState(false);
const handleModalClose = useCallback(() => setIsModalOpen(false), []);
Expand Down Expand Up @@ -206,6 +208,8 @@ export const MainHeader = () => {
}, [services, setServiceStatus]);

const serviceToggleButton = useMemo(() => {
if (isEvicted) return component;

if (serviceButtonState === ServiceButtonLoadingState.Pausing) {
return (
<Button type="default" size="large" ghost disabled loading>
Expand Down Expand Up @@ -294,6 +298,8 @@ export const MainHeader = () => {
storeState?.isInitialFunded,
totalEthBalance,
canStartAgent,
isEvicted,
component,
]);

return (
Expand Down
76 changes: 74 additions & 2 deletions frontend/components/Main/MainHeader/useEviction.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,78 @@
// hook to check if the agent is evicted
import { InfoCircleOutlined } from '@ant-design/icons';
import { Button, Flex, Popover, Typography } from 'antd';

import { COLOR } from '@/constants/colors';

const { Text } = Typography;

const AgentCannotUnstake = () => (
<Popover
trigger={['hover', 'click']}
placement="bottomLeft"
showArrow={false}
content={
<Flex vertical={false} gap={8} style={{ maxWidth: 260 }}>
<Text>
<InfoCircleOutlined style={{ color: COLOR.BLUE }} />
</Text>
{/* TODO: ask copy from Roman */}
<Text>
Agent cannot be staked until some date from backend or calculate in UI
</Text>
</Flex>
}
>
<Button type="default" size="large" disabled loading>
Start agent
</Button>
</Popover>
);

const CanStartAgent = () => {
const handleStartAgent = () => null; // TODO

return (
<Popover
trigger={['hover', 'click']}
placement="bottomLeft"
showArrow={false}
content={
<Flex vertical={false} gap={8} style={{ maxWidth: 260 }}>
<Text>
<InfoCircleOutlined style={{ color: COLOR.BLUE }} />
</Text>
{/* TODO: ask copy from Roman */}
<Text>Agent can be staked</Text>
</Flex>
}
>
<Button type="primary" size="large" onClick={handleStartAgent}>
Unstake and start agent
</Button>
</Popover>
);
};

export const useEviction = () => {
const isEvicted = true; // TODO
const isMinStakingDurationMet = true; // TODO

if (isEvicted) {
if (isMinStakingDurationMet) {
return {
isEvicted: true,
canStartAgent: true,
component: <CanStartAgent />,
};
}

return {
isEvicted: true,
canStartAgent: false,
component: <AgentCannotUnstake />,
};
}

// scenario 1: agent is evicted and min staking duration is NOT met
// ie, user CANNOT start the agent

Expand All @@ -17,6 +89,6 @@ export const useEviction = () => {
return {
isEvicted: false,
canStartAgent: true,
message: null,
component: null,
};
};

0 comments on commit 48ee3d0

Please sign in to comment.