Skip to content

Commit

Permalink
Merge pull request #183 from GeneralMagicio/fix-project-maxed-percentage
Browse files Browse the repository at this point in the history
fixed percentage decimal and prgress bar
  • Loading branch information
lovelgeorge99 authored Oct 8, 2024
2 parents 9ae886e + 0691b61 commit a9b25ba
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
9 changes: 5 additions & 4 deletions src/components/DonarDashboard/RoundCollectedInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const RoundCollectedInfo: FC<IRoundCollectedInfoProps> = ({
const updatePOLCap = async () => {
if (info) {
const { capAmount, totalDonationAmountInRound }: any =
await calculateCapAmount(info, Number(projectId));
await calculateCapAmount(info, Number(projectId), true);
setMaxPOLCap(capAmount);
setAmountDonatedInRound(totalDonationAmountInRound);
}
Expand All @@ -38,7 +38,8 @@ export const RoundCollectedInfo: FC<IRoundCollectedInfoProps> = ({
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}`
Expand Down Expand Up @@ -80,7 +81,7 @@ export const RoundCollectedInfo: FC<IRoundCollectedInfoProps> = ({
<div className='flex flex-col justify-between gap-2 font-redHatText w-full md:w-fit '>
<div className='flex gap-2 text-xs font-medium items-center justify-between md:w-[400px]'>
<div className='bg-white p-[2px] rounded-md flex gap-1'>
{percentage}% Collected
{truncatedProgress}% Collected
</div>

<div className='flex gap-2 items-center'>
Expand All @@ -94,7 +95,7 @@ export const RoundCollectedInfo: FC<IRoundCollectedInfoProps> = ({
<div className='h-2 bg-gray-200 rounded-lg overflow-hidden'>
<div
className={`h-full ${currentRound ? 'bg-giv-500' : 'bg-gray-500'}`}
style={{ width: `${percentage}%` }}
style={{ width: `${truncatedProgress}%` }}
></div>
</div>

Expand Down
7 changes: 4 additions & 3 deletions src/components/ProjectCard/ProjectHoverCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ export const ProjectHoverCard: FC<ProjectCardProps> = ({

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);
}
}
};
Expand Down
8 changes: 3 additions & 5 deletions src/components/ProjectDetail/DonateSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
};
Expand Down
8 changes: 4 additions & 4 deletions src/components/ProjectDetail/ProjectDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
};
Expand Down
13 changes: 9 additions & 4 deletions src/helpers/round.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 };
}
Expand Down

0 comments on commit a9b25ba

Please sign in to comment.