Skip to content

Commit

Permalink
Merge branch 'develop' into fedekunze/1010-lcd-stake
Browse files Browse the repository at this point in the history
  • Loading branch information
fedekunze authored Aug 10, 2018
2 parents 0f2c28d + 293ceee commit f272b6b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
* testnets not properly available after download @faboweb
* Tell the main process when we switch to the mock network. @NodeGuy
* improved tooltip styling @jolesbi
* Sort validators by "Your Votes" fixed @okwme
* Overflow bonding bar bug @okwme

## [0.9.3] - 2018-08-02
Expand Down
37 changes: 17 additions & 20 deletions app/src/renderer/components/staking/PageStaking.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ tm-page(title='Staking')
.delegates-container
tm-data-loading(v-if="delegates.loading && delegates.delegates.length === 0")
tm-data-empty(v-else-if="delegates.delegates.length === 0")
data-empty-search(v-else-if="filteredDelegates.length === 0")
data-empty-search(v-else-if="sortedFilteredEnrichedDelegates.length === 0")
template(v-else)
panel-sort(:sort='sort')
li-delegate(v-for='i in enrichedAndFilteredDelegates' :key='i.id' :delegate='i')
li-delegate(v-for='i in sortedFilteredEnrichedDelegates' :key='i.id' :delegate='i')

.fixed-button-bar(v-if="!delegates.loading")
template(v-if="userCanDelegate")
Expand Down Expand Up @@ -67,7 +67,7 @@ export default {
},
vpTotal() {
return this.delegates.delegates
.slice()
.slice(0)
.map(v => {
v.voting_power = v.voting_power ? parseInt(v.voting_power) : 0
return v
Expand All @@ -76,32 +76,29 @@ export default {
.slice(0, 100)
.reduce((sum, v) => sum + v.voting_power, 0)
},
enrichedAndFilteredDelegates() {
return this.filteredDelegates.map(d =>
Object.assign({}, d, {
your_votes: this.num.prettyInt(this.committedDelegations[d.id])
})
)
enrichedDelegates() {
return !this.somethingToSearch
? []
: this.delegates.delegates.map(v => {
v.small_moniker = v.moniker.toLowerCase()
v.percent_of_vote = num.percent(v.voting_power / this.vpTotal)
v.your_votes = this.num.prettyInt(this.committedDelegations[v.id])
return v
})
},
filteredDelegates() {
sortedFilteredEnrichedDelegates() {
let query = this.filters.delegates.search.query || ""
forEach(this.delegates.delegates, v => {
v.small_moniker = v.moniker.toLowerCase()
v.percent_of_vote = num.percent(v.voting_power / this.vpTotal)
})
let delegates = orderBy(
this.delegates.delegates,
let sortedEnrichedDelegates = orderBy(
this.enrichedDelegates.slice(0),
[this.sort.property, "small_moniker"],
[this.sort.order, "asc"]
)
if (this.filters.delegates.search.visible) {
return delegates.filter(i =>
return sortedEnrichedDelegates.filter(i =>
includes(JSON.stringify(i).toLowerCase(), query.toLowerCase())
)
} else {
return delegates
return sortedEnrichedDelegates
}
},
userCanDelegate() {
Expand Down
24 changes: 12 additions & 12 deletions test/unit/specs/components/staking/PageStaking.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ describe("PageStaking", () => {
wrapper.vm.sort.property = "owner"
wrapper.vm.sort.order = "desc"

expect(wrapper.vm.filteredDelegates.map(x => x.owner)).toEqual(
lcdClientMock.validators
)
expect(
wrapper.vm.sortedFilteredEnrichedDelegates.map(x => x.owner)
).toEqual(lcdClientMock.validators)

wrapper.vm.sort.property = "owner"
wrapper.vm.sort.order = "asc"

expect(wrapper.vm.filteredDelegates.map(x => x.owner)).toEqual(
lcdClientMock.validators.reverse()
)
expect(
wrapper.vm.sortedFilteredEnrichedDelegates.map(x => x.owner)
).toEqual(lcdClientMock.validators.reverse())
})

it("should filter the delegates", () => {
Expand All @@ -62,18 +62,18 @@ describe("PageStaking", () => {
"delegates",
lcdClientMock.validators[2].substr(20, 26)
])
expect(wrapper.vm.filteredDelegates.map(x => x.owner)).toEqual([
lcdClientMock.validators[2]
])
expect(
wrapper.vm.sortedFilteredEnrichedDelegates.map(x => x.owner)
).toEqual([lcdClientMock.validators[2]])
wrapper.update()
expect(wrapper.vm.$el).toMatchSnapshot()
store.commit("setSearchQuery", [
"delegates",
lcdClientMock.validators[1].substr(20, 26)
])
expect(wrapper.vm.filteredDelegates.map(x => x.owner)).toEqual([
lcdClientMock.validators[1]
])
expect(
wrapper.vm.sortedFilteredEnrichedDelegates.map(x => x.owner)
).toEqual([lcdClientMock.validators[1]])
})

it("should show the amount of selected delegates", () => {
Expand Down

0 comments on commit f272b6b

Please sign in to comment.