Poll for project details for auction details

This commit is contained in:
IshaVenikar 2024-10-29 18:56:45 +05:30
parent fa1ba6150a
commit 97354f35a1

View File

@ -46,27 +46,27 @@ export const AuctionCard = ({ project }: { project: Project }) => {
const result = await client.getAuctionData(project.auctionId);
setAuctionStatus(result.status);
setAuctionDetails(result);
setDeployers(project.deployers);
setFundsStatus(project.fundsReleased);
}, []);
}, [project.auctionId, project.deployers, project.fundsReleased]);
const fetchUpdatedProject = useCallback(async () => {
const updatedProject = await client.getProject(project.id);
setDeployers(updatedProject.project!.deployers!);
setFundsStatus(updatedProject.project!.fundsReleased!);
}, [project.id]);
const fetchData = useCallback(async () => {
await Promise.all([checkAuctionStatus(), fetchUpdatedProject()]);
}, [checkAuctionStatus, fetchUpdatedProject]);
useEffect(() => {
if (auctionStatus !== 'completed') {
checkAuctionStatus();
const intervalId = setInterval(checkAuctionStatus, WAIT_DURATION);
return () => clearInterval(intervalId);
}
fetchData();
if (auctionStatus === 'completed') {
const fetchUpdatedProject = async () => {
// 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);
setDeployers(updatedProject.project?.deployers || []);
};
fetchUpdatedProject();
}
}, [auctionStatus, client]);
const timerId = setInterval(() => {
fetchData();
}, WAIT_DURATION);
return () => clearInterval(timerId);
}, [fetchData]);
const renderAuctionStatus = useCallback(
() => (