Skip to content

Commit

Permalink
Jordan/1473 power not showing (#1493)
Browse files Browse the repository at this point in the history
* add percent_of_vote to validator in vuex module

* fixed da tests

* cha cha cha changelog
  • Loading branch information
jbibla authored and fedekunze committed Oct 26, 2018
1 parent 03056d5 commit a0c9035
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
* Updated contribution guidelines. @faboweb
* [\#1447](https://github.com/cosmos/voyager/issues/1447) Removed titles from all pages. @faboweb
* Updated PR template @fedekunze
* [\#1473](https://github.com/cosmos/voyager/issues/1473) added "percent of vote" to validator in vuex module instead of in component @jbibla

### Fixed

Expand Down
18 changes: 11 additions & 7 deletions app/src/renderer/vuex/modules/delegates.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import BN from "bignumber.js"
import { ratToBigNumber } from "scripts/common"
import num from "scripts/num"
import { isEmpty } from "lodash"
export default ({ node }) => {
const emptyState = {
Expand All @@ -16,18 +17,21 @@ export default ({ node }) => {
state.loading = loading
},
setDelegates(state, validators) {
validators.forEach(validator => {
validator.id = validator.operator_address
validator.voting_power = ratToBigNumber(validator.tokens)
})
state.delegates = validators

// update global power for quick access
state.globalPower = state.delegates
state.globalPower = validators
.reduce((sum, validator) => {
return sum.plus(ratToBigNumber(validator.tokens))
}, new BN(0))
.toNumber()

validators.forEach(validator => {
validator.id = validator.operator_address
validator.voting_power = ratToBigNumber(validator.tokens)
validator.percent_of_vote = num.percent(
validator.voting_power / state.globalPower
)
})
state.delegates = validators
},
setSelfBond(
state,
Expand Down
1 change: 1 addition & 0 deletions test/unit/specs/components/staking/PageValidator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@ describe(`onDelegation`, () => {
id: lcdClientMock.validators[0],
keybase: undefined,
operator_address: lcdClientMock.validators[0],
percent_of_vote: `65.52%`,
prev_bonded_shares: `0`,
proposer_reward_pool: null,
pub_key: `cosmoschiapudding123456789`,
Expand Down
4 changes: 4 additions & 0 deletions test/unit/specs/store/delegates.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ describe(`Module: Delegates`, () => {
mutations.setDelegates(state, [
{
operator_address: `foo`,
percent_of_vote: `100.00%`,
tokens: `10`
}
])
expect(state.delegates).toEqual([
{
id: `foo`,
operator_address: `foo`,
percent_of_vote: `100.00%`,
tokens: `10`,
voting_power: BN(10)
}
Expand All @@ -42,6 +44,7 @@ describe(`Module: Delegates`, () => {
{
id: `foo`,
operator_address: `foo`,
percent_of_vote: `100.00%`,
tokens: `12`,
updated: true,
voting_power: BN(12)
Expand All @@ -62,6 +65,7 @@ describe(`Module: Delegates`, () => {
{
id: `foo`,
operator_address: `foo`,
percent_of_vote: `100.00%`,
tokens: `4000/40`,
updated: true,
voting_power: BN(100)
Expand Down

0 comments on commit a0c9035

Please sign in to comment.