diff --git a/package.json b/package.json index 1417095..65e54b9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ghost-dao-interface", "private": true, - "version": "0.5.19", + "version": "0.5.20", "type": "module", "scripts": { "dev": "vite", diff --git a/src/containers/Governance/ProposalDetails.jsx b/src/containers/Governance/ProposalDetails.jsx index 720242f..353e8a9 100644 --- a/src/containers/Governance/ProposalDetails.jsx +++ b/src/containers/Governance/ProposalDetails.jsx @@ -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 }) => { - For: {formatNumber(forVotes.toString(), 2)} ({formatNumber(forVotes * HUNDRED / proposalQuorum, 1)}%) + For: {formatNumber(forVotes.toString(), 2)} ({formatNumber(forPercentage?.toString(), 1)}%) - Against: {formatNumber(againstVotes.toString(), 2)} ({formatNumber(againstVotes * HUNDRED / proposalQuorum, 1)}%) + Against: {formatNumber(againstVotes.toString(), 2)} ({formatNumber(againstPercentage?.toString(), 1)}%) { 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 (