Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fedekunze/1749-tally #1765

Merged
merged 17 commits into from
Dec 20, 2018
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.DS_Store
app/dist
builds/*
task/builds/*
coverage
node_modules
npm-debug.log
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- [\#1676](https://github.com/cosmos/voyager/issues/1676) Reduced minWidth css for ModalVote to have 2 buttons per line @sabau
- [\#1676](https://github.com/cosmos/voyager/issues/1670) Update balance in header after voting and depositing @faboweb
- [\#1572](https://github.com/cosmos/voyager/issues/1572) Fixed scroll bug when switching between tabs @jbibla
- [\#1749](https://github.com/cosmos/voyager/issues/1749) Fixed proposal tally update after voting @fedekunze
- [\#1765](https://github.com/cosmos/voyager/pull/1765) Fixed proposal deposit update after submitting a deposit @fedekunze

## [0.10.7] - 2018-10-10

Expand Down
25 changes: 17 additions & 8 deletions app/src/renderer/components/governance/LiProposal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,15 @@
</div>
</td>
<td>{{ `#` + proposal.proposal_id }}</td>
<td class="li-proposal__value yes">{{ proposal.tally_result.yes }}</td>
<td class="li-proposal__value no">{{ proposal.tally_result.no }}</td>
<td class="li-proposal__value no_with_veto">
{{ proposal.tally_result.no_with_veto }}
</td>
<td class="li-proposal__value abstain">
{{ proposal.tally_result.abstain }}
</td>
<td class="li-proposal__value yes">{{ tally.yes }}</td>
<td class="li-proposal__value no">{{ tally.no }}</td>
<td class="li-proposal__value no_with_veto">{{ tally.no_with_veto }}</td>
<td class="li-proposal__value abstain">{{ tally.abstain }}</td>
</tr>
</template>

<script>
import { mapGetters } from "vuex"
export default {
name: `li-proposal`,
props: {
Expand All @@ -49,6 +46,18 @@ export default {
}
},
computed: {
...mapGetters([`proposals`]),
tally() {
let proposalTally
proposalTally = this.proposals.tallies[this.proposal.proposal_id]
proposalTally.yes = Math.round(parseFloat(proposalTally.yes))
proposalTally.no = Math.round(parseFloat(proposalTally.no))
proposalTally.no_with_veto = Math.round(
parseFloat(proposalTally.no_with_veto)
)
proposalTally.abstain = Math.round(parseFloat(proposalTally.abstain))
return proposalTally
},
status() {
if (this.proposal.proposal_status === `Passed`) {
return {
Expand Down
61 changes: 24 additions & 37 deletions app/src/renderer/components/governance/PageProposal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,19 @@
<div class="page-profile__header__data__break" />
<dl class="colored_dl">
<dt>Yes</dt>
<dd>{{ proposal.tally_result.yes }} / {{ yesPercentage }}</dd>
<dd>{{ tally.yes }} / {{ yesPercentage }}</dd>
</dl>
<dl class="colored_dl">
<dt>No</dt>
<dd>{{ proposal.tally_result.no }} / {{ noPercentage }}</dd>
<dd>{{ tally.no }} / {{ noPercentage }}</dd>
</dl>
<dl class="colored_dl">
<dt>No with Veto</dt>
<dd>
{{ proposal.tally_result.no_with_veto }} /
{{ noWithVetoPercentage }}
</dd>
<dd>{{ tally.no_with_veto }} / {{ noWithVetoPercentage }}</dd>
</dl>
<dl class="colored_dl">
<dt>Abstain</dt>
<dd>
{{ proposal.tally_result.abstain }} / {{ abstainPercentage }}
</dd>
<dd>{{ tally.abstain }} / {{ abstainPercentage }}</dd>
</dl>
</div>
</div>
Expand Down Expand Up @@ -170,22 +165,7 @@ export default {
`votes`
]),
proposal() {
let proposal = this.proposals.proposals[this.proposalId]
if (proposal) {
proposal.tally_result.yes = Math.round(
parseFloat(proposal.tally_result.yes)
)
proposal.tally_result.no = Math.round(
parseFloat(proposal.tally_result.no)
)
proposal.tally_result.no_with_veto = Math.round(
parseFloat(proposal.tally_result.no_with_veto)
)
proposal.tally_result.abstain = Math.round(
parseFloat(proposal.tally_result.abstain)
)
}
return proposal
return this.proposals.proposals[this.proposalId]
},
proposalType() {
return this.proposal.proposal_type.toLowerCase()
Expand All @@ -201,27 +181,33 @@ export default {
},
totalVotes() {
return (
Number(this.proposal.tally_result.yes) +
Number(this.proposal.tally_result.no) +
Number(this.proposal.tally_result.no_with_veto) +
Number(this.proposal.tally_result.abstain)
this.tally.yes +
this.tally.no +
this.tally.no_with_veto +
this.tally.abstain
)
},
yesPercentage() {
return num.percentInt(this.proposal.tally_result.yes / this.totalVotes)
return num.percentInt(this.tally.yes / this.totalVotes)
},
noPercentage() {
return num.percentInt(this.proposal.tally_result.no / this.totalVotes)
return num.percentInt(this.tally.no / this.totalVotes)
},
noWithVetoPercentage() {
return num.percentInt(
this.proposal.tally_result.no_with_veto / this.totalVotes
)
return num.percentInt(this.tally.no_with_veto / this.totalVotes)
},
abstainPercentage() {
return num.percentInt(
this.proposal.tally_result.abstain / this.totalVotes
return num.percentInt(this.tally.abstain / this.totalVotes)
},
tally() {
let proposalTally = this.proposals.tallies[this.proposalId]
proposalTally.yes = Math.round(parseFloat(proposalTally.yes))
proposalTally.no = Math.round(parseFloat(proposalTally.no))
proposalTally.no_with_veto = Math.round(
parseFloat(proposalTally.no_with_veto)
)
proposalTally.abstain = Math.round(parseFloat(proposalTally.abstain))
return proposalTally
},
status() {
if (this.proposal.proposal_status === `Passed`)
Expand Down Expand Up @@ -253,7 +239,6 @@ export default {
methods: {
async onVote() {
this.showModalVote = true

// The error is already handled with notifyError in votes.js
await this.$store.dispatch(`getProposalVotes`, this.proposalId)
this.lastVote =
Expand All @@ -272,6 +257,7 @@ export default {
password
})

this.proposal = this.proposals.proposals[this.proposalId]
// TODO: get min deposit denom from gov params
this.$store.commit(`notify`, {
title: `Successful deposit!`,
Expand Down Expand Up @@ -302,6 +288,7 @@ export default {
this.proposalId
}`
})
this.proposal = this.proposals.proposals[this.proposalId]
} catch ({ message }) {
this.$store.commit(`notifyError`, {
title: `Error while voting on proposal #${this.proposalId}`,
Expand Down
14 changes: 1 addition & 13 deletions app/src/renderer/components/governance/TableProposals.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,10 @@ export default {
somethingToSearch() {
return Object.keys(this.proposals).length > 0
},
parsedProposals() {
let copiedProposals = JSON.parse(JSON.stringify(this.proposals))
return Object.values(copiedProposals).map(p => {
p.tally_result.yes = Math.round(parseFloat(p.tally_result.yes))
p.tally_result.no = Math.round(parseFloat(p.tally_result.no))
p.tally_result.no_with_veto = Math.round(
parseFloat(p.tally_result.no_with_veto)
)
p.tally_result.abstain = Math.round(parseFloat(p.tally_result.abstain))
return p
})
},
filteredProposals() {
let query = this.filters.proposals.search.query || ``
let proposals = orderBy(
this.parsedProposals,
this.proposals,
[this.sort.property],
[this.sort.order]
)
Expand Down
2 changes: 1 addition & 1 deletion app/src/renderer/connectors/lcdClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const Client = (axios, localLcdURL, remoteLcdURL) => {
true
)()
},
queryProposalTally: function(proposalId) {
getProposalTally: function(proposalId) {
return req(`GET`, `/gov/proposals/${proposalId}/tally`, true)()
},
getGovDepositParameters: req(`GET`, `/gov/parameters/deposit`, true),
Expand Down
42 changes: 34 additions & 8 deletions app/src/renderer/connectors/lcdClientMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,34 @@ let state = {
}
}
},
tallies: {
"1": {
yes: `500`,
no: `25`,
no_with_veto: `10`,
abstain: `56`
},
"2": {
yes: `0`,
no: `0`,
no_with_veto: `0`,
abstain: `0`
},
"5": {
yes: `0`,
no: `0`,
no_with_veto: `0`,
abstain: `0`
},
"6": {
yes: `10`,
no: `30`,
no_with_veto: `100`,
abstain: `20`
}
},
votes: {
1: [
"1": [
{
proposal_id: `1`,
voter: validators[0],
Expand All @@ -463,8 +489,8 @@ let state = {
option: `NoWithVeto`
}
],
2: [],
5: [
"2": [],
"5": [
{
proposal_id: `5`,
voter: validators[0],
Expand All @@ -476,7 +502,7 @@ let state = {
option: `Abstain`
}
],
6: [
"6": [
{
proposal_id: `6`,
voter: validators[0],
Expand All @@ -490,7 +516,7 @@ let state = {
]
},
deposits: {
1: [
"1": [
{
proposal_id: `1`,
depositor: validators[0],
Expand All @@ -516,7 +542,7 @@ let state = {
]
}
],
2: [
"2": [
{
proposal_id: `2`,
depositor: validators[0],
Expand All @@ -528,7 +554,7 @@ let state = {
]
}
],
5: [
"5": [
{
proposal_id: `5`,
depositor: validators[0],
Expand All @@ -550,7 +576,7 @@ let state = {
]
}
],
6: [
"6": [
{
proposal_id: `6`,
depositor: validators[0],
Expand Down
3 changes: 2 additions & 1 deletion app/src/renderer/vuex/modules/governance/deposits.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as Sentry from "@sentry/browser"
import Vue from "vue"

export default ({ node }) => {
const state = {
Expand All @@ -10,7 +11,7 @@ export default ({ node }) => {

const mutations = {
setProposalDeposits(state, proposalId, deposits) {
state.deposits[proposalId] = deposits
Vue.set(state.deposits, proposalId, deposits)
}
}
let actions = {
Expand Down
Loading