-
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 #439 from valory-xyz/refactor/services-context-hooks
Optimistic Services refactor, and small QoL changes to AgentButton, numberFormatters
- Loading branch information
Showing
24 changed files
with
535 additions
and
385 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { Abi } from '@/types/Abi'; | ||
|
||
export const ERC20_BALANCEOF_STRING_FRAGMENT: Abi = [ | ||
export const ERC20_BALANCE_OF_STRING_FRAGMENT: Abi = [ | ||
'function balanceOf(address owner) view returns (uint256)', | ||
]; |
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
59 changes: 59 additions & 0 deletions
59
frontend/components/MainPage/header/AgentButton/AgentButton.tsx
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,59 @@ | ||
import { Button } from 'antd'; | ||
import { useMemo } from 'react'; | ||
|
||
import { MiddlewareDeploymentStatus } from '@/client'; | ||
import { useService } from '@/hooks/useService'; | ||
import { useServices } from '@/hooks/useServices'; | ||
import { useStakingContractInfo } from '@/hooks/useStakingContractInfo'; | ||
|
||
import { | ||
CannotStartAgentDueToUnexpectedError, | ||
CannotStartAgentPopover, | ||
} from '../CannotStartAgentPopover'; | ||
import { AgentNotRunningButton } from './AgentNotRunningButton'; | ||
import { AgentRunningButton } from './AgentRunningButton'; | ||
import { AgentStartingButton } from './AgentStartingButton'; | ||
import { AgentStoppingButton } from './AgentStoppingButton'; | ||
|
||
export const AgentButton = () => { | ||
const { selectedService } = useServices(); | ||
const { | ||
service, | ||
deploymentStatus: serviceStatus, | ||
isLoaded, | ||
} = useService({ serviceConfigId: selectedService?.service_config_id }); | ||
const { isEligibleForStaking, isAgentEvicted } = useStakingContractInfo(); | ||
|
||
return useMemo(() => { | ||
if (!isLoaded) { | ||
return <Button type="primary" size="large" disabled loading />; | ||
} | ||
|
||
if (serviceStatus === MiddlewareDeploymentStatus.STOPPING) { | ||
return <AgentStoppingButton />; | ||
} | ||
|
||
if (serviceStatus === MiddlewareDeploymentStatus.DEPLOYING) { | ||
return <AgentStartingButton />; | ||
} | ||
|
||
if (serviceStatus === MiddlewareDeploymentStatus.DEPLOYED) { | ||
return <AgentRunningButton />; | ||
} | ||
|
||
if (!isEligibleForStaking && isAgentEvicted) | ||
return <CannotStartAgentPopover />; | ||
|
||
if ( | ||
!service || | ||
serviceStatus === MiddlewareDeploymentStatus.STOPPED || | ||
serviceStatus === MiddlewareDeploymentStatus.CREATED || | ||
serviceStatus === MiddlewareDeploymentStatus.BUILT || | ||
serviceStatus === MiddlewareDeploymentStatus.DELETED | ||
) { | ||
return <AgentNotRunningButton />; | ||
} | ||
|
||
return <CannotStartAgentDueToUnexpectedError />; | ||
}, [isLoaded, serviceStatus, isEligibleForStaking, isAgentEvicted, service]); | ||
}; |
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.