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

Jordan/2267+2278 validator table bugs #2294

Closed
wants to merge 4 commits into from
Closed
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
2 changes: 2 additions & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@

- [\#2257](https://github.com/cosmos/voyager/pull/2257) fixed console
- [\#2273](https://github.com/cosmos/voyager/issues/2273) fixed atoms and uatoms conversion @fedekunze
- [\#2267](https://github.com/cosmos/voyager/issues/2267) fixed sorting on validator table @jbibla
- [\#2278](https://github.com/cosmos/voyager/issues/2278) fixed commission calculation on validator table @jbibla
38 changes: 9 additions & 29 deletions app/src/renderer/components/staking/LiValidator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,20 @@
</div>
</td>
<td class="li-validator__delegated-steak">
{{
yourVotes.isLessThan(0.01) && yourVotes.isGreaterThan(0)
? num.shortNumber(0.01)
: num.shortNumber(yourVotes)
}}
</td>
<td class="li-validator__rewards data-table__row__cell__separator">
{{ rewards || "--" }}
{{ yourVotes.isGreaterThan(0) ? num.shortNumber(yourVotes) : `--` }}
</td>
<td class="li-validator__voting-power">
{{ validator.percent_of_vote ? validator.percent_of_vote : `--` }}
</td>
<td class="li-validator__uptime">
{{ uptime }}
{{
validator.percent_of_vote
? num.percent(validator.percent_of_vote)
: `--`
}}
</td>
<td class="li-validator__commission">
{{ commission }}
{{ validator.commission ? num.percent(validator.commission) : `--` }}
</td>
<td class="li-validator__slashes">
--
<td class="li-validator__uptime">
{{ validator.uptime ? num.percent(validator.uptime) : `--` }}
</td>
</tr>
</template>
Expand Down Expand Up @@ -95,20 +89,6 @@ export default {
`session`,
`lastHeader`
]),
commission() {
return `${this.num.pretty(this.validator.commission.rate)}%`
},
uptime() {
const rollingWindow = 10000 // param of slashing period
const info = this.validator.signing_info
if (info) {
// uptime in the past 10k blocks
const uptimeRollingWindow =
(rollingWindow - info.missed_blocks_counter) / rollingWindow
return num.percent(uptimeRollingWindow)
}
return `--`
},
yourVotes() {
return this.committedDelegations[this.validator.operator_address]
? BigNumber(
Expand Down
5 changes: 1 addition & 4 deletions app/src/renderer/components/staking/PageValidator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@
{{ percent(validator.commission.rate) }}
</dd>
</dl>
<dl
v-if="session.experimentalMode"
class="info_dl colored_dl"
>
<dl v-if="session.experimentalMode" class="info_dl colored_dl">
<dt>Slashes</dt>
<dd>--</dd>
</dl>
Expand Down
41 changes: 17 additions & 24 deletions app/src/renderer/components/staking/TableValidators.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ export default {
num: num,
query: ``,
sort: {
property: `percent_of_vote`,
order: `desc`
}
property: `commission`,
order: `asc`
},
rollingWindow: 10000 // param of slashing period
}),
computed: {
...mapGetters([
Expand All @@ -68,19 +69,23 @@ export default {
return this.validators.map(v =>
Object.assign({}, v, {
small_moniker: v.description.moniker.toLowerCase(),
percent_of_vote: num.percent(v.voting_power / this.vpTotal),
percent_of_vote: v.voting_power / this.vpTotal,
your_votes: this.num.full(
calculateTokens(v, this.committedDelegations[v.id])
),
keybase: this.keybase[v.description.identity]
commission: v.commission.rate,
keybase: this.keybase[v.description.identity],
uptime: v.signing_info
? (this.rollingWindow - v.signing_info.missed_blocks_counter)
/ this.rollingWindow : 0
})
)
},
sortedEnrichedDelegates() {
return orderBy(
this.enrichedDelegates.slice(0),
[this.sort.property, `small_moniker`],
[this.sort.order, `asc`]
[this.sort.property],
[this.sort.order]
)
},
userCanDelegate() {
Expand All @@ -102,36 +107,24 @@ export default {
} you have delegated to this validator`,
class: `your-votes`
},
{
title: `Rewards`,
value: `your_rewards`, // TODO: use real rewards
tooltip: `Rewards you have earned from this validator`,
class: `your-rewards`
},
{
title: `Voting Power`,
value: `percent_of_vote`,
tooltip: `Percentage of voting shares`,
class: `percent_of_vote`
},
{
title: `Uptime`,
value: `uptime`,
tooltip: `Ratio of blocks signed within the last 10k blocks`,
class: `uptime`
},
{
title: `Commission`,
value: `commission`,
tooltip: `The validator's commission`,
class: `commission`
},
{
title: `Slashes`,
value: `slashes`, // TODO: use real slashes
tooltip: `The validator's slashes`,
class: `slashes`
}
title: `Uptime`,
value: `uptime`,
tooltip: `Ratio of blocks signed within the last 10k blocks`,
class: `uptime`
},
]
}
},
Expand Down
42 changes: 17 additions & 25 deletions test/unit/specs/components/staking/LiValidator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,17 @@ describe(`LiValidator`, () => {
bond_height: `0`,
bond_intra_tx_counter: 6,
proposer_reward_pool: null,
commission: {
rate: `0.05`,
max_rate: `0.1`,
max_change_rate: `0.005`,
update_time: `1970-01-01T00:00:00Z`
},
commission: 5,
prev_bonded_shares: `0`,
voting_power: `10`,
percent_of_vote: `22%`,
voting_power: 10,
percent_of_vote: 0.22,
signing_info: {
start_height: 0,
index_offset: 465400,
jailed_until: `1970-01-01T00:00:00Z`,
missed_blocks_counter: 122
}
},
uptime: 0.98778883
}

beforeEach(() => {
Expand Down Expand Up @@ -82,7 +78,7 @@ describe(`LiValidator`, () => {
})

it(`should show the voting power`, () => {
expect(wrapper.html()).toContain(`22%`)
expect(wrapper.html()).toContain(`22.00%`)
})

it(`should show the validator status`, () => {
Expand Down Expand Up @@ -127,21 +123,27 @@ describe(`LiValidator`, () => {
expect(wrapper.vm.statusColor).toBe(`yellow`)
})

it(`should show the validator's uptime`, () => {
expect(wrapper.vm.uptime).toBe(`98.78%`)
it(`should include uptime as type:number`, () => {
expect(wrapper.vm.validator.uptime).toBe(0.98778883)
})

it(`should display uptime as a human readable percentage`, () => {
expect(wrapper.html()).toContain(`98.78%`)
})

it(`should display uptime as double-dash`, () => {
wrapper.setProps({
validator: Object.assign({}, validator, {
signing_info: null
uptime: null
})
})

expect(wrapper.vm.uptime).toBe(`--`)
expect(wrapper.vm.validator.uptime).toBe(null)
expect(wrapper.vm.$el).toMatchSnapshot()
})

it(`should show the validator's commission`, () => {
expect(wrapper.html()).toContain(wrapper.vm.validator.commission.rate)
expect(wrapper.html()).toContain(wrapper.vm.validator.commission)
})

it(`should show the type of the candidate`, () => {
Expand Down Expand Up @@ -175,16 +177,6 @@ describe(`LiValidator`, () => {
expect(wrapper.vm.delegateType).toBe(`Revoked`)
})

it(`shows rewards`, () => {
$store.getters.distribution.rewards = {
[validator.operator_address]: {
stake: 1230000000
}
}

expect(wrapper.find(`.li-validator__rewards`).html()).toContain(`1,230.0000…`)
})

it(`works if user is not signed in`, () => {
$store.getters.session.signedIn = false

Expand Down
Loading