From cb3b920f89308de22bf405586292f19266ea1e27 Mon Sep 17 00:00:00 2001 From: Fabian Date: Fri, 22 Mar 2019 16:39:38 +0100 Subject: [PATCH 01/17] moved throttling into modules --- .../renderer/components/common/TmBalance.vue | 10 ++-- .../components/staking/TabMyDelegations.vue | 17 ++----- .../components/staking/TabValidators.vue | 38 ++++----------- app/src/renderer/vuex/getters.js | 9 +++- app/src/renderer/vuex/modules/delegates.js | 31 ++++++++---- app/src/renderer/vuex/modules/distribution.js | 48 ++++++++++++++----- .../staking/TabMyDelegations.spec.js | 6 +-- .../components/staking/TabValidators.spec.js | 6 +-- test/unit/specs/store/distribution.spec.js | 6 +-- 9 files changed, 94 insertions(+), 77 deletions(-) diff --git a/app/src/renderer/components/common/TmBalance.vue b/app/src/renderer/components/common/TmBalance.vue index 07613afedb..feb85e8a43 100644 --- a/app/src/renderer/components/common/TmBalance.vue +++ b/app/src/renderer/components/common/TmBalance.vue @@ -45,7 +45,8 @@ export default { }, data() { return { - num + num, + lastUpdate: 0 } }, computed: { @@ -85,8 +86,11 @@ export default { lastHeader: { immediate: true, handler(newHeader) { - const waitTenBlocks = Number(newHeader.height) % 10 === 0 - if (this.session.signedIn && waitTenBlocks) { + const height = Number(newHeader.height) + // run the update queries the first time and after every 10 blocks + const waitedTenBlocks = height - this.lastUpdate > 10 + if (this.session.signedIn && (height === 0 || waitedTenBlocks)) { + this.lastUpdate = height this.$store.dispatch(`getTotalRewards`) this.$store.dispatch(`queryWalletBalances`) } diff --git a/app/src/renderer/components/staking/TabMyDelegations.vue b/app/src/renderer/components/staking/TabMyDelegations.vue index b5b74a069d..44bc1a76b4 100644 --- a/app/src/renderer/components/staking/TabMyDelegations.vue +++ b/app/src/renderer/components/staking/TabMyDelegations.vue @@ -75,7 +75,8 @@ export default { unbondTransactions: `Transactions currently in the undelegation period`, validatorURL: `/staking/validators`, time, - num + num, + lastUpdate: 0 }), computed: { ...mapGetters([ @@ -132,18 +133,8 @@ export default { }, lastHeader: { immediate: true, - handler(newHeader) { - const waitTwentyBlocks = Number(newHeader.height) % 20 === 0 - if ( - waitTwentyBlocks && - this.yourValidators && - this.yourValidators.length > 0 - ) { - this.$store.dispatch( - `getRewardsFromAllValidators`, - this.yourValidators - ) - } + handler() { + this.$store.dispatch(`getRewardsFromMyValidators`) } } }, diff --git a/app/src/renderer/components/staking/TabValidators.vue b/app/src/renderer/components/staking/TabValidators.vue index 5df836c5d3..e268a8da1b 100644 --- a/app/src/renderer/components/staking/TabValidators.vue +++ b/app/src/renderer/components/staking/TabValidators.vue @@ -24,28 +24,18 @@ export default { TmDataLoading, TmDataConnecting }, + data: () => ({ + lastUpdate: 0 + }), computed: { ...mapGetters([ `lastHeader`, `delegates`, `committedDelegations`, `connected`, - `session` - ]), - yourValidators( - { - committedDelegations, - delegates: { delegates }, - session: { signedIn } - } = this - ) { - return ( - signedIn && - delegates.filter( - ({ operator_address }) => operator_address in committedDelegations - ) - ) - } + `session`, + `yourValidators` + ]) }, watch: { "session.signedIn": function(signedIn) { @@ -53,25 +43,15 @@ export default { }, lastHeader: { immediate: true, - handler(newHeader) { - const waitTwentyBlocks = Number(newHeader.height) % 20 === 0 - if ( - waitTwentyBlocks && - this.yourValidators && - this.yourValidators.length > 0 - ) { - this.$store.dispatch( - `getRewardsFromAllValidators`, - this.yourValidators - ) - } + handler() { + this.$store.dispatch(`getRewardsFromMyValidators`) } } }, mounted() { this.$store.dispatch(`updateDelegates`) if (this.yourValidators) { - this.$store.dispatch(`getRewardsFromAllValidators`, this.yourValidators) + this.$store.dispatch(`getRewardsFromMyValidators`, this.yourValidators) } } } diff --git a/app/src/renderer/vuex/getters.js b/app/src/renderer/vuex/getters.js index 7ee5007c4a..81b50a611e 100644 --- a/app/src/renderer/vuex/getters.js +++ b/app/src/renderer/vuex/getters.js @@ -26,6 +26,11 @@ export const wallet = state => state.wallet // fee distribution export const distribution = state => state.distribution +export const yourValidators = (state, getters) => + state.session.signedIn && + getters.delegates.delegates.filter( + ({ operator_address }) => operator_address in getters.committedDelegations + ) // staking export const liquidAtoms = state => @@ -89,7 +94,7 @@ export const deposits = state => state.deposits.deposits export const governanceParameters = state => state.governanceParameters export const depositDenom = getters => getters.governanceParameters.loaded && - getters.governanceParameters.parameters.deposit.min_deposit + getters.governanceParameters.parameters.deposit.min_deposit ? getters.governanceParameters.parameters.deposit.min_deposit[0].denom : `uatom` @@ -101,4 +106,4 @@ export const nodeUrl = state => state.connection.connected ? state.connection.nodeUrl : undefined export const blocks = state => (state.blocks ? state.blocks.blocks : []) -export const block = state => (state.blocks ? state.blocks.block : []) \ No newline at end of file +export const block = state => (state.blocks ? state.blocks.block : []) diff --git a/app/src/renderer/vuex/modules/delegates.js b/app/src/renderer/vuex/modules/delegates.js index be5dc7222b..f060bc75ba 100644 --- a/app/src/renderer/vuex/modules/delegates.js +++ b/app/src/renderer/vuex/modules/delegates.js @@ -11,7 +11,8 @@ export default ({ node }) => { globalPower: null, loading: false, loaded: false, - error: null + error: null, + lastDelegatesUpdate: 0 } const state = JSON.parse(JSON.stringify(emptyState)) @@ -58,16 +59,28 @@ export default ({ node }) => { resetSessionData({ rootState }) { rootState.delegates = JSON.parse(JSON.stringify(emptyState)) }, - async updateSigningInfo({ commit }, validators) { - for (const validator of validators) { - if (validator.consensus_pubkey) { - const signing_info = await node.getValidatorSigningInfo( - validator.consensus_pubkey - ) - if (!isEmpty(signing_info)) validator.signing_info = signing_info + async updateSigningInfo( + { + commit, + getters: { lastHeader } + }, + validators + ) { + // throttle the update for validators for every 10 blocks + const waited10Blocks = + Number(lastHeader.height) - state.lastDelegatesUpdate > 10 + if (state.lastDelegatesUpdate === 0 || waited10Blocks) { + state.lastDelegatesUpdate = Number(lastHeader.height) + for (const validator of validators) { + if (validator.consensus_pubkey) { + const signing_info = await node.getValidatorSigningInfo( + validator.consensus_pubkey + ) + if (!isEmpty(signing_info)) validator.signing_info = signing_info + } } + commit(`setDelegates`, validators) } - commit(`setDelegates`, validators) }, async getDelegates({ state, commit, dispatch, rootState }) { commit(`setDelegateLoading`, true) diff --git a/app/src/renderer/vuex/modules/distribution.js b/app/src/renderer/vuex/modules/distribution.js index 4d08bb7fa2..2ff0acfba9 100644 --- a/app/src/renderer/vuex/modules/distribution.js +++ b/app/src/renderer/vuex/modules/distribution.js @@ -7,6 +7,7 @@ export default ({ node }) => { loading: false, loaded: false, error: null, + lastValidatorRewardsUpdate: 0, // keep track of last update so we can throttle the interval /* totalRewards use the following format: { denom1: amount1, @@ -69,9 +70,7 @@ export default ({ node }) => { resetSessionData({ rootState }) { rootState.distribution = JSON.parse(JSON.stringify(emptyState)) }, - async getTotalRewards( - { state, rootState: { session }, commit } - ) { + async getTotalRewards({ state, rootState: { session }, commit }) { state.loading = true try { const rewardsArray = await node.getDelegatorRewards(session.address) @@ -86,7 +85,10 @@ export default ({ node }) => { state.loading = false }, async withdrawAllRewards( - { rootState: { wallet }, dispatch }, + { + rootState: { wallet }, + dispatch + }, { password, submitType } ) { await dispatch(`sendTx`, { @@ -99,16 +101,38 @@ export default ({ node }) => { await dispatch(`queryWalletBalances`) await dispatch(`getAllTxs`) }, - async getRewardsFromAllValidators({ state, dispatch }, validators) { - state.loading = true - await Promise.all(validators.map(validator => - dispatch(`getRewardsFromValidator`, validator.operator_address) - )) - state.loading = false - state.loaded = true + async getRewardsFromMyValidators( + { + state, + dispatch, + getters: { lastHeader, yourValidators } + }, + validators + ) { + // throttle the update of validator rewards to every 20 blocks + const waitedTwentyBlocks = + Number(lastHeader.height) - state.lastValidatorRewardsUpdate > 20 + if ( + (state.lastValidatorRewardsUpdate === 0 || waitedTwentyBlocks) && + yourValidators && + yourValidators.length > 0 + ) { + state.loading = true + await Promise.all( + validators.map(validator => + dispatch(`getRewardsFromValidator`, validator.operator_address) + ) + ) + state.loading = false + state.loaded = true + } }, async getRewardsFromValidator( - { state, rootState: { session }, commit }, + { + state, + rootState: { session }, + commit + }, validatorAddr ) { state.loading = true diff --git a/test/unit/specs/components/staking/TabMyDelegations.spec.js b/test/unit/specs/components/staking/TabMyDelegations.spec.js index 4ebb237cb2..da43f0791d 100644 --- a/test/unit/specs/components/staking/TabMyDelegations.spec.js +++ b/test/unit/specs/components/staking/TabMyDelegations.spec.js @@ -166,7 +166,7 @@ describe(`Component: TabMyDelegations`, () => { { $store, yourValidators }, newHeader) expect($store.dispatch).not.toHaveBeenCalledWith( - `getRewardsFromAllValidators`, + `getRewardsFromMyValidators`, yourValidators ) }) @@ -179,7 +179,7 @@ describe(`Component: TabMyDelegations`, () => { { $store, yourValidators }, newHeader) expect($store.dispatch).not.toHaveBeenCalledWith( - `getRewardsFromAllValidators`, + `getRewardsFromMyValidators`, yourValidators ) }) @@ -193,7 +193,7 @@ describe(`Component: TabMyDelegations`, () => { { $store, yourValidators }, newHeader) expect($store.dispatch).toHaveBeenCalledWith( - `getRewardsFromAllValidators`, + `getRewardsFromMyValidators`, yourValidators ) }) diff --git a/test/unit/specs/components/staking/TabValidators.spec.js b/test/unit/specs/components/staking/TabValidators.spec.js index 7cc6fa6849..9d6f9a22c7 100644 --- a/test/unit/specs/components/staking/TabValidators.spec.js +++ b/test/unit/specs/components/staking/TabValidators.spec.js @@ -183,7 +183,7 @@ describe(`TabValidators`, () => { { $store, yourValidators }, newHeader) expect($store.dispatch).not.toHaveBeenCalledWith( - `getRewardsFromAllValidators`, + `getRewardsFromMyValidators`, yourValidators ) }) @@ -196,7 +196,7 @@ describe(`TabValidators`, () => { { $store, yourValidators }, newHeader) expect($store.dispatch).not.toHaveBeenCalledWith( - `getRewardsFromAllValidators`, + `getRewardsFromMyValidators`, yourValidators ) }) @@ -210,7 +210,7 @@ describe(`TabValidators`, () => { { $store, yourValidators }, newHeader) expect($store.dispatch).toHaveBeenCalledWith( - `getRewardsFromAllValidators`, + `getRewardsFromMyValidators`, yourValidators ) }) diff --git a/test/unit/specs/store/distribution.spec.js b/test/unit/specs/store/distribution.spec.js index 81c90a9b62..ea09c95215 100644 --- a/test/unit/specs/store/distribution.spec.js +++ b/test/unit/specs/store/distribution.spec.js @@ -139,13 +139,13 @@ describe(`Module: Fee Distribution`, () => { }) }) - describe(`getRewardsFromAllValidators`, () => { + describe(`getRewardsFromMyValidators`, () => { it(`success`, async () => { const validators = [ { operator_address: `cosmosvaloper1address1` }, { operator_address: `cosmosvaloper1address2` }, ] - await actions.getRewardsFromAllValidators( + await actions.getRewardsFromMyValidators( { state, dispatch }, validators ) @@ -166,7 +166,7 @@ describe(`Module: Fee Distribution`, () => { { operator_address: `cosmosvaloper1address2` }, ] dispatch = jest.fn(async () => Promise.reject(Error(`invalid address`))) - await expect(actions.getRewardsFromAllValidators( + await expect(actions.getRewardsFromMyValidators( { state, dispatch }, validators) ).rejects.toThrowError(`invalid address`) From 8419257874f48df537645dd6f027054790b5c2bb Mon Sep 17 00:00:00 2001 From: Fabian Date: Fri, 22 Mar 2019 16:44:01 +0100 Subject: [PATCH 02/17] changelog --- PENDING.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/PENDING.md b/PENDING.md index 30e03ef833..c6041c91b6 100644 --- a/PENDING.md +++ b/PENDING.md @@ -2,3 +2,7 @@ - [\#1337](https://github.com/cosmos/voyager/issues/1337) Updated modals tests acording to standard @fedekunze - [\#2328](https://github.com/cosmos/voyager/pull/2328) Changed "Total Rewards" to "Pending Rewards" in the balance header @faboweb + +### Fixed + +- [\#2330](https://github.com/cosmos/voyager/issues/2330) Fixed rewards not updating as expected @faboweb \ No newline at end of file From 6fb84db382b22f2de5ed55496e26ee3053eb4362 Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Sat, 23 Mar 2019 11:37:53 +0100 Subject: [PATCH 03/17] update li transactions --- .../transactions/LiAnyTransaction.vue | 122 ++++++++++-------- .../transactions/LiBankTransaction.vue | 17 ++- .../LiDistributionTransaction.vue | 19 +-- .../transactions/LiGovTransaction.vue | 23 ++-- .../transactions/LiStakeTransaction.vue | 17 ++- .../components/transactions/LiTransaction.vue | 2 +- test/unit/specs/store/json/txs.js | 1 - 7 files changed, 115 insertions(+), 86 deletions(-) diff --git a/app/src/renderer/components/transactions/LiAnyTransaction.vue b/app/src/renderer/components/transactions/LiAnyTransaction.vue index ee1af4f686..0881b2e2b5 100644 --- a/app/src/renderer/components/transactions/LiAnyTransaction.vue +++ b/app/src/renderer/components/transactions/LiAnyTransaction.vue @@ -1,46 +1,61 @@ diff --git a/app/src/renderer/components/transactions/LiStakeTransaction.vue b/app/src/renderer/components/transactions/LiStakeTransaction.vue index 371463c513..44a2eeec58 100644 --- a/app/src/renderer/components/transactions/LiStakeTransaction.vue +++ b/app/src/renderer/components/transactions/LiStakeTransaction.vue @@ -1,8 +1,8 @@