From 97354f35a1f3e0a75d1af11fb03e39bd3d7e3637 Mon Sep 17 00:00:00 2001 From: IshaVenikar Date: Tue, 29 Oct 2024 18:56:45 +0530 Subject: [PATCH] Poll for project details for auction details --- .../project/overview/Activity/AuctionCard.tsx | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/packages/frontend/src/components/projects/project/overview/Activity/AuctionCard.tsx b/packages/frontend/src/components/projects/project/overview/Activity/AuctionCard.tsx index 6927c2d8..5e93a1d4 100644 --- a/packages/frontend/src/components/projects/project/overview/Activity/AuctionCard.tsx +++ b/packages/frontend/src/components/projects/project/overview/Activity/AuctionCard.tsx @@ -42,31 +42,31 @@ export const AuctionCard = ({ project }: { project: Project }) => { ); - const checkAuctionStatus = useCallback(async () => { - const result = await client.getAuctionData(project.auctionId); - setAuctionStatus(result.status); - setAuctionDetails(result); - setDeployers(project.deployers); - setFundsStatus(project.fundsReleased); - }, []); + const checkAuctionStatus = useCallback(async () => { + const result = await client.getAuctionData(project.auctionId); + setAuctionStatus(result.status); + setAuctionDetails(result); + }, [project.auctionId, project.deployers, project.fundsReleased]); - useEffect(() => { - if (auctionStatus !== 'completed') { - checkAuctionStatus(); - const intervalId = setInterval(checkAuctionStatus, WAIT_DURATION); - return () => clearInterval(intervalId); - } + const fetchUpdatedProject = useCallback(async () => { + const updatedProject = await client.getProject(project.id); + setDeployers(updatedProject.project!.deployers!); + setFundsStatus(updatedProject.project!.fundsReleased!); + }, [project.id]); - 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 fetchData = useCallback(async () => { + await Promise.all([checkAuctionStatus(), fetchUpdatedProject()]); + }, [checkAuctionStatus, fetchUpdatedProject]); + + useEffect(() => { + fetchData(); + + const timerId = setInterval(() => { + fetchData(); + }, WAIT_DURATION); + + return () => clearInterval(timerId); + }, [fetchData]); const renderAuctionStatus = useCallback( () => (