Skip to content

Commit

Permalink
Ana/fix rewards updating (#3235)
Browse files Browse the repository at this point in the history
* fix lint error

* fix more lint errors

* add userrewardsincremented. err cannot query field

* changelog

* fix user rewards increment add validator fragment

* get rid of user rewards increment subscription

* rewards updating in tmbalance

* update rewards also for validators

* delete unnecessary code

* delete usertransaction added completely

* pass logic from livalidator to tablevalidators

* fix lint
  • Loading branch information
Bitcoinera authored and faboweb committed Dec 3, 2019
1 parent 8a2915a commit 067d24a
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 24 deletions.
1 change: 1 addition & 0 deletions changes/ana_fix-rewards-updating
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Added] [#3095](https://github.com/cosmos/lunie/issues/3095) Add the subscription to automatically update the user rewards @Bitcoinera
20 changes: 20 additions & 0 deletions src/components/common/TmBalance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,26 @@ export default {
// query if successful or not as even an unsuccessful tx costs fees
refetchNetworkOnly(this.$apollo.queries.overview)
}
},
blockAdded: {
variables() {
return {
networkId: this.network
}
},
query() {
return gql`
subscription($networkId: String!) {
blockAdded(networkId: $networkId) {
height
chainId
}
}
`
},
result() {
refetchNetworkOnly(this.$apollo.queries.overview)
}
}
}
}
Expand Down
11 changes: 0 additions & 11 deletions src/components/staking/LiValidator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
<script>
import { percent, shortDecimals, atoms } from "scripts/num"
import Avatar from "common/Avatar"
export default {
name: `li-validator`,
components: {
Expand Down Expand Up @@ -109,50 +108,42 @@ export default {
border-bottom: 1px solid var(--bc-dim);
border-radius: 0.25rem;
}
.li-validator:last-child {
border-bottom: none;
}
.validator-info {
display: flex;
flex-direction: column;
padding-left: 1rem;
text-overflow: ellipsis;
}
.li-validator h4,
.li-validator h5 {
font-size: var(--sm);
display: inline-block;
}
.li-validator h5 {
padding-left: 0.5rem;
color: var(--success);
}
.li-validator:hover {
cursor: pointer;
background: var(--hover-bg);
color: var(--bright);
}
.li-validator-name {
font-size: 1rem;
line-height: 18px;
font-weight: 500;
color: var(--bright);
display: inline-block;
}
.li-validator-image {
border-radius: 0.25rem;
height: 2.5rem;
width: 2.5rem;
border: 1px solid var(--bc-dim);
}
.validator-status {
text-transform: uppercase;
font-size: 10px;
Expand All @@ -161,12 +152,10 @@ export default {
padding: 2px 4px;
border-radius: 0.25rem;
}
.validator-status.inactive {
color: var(--warning);
border-color: var(--warning);
}
.validator-status.active {
color: var(--success);
border-color: var(--success);
Expand Down
28 changes: 15 additions & 13 deletions src/components/staking/PageValidator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,15 @@ import moment from "moment"
import { mapGetters, mapState } from "vuex"
import { atoms, shortDecimals, fullDecimals, percent } from "scripts/num"
import { noBlanks, fromNow } from "src/filters"
import refetchNetworkOnly from "scripts/refetch-network-only"
import TmBtn from "common/TmBtn"
import DelegationModal from "src/ActionModal/components/DelegationModal"
import UndelegationModal from "src/ActionModal/components/UndelegationModal"
import Avatar from "common/Avatar"
import Bech32 from "common/Bech32"
import TmPage from "common/TmPage"
import gql from "graphql-tag"
import { ValidatorProfile, UserTransactionAdded } from "src/gql"
import { ValidatorProfile } from "src/gql"
function getStatusText(statusDetailed) {
switch (statusDetailed) {
Expand Down Expand Up @@ -334,23 +335,24 @@ export default {
}
},
$subscribe: {
userTransactionAdded: {
blockAdded: {
variables() {
return {
networkId: this.network,
address: this.userAddress
networkId: this.network
}
},
skip() {
return !this.userAddress
query() {
return gql`
subscription($networkId: String!) {
blockAdded(networkId: $networkId) {
height
chainId
}
}
`
},
query: UserTransactionAdded,
result({ data }) {
if (data.userTransactionAdded.success) {
this.$apollo.queries.validator.refetch()
this.$apollo.queries.rewards.refetch()
this.$apollo.queries.delegation.refetch()
}
result() {
refetchNetworkOnly(this.$apollo.queries.rewards)
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions src/components/staking/TableValidators.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

<script>
import { mapGetters } from "vuex"
import refetchNetworkOnly from "scripts/refetch-network-only"
import orderBy from "lodash.orderby"
import LiValidator from "staking/LiValidator"
import PanelSort from "staking/PanelSort"
Expand Down Expand Up @@ -152,6 +153,28 @@ export default {
update: result => {
return result.rewards || []
}
},
$subscribe: {
blockAdded: {
variables() {
return {
networkId: this.network
}
},
query() {
return gql`
subscription($networkId: String!) {
blockAdded(networkId: $networkId) {
height
chainId
}
}
`
},
result() {
refetchNetworkOnly(this.$apollo.queries.rewards)
}
}
}
}
}
Expand Down

0 comments on commit 067d24a

Please sign in to comment.