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

Staking fixes #912

Merged
merged 31 commits into from
Jul 12, 2018
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a08bf02
Show validator 'Revoked' status in LiDelegate
mappum Jul 3, 2018
d754f02
Show inline errors when attempting to bond too much
mappum Jul 3, 2018
dadb948
Hide grey bar (old stake value) when 0
mappum Jul 3, 2018
81df298
Indicate revocation in PageBond
mappum Jul 3, 2018
bdb8a60
Update CHANGELOG
mappum Jul 3, 2018
c2e7e5c
Update PageBond snapshot
mappum Jul 3, 2018
7e29213
Fetch validator set to indicate which candidates are validators
mappum Jul 3, 2018
fb864aa
inscreased coverage
Jul 8, 2018
77b0f94
added revoked candidate to lcd client mock + added revoked warning
Jul 8, 2018
da78862
added test for revoked warning
Jul 8, 2018
4352d4d
Merge branch 'develop' into matt/842-staking-fixes
faboweb Jul 8, 2018
fe7c7fd
merged develop
Jul 9, 2018
319a80c
added doBefore callback to vuex setup
Jul 9, 2018
ee9ccae
added more coverage for pagebond
Jul 9, 2018
15fcecb
Merge branch 'matt/842-staking-fixes' of https://github.com/cosmos/vo…
Jul 9, 2018
1d6bf2d
fixed NaN displaying for steak
Jul 9, 2018
96158e3
readded most delegation tests
Jul 10, 2018
08c28fb
Merge remote-tracking branch 'origin/develop' into matt/842-staking-f…
Jul 10, 2018
7eda9a2
fixed unable to bond just to committed candidates
Jul 10, 2018
2d4d996
fixed showing wrong shares after bonding
Jul 10, 2018
7d463f4
moved your votes into the view it belongs to
Jul 10, 2018
c55215a
changelog
Jul 10, 2018
5dead47
Merge branch 'develop' into matt/842-staking-fixes
okwme Jul 10, 2018
09aec80
full coverage on delegation
Jul 11, 2018
2cfbe77
updated snapshots with more diverse candidate setup
Jul 11, 2018
599e565
Merge branch 'matt/842-staking-fixes' of https://github.com/cosmos/vo…
Jul 11, 2018
508c444
added helpers for querying commits and dispatches
Jul 11, 2018
c174947
increased coverage on pageBond
Jul 11, 2018
d994124
removed dead code
Jul 11, 2018
818ace1
Merge branch 'develop' into matt/842-staking-fixes
faboweb Jul 11, 2018
1b2da60
Merge branch 'develop' into matt/842-staking-fixes
okwme Jul 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added

* Indicate if a validator has been revoked in the Staking UI @mappum

### Changed

* Copy the network configuration only during local builds. @NodeGuy
Expand Down
6 changes: 5 additions & 1 deletion app/src/renderer/components/staking/LiDelegate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ export default {
return this.user.atoms > 0
},
delegateType() {
return this.delegate.isValidator ? "Validator" : "Candidate"
return this.delegate.revoked
? "Revoked"
: this.delegate.isValidator
? "Validator"
: "Candidate"
}
},
data: () => ({ num: num }),
Expand Down
64 changes: 37 additions & 27 deletions app/src/renderer/components/staking/PageBond.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ tm-page.page-bond(:title="`Bond ${denom}`")
:class="bondGroupClass(delta(d.atoms, d.oldAtoms))")
.bond-group__fields
.bond-bar
label.bond-bar__label {{ d.delegate.moniker }}
label.bond-bar__label(v-if="!d.delegate.revoked") {{ d.delegate.moniker }}
label.bond-bar__label.revoked(v-if="d.delegate.revoked") {{ d.delegate.moniker }}
label.bond-bar__revoked(v-if="d.delegate.revoked") REVOKED
.bond-bar__input
.bond-bar-old__outer
.bond-bar-old__inner(:style="styleBondBarInner(d.oldAtoms)")
.bond-bar-old__inner(
:style="styleBondBarInner(d.oldAtoms)"
v-if="d.oldAtoms > 0")
.bond-bar__outer
.bond-bar__inner.bond-bar__inner--editable(:id="'delegate-' + d.id"
:style="styleBondBarInner(d.atoms)")
Expand All @@ -57,9 +61,9 @@ tm-page.page-bond(:title="`Bond ${denom}`")
placeholder="Atoms"
step="1"
min="0"
:max="$v.fields.delegates.$each[index].atoms.$params.between.max"
:max=newUnbondedAtoms
v-model.number="d.atoms"
@change.native="limitMax(d, $event)")
@change.native="limitMax(d, parseInt($event.target.max))")

tm-form-msg(name="Atoms" type="required"
v-if="!$v.fields.delegates.$each[index].atoms.required")
Expand Down Expand Up @@ -99,6 +103,7 @@ tm-page.page-bond(:title="`Bond ${denom}`")

tm-form-group(field-id="bond-confirm" field-label=''
:error='$v.fields.bondConfirm.$error')
tm-form-msg(v-if="showsRevokedValidators") A revoked validator is not validating and therefor is not producing rewards. The revoked state may be temporary.
.tm-field-checkbox
.tm-field-checkbox-input
input#bond-confirm(type="checkbox" v-model="fields.bondConfirm")
Expand Down Expand Up @@ -188,6 +193,9 @@ export default {
},
unbondedAtomsDeltaPct() {
return this.percent(this.unbondedAtomsDelta, this.totalAtoms)
},
showsRevokedValidators() {
return !!this.fields.delegates.find(d => d.delegate.revoked)
}
},
data: () => ({
Expand Down Expand Up @@ -320,16 +328,14 @@ export default {
},
updateDelegateAtoms(delegateId, rawAtoms) {
let d = this.fields.delegates.find(d => d.id === delegateId)
if (d) {
d.bondedRatio = rawAtoms / this.totalAtoms
d.atoms = Math.round(rawAtoms)
d.deltaAtoms = this.delta(rawAtoms, d.oldAtoms, "int")
d.deltaAtomsPercent = this.percent(
this.delta(rawAtoms, d.oldAtoms),
this.totalAtoms
)
return d
}
d.bondedRatio = rawAtoms / this.totalAtoms
d.atoms = Math.round(rawAtoms)
d.deltaAtoms = this.delta(rawAtoms, d.oldAtoms, "int")
d.deltaAtomsPercent = this.percent(
this.delta(rawAtoms, d.oldAtoms),
this.totalAtoms
)
return d
},
setBondBarOuterWidth() {
let outerBar = this.$el.querySelector(".bond-bar__outer")
Expand All @@ -355,10 +361,8 @@ export default {
}
return value + "%"
},
limitMax(delegate, event) {
let max = parseInt(event.target.max)
limitMax(delegate, max) {
if (delegate.atoms >= max) {
console.log(`${delegate.atoms} <= ${max}`)
delegate.atoms = max
return
}
Expand Down Expand Up @@ -423,19 +427,22 @@ export default {

.bond-delta
color var(--success)

span:before
content '+'
display inline

&.bond-group--unbonding
.bond-bar__inner
background var(--warning)

.bond-delta
color var(--warning)

.bond-group--negative
.bond-bar-old__inner
background var(--input-bc)

.bond-delta
color var(--input-bc)

Expand All @@ -455,25 +462,31 @@ export default {
font-size x
text-align left

.bond-bar__label.revoked
text-decoration line-through

.bond-bar__revoked
color red
font-weight bold
margin-left 6px

.bond-bar__input
height 2rem
border-radius 1rem
border 1px solid var(--input-bc)
padding 1px
position relative

.bond-bar__outer
.bond-bar-old__outer
height 2rem - 4*px
.bond-bar__outer, .bond-bar-old__outer
height 2rem - 4 * px
border-radius 1rem
position absolute
top 1px
left 1px
right 1px
bottom 1px

.bond-bar__inner
.bond-bar-old__inner
.bond-bar__inner, .bond-bar-old__inner
height 2rem - 0.25rem
border-radius 1rem
background var(--dim)
Expand All @@ -482,7 +495,6 @@ export default {

.bond-bar__inner
position relative

// debug
color var(--app-bg)
font-size xs
Expand All @@ -500,11 +512,9 @@ export default {
background var(--txt)
border-radius 1rem
z-index z(listItem)

display flex
align-items center
justify-content center

content 'drag_handle'
font-size x
font-family 'Material Icons'
Expand All @@ -517,12 +527,12 @@ export default {
display flex
align-items center
justify-content flex-end

span
font-size sm
font-weight 500

.bond-percent
.bond-value
.bond-percent, .bond-value
input
text-align right

Expand Down
1 change: 1 addition & 0 deletions app/src/renderer/connectors/lcdClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Object.assign(Client.prototype, {
// staking
updateDelegations: req("POST", "/stake/delegations"),
candidates: req("GET", "/stake/validators"),
getValidators: req("GET", "/validatorsets/latest"),
queryDelegation: function(delegator, validator) {
return req("GET", `/stake/${delegator}/bonding_status/${validator}`).call(
this
Expand Down
11 changes: 9 additions & 2 deletions app/src/renderer/connectors/lcdClientMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,10 @@ let state = {
pool_shares: { amount: "19/1" },
description: {
description: "Herr Schmidt",
moniker: "herr_schmidt",
moniker: "herr_schmidt_revoked",
country: "DE"
}
},
revoked: true
}
],
sendHeight: 2
Expand Down Expand Up @@ -362,6 +363,12 @@ module.exports = {
async candidates() {
return state.candidates
},
async getValidators() {
return {
block_height: 1,
validators: state.candidates
}
},
// exports to be used in tests
state,
addresses,
Expand Down
10 changes: 0 additions & 10 deletions app/src/renderer/scripts/indicateValidators.js

This file was deleted.

12 changes: 6 additions & 6 deletions app/src/renderer/vuex/modules/delegates.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import indicateValidators from "scripts/indicateValidators"

export default ({ dispatch, node }) => {
const state = {
delegates: [],
Expand Down Expand Up @@ -41,13 +39,15 @@ export default ({ dispatch, node }) => {
async getDelegates({ state, dispatch, commit, rootState }) {
commit("setDelegateLoading", true)
let delegates = await node.candidates()
let { validators } = await node.getValidators()
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is only happening once. can we use the rpc event to requery the validators when they change?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Put this as a follow up #946

for (let delegate of delegates) {
if (validators.find(v => v.pub_key === delegate.pub_key)) {
delegate.isValidator = true
}
commit("addDelegate", delegate)
}
commit(
"setDelegates",
indicateValidators(state.delegates, rootState.config.maxValidators)
)

commit("setDelegates", delegates)
commit("setDelegateLoading", false)

return state.delegates
Expand Down
22 changes: 17 additions & 5 deletions test/unit/helpers/vuex-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function vuexSetup() {
function init(
componentConstructor,
testType = shallow,
{ stubs, getters = {}, propsData }
{ stubs, getters = {}, propsData, doBefore = ({ store, router }) => {} }
) {
const node = Object.assign({}, require("../helpers/node_mock"))
const modules = Modules({ node })
Expand All @@ -35,6 +35,10 @@ export default function vuexSetup() {
store.commit("addHistory", from.fullPath)
next()
})

// execute some preparation logic on the store or router before mounting
doBefore({ store, router })

return {
node,
store,
Expand All @@ -53,17 +57,25 @@ export default function vuexSetup() {

return {
localVue,
shallow: (componentConstructor, { stubs, getters, propsData } = {}) =>
shallow: (
componentConstructor,
{ stubs, getters, propsData, doBefore } = {}
) =>
init(componentConstructor, shallow, {
stubs,
getters,
propsData
propsData,
doBefore
}),
mount: (componentConstructor, { stubs, getters, propsData } = {}) =>
mount: (
componentConstructor,
{ stubs, getters, propsData, doBefore } = {}
) =>
init(componentConstructor, mount, {
stubs,
getters,
propsData
propsData,
doBefore
})
}
}
23 changes: 23 additions & 0 deletions test/unit/specs/components/staking/LiDelegate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,27 @@ describe("LiDelegate", () => {
expect(wrapper.vm.inCart).toBeFalsy()
expect(wrapper.html()).not.toContain("li-delegate-active")
})

it("should show the type of the candidate", () => {
wrapper.vm.delegate = {
revoked: false,
isValidator: false
}
expect(wrapper.vm.delegateType).toBe("Candidate")
wrapper.vm.delegate = {
revoked: false,
isValidator: true
}
expect(wrapper.vm.delegateType).toBe("Validator")
wrapper.vm.delegate = {
revoked: true,
isValidator: false
}
expect(wrapper.vm.delegateType).toBe("Revoked")
wrapper.vm.delegate = {
revoked: true,
isValidator: true
}
expect(wrapper.vm.delegateType).toBe("Revoked")
})
})
Loading