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

@ -42,31 +42,31 @@ export const AuctionCard = ({ project }: { project: Project }) => {
<LoadingIcon className="animate-spin" /> <LoadingIcon className="animate-spin" />
); );
const checkAuctionStatus = useCallback(async () => { const checkAuctionStatus = useCallback(async () => {
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);
}, []);
useEffect(() => { const fetchUpdatedProject = useCallback(async () => {
if (auctionStatus !== 'completed') { const updatedProject = await client.getProject(project.id);
checkAuctionStatus(); setDeployers(updatedProject.project!.deployers!);
const intervalId = setInterval(checkAuctionStatus, WAIT_DURATION); setFundsStatus(updatedProject.project!.fundsReleased!);
return () => clearInterval(intervalId); }, [project.id]);
}
if (auctionStatus === 'completed') { const fetchData = useCallback(async () => {
const fetchUpdatedProject = async () => { await Promise.all([checkAuctionStatus(), fetchUpdatedProject()]);
// Wait for 5 secs since the project is not immediately updated with deployer LRNs }, [checkAuctionStatus, fetchUpdatedProject]);
await new Promise((resolve) => setTimeout(resolve, WAIT_DURATION));
const updatedProject = await client.getProject(project.id); useEffect(() => {
setDeployers(updatedProject.project?.deployers || []); fetchData();
};
fetchUpdatedProject(); const timerId = setInterval(() => {
} fetchData();
}, [auctionStatus, client]); }, WAIT_DURATION);
return () => clearInterval(timerId);
}, [fetchData]);
const renderAuctionStatus = useCallback( const renderAuctionStatus = useCallback(
() => ( () => (