diff --git a/src/components/DonarDashboard/RoundCollectedInfo.tsx b/src/components/DonarDashboard/RoundCollectedInfo.tsx index 060c1135..c14b3ae9 100644 --- a/src/components/DonarDashboard/RoundCollectedInfo.tsx +++ b/src/components/DonarDashboard/RoundCollectedInfo.tsx @@ -24,7 +24,7 @@ export const RoundCollectedInfo: FC = ({ const updatePOLCap = async () => { if (info) { const { capAmount, totalDonationAmountInRound }: any = - await calculateCapAmount(info, Number(projectId)); + await calculateCapAmount(info, Number(projectId), true); setMaxPOLCap(capAmount); setAmountDonatedInRound(totalDonationAmountInRound); } @@ -38,7 +38,8 @@ export const RoundCollectedInfo: FC = ({ const endData = info.__typename === 'EarlyAccessRound' ? info.endDate : info.endDate; - const percentage = ((amountDonatedInRound / maxPOLCap) * 100).toFixed(2); + const percentage = (amountDonatedInRound / maxPOLCap) * 100; + const truncatedProgress = Math.floor(percentage * 100) / 100; const title = info.__typename === 'EarlyAccessRound' ? `Early Access - Round ${info.roundNumber}` @@ -80,7 +81,7 @@ export const RoundCollectedInfo: FC = ({
- {percentage}% Collected + {truncatedProgress}% Collected
@@ -94,7 +95,7 @@ export const RoundCollectedInfo: FC = ({
diff --git a/src/components/ProjectCard/ProjectHoverCard.tsx b/src/components/ProjectCard/ProjectHoverCard.tsx index 79acedd5..3e6b4a62 100644 --- a/src/components/ProjectCard/ProjectHoverCard.tsx +++ b/src/components/ProjectCard/ProjectHoverCard.tsx @@ -80,9 +80,10 @@ export const ProjectHoverCard: FC = ({ let tempprogress = 0; if (maxPOLCap > 0) { - tempprogress = - Math.round((amountDonatedInRound / capAmount) * 100 * 100) / 100; - setProgress(tempprogress); + tempprogress = tempprogress = + (totalDonationAmountInRound / maxPOLCap) * 100; + const truncatedProgress = Math.floor(tempprogress * 100) / 100; + setProgress(truncatedProgress); } } }; diff --git a/src/components/ProjectDetail/DonateSection.tsx b/src/components/ProjectDetail/DonateSection.tsx index c67a635c..ec8e6e4f 100644 --- a/src/components/ProjectDetail/DonateSection.tsx +++ b/src/components/ProjectDetail/DonateSection.tsx @@ -37,14 +37,12 @@ const DonateSection = () => { await calculateCapAmount(activeRoundDetails, Number(projectData.id)); setMaxPOLCap(capAmount); - console.log(totalDonationAmountInRound, '----------------------'); let tempprogress = 0; if (maxPOLCap > 0) { - tempprogress = - Math.round((totalDonationAmountInRound / capAmount) * 100 * 100) / - 100; - setProgress(tempprogress); + tempprogress = (totalDonationAmountInRound / maxPOLCap) * 100; + const truncatedProgress = Math.floor(tempprogress * 100) / 100; + setProgress(truncatedProgress); } } }; diff --git a/src/components/ProjectDetail/ProjectDetail.tsx b/src/components/ProjectDetail/ProjectDetail.tsx index ffb07fb0..c1e80da5 100644 --- a/src/components/ProjectDetail/ProjectDetail.tsx +++ b/src/components/ProjectDetail/ProjectDetail.tsx @@ -40,10 +40,10 @@ const ProjectDetail = () => { let tempprogress = 0; if (maxPOLCap > 0) { - tempprogress = - Math.round((totalDonationAmountInRound / capAmount) * 100 * 100) / - 100; - setProgress(tempprogress); + tempprogress = tempprogress = + (totalDonationAmountInRound / maxPOLCap) * 100; + const truncatedProgress = Math.floor(tempprogress * 100) / 100; + setProgress(truncatedProgress); } } }; diff --git a/src/helpers/round.ts b/src/helpers/round.ts index 07e4f835..f3cee01b 100644 --- a/src/helpers/round.ts +++ b/src/helpers/round.ts @@ -3,6 +3,7 @@ import { fetchProjectRoundRecords } from '@/services/round.services'; export const calculateCapAmount = async ( activeRoundDetails: any, projectId: number, + includeCumulativeAmount: boolean = false, ) => { if (!activeRoundDetails) return null; @@ -21,11 +22,15 @@ export const calculateCapAmount = async ( if (roundRecords?.length > 0) { const cumulativeAmount = roundRecords[0].cumulativePastRoundsDonationAmounts; - const totalDonationAmountInRound = roundRecords[0].totalDonationAmount; - const capAmount = cumulativeAmount - ? maxPOLAmount - cumulativeAmount - : maxPOLAmount; + const totalDonationAmountInRound = includeCumulativeAmount + ? roundRecords[0].totalDonationAmount + : roundRecords[0].totalDonationAmount + cumulativeAmount; + + const capAmount = + cumulativeAmount && includeCumulativeAmount + ? maxPOLAmount - cumulativeAmount + : maxPOLAmount; return { capAmount, totalDonationAmountInRound }; }