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/1464 li governance txs #1481

Merged
merged 10 commits into from
Nov 7, 2018
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
* [\#1436](https://github.com/cosmos/voyager/issues/1436) governance endpoints and vuex module @fedekunze
* [\#1482](https://github.com/cosmos/voyager/issues/1482) Added ESLint errors: no-var. @sgobotta
* [\#1449](https://github.com/cosmos/voyager/issues/1449) shortNumber to num scripts for more readable numbers. @jbibla
* [\#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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ tm-page(data-title='Governance').governance
tm-balance(:tabs="tabs")

div(slot="menu"): vm-tool-bar
router-link(to="/proposals/new" exact v-tooltip.bottom="'New Proposal'")
router-link(to="/governance/proposals/new" exact v-tooltip.bottom="'New Proposal'")
i.material-icons add
a(@click='setSearch()' v-tooltip.bottom="'Search'")
i.search.material-icons search
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template lang="pug">
tm-page(data-title="Text Proposal")
div(slot="menu"): vm-tool-bar
router-link(to="/proposals/new" exact v-tooltip.bottom="'Back'")
router-link(to="/governance/proposals/new" exact v-tooltip.bottom="'Back'")
i.material-icons arrow_back
tm-form-struct(:submit="onSubmit")
tm-form-group(:error="$v.fields.title.$error"
Expand Down
8 changes: 3 additions & 5 deletions app/src/renderer/components/wallet/PageTransactions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ tm-page(data-title='Transactions')
tm-li-any-transaction(
:validators="delegates.delegates"
:validatorURL='validatorURL'
:proposalsURL='proposalsURL'
:key="shortid.generate()"
:transaction="tx"
:address="wallet.address"
Expand Down Expand Up @@ -92,16 +93,13 @@ export default {
property: `height`,
order: `desc`
},
validatorURL: `/staking/validators`
validatorURL: `/staking/validators`,
proposalsURL: `/governance/proposals`
}),
methods: {
refreshTransactions() {
this.$store.dispatch(`getAllTxs`)
},
async endUnbonding(transaction) {
let validatorAddr = transaction.tx.value.msg[0].value.validator_addr
await this.$store.dispatch(`endUnbonding`, validatorAddr)
},
enrichUnbondingTransactions(transaction) {
let copiedTransaction = JSON.parse(JSON.stringify(transaction))
let type = copiedTransaction.tx.value.msg[0].type
Expand Down
10 changes: 10 additions & 0 deletions app/src/renderer/connectors/lcdClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@ const Client = (axios, localLcdURL, remoteLcdURL) => {
true
)()
},
getGovernanceTxs: function(addr) {
return Promise.all([
req(
`GET`,
`/txs?tag=action=submit-proposal&proposer='${addr}'`,
true
)(),
req(`GET`, `/txs?tag=action=deposit&depositer='${addr}'`, true)()
]).then(([proposalTxs, depositTxs]) => [].concat(proposalTxs, depositTxs))
},
submitProposal: function(data) {
return req(`POST`, `/gov/proposals`, true)(data)
},
Expand Down
102 changes: 102 additions & 0 deletions app/src/renderer/connectors/lcdClientMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,95 @@ let state = {
},
hash: `A7C6DE5CA923AF08E6088F1348047F16BABB9F48`,
height: 150
},
{
hash: `QSDFGE5CA923AF08E6088F1348047F16BAHH8K31`,
height: 56673,
tx: {
type: `8EFE47F0625DE8`,
value: {
msg: [
{
type: `cosmos-sdk/MsgSubmitProposal`,
value: {
proposer: `cosmos15ky9du8a2wlstz6fpx3p4mqpjyrm5ctpesxxn9`,
proposal_type: `Text`,
title: `Test Proposal`,
description: `This is a test proposal`,
initial_deposit: [
{
denom: `stake`,
amount: `100`
}
]
}
}
]
}
}
},
{
hash: `QASDE5CA923AF08EEE38F1348047F16BAHH8K31`,
height: 213,
tx: {
type: `8EFE47F0625DE8`,
value: {
msg: [
{
type: `cosmos-sdk/MsgDeposit`,
value: {
depositer: `cosmos15ky9du8a2wlstz6fpx3p4mqpjyrm5ctpesxxn9`,
proposal_id: `1`,
amount: [
{
denom: `stake`,
amount: `100`
}
]
}
}
]
}
}
},
{
tx: {
value: {
msg: [
{
type: `cosmos-sdk/MsgDelegate`,
value: {
validator_addr: validators[0],
delegator_addr: addresses[0],
delegation: {
amount: `24`,
denom: `steak`
}
}
}
]
}
},
hash: `A7C6DE5CB923AF08E6088F1348047F16BABB9F48`,
height: 160
},
{
tx: {
value: {
msg: [
{
type: `cosmos-sdk/BeginUnbonding`,
value: {
validator_addr: validators[0],
delegator_addr: addresses[0],
shares: `5`
}
}
]
}
},
hash: `A7C6FDE5CA923AF08E6088F1348047F16BABB9F48`,
height: 170
}
],
stake: {
Expand Down Expand Up @@ -789,6 +878,19 @@ module.exports = {
}
})
},
async getGovernaceTxs(addr) {
return state.txs.filter(tx => {
let type = tx.tx.value.msg[0].type

if (type === `cosmos-sdk/MsgSubmitProposal`) {
return tx.tx.value.msg[0].value.proposer === addr
} else if (type === `cosmos-sdk/MsgDeposit`) {
return tx.tx.value.msg[0].value.depositer === addr
}

return false
})
},
// exports to be used in tests
state,
addresses,
Expand Down
11 changes: 7 additions & 4 deletions app/src/renderer/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@ export default [
path: `/governance`,
name: `Governance`,
component: governance(`Governance`),
redirect: `proposals/`,
redirect: `/governance/proposals`,
children: [
{
path: `/proposals`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this on purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah

path: `proposals`,
name: `Proposals`,
component: require(`./components/governance/TabProposals`).default
}
]
},
{ path: `proposals/new`, component: governance(`ProposalsNewText`) },
{
path: `/governance/proposals/new`,
component: governance(`ProposalsNewText`)
},
// TODO: enable once PageProposal is finished
// {
// path: `proposals/:proposal`,
// path: `governance/proposals/:proposal`,
// name: `proposal`,
// component: governance(`Proposal`)
// },
Expand Down
18 changes: 14 additions & 4 deletions app/src/renderer/vuex/modules/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ export default ({ node }) => {
let emptyState = {
loading: false,
wallet: [], // {height, result: { gas, tags }, tx: { type, value: { fee: { amount: [{denom, amount}], gas}, msg: {type, inputs, outputs}}, signatures} }}
staking: []
staking: [],
governance: []
}
let state = JSON.parse(JSON.stringify(emptyState))

// properties under which txs of different categories are store
const txCategories = [`staking`, `wallet`]
// properties under which txs of different categories are stored
const txCategories = [`staking`, `wallet`, `governance`]

let mutations = {
setWalletTxs(state, txs) {
Expand All @@ -18,6 +19,9 @@ export default ({ node }) => {
setStakingTxs(state, txs) {
state.staking = txs
},
setGovernanceTxs(state, txs) {
state.governance = txs
},
setHistoryLoading(state, loading) {
state.loading = loading
},
Expand Down Expand Up @@ -47,10 +51,13 @@ export default ({ node }) => {
const stakingTxs = await dispatch(`getTx`, `staking`)
commit(`setStakingTxs`, stakingTxs)

const governanceTxs = await dispatch(`getTx`, `governance`)
commit(`setGovernanceTxs`, governanceTxs)

const walletTxs = await dispatch(`getTx`, `wallet`)
commit(`setWalletTxs`, walletTxs)

const allTxs = stakingTxs.concat(walletTxs)
const allTxs = stakingTxs.concat(governanceTxs.concat(walletTxs))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐱 within a 🐱 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

await dispatch(`enrichTransactions`, {
transactions: allTxs
})
Expand All @@ -69,6 +76,9 @@ export default ({ node }) => {
case `staking`:
response = await node.getDelegatorTxs(address)
break
case `governance`:
response = await node.getGovernanceTxs(address)
break
case `wallet`:
response = await node.txs(address)
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ exports[`PageGovernance has the expected html structure 1`] = `
</div>
<div class=\\"tabs\\">
<div class=\\"tab\\">
<a href=\\"#/proposals\\" class=\\"\\">Proposals</a>
<a href=\\"#/governance/proposals\\" class=\\"\\">Proposals</a>
</div>
</div>
</div>
Expand All @@ -54,7 +54,7 @@ exports[`PageGovernance has the expected html structure 1`] = `
<div class=\\"tm-tool-bar\\">
<div class=\\"tm-tool-bar-container\\">
<div class=\\"main\\">
<a disabled=\\"disabled\\" class=\\"back\\"><i class=\\"material-icons\\">arrow_back</i></a><a href=\\"#/proposals/new\\" class=\\"\\"><i class=\\"material-icons\\">add</i></a><a><i class=\\"search material-icons\\">search</i></a><a class=\\"help\\"><i class=\\"material-icons\\">help_outline</i></a><a href=\\"#/preferences\\" class=\\"settings\\"><i id=\\"settings\\" class=\\"material-icons\\">settings</i></a><a id=\\"signOut-btn\\"><i class=\\"material-icons\\">exit_to_app</i></a>
<a disabled=\\"disabled\\" class=\\"back\\"><i class=\\"material-icons\\">arrow_back</i></a><a href=\\"#/governance/proposals/new\\" class=\\"\\"><i class=\\"material-icons\\">add</i></a><a><i class=\\"search material-icons\\">search</i></a><a class=\\"help\\"><i class=\\"material-icons\\">help_outline</i></a><a href=\\"#/preferences\\" class=\\"settings\\"><i id=\\"settings\\" class=\\"material-icons\\">settings</i></a><a id=\\"signOut-btn\\"><i class=\\"material-icons\\">exit_to_app</i></a>
</div>
</div>
</div>
Expand Down
55 changes: 10 additions & 45 deletions test/unit/specs/components/wallet/PageTransactions.spec.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,7 @@
import setup from "../../../helpers/vuex-setup"
import PageTransactions from "renderer/components/wallet/PageTransactions"
import mockTransactions from "../../store/json/txs.js"
import lcdclientMock from "renderer/connectors/lcdClientMock.js"

let stakingTxs = [
{
tx: {
value: {
msg: [
{
type: `cosmos-sdk/MsgDelegate`,
value: {
validator_addr: lcdclientMock.validators[0],
delegator_addr: lcdclientMock.addresses[0],
delegation: {
amount: `24`,
denom: `steak`
}
}
}
]
}
},
hash: `A7C6DE5CB923AF08E6088F1348047F16BABB9F48`,
height: 160
},
{
tx: {
value: {
msg: [
{
type: `cosmos-sdk/BeginUnbonding`,
value: {
validator_addr: lcdclientMock.validators[0],
delegator_addr: lcdclientMock.addresses[0],
shares: `5`
}
}
]
}
},
hash: `A7C6FDE5CA923AF08E6088F1348047F16BABB9F48`,
height: 170
}
]
import lcdClientMock from "renderer/connectors/lcdClientMock.js"

describe(`PageTransactions`, () => {
let wrapper, store
Expand All @@ -56,7 +14,7 @@ describe(`PageTransactions`, () => {
"data-empty-tx": `<data-empty-tx />`
},
methods: {
refreshTransactions: jest.fn()
refreshTransactions: jest.fn() // we don't want to call getAllTxs on mount
}
})
wrapper = instance.wrapper
Expand All @@ -65,7 +23,8 @@ describe(`PageTransactions`, () => {
store.commit(`setConnected`, true)
store.commit(`setWalletAddress`, `tb1d4u5zerywfjhxuc9nudvw`)
store.commit(`setWalletTxs`, mockTransactions)
store.commit(`setStakingTxs`, stakingTxs)
store.commit(`setStakingTxs`, lcdClientMock.state.txs.slice(4))
store.commit(`setGovernanceTxs`, lcdClientMock.state.txs.slice(2, 4))
wrapper.update()
})

Expand Down Expand Up @@ -126,6 +85,7 @@ describe(`PageTransactions`, () => {
expect(wrapper.vm.somethingToSearch).toBe(true)
store.commit(`setWalletTxs`, [])
store.commit(`setStakingTxs`, [])
store.commit(`setGovernanceTxs`, [])
expect(wrapper.vm.somethingToSearch).toBe(false)
store.commit(`setWalletTxs`, mockTransactions)
expect(wrapper.vm.somethingToSearch).toBe(true)
Expand All @@ -136,6 +96,7 @@ describe(`PageTransactions`, () => {
it(`should show an error if there are no transactions`, () => {
store.commit(`setWalletTxs`, [])
store.commit(`setStakingTxs`, [])
store.commit(`setGovernanceTxs`, [])
wrapper.update()
expect(wrapper.contains(`data-empty-tx`)).toBe(true)
})
Expand All @@ -145,10 +106,14 @@ describe(`PageTransactions`, () => {
stubs: {
"tm-li-transaction": `<tm-li-transaction />`,
"data-empty-tx": `<data-empty-tx />`
},
methods: {
refreshTransactions: jest.fn() // we don't want to call getAllTxs on mount
}
})
store.commit(`setWalletTxs`, [])
store.commit(`setStakingTxs`, [])
store.commit(`setGovernanceTxs`, [])
wrapper.update()
expect(wrapper.vm.setSearch()).toEqual(false)
})
Expand Down
Loading