Skip to content
This repository was archived by the owner on Mar 16, 2026. It is now read-only.

Commit b2daa49

Browse files
authored
Merge pull request #727 from aibtcdev/floating-point
fix(proposals): Increase precision of voting metrics display
2 parents 2cc7f15 + ed4fcdc commit b2daa49

4 files changed

Lines changed: 13 additions & 13 deletions

File tree

src/components/proposals/ProposalCard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export default function ProposalCard({
101101
const quorumPercentage = safeNumberFromBigInt(proposal.voting_quorum);
102102
const thresholdPercentage = safeNumberFromBigInt(proposal.voting_threshold);
103103

104-
// Calculate if requirements are met
104+
// Calculate if requirements are met (using exact floating point comparison)
105105
const metQuorum = calculations.participationRate >= quorumPercentage;
106106
const metThreshold =
107107
calculations.totalVotes > 0
@@ -125,7 +125,7 @@ export default function ProposalCard({
125125
}
126126

127127
if (isActive) {
128-
return percentage !== undefined ? `${percentage.toFixed(1)}%` : "0%";
128+
return percentage !== undefined ? `${percentage.toFixed(4)}%` : "0%";
129129
}
130130

131131
return met ? "Passed" : "Failed";

src/components/proposals/ProposalHeader.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export function ProposalHeader({ proposal }: ProposalHeaderProps) {
5151
const quorumPercentage = safeNumberFromBigInt(proposal.voting_quorum);
5252
const thresholdPercentage = safeNumberFromBigInt(proposal.voting_threshold);
5353

54-
// Calculate if requirements are met
54+
// Calculate if requirements are met (using exact floating point comparison)
5555
const metQuorum = calculations.participationRate >= quorumPercentage;
5656
const metThreshold =
5757
calculations.totalVotes > 0
@@ -70,7 +70,7 @@ export function ProposalHeader({ proposal }: ProposalHeaderProps) {
7070
// Helper function to get status text
7171
const getStatusText = (isMet: boolean, percentage: number) => {
7272
if (isMet) return "Passed";
73-
return `${percentage.toFixed(1)}%`;
73+
return `${percentage.toFixed(4)}%`;
7474
};
7575

7676
// Get DAO/token image - prioritize token image, fallback to DAO image if available

src/components/proposals/VotesTable.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const VotesTable = ({ proposalId, limit }: VotesTableProps) => {
7272
return (
7373
<Badge variant="secondary" className="text-xs">
7474
{typeof finalScore === "number"
75-
? finalScore.toFixed(1)
75+
? finalScore.toFixed(4)
7676
: String(finalScore)}
7777
</Badge>
7878
);
@@ -82,7 +82,7 @@ const VotesTable = ({ proposalId, limit }: VotesTableProps) => {
8282
return (
8383
<Badge variant="secondary" className="text-xs">
8484
{typeof parsedScore === "number"
85-
? parsedScore.toFixed(1)
85+
? parsedScore.toFixed(4)
8686
: String(parsedScore)}
8787
</Badge>
8888
);

src/components/proposals/VotingProgressChart.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const VotingProgressChart = ({
9090
const quorumPercentage = safeNumberFromBigInt(proposal.voting_quorum);
9191
const thresholdPercentage = safeNumberFromBigInt(proposal.voting_threshold);
9292

93-
// Calculate if requirements are met
93+
// Calculate if requirements are met (using exact floating point comparison)
9494
const metQuorum = calculations.participationRate >= quorumPercentage;
9595
const metThreshold =
9696
calculations.totalVotes > 0
@@ -127,7 +127,7 @@ const VotingProgressChart = ({
127127
return "Met";
128128
}
129129
return percentage !== undefined
130-
? `In Progress (${percentage.toFixed(1)}%)`
130+
? `In Progress (${percentage.toFixed(4)}%)`
131131
: "In Progress";
132132
}
133133

@@ -492,7 +492,7 @@ const VotingProgressChart = ({
492492
decimals={8}
493493
variant="abbreviated"
494494
/>{" "}
495-
({enhancedCalculations.votesForPercent.toFixed(1)}%)
495+
({enhancedCalculations.votesForPercent.toFixed(4)}%)
496496
</span>
497497
) : (
498498
<span className="text-destructive">Failed to fetch</span>
@@ -507,7 +507,7 @@ const VotingProgressChart = ({
507507
decimals={8}
508508
variant="abbreviated"
509509
/>{" "}
510-
({enhancedCalculations.votesAgainstPercent.toFixed(1)}%)
510+
({enhancedCalculations.votesAgainstPercent.toFixed(4)}%)
511511
</span>
512512
) : (
513513
<span className="text-destructive">Failed to fetch</span>
@@ -592,7 +592,7 @@ const VotingProgressChart = ({
592592
<div className="flex items-center gap-1">
593593
<div className="w-2 h-2 bg-green-500 rounded-sm flex-shrink-0" />
594594
<span className="break-words">
595-
Approval: {enhancedCalculations.approvalRate.toFixed(1)}% of votes
595+
Approval: {enhancedCalculations.approvalRate.toFixed(4)}% of votes
596596
cast
597597
</span>
598598
</div>
@@ -658,7 +658,7 @@ const VotingProgressChart = ({
658658
</span>
659659
</div>
660660
<div className="text-xs text-muted-foreground">
661-
{enhancedCalculations.participationRate.toFixed(1)}% of{" "}
661+
{enhancedCalculations.participationRate.toFixed(4)}% of{" "}
662662
{enhancedCalculations.quorumPercentage}% required
663663
</div>
664664
</div>
@@ -715,7 +715,7 @@ const VotingProgressChart = ({
715715
</span>
716716
</div>
717717
<div className="text-xs text-muted-foreground">
718-
{enhancedCalculations.approvalRate.toFixed(1)}% of{" "}
718+
{enhancedCalculations.approvalRate.toFixed(4)}% of{" "}
719719
{enhancedCalculations.thresholdPercentage}% required
720720
</div>
721721
</div>

0 commit comments

Comments
 (0)