Skip to content

Commit

Permalink
Merge pull request #1101 from cosmos/billy/1096-votes-sorting
Browse files Browse the repository at this point in the history
Billy/1096 votes sorting
  • Loading branch information
okwme authored Aug 9, 2018
2 parents 192eca4 + 4d629e5 commit 293ceee
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 34 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,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
19 changes: 17 additions & 2 deletions test/e2e/launch.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,24 @@ let fs = require("fs-extra")
const testDir = join(__dirname, "../../testArtifacts")

let app, cliHome, nodeHome, started, crashed
let binary = process.env.BINARY_PATH || process.env.GOPATH + "/bin/gaiacli"

const osFolderName = (function() {
switch (process.platform) {
case "win32":
return "windows_amd64"
case "darwin":
return "darwin_amd64"
case "linux":
return "linux_amd64"
}
})()
let binary =
process.env.BINARY_PATH ||
join(__dirname, "../../builds/gaia/", osFolderName, "gaiacli")

let nodeBinary =
process.env.NODE_BINARY_PATH || process.env.GOPATH + "/bin/gaiad"
process.env.NODE_BINARY_PATH ||
join(__dirname, "../../builds/gaia/", osFolderName, "gaiad")

/*
* NOTE: don't use a global `let client = app.client` as the client object changes when restarting the app
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 293ceee

Please sign in to comment.