Skip to content

Commit

Permalink
Merge pull request #28 from valory-xyz/misc-fixes-before-packaging
Browse files Browse the repository at this point in the history
Misc fixes before packaging
  • Loading branch information
truemiller authored Feb 29, 2024
2 parents d0eceb2 + feb266e commit 92ff5db
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 11,275 deletions.
90 changes: 49 additions & 41 deletions frontend/components/Spawn/SpawnStakingCheck.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,47 +54,51 @@ export const SpawnStakingCheck = ({
message.error('Service creation already in progress');
return;
}

setIsCreating(true);
return createService({
...serviceTemplate,
configuration: {
...serviceTemplate.configuration,
rpc,
use_staking: isStaking,
},
})
.then((service: Service) => {
setService(service);

// Set agent funding requirements
if (service.chain_data?.instances) {
setAgentFundRequirements(
service.chain_data.instances.reduce(
(acc: FundsRequirementMap, address: Address) => ({
...acc,
[address]:
serviceTemplate.configuration.fund_requirements.agent,
}),
{},
),
);
}

// Set multisig funding requirements from multisig/safe
if (service.chain_data?.multisig) {
const { multisig } = service.chain_data;
const { safe } = serviceTemplate.configuration.fund_requirements;
setAgentFundRequirements((prev: FundsRequirementMap) => ({
...prev,
[multisig]: safe,
}));
}
return Promise.resolve(service);
})
.catch(() => {
return Promise.reject();
})
.finally(() => setIsCreating(false));

let service: Service;
try {
service = await createService({
...serviceTemplate,
configuration: {
...serviceTemplate.configuration,
rpc,
use_staking: isStaking,
},
});
} catch (e) {
message.error('Failed to create service');
setIsCreating(false);
return;
}

setService(service);

// Set agent funding requirements
if (service.chain_data?.instances) {
setAgentFundRequirements(
service.chain_data.instances.reduce(
(acc: FundsRequirementMap, address: Address) => ({
...acc,
[address]: serviceTemplate.configuration.fund_requirements.agent,
}),
{},
),
);
}

// Set multisig funding requirements from multisig/safe
if (service.chain_data?.multisig) {
const { multisig } = service.chain_data;
const { safe } = serviceTemplate.configuration.fund_requirements;
setAgentFundRequirements((prev: FundsRequirementMap) => ({
...prev,
[multisig]: safe,
}));
}

return service;
},
[
createService,
Expand Down Expand Up @@ -145,7 +149,9 @@ export const SpawnStakingCheck = ({
message.error(`${userPublicKey} requires more OLAS to stake`);
return setButtonClicked(undefined);
}

const service: Service | undefined = await create(true);

if (!service) {
message.error('Failed to create service');
} else {
Expand All @@ -157,14 +163,16 @@ export const SpawnStakingCheck = ({
setIsStaking(true);
setSpawnScreenState(nextPage);
}
setButtonClicked(undefined);
}

setButtonClicked(undefined);
};

const handleNo = async () => {
setButtonClicked(ButtonOptions.NO);

const service: Service | undefined = await create(false);

if (!service) {
message.error('Failed to create service');
} else {
Expand Down
11 changes: 11 additions & 0 deletions frontend/components/YourAgents/ServiceCard/ServiceCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@ export const ServiceCard = ({ service }: ServiceCardProps) => {
}, [deleteServiceState, deleteServices, isDeleting, service.hash]);

const buttons: JSX.Element = useMemo(() => {
if (serviceStatus === DeploymentStatus.CREATED)
return (
<Button
danger
onClick={handleDelete}
disabled={isDeleting}
loading={isDeleting}
>
Delete this agent
</Button>
);
if (serviceStatus === DeploymentStatus.DEPLOYED) {
return (
<Button
Expand Down
Loading

0 comments on commit 92ff5db

Please sign in to comment.