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/2330 poquito requests 2 #2333

Merged
merged 8 commits into from
Mar 24, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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: 4 additions & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 7 additions & 3 deletions app/src/renderer/components/common/TmBalance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export default {
},
data() {
return {
num
num,
lastUpdate: 0
}
},
computed: {
Expand Down Expand Up @@ -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
faboweb marked this conversation as resolved.
Show resolved Hide resolved
if (this.session.signedIn && (height === 0 || waitedTenBlocks)) {
this.lastUpdate = height
this.$store.dispatch(`getTotalRewards`)
this.$store.dispatch(`queryWalletBalances`)
}
Expand Down
17 changes: 4 additions & 13 deletions app/src/renderer/components/staking/TabMyDelegations.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export default {
unbondTransactions: `Transactions currently in the undelegation period`,
validatorURL: `/staking/validators`,
time,
num
num,
lastUpdate: 0
}),
computed: {
...mapGetters([
Expand Down Expand Up @@ -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`)
}
}
},
Expand Down
38 changes: 9 additions & 29 deletions app/src/renderer/components/staking/TabValidators.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,54 +24,34 @@ 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) {
signedIn && this.$store.dispatch(`updateDelegates`)
},
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)
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions app/src/renderer/vuex/getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down Expand Up @@ -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`

Expand All @@ -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 : [])
export const block = state => (state.blocks ? state.blocks.block : [])
31 changes: 22 additions & 9 deletions app/src/renderer/vuex/modules/delegates.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export default ({ node }) => {
globalPower: null,
loading: false,
loaded: false,
error: null
error: null,
lastDelegatesUpdate: 0
faboweb marked this conversation as resolved.
Show resolved Hide resolved
}
const state = JSON.parse(JSON.stringify(emptyState))

Expand Down Expand Up @@ -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
faboweb marked this conversation as resolved.
Show resolved Hide resolved
if (state.lastDelegatesUpdate === 0 || waited10Blocks) {
faboweb marked this conversation as resolved.
Show resolved Hide resolved
state.lastDelegatesUpdate = Number(lastHeader.height)
faboweb marked this conversation as resolved.
Show resolved Hide resolved
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)
Expand Down
48 changes: 36 additions & 12 deletions app/src/renderer/vuex/modules/distribution.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -86,7 +85,10 @@ export default ({ node }) => {
state.loading = false
},
async withdrawAllRewards(
{ rootState: { wallet }, dispatch },
{
rootState: { wallet },
dispatch
},
{ password, submitType }
) {
await dispatch(`sendTx`, {
Expand All @@ -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
faboweb marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
6 changes: 3 additions & 3 deletions test/unit/specs/components/staking/TabMyDelegations.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ describe(`Component: TabMyDelegations`, () => {
{ $store, yourValidators },
newHeader)
expect($store.dispatch).not.toHaveBeenCalledWith(
`getRewardsFromAllValidators`,
`getRewardsFromMyValidators`,
yourValidators
)
})
Expand All @@ -179,7 +179,7 @@ describe(`Component: TabMyDelegations`, () => {
{ $store, yourValidators },
newHeader)
expect($store.dispatch).not.toHaveBeenCalledWith(
`getRewardsFromAllValidators`,
`getRewardsFromMyValidators`,
yourValidators
)
})
Expand All @@ -193,7 +193,7 @@ describe(`Component: TabMyDelegations`, () => {
{ $store, yourValidators },
newHeader)
expect($store.dispatch).toHaveBeenCalledWith(
`getRewardsFromAllValidators`,
`getRewardsFromMyValidators`,
yourValidators
)
})
Expand Down
6 changes: 3 additions & 3 deletions test/unit/specs/components/staking/TabValidators.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ describe(`TabValidators`, () => {
{ $store, yourValidators },
newHeader)
expect($store.dispatch).not.toHaveBeenCalledWith(
`getRewardsFromAllValidators`,
`getRewardsFromMyValidators`,
yourValidators
)
})
Expand All @@ -196,7 +196,7 @@ describe(`TabValidators`, () => {
{ $store, yourValidators },
newHeader)
expect($store.dispatch).not.toHaveBeenCalledWith(
`getRewardsFromAllValidators`,
`getRewardsFromMyValidators`,
yourValidators
)
})
Expand All @@ -210,7 +210,7 @@ describe(`TabValidators`, () => {
{ $store, yourValidators },
newHeader)
expect($store.dispatch).toHaveBeenCalledWith(
`getRewardsFromAllValidators`,
`getRewardsFromMyValidators`,
yourValidators
)
})
Expand Down
6 changes: 3 additions & 3 deletions test/unit/specs/store/distribution.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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`)
Expand Down