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

Fabo/2341 better validator updates #2370

Merged
merged 10 commits into from
Mar 27, 2019
Merged
Show file tree
Hide file tree
Changes from 9 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
4 changes: 3 additions & 1 deletion PENDING.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
[Changed] Reduced keybase caching timeouts @faboweb
[Fixed] [\#2370](https://github.com/cosmos/lunie/pull/2370) Better inplace updates to validators so the information (like signing info) never hides again once it was once loaded @faboweb
[Fixed] [\#2370](https://github.com/cosmos/lunie/pull/2370) Pages now scroll back to the top on tab changes @faboweb
[Changed] Reduced keybase caching timeouts @faboweb
9 changes: 7 additions & 2 deletions app/src/renderer/components/common/TmPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,14 @@ export default {
return refresh ? { connected, refresh } : undefined
}
},
watch: {
$route() {
this.scrollContainer.scrollTop = 0
}
},
async mounted() {
const container = this.$el.querySelector(`.tm-page-main`)
this.perfectScrollbar = new PerfectScrollbar(container)
this.scrollContainer = this.$el.querySelector(`.tm-page-main`)
this.perfectScrollbar = new PerfectScrollbar(this.scrollContainer)
}
}
</script>
Expand Down
30 changes: 27 additions & 3 deletions app/src/renderer/vuex/modules/delegates.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import * as Sentry from "@sentry/browser"
import BN from "bignumber.js"
import { ratToBigNumber } from "scripts/common"
import num from "scripts/num"
import { isEmpty } from "lodash"
import { isEmpty, merge } from "lodash"
import b32 from "scripts/b32"
import Vue from "vue"

export default ({ node }) => {
const emptyState = {
Expand Down Expand Up @@ -34,8 +35,9 @@ export default ({ node }) => {
validator.percent_of_vote = num.percent(
validator.voting_power / state.globalPower
)

upsertValidator(state, validator)
})
state.delegates = validators
},
setSelfBond(
state,
Expand Down Expand Up @@ -76,7 +78,12 @@ export default ({ node }) => {
const signing_info = await node.getValidatorSigningInfo(
validator.consensus_pubkey
)
if (!isEmpty(signing_info)) validator.signing_info = signing_info
if (!isEmpty(signing_info)) {
upsertValidator(
state,
Object.assign({},validator, { signing_info })
)
}
}
}
commit(`setDelegates`, validators)
Expand Down Expand Up @@ -142,3 +149,20 @@ export default ({ node }) => {
actions
}
}

// incrementally add the validator to the list or update it in place
// "upsert": (computing, databases) An operation that inserts rows into a database table if they do not already exist, or updates them if they do.
function upsertValidator(state, validator) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nice addition ! this will be way faster with the object refactor

const oldValidatorIndex = state.delegates.findIndex((oldValidator) =>
oldValidator.operator_address === validator.operator_address
)
if (oldValidatorIndex === -1) {
state.delegates.push(validator)
return
}
Vue.set(
state.delegates,
oldValidatorIndex,
merge(state.delegates[oldValidatorIndex], validator)
)
}
13 changes: 12 additions & 1 deletion app/src/renderer/vuex/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ export function storeUpdateHandler(mutation, state, pending) {
`setProposalDeposits`,
`setProposalVotes`,
`setProposalTally`,
`setGovParameters`
`setGovParameters`,
`setTotalRewards`,
`setDelegationRewards`,
`setDistributionParameters`
]

if (updatingMutations.indexOf(mutation.type) === -1) return
Expand Down Expand Up @@ -156,6 +159,14 @@ export async function loadPersistedState({ state, commit, dispatch }) {
loaded: true,
loading: false
},
delegation: {
loaded: true,
loading: false
},
distribution: {
loaded: true,
loading: false
},
proposals: {
loaded: true,
loading: false
Expand Down
10 changes: 10 additions & 0 deletions test/unit/specs/components/common/TmPage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,14 @@ describe(`TmPage`, () => {
expect(wrapper.vm.refreshable).toEqual({ connected: true, refresh })
})

it(`scrolls back to the top on a route change`, () => {
const self = {
scrollContainer: {
scrollTop: 100
}
}
TmPage.watch.$route.call(self)
expect(self.scrollContainer.scrollTop).toBe(0)
})

})