add tx history and delegations

This commit is contained in:
liangping 2021-12-22 15:43:07 +08:00
parent af9f1cac45
commit 8d5cdbf0f4
12 changed files with 132 additions and 56 deletions

View File

@ -43,7 +43,8 @@ export function getLocalTxHistory() {
return getLocalObject('txHistory') return getLocalObject('txHistory')
} }
export function setLocalTxHistory(newTx) { export function setLocalTxHistory(tx) {
const newTx = tx
const txs = getLocalTxHistory() const txs = getLocalTxHistory()
if (txs) { if (txs) {
txs.push(newTx) txs.push(newTx)

View File

@ -516,7 +516,12 @@ export default {
signerData, signerData,
).then(bodyBytes => { ).then(bodyBytes => {
this.$http.broadcastTx(bodyBytes).then(res => { this.$http.broadcastTx(bodyBytes).then(res => {
setLocalTxHistory({ op: 'delegate', hash: res.tx_response.txhash, time: new Date() }) setLocalTxHistory({
chain: this.$store.state.chains.selected,
op: 'delegate',
hash: res.tx_response.txhash,
time: new Date(),
})
this.$bvModal.hide('delegate-window') this.$bvModal.hide('delegate-window')
this.$toast({ this.$toast({
component: ToastificationContent, component: ToastificationContent,

View File

@ -457,7 +457,12 @@ export default {
signerData, signerData,
).then(bodyBytes => { ).then(bodyBytes => {
this.$http.broadcastTx(bodyBytes, this.selectedChain).then(res => { this.$http.broadcastTx(bodyBytes, this.selectedChain).then(res => {
setLocalTxHistory({ op: 'deposit', hash: res.tx_response.txhash, time: new Date() }) setLocalTxHistory({
chain: this.$store.state.chains.selected,
op: 'deposit',
hash: res.tx_response.txhash,
time: new Date(),
})
this.$bvModal.hide('deposit-window') this.$bvModal.hide('deposit-window')
this.$toast({ this.$toast({
component: ToastificationContent, component: ToastificationContent,

View File

@ -453,7 +453,12 @@ export default {
signerData, signerData,
).then(bodyBytes => { ).then(bodyBytes => {
this.$http.broadcastTx(bodyBytes).then(res => { this.$http.broadcastTx(bodyBytes).then(res => {
setLocalTxHistory({ op: 'redelegate', hash: res.tx_response.txhash, time: new Date() }) setLocalTxHistory({
chain: this.$store.state.chains.selected,
op: 'redelegate',
hash: res.tx_response.txhash,
time: new Date(),
})
this.$bvModal.hide('redelegate-window') this.$bvModal.hide('redelegate-window')
this.$toast({ this.$toast({
component: ToastificationContent, component: ToastificationContent,

View File

@ -552,7 +552,12 @@ export default {
signerData, signerData,
).then(bodyBytes => { ).then(bodyBytes => {
this.$http.broadcastTx(bodyBytes, this.selectedChain).then(res => { this.$http.broadcastTx(bodyBytes, this.selectedChain).then(res => {
setLocalTxHistory({ op: 'send', hash: res.txhash, time: new Date() }) setLocalTxHistory({
chain: this.$store.state.chains.selected,
op: 'transfer',
hash: res.tx_response.txhash,
time: new Date(),
})
this.$bvModal.hide('ibc-transfer-window') this.$bvModal.hide('ibc-transfer-window')
this.$toast({ this.$toast({
component: ToastificationContent, component: ToastificationContent,

View File

@ -455,7 +455,12 @@ export default {
signerData, signerData,
).then(bodyBytes => { ).then(bodyBytes => {
this.$http.broadcastTx(bodyBytes, this.selectedChain).then(res => { this.$http.broadcastTx(bodyBytes, this.selectedChain).then(res => {
setLocalTxHistory({ op: 'send', hash: res.txhash, time: new Date() }) setLocalTxHistory({
chain: this.$store.state.chains.selected,
op: 'send',
hash: res.tx_response.txhash,
time: new Date(),
})
this.$bvModal.hide('transfer-window') this.$bvModal.hide('transfer-window')
this.$toast({ this.$toast({
component: ToastificationContent, component: ToastificationContent,

View File

@ -431,7 +431,12 @@ export default {
signerData, signerData,
).then(bodyBytes => { ).then(bodyBytes => {
this.$http.broadcastTx(bodyBytes, this.selectedChain).then(res => { this.$http.broadcastTx(bodyBytes, this.selectedChain).then(res => {
setLocalTxHistory({ op: 'unbond', hash: res.tx_response.txhash, time: new Date() }) setLocalTxHistory({
chain: this.$store.state.chains.selected,
op: 'unbond',
hash: res.tx_response.txhash,
time: new Date(),
})
this.$bvModal.hide('unbond-window') this.$bvModal.hide('unbond-window')
this.$toast({ this.$toast({
component: ToastificationContent, component: ToastificationContent,

View File

@ -432,7 +432,12 @@ export default {
signerData, signerData,
).then(bodyBytes => { ).then(bodyBytes => {
this.$http.broadcastTx(bodyBytes, this.selectedChain).then(res => { this.$http.broadcastTx(bodyBytes, this.selectedChain).then(res => {
setLocalTxHistory({ op: 'vote', hash: res.tx_response.txhash, time: new Date() }) setLocalTxHistory({
chain: this.$store.state.chains.selected,
op: 'vote',
hash: res.tx_response.txhash,
time: new Date(),
})
this.$bvModal.hide('vote-window') this.$bvModal.hide('vote-window')
this.$toast({ this.$toast({
component: ToastificationContent, component: ToastificationContent,

View File

@ -338,7 +338,12 @@ export default {
signerData, signerData,
).then(bodyBytes => { ).then(bodyBytes => {
this.$http.broadcastTx(bodyBytes, this.selectedChain).then(res => { this.$http.broadcastTx(bodyBytes, this.selectedChain).then(res => {
setLocalTxHistory({ op: 'withdraw', hash: res.tx_response.txhash, time: new Date() }) setLocalTxHistory({
chain: this.$store.state.chains.selected,
op: 'withdraw',
hash: res.tx_response.txhash,
time: new Date(),
})
this.$bvModal.hide('withdraw-commission-window') this.$bvModal.hide('withdraw-commission-window')
this.$toast({ this.$toast({
component: ToastificationContent, component: ToastificationContent,

View File

@ -363,7 +363,12 @@ export default {
signerData, signerData,
).then(bodyBytes => { ).then(bodyBytes => {
this.$http.broadcastTx(bodyBytes, this.selectedChain).then(res => { this.$http.broadcastTx(bodyBytes, this.selectedChain).then(res => {
setLocalTxHistory({ op: 'withdraw', hash: res.tx_response.txhash, time: new Date() }) setLocalTxHistory({
chain: this.$store.state.chains.selected,
op: 'withdraw',
hash: res.tx_response.txhash,
time: new Date(),
})
this.$bvModal.hide('withdraw-window') this.$bvModal.hide('withdraw-window')
this.$toast({ this.$toast({
component: ToastificationContent, component: ToastificationContent,

View File

@ -9,9 +9,13 @@
Connect Wallet Connect Wallet
</b-card> </b-card>
</router-link> </router-link>
<b-card v-else> <b-card
v-for="(items,k) in groupedDelegations"
:key="k"
:title="k"
>
<b-table <b-table
:items="formatedDelegations" :items="items"
stacked="sm" stacked="sm"
:fields="fields" :fields="fields"
> >
@ -29,8 +33,7 @@
</template> </template>
<template #cell(delegator)="data"> <template #cell(delegator)="data">
<router-link :to="`/${data.item.validator.chain}/account/${data.item.delegator_address}`"> <router-link :to="`/${data.item.validator.chain}/account/${data.item.delegator_address}`">
{{ data.value }}<br> Withdraw
<small>{{ data.item.delegator_address }}</small>
</router-link> </router-link>
</template> </template>
<template #cell(action)="data"> <template #cell(action)="data">
@ -69,6 +72,8 @@
</template> </template>
</b-table> </b-table>
</b-card> </b-card>
<!--- not completed--->
<operation-withdraw-component :address="address" /> <operation-withdraw-component :address="address" />
<operation-unbond-component <operation-unbond-component
:address="address" :address="address"
@ -126,11 +131,6 @@ export default {
sortable: true, sortable: true,
// sortByFormatted: true, // sortByFormatted: true,
}, },
{
key: 'delegator',
sortable: true,
// sortByFormatted: true,
},
{ {
key: 'delegation', key: 'delegation',
sortable: true, sortable: true,
@ -141,6 +141,12 @@ export default {
sortable: true, sortable: true,
// sortByFormatted: true, // sortByFormatted: true,
}, },
{
key: 'delegator',
label: '',
sortable: true,
// sortByFormatted: true,
},
], ],
address: '', address: '',
selectedValidator: '', selectedValidator: '',
@ -165,6 +171,30 @@ export default {
// action: '', // action: '',
})) }))
}, },
groupedDelegations() {
const group = {}
this.delegations.forEach(x => {
const d = {
validator: {
logo: x.chain.logo,
validator: x.delegation.validator_address,
moniker: this.findMoniker(x.chain.chain_name, x.delegation.validator_address),
chain: x.chain.chain_name,
},
delegator: x.keyname,
delegator_address: x.delegation.delegator_address,
delegation: formatToken(x.balance),
reward: this.findReward(x.delegation.delegator_address, x.delegation.validator_address),
// action: '',
}
if (group[x.keyname]) {
group[x.keyname].push(d)
} else {
group[x.keyname] = [d]
}
})
return group
},
}, },
created() { created() {
this.init() this.init()

View File

@ -1,62 +1,62 @@
<template> <template>
<div> <div>
<b-table <b-table
:items="deleTable" :items="history"
:fields="fields"
stacked="sm" stacked="sm"
> >
<template #cell(action)="data"> <template #cell(chain)="data">
<!-- size --> <b-avatar
<b-button-group
size="sm" size="sm"
> :src="data.item.chain.logo"
<b-button /> {{ data.item.chain.chain_name }}
v-b-modal.delegate-window </template>
v-ripple.400="'rgba(113, 102, 240, 0.15)'" <template #cell(hash)="data">
v-b-tooltip.hover.top="'Delegate'" <router-link :to="`/${data.item.chain.chain_name}/tx/${data.value}`">
variant="outline-primary" {{ data.value }}
@click="selectValue(data.value)" </router-link>
>
<feather-icon icon="LogInIcon" />
</b-button>
<b-button
v-b-modal.redelegate-window
v-ripple.400="'rgba(113, 102, 240, 0.15)'"
v-b-tooltip.hover.top="'Redelegate'"
variant="outline-primary"
@click="selectValue(data.value)"
>
<feather-icon icon="ShuffleIcon" />
</b-button>
<b-button
v-b-modal.unbond-window
v-ripple.400="'rgba(113, 102, 240, 0.15)'"
v-b-tooltip.hover.top="'Unbond'"
variant="outline-primary"
@click="selectValue(data.value)"
>
<feather-icon icon="LogOutIcon" />
</b-button>
</b-button-group>
</template> </template>
</b-table> </b-table>
<div class="text-center">
<b-button @click="clear()">
Clear History
</b-button>
</div>
</div> </div>
</template> </template>
<script> <script>
import { import {
BButton, VBTooltip, BTable, VBTooltip, BTable, BAvatar, BButton,
} from 'bootstrap-vue' } from 'bootstrap-vue'
import { getLocalTxHistory } from '@/libs/utils'
export default { export default {
components: { components: {
BButton, BTable, BAvatar, BButton,
BTable,
}, },
directives: { directives: {
'b-tooltip': VBTooltip, 'b-tooltip': VBTooltip,
}, },
data() {
return {
fields: [
{ key: 'chain', label: 'BLOCKCHAIN' },
{ key: 'op', label: 'ACTION' },
{ key: 'hash', label: 'TX HASH' },
{ key: 'time', label: 'TIME' },
],
history: [],
}
},
created() { created() {
this.history = getLocalTxHistory()
},
methods: {
clear() {
this.history = []
localStorage.setItem('txHistory', [])
},
}, },
} }
</script> </script>