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')
}
export function setLocalTxHistory(newTx) {
export function setLocalTxHistory(tx) {
const newTx = tx
const txs = getLocalTxHistory()
if (txs) {
txs.push(newTx)

View File

@ -516,7 +516,12 @@ export default {
signerData,
).then(bodyBytes => {
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.$toast({
component: ToastificationContent,

View File

@ -457,7 +457,12 @@ export default {
signerData,
).then(bodyBytes => {
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.$toast({
component: ToastificationContent,

View File

@ -453,7 +453,12 @@ export default {
signerData,
).then(bodyBytes => {
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.$toast({
component: ToastificationContent,

View File

@ -552,7 +552,12 @@ export default {
signerData,
).then(bodyBytes => {
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.$toast({
component: ToastificationContent,

View File

@ -455,7 +455,12 @@ export default {
signerData,
).then(bodyBytes => {
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.$toast({
component: ToastificationContent,

View File

@ -431,7 +431,12 @@ export default {
signerData,
).then(bodyBytes => {
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.$toast({
component: ToastificationContent,

View File

@ -432,7 +432,12 @@ export default {
signerData,
).then(bodyBytes => {
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.$toast({
component: ToastificationContent,

View File

@ -338,7 +338,12 @@ export default {
signerData,
).then(bodyBytes => {
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.$toast({
component: ToastificationContent,

View File

@ -363,7 +363,12 @@ export default {
signerData,
).then(bodyBytes => {
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.$toast({
component: ToastificationContent,

View File

@ -9,9 +9,13 @@
Connect Wallet
</b-card>
</router-link>
<b-card v-else>
<b-card
v-for="(items,k) in groupedDelegations"
:key="k"
:title="k"
>
<b-table
:items="formatedDelegations"
:items="items"
stacked="sm"
:fields="fields"
>
@ -29,8 +33,7 @@
</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>
Withdraw
</router-link>
</template>
<template #cell(action)="data">
@ -69,6 +72,8 @@
</template>
</b-table>
</b-card>
<!--- not completed--->
<operation-withdraw-component :address="address" />
<operation-unbond-component
:address="address"
@ -126,11 +131,6 @@ export default {
sortable: true,
// sortByFormatted: true,
},
{
key: 'delegator',
sortable: true,
// sortByFormatted: true,
},
{
key: 'delegation',
sortable: true,
@ -141,6 +141,12 @@ export default {
sortable: true,
// sortByFormatted: true,
},
{
key: 'delegator',
label: '',
sortable: true,
// sortByFormatted: true,
},
],
address: '',
selectedValidator: '',
@ -165,6 +171,30 @@ export default {
// 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() {
this.init()

View File

@ -1,62 +1,62 @@
<template>
<div>
<b-table
:items="deleTable"
:items="history"
:fields="fields"
stacked="sm"
>
<template #cell(action)="data">
<!-- size -->
<b-button-group
<template #cell(chain)="data">
<b-avatar
size="sm"
>
<b-button
v-b-modal.delegate-window
v-ripple.400="'rgba(113, 102, 240, 0.15)'"
v-b-tooltip.hover.top="'Delegate'"
variant="outline-primary"
@click="selectValue(data.value)"
>
<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>
:src="data.item.chain.logo"
/> {{ data.item.chain.chain_name }}
</template>
<template #cell(hash)="data">
<router-link :to="`/${data.item.chain.chain_name}/tx/${data.value}`">
{{ data.value }}
</router-link>
</template>
</b-table>
<div class="text-center">
<b-button @click="clear()">
Clear History
</b-button>
</div>
</div>
</template>
<script>
import {
BButton, VBTooltip, BTable,
VBTooltip, BTable, BAvatar, BButton,
} from 'bootstrap-vue'
import { getLocalTxHistory } from '@/libs/utils'
export default {
components: {
BButton,
BTable,
BTable, BAvatar, BButton,
},
directives: {
'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() {
this.history = getLocalTxHistory()
},
methods: {
clear() {
this.history = []
localStorage.setItem('txHistory', [])
},
},
}
</script>