From 9fa64ca374b402515c57cb61cf75a29f00c4cebf Mon Sep 17 00:00:00 2001 From: mohandast52 Date: Thu, 19 Dec 2024 16:25:38 +0530 Subject: [PATCH] refactor: simplify useServiceDeployment and reorganize AgentNotRunningButton component --- .../AgentButton/AgentNotRunningButton.tsx | 44 ++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/frontend/components/MainPage/header/AgentButton/AgentNotRunningButton.tsx b/frontend/components/MainPage/header/AgentButton/AgentNotRunningButton.tsx index 16191543..bee5fb72 100644 --- a/frontend/components/MainPage/header/AgentButton/AgentNotRunningButton.tsx +++ b/frontend/components/MainPage/header/AgentButton/AgentNotRunningButton.tsx @@ -37,7 +37,7 @@ import { WalletService } from '@/service/Wallet'; import { AgentConfig } from '@/types/Agent'; import { delayInSeconds } from '@/utils/delay'; -export function useServiceDeployment() { +const useServiceDeployment = () => { const { storeState } = useStore(); const { showNotification } = useElectronApi(); @@ -113,8 +113,9 @@ export function useServiceDeployment() { isServicesLoading || isServiceRunning || !isAllStakingContractDetailsRecordLoaded - ) + ) { return false; + } if (isNil(requiredStakedOlas)) return false; @@ -292,8 +293,9 @@ export function useServiceDeployment() { const handleStart = useCallback(async () => { if (!masterWallets?.[0]) return; - if (!selectedStakingProgramId) + if (!selectedStakingProgramId) { throw new Error('Staking program ID required'); + } const selectedServiceTemplate = SERVICE_TEMPLATES.find( (template) => template.agentType === selectedAgentType, @@ -351,25 +353,9 @@ export function useServiceDeployment() { const buttonText = `Start agent ${service ? '' : '& stake'}`; return { isDeployable, handleStart, buttonText }; -} - -// Original component, now simplified -export const AgentNotRunningButton = () => { - const { isDeployable, handleStart, buttonText } = useServiceDeployment(); - - return ( - - ); }; -export const createSafeIfNeeded = async ({ +const createSafeIfNeeded = async ({ masterSafes, masterSafesOwners, masterEoa, @@ -427,3 +413,21 @@ export const createSafeIfNeeded = async ({ [...otherChainOwners][0], ); }; + +/** + * Agent Not Running Button + */ +export const AgentNotRunningButton = () => { + const { isDeployable, handleStart, buttonText } = useServiceDeployment(); + + return ( + + ); +};