Integrate SP auctions for app deployment #2

Merged
nabarun merged 42 commits from ng-integrate-auction into main 2024-10-18 12:37:01 +00:00
2 changed files with 66 additions and 48 deletions
Showing only changes of commit e10c8f4818 - Show all commits

View File

@ -1080,6 +1080,7 @@ export class Service {
if (deployment.isCurrent) { if (deployment.isCurrent) {
const currentDeploymentURL = `https://${(deployment.project.name).toLowerCase()}.${deployment.baseDomain}`; const currentDeploymentURL = `https://${(deployment.project.name).toLowerCase()}.${deployment.baseDomain}`;
// TODO: Store the latest DNS deployment record
const deploymentRecords = const deploymentRecords =
await this.laconicRegistry.getDeploymentRecordsByFilter({ await this.laconicRegistry.getDeploymentRecordsByFilter({
application: deployment.applicationRecordId, application: deployment.applicationRecordId,
@ -1094,8 +1095,12 @@ export class Service {
return false; return false;
} }
// Multiple records are fetched, take the latest record
const latestRecord = deploymentRecords
.sort((a, b) => new Date(b.createTime).getTime() - new Date(a.createTime).getTime())[0];
await this.laconicRegistry.createApplicationDeploymentRemovalRequest({ await this.laconicRegistry.createApplicationDeploymentRemovalRequest({
deploymentId: deploymentRecords[deploymentRecords.length - 1].id, deploymentId: latestRecord.id,
deployerLrn: deployment.deployerLrn deployerLrn: deployment.deployerLrn
}); });
} }

View File

@ -12,7 +12,7 @@ import { CheckRoundFilledIcon, LoadingIcon } from 'components/shared/CustomIcon'
import { useGQLClient } from 'context/GQLClientContext'; import { useGQLClient } from 'context/GQLClientContext';
import { Button, Heading, Tag } from 'components/shared'; import { Button, Heading, Tag } from 'components/shared';
const CHECK_AUCTION_STATUS_INTERVAL = 2000; const WAIT_DURATION = 5000;
export const AuctionCard = ({ project }: { project: Project }) => { export const AuctionCard = ({ project }: { project: Project }) => {
const [auctionStatus, setAuctionStatus] = useState<string>(''); const [auctionStatus, setAuctionStatus] = useState<string>('');
@ -28,21 +28,36 @@ export const AuctionCard = ({ project }: { project: Project }) => {
const result = await client.getAuctionData(project.auctionId); const result = await client.getAuctionData(project.auctionId);
setAuctionStatus(result.status); setAuctionStatus(result.status);
setAuctionDetails(result); setAuctionDetails(result);
setDeployerLrns(project.deployerLrns); }, [client, project.auctionId]);
}, [client, project.auctionId, project.deployerLrns]);
useEffect(() => { useEffect(() => {
const fetchUpdatedProject = async () => {
if (auctionStatus === 'completed') {
// Wait for 5 secs since the project is not immediately updated with deployer LRNs
await new Promise((resolve) => setTimeout(resolve, WAIT_DURATION));
const updatedProject = await client.getProject(project.id);
setDeployerLrns(updatedProject.project!.deployerLrns || []);
}
};
if (auctionStatus !== 'completed') { if (auctionStatus !== 'completed') {
const intervalId = setInterval(checkAuctionStatus, CHECK_AUCTION_STATUS_INTERVAL); const intervalId = setInterval(checkAuctionStatus, WAIT_DURATION);
checkAuctionStatus(); checkAuctionStatus();
return () => clearInterval(intervalId); return () => clearInterval(intervalId);
} else {
fetchUpdatedProject();
} }
}, [auctionStatus, checkAuctionStatus]); }, [auctionStatus, checkAuctionStatus, client]);
const renderAuctionStatus = useCallback( const renderAuctionStatus = useCallback(
() => ( () => (
<Tag leftIcon={getIconByAuctionStatus(auctionStatus)} size="xs" type={auctionStatus === 'completed' ? 'positive' : 'emphasized'}> <Tag
leftIcon={getIconByAuctionStatus(auctionStatus)}
size="xs"
type={auctionStatus === 'completed' ? 'positive' : 'emphasized'}
>
{auctionStatus.toUpperCase()} {auctionStatus.toUpperCase()}
</Tag> </Tag>
), ),
@ -74,7 +89,7 @@ export const AuctionCard = ({ project }: { project: Project }) => {
</span> </span>
</div> </div>
{project.deployerLrns && ( {deployerLrns.length > 0 && (
<div className="mt-3"> <div className="mt-3">
<span className="text-elements-high-em text-sm font-medium tracking-tight">Deployer LRNs</span> <span className="text-elements-high-em text-sm font-medium tracking-tight">Deployer LRNs</span>
{deployerLrns.map((lrn, index) => ( {deployerLrns.map((lrn, index) => (
@ -89,9 +104,7 @@ export const AuctionCard = ({ project }: { project: Project }) => {
<Dialog open={openDialog} onClose={handleCloseDialog} fullWidth maxWidth="md"> <Dialog open={openDialog} onClose={handleCloseDialog} fullWidth maxWidth="md">
<DialogTitle>Auction Details</DialogTitle> <DialogTitle>Auction Details</DialogTitle>
<DialogContent> <DialogContent>
{auctionDetails && ( {auctionDetails && <pre>{JSON.stringify(auctionDetails, null, 2)}</pre>}
<pre>{JSON.stringify(auctionDetails, null, 2)}</pre>
)}
</DialogContent> </DialogContent>
<DialogActions> <DialogActions>
<Button onClick={handleCloseDialog}>Close</Button> <Button onClick={handleCloseDialog}>Close</Button>