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: "Start Agent" button fix #235

Merged
merged 4 commits into from
Jul 19, 2024
Merged
Changes from 1 commit
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
47 changes: 20 additions & 27 deletions frontend/components/Main/MainHeader/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { InfoCircleOutlined } from '@ant-design/icons';
import { Badge, Button, Flex, Popover, Skeleton, Typography } from 'antd';
import {
Badge,
Button,
ButtonProps,
Flex,
Popover,
Skeleton,
Typography,
} from 'antd';
import Image from 'next/image';
import { useCallback, useEffect, useMemo, useState } from 'react';

Expand Down Expand Up @@ -210,14 +218,6 @@ export const MainHeader = () => {
const serviceToggleButton = useMemo(() => {
if (!canStartAgent) return <CannotStartAgent />;

if (canStartAgent && isAgentEvicted) {
return (
<Button type="primary" size="large" onClick={handleStart}>
Start agent
</Button>
);
}

if (serviceButtonState === ServiceButtonLoadingState.Pausing) {
return (
<Button type="default" size="large" ghost disabled loading>
Expand Down Expand Up @@ -274,27 +274,20 @@ export const MainHeader = () => {
totalEthBalance > requiredGas
);
})();

const serviceExists = !!services?.[0];

if (!isDeployable) {
return (
<Button type="default" size="large" disabled>
Start agent {!serviceExists && '& stake'}
</Button>
);
}
const canActivateAgent = canStartAgent && (isAgentEvicted || isDeployable);
Copy link
Collaborator

Choose a reason for hiding this comment

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

getting lost with these can variables, they need more context

i.e. canStartAgent is not solely determined by the staking contract, and needs to be renamed to something more fitting, unsure what exactly but it should infer it's relation to the staking contract

canActivateAgent, i'm lost on what this represents too :/ canStartAgent already factors in isAgentEvicted

image


return (
<Button
type="primary"
size="large"
disabled={!canStartAgent}
onClick={handleStart}
>
Start agent {!serviceExists && '& stake'}
</Button>
);
const buttonProps: ButtonProps = {
type: canActivateAgent ? 'primary' : 'default',
size: 'large',
disabled: !canStartAgent || !isDeployable,
onClick: canActivateAgent ? handleStart : undefined,
};

const buttonText = `Start agent ${!serviceExists ? '& stake' : ''}`;

return <Button {...buttonProps}>{buttonText}</Button>;
}, [
handlePause,
handleStart,
Expand Down
Loading