Skip to content

Commit

Permalink
refactor: simplify useServiceDeployment and reorganize AgentNotRunnin…
Browse files Browse the repository at this point in the history
…gButton component
  • Loading branch information
mohandast52 committed Dec 19, 2024
1 parent dacfc68 commit 9fa64ca
Showing 1 changed file with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -113,8 +113,9 @@ export function useServiceDeployment() {
isServicesLoading ||
isServiceRunning ||
!isAllStakingContractDetailsRecordLoaded
)
) {
return false;
}

if (isNil(requiredStakedOlas)) return false;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 (
<Button
type="primary"
size="large"
disabled={!isDeployable}
onClick={isDeployable ? handleStart : undefined}
>
{buttonText}
</Button>
);
};

export const createSafeIfNeeded = async ({
const createSafeIfNeeded = async ({
masterSafes,
masterSafesOwners,
masterEoa,
Expand Down Expand Up @@ -427,3 +413,21 @@ export const createSafeIfNeeded = async ({
[...otherChainOwners][0],
);
};

/**
* Agent Not Running Button
*/
export const AgentNotRunningButton = () => {
const { isDeployable, handleStart, buttonText } = useServiceDeployment();

return (
<Button
type="primary"
size="large"
disabled={!isDeployable}
onClick={isDeployable ? handleStart : undefined}
>
{buttonText}
</Button>
);
};

0 comments on commit 9fa64ca

Please sign in to comment.