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); const result = await client.getAuctionData(project.auctionId);
setAuctionStatus(result.status); setAuctionStatus(result.status);
setAuctionDetails(result); setAuctionDetails(result);
setDeployers(project.deployers); }, [project.auctionId, project.deployers, project.fundsReleased]);
setFundsStatus(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(() => { useEffect(() => {
if (auctionStatus !== 'completed') { fetchData();
checkAuctionStatus();
const intervalId = setInterval(checkAuctionStatus, WAIT_DURATION);
return () => clearInterval(intervalId);
}
if (auctionStatus === 'completed') { const timerId = setInterval(() => {
const fetchUpdatedProject = async () => { fetchData();
// Wait for 5 secs since the project is not immediately updated with deployer LRNs }, WAIT_DURATION);
await new Promise((resolve) => setTimeout(resolve, WAIT_DURATION));
const updatedProject = await client.getProject(project.id); return () => clearInterval(timerId);
setDeployers(updatedProject.project?.deployers || []); }, [fetchData]);
};
fetchUpdatedProject();
}
}, [auctionStatus, client]);
const renderAuctionStatus = useCallback( const renderAuctionStatus = useCallback(
() => ( () => (