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

jbibla+fedekunze/1501 Modal Vote #1541

Merged
merged 58 commits into from
Nov 12, 2018
Merged
Show file tree
Hide file tree
Changes from 56 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
732f9cc
get started with page validator
jbibla Nov 6, 2018
5f11091
displaying all the data on page proposal
jbibla Nov 6, 2018
2a6b2b9
hooked up page proposal with li proposal and router
jbibla Nov 7, 2018
aa642fb
update snapshotteroos
jbibla Nov 7, 2018
06c4d1d
cha cha changelog
jbibla Nov 7, 2018
1a4b057
thanks, linter.
jbibla Nov 7, 2018
d4f8e47
Merge branch 'develop' into jordan/1502-page-proposal
jbibla Nov 7, 2018
8492b46
update snapshots
jbibla Nov 7, 2018
113db7e
updates snapshot
jbibla Nov 7, 2018
13ae57f
remove unused code
jbibla Nov 8, 2018
fe76e95
ModalVote
Nov 8, 2018
909cdfe
page proposal tests
jbibla Nov 8, 2018
680d366
Merge branch 'develop' into jordan/1502-page-proposal
jbibla Nov 8, 2018
3e4e6aa
ModalVote unit tests
Nov 8, 2018
dba9e91
Merge branch 'develop' into jordan/1502-page-proposal
jbibla Nov 8, 2018
26f26c5
lint
jbibla Nov 8, 2018
74420f3
more unit tests
Nov 8, 2018
95cb959
Changelog
Nov 8, 2018
50a63d0
lint and fix tests
Nov 8, 2018
5728941
Merge branch 'develop' of https://github.com/cosmos/voyager into jbib…
Nov 8, 2018
4930596
fix e2e tests
Nov 8, 2018
40efa8b
test option click
Nov 8, 2018
012ef05
test case for onVote
Nov 8, 2018
5c4f6cb
fixed e2e test 😭
jbibla Nov 8, 2018
22eced1
reduced code duplication and cleaned up tests
jbibla Nov 8, 2018
74443d1
clean up tests
jbibla Nov 8, 2018
34ab41a
update the good ol' snapperoos
jbibla Nov 8, 2018
8ab024e
removed switch, fixed tests, snap snaps
jbibla Nov 8, 2018
c4078f2
disable non selected option buttons
Nov 8, 2018
07ce28d
set empty option if button is clicked twice
Nov 8, 2018
09b1a58
fedes feedback
jbibla Nov 9, 2018
99c5296
added one more test
jbibla Nov 9, 2018
7963057
added else condition
jbibla Nov 9, 2018
945f645
Merge branch 'jordan/1502-page-proposal' of https://github.com/cosmos…
Nov 9, 2018
960313d
Add ModalVote to PageProposal
Nov 9, 2018
5602a4e
Change 'test' for 'describe' and 'it' on unit test
Nov 9, 2018
0956593
Update vuex functions and lcdClients to cast votes
Nov 9, 2018
a353202
merge develop and conflicts
Nov 9, 2018
295c3d5
pending conflict
Nov 9, 2018
f6040dc
update form styles
jbibla Nov 9, 2018
2de76ff
fixed modal vote tests
jbibla Nov 9, 2018
8f6f092
updated votes test
jbibla Nov 9, 2018
71b6f5b
fix lcd client test
jbibla Nov 9, 2018
6095d6f
revert buttons back to normal
jbibla Nov 9, 2018
c849ccc
update snapshot
jbibla Nov 9, 2018
1a948bf
fixed the if else
jbibla Nov 9, 2018
e41007c
skip failing test
jbibla Nov 9, 2018
7b6591e
remove da lint
jbibla Nov 9, 2018
eeaede7
Fix broken unit tests in PageProposal.spec.
Nov 9, 2018
a89bb6f
increase tally and cleanup
Nov 10, 2018
08b547b
test mocked submitVote
Nov 10, 2018
8ea9425
delete unused data and cleanup
Nov 10, 2018
0459091
fix some tests
Nov 10, 2018
4aa3499
tests and snapshots
Nov 10, 2018
f82c97a
fix odd failing test
Nov 12, 2018
9be7d5a
test voting with nonexistent account and wrong seq
Nov 12, 2018
83879dc
Address @faboweb 's comments pt 1
Nov 12, 2018
79b6a77
refactor select option func on modal vote
Nov 12, 2018
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
* [\#1464](https://github.com/cosmos/voyager/issues/1464) Added governance transactions to tx history page @fedekunze
* [\1401](https://github.com/cosmos/voyager/issues/1401) Display governance proposals index. @fedekunze
* [\#1472](https://github.com/cosmos/voyager/issues/1472) Added mock functionality for redelegation @fedekunze + @faboweb
* [\#1501](https://github.com/cosmos/voyager/issues/1501) Vote on proposals through modal @fedekunze + @jbibla
* [\1502](https://github.com/cosmos/voyager/issues/1502) A page for each proposal. @jbibla

### Changed
Expand Down
176 changes: 176 additions & 0 deletions app/src/renderer/components/governance/ModalVote.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
<template lang="pug">
.modal-vote#modal-vote(v-click-outside="close")
.modal-vote-header
img.icon(class='modal-vote-atom' src="~assets/images/cosmos-logo.png")
span.tm-modal-title Vote
.tm-modal-icon.tm-modal-close#closeBtn(@click="close()")
i.material-icons close

div
h2 Title: {{ proposalTitle }}
h3 Proposal ID: {{ `#` + proposalId }}

tm-form-group.modal-vote-form-group.options
tm-btn#vote-yes(
@click.native="voteYes"
:class="[option === `yes` ? 'active' : '']"
color="secondary"
value="Yes"
size="md")

tm-btn#vote-no(
@click.native="voteNo"
:class="[option === `no` ? 'active' : '']"
color="secondary"
value="No"
size="md")

tm-btn#vote-veto(
@click.native="voteVeto"
:class="[option === `no_with_veto` ? 'active' : '']"
color="secondary"
value="No With Veto"
size="md")

tm-btn#vote-abstain(
@click.native="voteAbstain"
:class="[option === `abstain` ? 'active' : '']"
color="secondary"
value="Abstain"
size="md")

tm-form-group.modal-vote-form-group
.modal-vote-footer
tm-btn#cast-vote(
@click.native="onVote"
:disabled="$v.option.$invalid"
color="primary"
value="Vote"
size="lg")
</template>

<script>
import ClickOutside from "vue-click-outside"
import { required } from "vuelidate/lib/validators"
import Modal from "common/TmModal"
import { TmBtn, TmField, TmFormGroup, TmFormMsg } from "@tendermint/ui"

const isValid = option =>
option === `yes` ||
option === `no` ||
option === `no_with_veto` ||
option === `abstain`

export default {
name: `modal-vote`,
props: [`proposalId`, `proposalTitle`],
components: {
Modal,
TmBtn,
TmField,
TmFormGroup,
TmFormMsg
},
data: () => ({
option: ``
}),
validations() {
return {
option: {
required,
isValid
faboweb marked this conversation as resolved.
Show resolved Hide resolved
}
}
},
methods: {
close() {
this.$emit(`update:showModalVote`, false)
},
voteYes() {
faboweb marked this conversation as resolved.
Show resolved Hide resolved
if (this.option === `yes`) {
this.option = ``
} else {
this.option = `yes`
}
},
voteNo() {
if (this.option === `no`) {
this.option = ``
} else {
this.option = `no`
}
},
voteVeto() {
if (this.option === `no_with_veto`) {
this.option = ``
} else {
this.option = `no_with_veto`
}
},
voteAbstain() {
if (this.option === `abstain`) {
this.option = ``
} else {
this.option = `abstain`
}
},
onVote() {
this.$emit(`castVote`, { option: this.option })
this.close()
}
},
directives: {
ClickOutside
}
}
</script>

<style lang="stylus">
@import '~variables'

.modal-vote
background var(--app-nav)
display flex
flex-direction column
height 50%
justify-content space-between
left 50%
padding 2rem
position fixed
top 50%
width 40%
z-index z(modal)

&-header
align-items center
display flex

&-atom
height 4rem
width 4rem

&-form-group
display block
padding 0

&-footer
display flex
justify-content flex-end

h3
margin 0

button
margin 0
min-width 50%

span
margin 0.25rem

&.active
span
background var(--tertiary)

.tm-btn__container
padding 0.5rem
</style>
44 changes: 41 additions & 3 deletions app/src/renderer/components/governance/PageProposal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ tm-page(data-title='Proposal')
span.validator-profile__status(v-bind:class="status.color" v-tooltip.top="status.message")
.validator-profile__header__name__title {{ proposal.title }}
.column.validator-profile__header__actions
tm-btn(v-if="status.button === 'vote'" value="Vote" color="primary")
tm-btn#vote-btn(v-if="status.button === 'vote'" value="Vote" color="primary" @click.native="onVote")
tm-btn(v-if="status.button === 'deposit'" value="Deposit" color="primary")
tm-btn(v-if="!status.button" disabled value="Deposit / Vote" color="primary")

Expand Down Expand Up @@ -44,6 +44,14 @@ tm-page(data-title='Proposal')
.column
.row
text-block(:content="proposal.description")

modal-vote(
v-if="showModalVote"
v-on:castVote="castVote"
:showModalVote.sync="showModalVote"
:proposalId="proposal.proposal_id"
:proposalTitle="proposal.title"
)
</template>

<script>
Expand All @@ -52,17 +60,22 @@ import { TmBtn, TmPage, TmToolBar } from "@tendermint/ui"
import TmBalance from "common/TmBalance"
import FieldVote from "common/TmFieldVote"
import TextBlock from "common/TextBlock"
import ModalVote from "./ModalVote"
export default {
name: `page-proposal`,
props: [`proposal`, `status`],
components: {
TmBalance,
TmBtn,
FieldVote,
ModalVote,
TmToolBar,
TmPage,
TextBlock
},
data: () => ({
showModalVote: false
}),
computed: {
proposalType() {
return this.proposal.proposal_type.toLowerCase()
Expand All @@ -71,9 +84,9 @@ export default {
return `#` + num.prettyInt(this.proposal.submit_block)
},
voteBlock() {
if (this.proposal.submit_block === this.proposal.voting_start_block) {
if (this.proposal.submit_block === this.proposal.voting_start_block)
return `the same block`
} else {
else {
return `block #` + num.prettyInt(this.proposal.voting_start_block)
}
},
Expand Down Expand Up @@ -101,6 +114,31 @@ export default {
this.proposal.tally_result.abstain / this.totalVotes
)
}
},
methods: {
onVote() {
this.showModalVote = true
},
async castVote({ option }) {
let proposalId = this.proposal.proposal_id

try {
await this.$store.dispatch(`submitVote`, { proposalId, option })

this.$store.commit(`notify`, {
title: `Successful vote!`,
body: `You have successfully voted ${option} on proposal #${
this.proposal.proposal_id
}`
})
} catch (exception) {
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
const { message } = exception
this.$store.commit(`notifyError`, {
title: `Error while voting on proposal #${this.proposal.proposal_id}`,
body: message
})
}
}
}
}
</script>
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 @@ -192,7 +192,7 @@ const Client = (axios, localLcdURL, remoteLcdURL) => {
submitProposal: function(data) {
return req(`POST`, `/gov/proposals`, true)(data)
},
submitVote: function(proposalId, data) {
submitProposalVote: function(proposalId, data) {
return req(`POST`, `/gov/proposals/${proposalId}/votes`, true)(data)
},
submitDeposit: function(proposalId, data) {
Expand Down
Loading