fix for the percentage calculations
Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
This commit is contained in:
parent
675c0904af
commit
a79a877838
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "ghost-dao-interface",
|
||||
"private": true,
|
||||
"version": "0.5.19",
|
||||
"version": "0.5.20",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@ -116,10 +116,22 @@ const ProposalDetails = ({ chainId, address, connect, config }) => {
|
||||
return new DecimalBigNumber(value, 0);
|
||||
}, [totalVotes, totalSupply]);
|
||||
|
||||
const forPercentage = useMemo(() => {
|
||||
if (totalSupply._value === 0n) return new DecimalBigNumber(0n, 2);
|
||||
const value = (forVotes?._value ?? 0n) * 10000n / (totalSupply?._value ?? 1n);
|
||||
return new DecimalBigNumber(value, 2);
|
||||
}, [forVotes, totalSupply]);
|
||||
|
||||
const againstPercentage= useMemo(() => {
|
||||
if (totalSupply._value === 0n) return new DecimalBigNumber(0n, 2);
|
||||
const value = (againstVotes?._value ?? 0n) * 10000n / (totalSupply?._value ?? 1n);
|
||||
return new DecimalBigNumber(value, 2);
|
||||
}, [againstVotes, totalSupply]);
|
||||
|
||||
const voteWeightPercentage = useMemo(() => {
|
||||
if (totalSupply._value === 0n) return 0;
|
||||
const value = (pastVotes?._value ?? 0n) * 100n / (totalSupply?._value ?? 1n);
|
||||
return new DecimalBigNumber(value, 0);
|
||||
if (totalSupply._value === 0n) return new DecimalBigNumber(0n, 2);
|
||||
const value = (pastVotes?._value ?? 0n) * 10000n / (totalSupply?._value ?? 1n);
|
||||
return new DecimalBigNumber(value, 2);
|
||||
}, [pastVotes, totalSupply]);
|
||||
|
||||
const voteValue = useMemo(() => {
|
||||
@ -131,14 +143,15 @@ const ProposalDetails = ({ chainId, address, connect, config }) => {
|
||||
|
||||
const voteTarget = useMemo(() => {
|
||||
const first = (5n * againstVotes._value + forVotes._value);
|
||||
const second = BigInt(Math.sqrt(Number(totalVotes._value)));
|
||||
const second = BigInt(Math.floor(Math.sqrt(Number(totalVotes._value))));
|
||||
const bias = 3n * first + second;
|
||||
const denominator = totalVotes._value + bias;
|
||||
|
||||
if (denominator === 0n) {
|
||||
return 80;
|
||||
}
|
||||
return Number(totalVotes?._value / denominator) + 1;
|
||||
|
||||
return Number(totalVotes?._value * 100n / denominator);
|
||||
}, [againstVotes, forVotes, totalVotes]);
|
||||
|
||||
const nativeCurrency = useMemo(() => {
|
||||
@ -161,7 +174,7 @@ const ProposalDetails = ({ chainId, address, connect, config }) => {
|
||||
const result = await castVote(chainId, address, proposalId, support);
|
||||
|
||||
if (result) {
|
||||
const toStore = JSON.stringify(proposalId.toString()));
|
||||
const toStore = JSON.stringify(proposalId.toString());
|
||||
localStorage.setItem(VOTED_PROPOSALS_PREFIX, toStore);
|
||||
}
|
||||
|
||||
@ -227,10 +240,10 @@ const ProposalDetails = ({ chainId, address, connect, config }) => {
|
||||
<Box display="flex" flexDirection="column">
|
||||
<Box display="flex" justifyContent="space-between">
|
||||
<Typography sx={{ textShadow: "0 0 black", fontWeight: 600 }} variant="body1" color={theme.colors.feedback.success}>
|
||||
For: {formatNumber(forVotes.toString(), 2)} ({formatNumber(forVotes * HUNDRED / proposalQuorum, 1)}%)
|
||||
For: {formatNumber(forVotes.toString(), 2)} ({formatNumber(forPercentage?.toString(), 1)}%)
|
||||
</Typography>
|
||||
<Typography sx={{ textShadow: "0 0 black", fontWeight: 600 }} variant="body1" color={theme.colors.feedback.error}>
|
||||
Against: {formatNumber(againstVotes.toString(), 2)} ({formatNumber(againstVotes * HUNDRED / proposalQuorum, 1)}%)
|
||||
Against: {formatNumber(againstVotes.toString(), 2)} ({formatNumber(againstPercentage?.toString(), 1)}%)
|
||||
</Typography>
|
||||
</Box>
|
||||
<LinearProgressBar
|
||||
|
||||
@ -202,13 +202,16 @@ const ProposalRow = ({ proposal, blockNumber, openProposal, chainId }) => {
|
||||
const forVotes = proposal?.votes?.at(1)?._value ?? 0n;
|
||||
const totalVotes = againstVotes + forVotes;
|
||||
|
||||
const bias = 3n * (5n * againstVotes + forVotes) + BigInt(Math.sqrt(Number(totalVotes)));
|
||||
const first = (5n * againstVotes + forVotes);
|
||||
const second = BigInt(Math.floor(Math.sqrt(Number(totalVotes))));
|
||||
const bias = 3n * first + second;
|
||||
const denominator = totalVotes + bias;
|
||||
|
||||
if (denominator === 0n) {
|
||||
return 80;
|
||||
}
|
||||
return Number(totalVotes / denominator);
|
||||
|
||||
return Number(totalVotes * 100n / denominator);
|
||||
}, [proposal]);
|
||||
|
||||
return (
|
||||
|
||||
Loading…
Reference in New Issue
Block a user