From 72ee83819bcb853280fc20019d2ecea28d770614 Mon Sep 17 00:00:00 2001 From: Cosmhyccc Date: Mon, 11 May 2026 20:53:37 -0400 Subject: [PATCH] Fix sparse proposal vote counts --- components/Proposals.vue | 18 ++++++++++++++---- pages/proposals/_id/index.vue | 14 +++++++++++++- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/components/Proposals.vue b/components/Proposals.vue index 730c64d..0962635 100644 --- a/components/Proposals.vue +++ b/components/Proposals.vue @@ -10,10 +10,10 @@ --> - - - - + + + + @@ -94,6 +94,16 @@ export default { } }, methods: { + hasVoteCounts (proposal) { + return proposal && Array.isArray(proposal.vote_counts) && proposal.vote_counts.length > 0 + }, + proposalVoteWeight (proposal, voteType) { + if (!this.hasVoteCounts(proposal)) { + return 0 + } + const voteCount = proposal.vote_counts.find(voteCount => parseInt(voteCount.key) === voteType) + return voteCount ? Number(voteCount.value) || 0 : 0 + }, print (x) { console.log(x) } diff --git a/pages/proposals/_id/index.vue b/pages/proposals/_id/index.vue index 73ecbd4..2cbddec 100644 --- a/pages/proposals/_id/index.vue +++ b/pages/proposals/_id/index.vue @@ -427,7 +427,19 @@ export default { } }, votePercentage (vote, proposal) { - return (vote.weight / (proposal.vote_counts[0].value + proposal.vote_counts[1].value + proposal.vote_counts[2].value) * 100).toFixed(2) + const totalWeight = this.proposalVoteWeight(proposal) + if (totalWeight === 0) { + return '0.00' + } + return (vote.weight / totalWeight * 100).toFixed(2) + }, + proposalVoteWeight (proposal) { + if (!proposal || !Array.isArray(proposal.vote_counts)) { + return 0 + } + return proposal.vote_counts.reduce((total, voteCount) => { + return total + (Number(voteCount.value) || 0) + }, 0) }, async assignToNextCycle () { if (this.$dao.proposalConfig && this.proposal) {