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

Colw/graphql validators #2926

Merged
merged 25 commits into from
Sep 2, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions changes/colw_graphql-validators
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Changed] [#2926](https://github.com/cosmos/lunie/pull/2926) Fetch validator information using graphql @colw
2 changes: 1 addition & 1 deletion src/components/common/TmPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default {
default: false
},
error: {
type: Error,
type: Boolean,
default: undefined
},
tabs: {
Expand Down
30 changes: 24 additions & 6 deletions src/components/staking/DelegationsOverview.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<template>
<div>
<div v-if="delegation.loaded && yourValidators.length > 0">
<div v-if="!$apollo.queries.validators.loading && validators.length > 0">
<TableValidators
:validators="yourValidators"
:validators="validators"
show-on-mobile="expectedReturns"
/>
</div>
<TmDataMsg
v-else-if="yourValidators.length === 0"
v-else-if="validators.length === 0"
icon="sentiment_dissatisfied"
>
<div slot="title">
Expand All @@ -23,19 +23,37 @@
</template>

<script>
import { mapState, mapGetters } from "vuex"
import { mapGetters } from "vuex"
import TmDataMsg from "common/TmDataMsg"
import TableValidators from "staking/TableValidators"
import { SomeValidators, AllValidatorsResult } from "src/gql"

export default {
name: `delegations-overview`,
components: {
TableValidators,
TmDataMsg
},
data: () => ({
validators: []
}),
computed: {
...mapState([`delegation`]),
...mapGetters([`bondDenom`, `yourValidators`])
...mapGetters([`committedDelegations`]),
delegationsAddressList() {
return Object.keys(this.committedDelegations)
}
},
apollo: {
validators: {
query: SomeValidators,
variables() {
/* istanbul ignore next */
return {
addressList: this.delegationsAddressList
}
},
update: AllValidatorsResult
}
}
}
</script>
Expand Down
63 changes: 19 additions & 44 deletions src/components/staking/LiValidator.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<tr
class="li-validator"
:data-moniker="validator.description.moniker"
:data-moniker="validator.moniker"
@click="
$router.push({
name: 'validator',
Expand All @@ -10,29 +10,21 @@
"
>
<td class="data-table__row__info">
<ApolloQuery
:query="ValidatorProfile"
:variables="{ address: validator.operator_address }"
:update="validatorProfileResultUpdate"
>
<template v-slot="{ result: { loading, error, data: keybase } }">
<Avatar
v-if="!keybase || !keybase.avatarUrl || loading || error"
class="li-validator-image"
alt="generic validator logo - generated avatar from address"
:address="validator.operator_address"
/>
<img
v-else-if="keybase && keybase.avatarUrl"
:src="keybase.avatarUrl"
class="li-validator-image"
:alt="`validator logo for ` + validator.description.moniker"
/>
</template>
</ApolloQuery>
<Avatar
v-if="!validator || !validator.avatarUrl"
class="li-validator-image"
alt="generic validator logo - generated avatar from address"
:address="validator.operator_address"
/>
<img
v-else-if="validator && validator.avatarUrl"
:src="validator.avatarUrl"
class="li-validator-image"
:alt="`validator logo for ` + validator.moniker"
/>
<div class="validator-info">
<h3 class="li-validator-name">
{{ validator.description.moniker }}
{{ validator.moniker }}
</h3>
<div v-if="validator.my_delegations > 0">
<h4>
Expand All @@ -50,17 +42,14 @@
}}
</td>
<td :class="{ 'hide-xs': showOnMobile !== 'voting-power' }">
{{ validator.tokens ? percentOfVotingPower : `--` }}
{{ validator.voting_power | percent }}
</td>
</tr>
</template>

<script>
import { mapState } from "vuex"
import { percent, shortDecimals, atoms } from "scripts/num"
import Avatar from "common/Avatar"
import BN from "bignumber.js"
import { ValidatorProfile, validatorProfileResultUpdate } from "src/gql"
export default {
name: `li-validator`,
Expand All @@ -69,7 +58,8 @@ export default {
},
filters: {
atoms,
shortDecimals
shortDecimals,
percent
},
props: {
validator: {
Expand All @@ -78,27 +68,12 @@ export default {
},
showOnMobile: {
type: String,
/* istanbul ignore next */
default: () => "returns"
}
},
data: () => ({
ValidatorProfile
}),
computed: {
...mapState([`pool`]),
percentOfVotingPower() {
return percent(
BN(this.validator.tokens)
.div(this.pool.pool.bonded_tokens)
.toFixed(4)
)
}
},
methods: {
shortDecimals,
atoms,
percent,
validatorProfileResultUpdate
percent
}
}
</script>
Expand Down
Loading