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

Misc fixes before packaging #28

Merged
merged 4 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading