update my delegations

This commit is contained in:
liangping 2021-12-14 12:01:37 +08:00
parent 42d5a75ed6
commit 9c26bcd220
4 changed files with 121 additions and 44 deletions

View File

@ -276,7 +276,7 @@ export default class ChainFetch {
if (compareVersions(config ? config.sdk_version : this.config.sdk_version, '0.40') < 0) { if (compareVersions(config ? config.sdk_version : this.config.sdk_version, '0.40') < 0) {
return this.get(`/distribution/delegators/${address}/rewards`, config).then(data => commonProcess(data)) return this.get(`/distribution/delegators/${address}/rewards`, config).then(data => commonProcess(data))
} }
return this.get(`/cosmos/distribution/v1beta1/delegators/${address}/rewards`).then(data => commonProcess(data)) return this.get(`/cosmos/distribution/v1beta1/delegators/${address}/rewards`, config).then(data => commonProcess(data))
} }
async getStakingValidators(address) { async getStakingValidators(address) {

View File

@ -19,7 +19,7 @@
> >
<template #overlay> <template #overlay>
<div class="text-center"> <div class="text-center">
<b-icon <b-avatar
icon="stopwatch" icon="stopwatch"
font-scale="3" font-scale="3"
animation="cylon" animation="cylon"
@ -277,9 +277,10 @@
<script> <script>
import { ValidationProvider, ValidationObserver } from 'vee-validate' import { ValidationProvider, ValidationObserver } from 'vee-validate'
import { import {
BModal, BRow, BCol, BInputGroup, BFormInput, BFormGroup, BFormSelect, BFormSelectOption, BAvatar, BModal, BRow, BCol, BInputGroup, BFormInput, BFormGroup, BFormSelect, BFormSelectOption,
BForm, BFormRadioGroup, BFormRadio, BButton, BInputGroupAppend, BFormCheckbox, BOverlay, BForm, BFormRadioGroup, BFormRadio, BButton, BInputGroupAppend, BFormCheckbox, BOverlay,
} from 'bootstrap-vue' } from 'bootstrap-vue'
import Ripple from 'vue-ripple-directive'
import { import {
required, email, url, between, alpha, integer, password, min, digits, alphaDash, length, required, email, url, between, alpha, integer, password, min, digits, alphaDash, length,
} from '@validations' } from '@validations'
@ -292,6 +293,7 @@ import ToastificationContent from '@core/components/toastification/Toastificatio
export default { export default {
name: 'DelegateDialogue', name: 'DelegateDialogue',
components: { components: {
BAvatar,
BModal, BModal,
BRow, BRow,
BCol, BCol,
@ -314,6 +316,9 @@ export default {
// eslint-disable-next-line vue/no-unused-components // eslint-disable-next-line vue/no-unused-components
ToastificationContent, ToastificationContent,
}, },
directives: {
Ripple,
},
props: { props: {
validatorAddress: { validatorAddress: {
type: String, type: String,
@ -527,8 +532,6 @@ export default {
}).catch(e => { }).catch(e => {
this.error = e this.error = e
}) })
// Send tokens
// return client.sendTokens(this.address, this.recipient, sendCoins, this.memo)
return '' return ''
}, },
}, },

View File

@ -501,24 +501,12 @@ export default {
})) }))
} }
if (this.unbonding) { if (this.unbonding) {
// total = total.concat(this.unbonding.map(x => {
// const xh = x.entries[0]
// xh.type = 'unbonding'
// xh.color = 'text-warning'
// xh.icon = 'TrendingUpIcon'
// return xh
// }))
let tmp1 = 0 let tmp1 = 0
this.unbonding.forEach(x => { this.unbonding.forEach(x => {
x.entries.forEach(e => { x.entries.forEach(e => {
tmp1 += Number(e.balance) tmp1 += Number(e.balance)
}) })
}) })
// this.redelegations.forEach(x => {
// x.entries.forEach(e => {
// tmp1 += Number(e.balance)
// })
// })
const unbonding = this.formatCurrency(tmp1, stakingDenom) const unbonding = this.formatCurrency(tmp1, stakingDenom)
sumCurrency += unbonding sumCurrency += unbonding
sum += tmp1 sum += tmp1
@ -620,19 +608,12 @@ export default {
this.$http.getStakingDelegations(this.address).then(res => { this.$http.getStakingDelegations(this.address).then(res => {
this.delegations = res.delegation_responses || res this.delegations = res.delegation_responses || res
}) })
// this.$http.getStakingRedelegations(this.address).then(res => {
// this.redelegations = res.redelegation_responses || res
// })
this.$http.getStakingUnbonding(this.address).then(res => { this.$http.getStakingUnbonding(this.address).then(res => {
this.unbonding = res.unbonding_responses || res this.unbonding = res.unbonding_responses || res
}) })
this.$http.getTxsBySender(this.address).then(res => { this.$http.getTxsBySender(this.address).then(res => {
this.transactions = res this.transactions = res
}) })
// this.$http.getStakingValidators(this.address).then(res => {
// console.log(res)
// })
}, },
methods: { methods: {
pageload(v) { pageload(v) {

View File

@ -1,9 +1,19 @@
<template> <template>
<div> <div>
<b-card> <router-link
v-if="delegations.length === 0"
to="/wallet/import"
>
<b-card class="addzone text-center">
<feather-icon icon="PlusIcon" />
Connect Wallet
</b-card>
</router-link>
<b-card v-else>
<b-table <b-table
:items="formatedDelegations(delegations)" :items="formatedDelegations"
stacked="sm" stacked="sm"
:fields="fields"
> >
<template #cell(validator)="data"> <template #cell(validator)="data">
@ -17,6 +27,12 @@
{{ data.item.validator.moniker }} {{ data.item.validator.moniker }}
</router-link> </router-link>
</template> </template>
<template #cell(delegator)="data">
<router-link :to="`/${data.item.validator.chain}/account/${data.item.delegator_address}`">
{{ data.value }}<br>
<small>{{ data.item.delegator_address }}</small>
</router-link>
</template>
<template #cell(action)="data"> <template #cell(action)="data">
<!-- size --> <!-- size -->
<b-button-group <b-button-group
@ -27,7 +43,7 @@
v-ripple.400="'rgba(113, 102, 240, 0.15)'" v-ripple.400="'rgba(113, 102, 240, 0.15)'"
v-b-tooltip.hover.top="'Delegate'" v-b-tooltip.hover.top="'Delegate'"
variant="outline-primary" variant="outline-primary"
@click="selectValue(data.value)" @click="selectValue(data.item)"
> >
<feather-icon icon="LogInIcon" /> <feather-icon icon="LogInIcon" />
</b-button> </b-button>
@ -36,7 +52,7 @@
v-ripple.400="'rgba(113, 102, 240, 0.15)'" v-ripple.400="'rgba(113, 102, 240, 0.15)'"
v-b-tooltip.hover.top="'Redelegate'" v-b-tooltip.hover.top="'Redelegate'"
variant="outline-primary" variant="outline-primary"
@click="selectValue(data.value)" @click="selectValue(data.item)"
> >
<feather-icon icon="ShuffleIcon" /> <feather-icon icon="ShuffleIcon" />
</b-button> </b-button>
@ -45,7 +61,7 @@
v-ripple.400="'rgba(113, 102, 240, 0.15)'" v-ripple.400="'rgba(113, 102, 240, 0.15)'"
v-b-tooltip.hover.top="'Unbond'" v-b-tooltip.hover.top="'Unbond'"
variant="outline-primary" variant="outline-primary"
@click="selectValue(data.value)" @click="selectValue(data.item)"
> >
<feather-icon icon="LogOutIcon" /> <feather-icon icon="LogOutIcon" />
</b-button> </b-button>
@ -53,6 +69,19 @@
</template> </template>
</b-table> </b-table>
</b-card> </b-card>
<operation-withdraw-component :address="address" />
<operation-unbond-component
:address="address"
:validator-address.sync="selectedValidator"
/>
<operation-delegate-component
:address="address"
:validator-address.sync="selectedValidator"
/>
<operation-redelegate-component
:address="address"
:validator-address.sync="selectedValidator"
/>
</div> </div>
</template> </template>
@ -62,10 +91,15 @@ import {
} from 'bootstrap-vue' } from 'bootstrap-vue'
import Ripple from 'vue-ripple-directive' import Ripple from 'vue-ripple-directive'
import { import {
formatToken, getCachedValidators, getLocalAccounts, getLocalChains, formatToken, getCachedValidators, getLocalAccounts, getLocalChains, tokenFormatter,
} from '@/libs/data' } from '@/libs/data'
import FeatherIcon from '@/@core/components/feather-icon/FeatherIcon.vue' import FeatherIcon from '@/@core/components/feather-icon/FeatherIcon.vue'
import OperationWithdrawComponent from './OperationWithdrawComponent.vue'
import OperationUnbondComponent from './OperationUnbondComponent.vue'
import OperationDelegateComponent from './OperationDelegateComponent.vue'
import OperationRedelegateComponent from './OperationRedelegateComponent.vue'
export default { export default {
components: { components: {
BAvatar, BAvatar,
@ -74,6 +108,11 @@ export default {
BTable, BTable,
BCard, BCard,
FeatherIcon, FeatherIcon,
OperationWithdrawComponent,
OperationDelegateComponent,
OperationRedelegateComponent,
OperationUnbondComponent,
}, },
directives: { directives: {
'b-tooltip': VBTooltip, 'b-tooltip': VBTooltip,
@ -81,23 +120,38 @@ export default {
}, },
data() { data() {
return { return {
fields: [
{
key: 'validator',
sortable: true,
// sortByFormatted: true,
},
{
key: 'delegator',
sortable: true,
// sortByFormatted: true,
},
{
key: 'delegation',
sortable: true,
// sortByFormatted: true,
},
{
key: 'reward',
sortable: true,
// sortByFormatted: true,
},
],
address: '',
selectedValidator: '',
accounts: [], accounts: [],
delegations: [], delegations: [],
rewards: {},
} }
}, },
computed: { computed: {
formatedDelegations() {
}, return this.delegations.map(x => ({
created() {
this.init()
},
methods: {
selectValue(v) {
return v
},
formatedDelegations(v) {
// console.log('v', v)
return v.map(x => ({
validator: { validator: {
logo: x.chain.logo, logo: x.chain.logo,
validator: x.delegation.validator_address, validator: x.delegation.validator_address,
@ -105,10 +159,23 @@ export default {
chain: x.chain.chain_name, chain: x.chain.chain_name,
}, },
delegator: x.keyname, delegator: x.keyname,
delegator_address: x.delegation.delegator_address,
delegation: formatToken(x.balance), delegation: formatToken(x.balance),
reward: this.findReward(x.delegation.delegator_address, x.delegation.validator_address),
// action: '', // action: '',
})) }))
}, },
},
created() {
this.init()
},
methods: {
selectValue(v) {
this.address = v.delegator_address
this.selectedValidator = v.validator.validator
console.log(v, this.address, this.selectedValidator)
return v
},
findMoniker(chain, addr) { findMoniker(chain, addr) {
const vals = JSON.parse(getCachedValidators(chain)) const vals = JSON.parse(getCachedValidators(chain))
const val = vals.find(x => x.operator_address === addr) const val = vals.find(x => x.operator_address === addr)
@ -117,18 +184,30 @@ export default {
} }
return addr return addr
}, },
findReward(delegator, validator) {
const reward = this.rewards[delegator]?.rewards.find(x => x.validator_address === validator) || null
console.log(reward, delegator, validator)
if (reward) {
return tokenFormatter(reward.reward)
}
return '-'
},
init() { init() {
this.accounts = getLocalAccounts() this.accounts = getLocalAccounts()
const chains = getLocalChains() const chains = getLocalChains()
if (this.accounts) { if (this.accounts) {
Object.keys(this.accounts).forEach(acc => { Object.keys(this.accounts).forEach(acc => {
this.accounts[acc].address.forEach(add => { this.accounts[acc].address.forEach(add => {
this.$http.getStakingDelegations(add.addr, chains[add.chain]).then(res => { const chain = chains[add.chain]
this.$http.getStakingReward(add.addr, chain).then(res => {
this.rewards[add.addr] = res
})
this.$http.getStakingDelegations(add.addr, chain).then(res => {
if (res.delegation_responses && res.delegation_responses.length > 0) { if (res.delegation_responses && res.delegation_responses.length > 0) {
const delegation = res.delegation_responses.map(x => { const delegation = res.delegation_responses.map(x => {
const x2 = x const x2 = x
x2.keyname = acc x2.keyname = acc
x2.chain = chains[add.chain] x2.chain = chain
return x2 return x2
}) })
this.delegations = this.delegations.concat(delegation) this.delegations = this.delegations.concat(delegation)
@ -141,3 +220,17 @@ export default {
}, },
} }
</script> </script>
<style lang="css">
.addzone {
border: 2px dashed #ced4da;
background: #fff;
border-radius: 6px;
cursor: pointer;
box-shadow: none;
}
.addzone :hover {
border: 2px dashed #7367F0;
}
</style>