Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions components/Proposals.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
<font-awesome-icon v-else-if="proposal.vote_counts[1].value < proposal.vote_counts[2].value" :icon="['fa', 'arrow-down']" style="font-size: 20px" class="has-text-danger" />
<font-awesome-icon v-else :icon="['fa', 'minus']" style="font-size: 20px"/>
</span> -->
<span v-if="proposal.vote_counts[1] != undefined && proposal.vote_counts[2] != undefined" class="icon">
<img src="@/assets/img/up.svg" class="" v-if="proposal.vote_counts[1].value > proposal.vote_counts[2].value">
<img src="@/assets/img/down.svg" class="" v-else-if="proposal.vote_counts[1].value < proposal.vote_counts[2].value">
<img src="@/assets/img/empty.svg" class="" v-else>
<span v-if="hasVoteCounts(proposal)" class="icon">
<img v-if="proposalVoteWeight(proposal, 1) > proposalVoteWeight(proposal, 2)" src="@/assets/img/up.svg" class="">
<img v-else-if="proposalVoteWeight(proposal, 1) < proposalVoteWeight(proposal, 2)" src="@/assets/img/down.svg" class="">
<img v-else src="@/assets/img/empty.svg" class="">
</span>
<span v-else class="icon">
<img src="@/assets/img/empty.svg" class="">
Expand Down Expand Up @@ -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)
}
Expand Down
14 changes: 13 additions & 1 deletion pages/proposals/_id/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down