Skip to content

Commit

Permalink
Better comments
Browse files Browse the repository at this point in the history
  • Loading branch information
catalinred committed Sep 12, 2024
1 parent ff58c22 commit 86dc69c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/hooks/useTransactionStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,28 @@ export const fetchSuperminority = async () => {
Number(BigInt(b.activatedStake) - BigInt(a.activatedStake)),
);

// Calculate total stake from sorted validators
const totalStake = sortedValidators.reduce(
(sum, validator) => sum + BigInt(validator.activatedStake),
BigInt(0),
);
const oneThirdStake = totalStake / BigInt(3);

// Calculate one-third of the total stake
const oneThirdStake = totalStake / BigInt(3);
let cumulativeStake = BigInt(0);
let superminorityCount = 0;

// Count superminority
for (const validator of sortedValidators) {
if (cumulativeStake > oneThirdStake) break;
cumulativeStake += BigInt(validator.activatedStake);
superminorityCount++;
}

return superminorityCount; // Return the count of superminority validators
return superminorityCount;
} catch (error) {
console.error("Error fetching superminority:", error);
return null; // Return null in case of error
return null;
}
};

Expand Down

0 comments on commit 86dc69c

Please sign in to comment.