redelegate
This commit is contained in:
parent
b8678a9baa
commit
15e6b92ece
@ -128,6 +128,7 @@
|
|||||||
variant="primary"
|
variant="primary"
|
||||||
size="sm"
|
size="sm"
|
||||||
class="mr-25"
|
class="mr-25"
|
||||||
|
@click="setOperationModalType('Delegate')"
|
||||||
>
|
>
|
||||||
<feather-icon
|
<feather-icon
|
||||||
icon="LogInIcon"
|
icon="LogInIcon"
|
||||||
@ -186,6 +187,15 @@
|
|||||||
>
|
>
|
||||||
<feather-icon icon="ShuffleIcon" />
|
<feather-icon icon="ShuffleIcon" />
|
||||||
</b-button>
|
</b-button>
|
||||||
|
<b-button
|
||||||
|
v-b-modal.operation-modal
|
||||||
|
v-ripple.400="'rgba(113, 102, 240, 0.15)'"
|
||||||
|
v-b-tooltip.hover.top="'Redelegate'"
|
||||||
|
variant="outline-primary"
|
||||||
|
@click="selectValue(data.value,'Redelegate')"
|
||||||
|
>
|
||||||
|
<feather-icon icon="ShuffleIcon" />
|
||||||
|
</b-button>
|
||||||
<b-button
|
<b-button
|
||||||
v-b-modal.unbond-window
|
v-b-modal.unbond-window
|
||||||
v-ripple.400="'rgba(113, 102, 240, 0.15)'"
|
v-ripple.400="'rgba(113, 102, 240, 0.15)'"
|
||||||
@ -365,9 +375,9 @@
|
|||||||
:validator-address.sync="selectedValidator"
|
:validator-address.sync="selectedValidator"
|
||||||
/>
|
/>
|
||||||
<operation-modal
|
<operation-modal
|
||||||
type="Delegate"
|
:type="operationModalType"
|
||||||
:address="address"
|
:address="address"
|
||||||
:validator-address.sync="selectedValidator"
|
:validator-address="selectedValidator"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -452,6 +462,7 @@ export default {
|
|||||||
unbonding: [],
|
unbonding: [],
|
||||||
quotes: {},
|
quotes: {},
|
||||||
transactions: [],
|
transactions: [],
|
||||||
|
operationModalType: '',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -638,8 +649,12 @@ export default {
|
|||||||
this.transactions = res
|
this.transactions = res
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
selectValue(v) {
|
selectValue(v, type) {
|
||||||
this.selectedValidator = v
|
this.selectedValidator = v
|
||||||
|
this.setOperationModalType(type)
|
||||||
|
},
|
||||||
|
setOperationModalType(type) {
|
||||||
|
this.operationModalType = type
|
||||||
},
|
},
|
||||||
formatHash: abbrAddress,
|
formatHash: abbrAddress,
|
||||||
formatDenom(v) {
|
formatDenom(v) {
|
||||||
|
@ -210,13 +210,20 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
console.log('mounted----------->')
|
|
||||||
this.loadBalance()
|
this.loadBalance()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
printDenom() {
|
loadBalance() {
|
||||||
return formatTokenDenom(this.IBCDenom[this.token] || this.token)
|
this.account = this.computeAccount()
|
||||||
|
this.$http.getValidatorList().then(v => {
|
||||||
|
this.validators = v
|
||||||
|
})
|
||||||
|
this.$http.getValidatorUnbondedList().then(v => {
|
||||||
|
this.unbundValidators = v
|
||||||
|
})
|
||||||
|
this.onChange()
|
||||||
},
|
},
|
||||||
|
|
||||||
onChange() {
|
onChange() {
|
||||||
if (this.selectedAddress) {
|
if (this.selectedAddress) {
|
||||||
this.$http.getBankBalances(this.selectedAddress).then(res => {
|
this.$http.getBankBalances(this.selectedAddress).then(res => {
|
||||||
@ -234,7 +241,8 @@ export default {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
console.log(this.$parent)
|
console.log('onChange----------->')
|
||||||
|
// TODO: this.$emit()
|
||||||
// this.$parent.getAuthAccount(this.selectedAddress)
|
// this.$parent.getAuthAccount(this.selectedAddress)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -254,17 +262,10 @@ export default {
|
|||||||
this.selectedValidator = this.validatorAddress
|
this.selectedValidator = this.validatorAddress
|
||||||
return array
|
return array
|
||||||
},
|
},
|
||||||
loadBalance() {
|
printDenom() {
|
||||||
this.account = this.computeAccount()
|
return formatTokenDenom(this.IBCDenom[this.token] || this.token)
|
||||||
// if (this.account && this.account.length > 0) this.selectedAddress
|
|
||||||
this.$http.getValidatorList().then(v => {
|
|
||||||
this.validators = v
|
|
||||||
})
|
|
||||||
this.$http.getValidatorUnbondedList().then(v => {
|
|
||||||
this.unbundValidators = v
|
|
||||||
})
|
|
||||||
this.onChange()
|
|
||||||
},
|
},
|
||||||
|
|
||||||
format(v) {
|
format(v) {
|
||||||
return formatToken(v, this.IBCDenom)
|
return formatToken(v, this.IBCDenom)
|
||||||
},
|
},
|
||||||
|
240
src/views/components/OperationModal/components/Redelegate.vue
Normal file
240
src/views/components/OperationModal/components/Redelegate.vue
Normal file
@ -0,0 +1,240 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<b-row>
|
||||||
|
<b-col>
|
||||||
|
<b-form-group
|
||||||
|
label="Delegator"
|
||||||
|
label-for="Account"
|
||||||
|
>
|
||||||
|
<validation-provider
|
||||||
|
#default="{ errors }"
|
||||||
|
rules="required"
|
||||||
|
name="Delegator"
|
||||||
|
>
|
||||||
|
<b-form-input
|
||||||
|
v-model="address"
|
||||||
|
readonly
|
||||||
|
/>
|
||||||
|
<small class="text-danger">{{ errors[0] }}</small>
|
||||||
|
</validation-provider>
|
||||||
|
</b-form-group>
|
||||||
|
</b-col>
|
||||||
|
</b-row>
|
||||||
|
<b-row>
|
||||||
|
<b-col>
|
||||||
|
<b-form-group
|
||||||
|
label="From Validator"
|
||||||
|
label-for="validator"
|
||||||
|
>
|
||||||
|
<v-select
|
||||||
|
:value="validatorAddress"
|
||||||
|
:options="valOptions"
|
||||||
|
:reduce="val => val.value"
|
||||||
|
placeholder="Select a validator"
|
||||||
|
:disabled="true"
|
||||||
|
/>
|
||||||
|
</b-form-group>
|
||||||
|
</b-col>
|
||||||
|
</b-row>
|
||||||
|
<b-row>
|
||||||
|
<b-col>
|
||||||
|
<b-form-group
|
||||||
|
label="Current Delegation"
|
||||||
|
label-for="Token"
|
||||||
|
>
|
||||||
|
<validation-provider
|
||||||
|
#default="{ errors }"
|
||||||
|
rules="required"
|
||||||
|
name="Token"
|
||||||
|
>
|
||||||
|
<v-select
|
||||||
|
v-model="token"
|
||||||
|
:options="tokenOptions"
|
||||||
|
:reduce="token => token.value"
|
||||||
|
/>
|
||||||
|
<small class="text-danger">{{ errors[0] }}</small>
|
||||||
|
</validation-provider>
|
||||||
|
</b-form-group>
|
||||||
|
</b-col>
|
||||||
|
</b-row>
|
||||||
|
<b-row>
|
||||||
|
<b-col>
|
||||||
|
<b-form-group
|
||||||
|
label="To Validator"
|
||||||
|
label-for="validator"
|
||||||
|
>
|
||||||
|
<v-select
|
||||||
|
v-model="toValidator"
|
||||||
|
:options="valOptions"
|
||||||
|
:reduce="val => val.value"
|
||||||
|
placeholder="Select a validator"
|
||||||
|
/>
|
||||||
|
</b-form-group>
|
||||||
|
</b-col>
|
||||||
|
</b-row>
|
||||||
|
<b-row>
|
||||||
|
<b-col>
|
||||||
|
<b-form-group
|
||||||
|
label="Amount"
|
||||||
|
label-for="Amount"
|
||||||
|
>
|
||||||
|
<validation-provider
|
||||||
|
v-slot="{ errors }"
|
||||||
|
rules="required|regex:^([0-9\.]+)$"
|
||||||
|
name="amount"
|
||||||
|
>
|
||||||
|
<b-input-group>
|
||||||
|
<b-form-input
|
||||||
|
id="Amount"
|
||||||
|
v-model="amount"
|
||||||
|
:state="errors.length > 0 ? false:null"
|
||||||
|
placeholder="Input a number"
|
||||||
|
type="number"
|
||||||
|
/>
|
||||||
|
<b-input-group-append is-text>
|
||||||
|
{{ printDenom() }}
|
||||||
|
</b-input-group-append>
|
||||||
|
</b-input-group>
|
||||||
|
<small class="text-danger">{{ errors[0] }}</small>
|
||||||
|
</validation-provider>
|
||||||
|
</b-form-group>
|
||||||
|
</b-col>
|
||||||
|
</b-row>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { ValidationProvider } from 'vee-validate'
|
||||||
|
import {
|
||||||
|
BRow, BCol, BInputGroup, BFormInput, BFormGroup,
|
||||||
|
BInputGroupAppend,
|
||||||
|
} from 'bootstrap-vue'
|
||||||
|
import {
|
||||||
|
required, email, url, between, alpha, integer, password, min, digits, alphaDash, length,
|
||||||
|
} from '@validations'
|
||||||
|
import {
|
||||||
|
formatToken, formatTokenDenom, getUnitAmount,
|
||||||
|
} from '@/libs/utils'
|
||||||
|
import vSelect from 'vue-select'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'UnbondDialogue',
|
||||||
|
components: {
|
||||||
|
BRow,
|
||||||
|
BCol,
|
||||||
|
BInputGroup,
|
||||||
|
BFormInput,
|
||||||
|
BFormGroup,
|
||||||
|
vSelect,
|
||||||
|
BInputGroupAppend,
|
||||||
|
ValidationProvider,
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
validatorAddress: {
|
||||||
|
type: String,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
address: {
|
||||||
|
type: String,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
selectedAddress: this.address,
|
||||||
|
availableAddress: [],
|
||||||
|
unbundValidators: [],
|
||||||
|
validators: [],
|
||||||
|
toValidator: null,
|
||||||
|
token: '',
|
||||||
|
amount: null,
|
||||||
|
chainId: '',
|
||||||
|
selectedChain: '',
|
||||||
|
balance: [],
|
||||||
|
delegations: [],
|
||||||
|
memo: '',
|
||||||
|
feeDenom: '',
|
||||||
|
error: null,
|
||||||
|
sequence: 1,
|
||||||
|
accountNumber: 0,
|
||||||
|
account: [],
|
||||||
|
|
||||||
|
required,
|
||||||
|
password,
|
||||||
|
email,
|
||||||
|
min,
|
||||||
|
integer,
|
||||||
|
url,
|
||||||
|
alpha,
|
||||||
|
between,
|
||||||
|
digits,
|
||||||
|
length,
|
||||||
|
alphaDash,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
valOptions() {
|
||||||
|
const vals = this.validators.map(x => ({ value: x.operator_address, label: `${x.description.moniker} (${Number(x.commission.rate) * 100}%)` }))
|
||||||
|
const unbunded = this.unbundValidators.map(x => ({ value: x.operator_address, label: `* ${x.description.moniker} (${Number(x.commission.rate) * 100}%)` }))
|
||||||
|
return vals.concat(unbunded)
|
||||||
|
},
|
||||||
|
tokenOptions() {
|
||||||
|
if (!this.delegations) return []
|
||||||
|
return this.delegations.filter(x => x.delegation.validator_address === this.validatorAddress).map(x => ({ value: x.balance.denom, label: formatToken(x.balance) }))
|
||||||
|
},
|
||||||
|
msg() {
|
||||||
|
return [{
|
||||||
|
typeUrl: '/cosmos.staking.v1beta1.MsgBeginRedelegate',
|
||||||
|
value: {
|
||||||
|
delegatorAddress: this.address,
|
||||||
|
validatorSrcAddress: this.validatorAddress,
|
||||||
|
validatorDstAddress: this.toValidator,
|
||||||
|
amount: {
|
||||||
|
amount: getUnitAmount(this.amount, this.token),
|
||||||
|
denom: this.token,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.loadBalance()
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
printDenom() {
|
||||||
|
return formatTokenDenom(this.token)
|
||||||
|
},
|
||||||
|
loadBalance() {
|
||||||
|
this.$http.getValidatorList().then(v => {
|
||||||
|
this.validators = v
|
||||||
|
})
|
||||||
|
this.$http.getValidatorUnbondedList().then(v => {
|
||||||
|
this.unbundValidators = v
|
||||||
|
})
|
||||||
|
this.$http.getBankBalances(this.address).then(res => {
|
||||||
|
if (res && res.length > 0) {
|
||||||
|
this.balance = res.reverse()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
this.$http.getStakingDelegations(this.address).then(res => {
|
||||||
|
this.delegations = res.delegation_responses
|
||||||
|
console.log(res)
|
||||||
|
this.delegations.forEach(x => {
|
||||||
|
if (x.delegation.validator_address === this.validatorAddress) {
|
||||||
|
this.token = x.balance.denom
|
||||||
|
this.feeDenom = x.balance.denom
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
format(v) {
|
||||||
|
return formatToken(v)
|
||||||
|
},
|
||||||
|
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<style lang="scss">
|
||||||
|
@import '@core/scss/vue/libs/vue-select.scss';
|
||||||
|
</style>
|
@ -41,7 +41,7 @@
|
|||||||
:is="type"
|
:is="type"
|
||||||
ref="component"
|
ref="component"
|
||||||
:address="address"
|
:address="address"
|
||||||
:validator-address.sync="selectedValidator"
|
:validator-address="selectedValidator"
|
||||||
/>
|
/>
|
||||||
<b-row>
|
<b-row>
|
||||||
<b-col>
|
<b-col>
|
||||||
@ -143,13 +143,14 @@ 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'
|
||||||
import {
|
import {
|
||||||
abbrAddress, extractAccountNumberAndSequence, getLocalAccounts, setLocalTxHistory, sign, timeIn,
|
extractAccountNumberAndSequence, setLocalTxHistory, sign, timeIn,
|
||||||
} from '@/libs/utils'
|
} from '@/libs/utils'
|
||||||
import vSelect from 'vue-select'
|
import vSelect from 'vue-select'
|
||||||
import ToastificationContent from '@core/components/toastification/ToastificationContent.vue'
|
import ToastificationContent from '@core/components/toastification/ToastificationContent.vue'
|
||||||
|
|
||||||
import WalletInputVue from '../WalletInput.vue'
|
import WalletInputVue from '../WalletInput.vue'
|
||||||
import Delegate from './components/Delegate.vue'
|
import Delegate from './components/Delegate.vue'
|
||||||
|
import Redelegate from './components/Redelegate.vue'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'DelegateDialogue',
|
name: 'DelegateDialogue',
|
||||||
@ -176,6 +177,7 @@ export default {
|
|||||||
// eslint-disable-next-line vue/no-unused-components
|
// eslint-disable-next-line vue/no-unused-components
|
||||||
ToastificationContent,
|
ToastificationContent,
|
||||||
Delegate,
|
Delegate,
|
||||||
|
Redelegate,
|
||||||
},
|
},
|
||||||
directives: {
|
directives: {
|
||||||
Ripple,
|
Ripple,
|
||||||
@ -197,26 +199,20 @@ export default {
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
selectedAddress: this.address,
|
selectedAddress: this.address,
|
||||||
availableAddress: [],
|
|
||||||
validators: [],
|
|
||||||
unbundValidators: [],
|
|
||||||
selectedValidator: null,
|
selectedValidator: null,
|
||||||
token: '',
|
token: '',
|
||||||
amount: null,
|
|
||||||
chainId: '',
|
chainId: '',
|
||||||
selectedChain: '',
|
|
||||||
balance: [],
|
balance: [],
|
||||||
delegations: [],
|
|
||||||
IBCDenom: {},
|
IBCDenom: {},
|
||||||
memo: '',
|
|
||||||
fee: '900',
|
|
||||||
feeDenom: '',
|
|
||||||
wallet: 'ledgerUSB',
|
|
||||||
error: null,
|
error: null,
|
||||||
sequence: 1,
|
sequence: 1,
|
||||||
accountNumber: 0,
|
accountNumber: 0,
|
||||||
advance: false,
|
advance: false,
|
||||||
|
fee: '900',
|
||||||
|
feeDenom: '',
|
||||||
|
wallet: 'ledgerUSB',
|
||||||
gas: '200000',
|
gas: '200000',
|
||||||
|
memo: '',
|
||||||
|
|
||||||
required,
|
required,
|
||||||
password,
|
password,
|
||||||
@ -237,35 +233,8 @@ export default {
|
|||||||
return this.balance.filter(item => !item.denom.startsWith('ibc'))
|
return this.balance.filter(item => !item.denom.startsWith('ibc'))
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
created() {
|
|
||||||
// console.log('address: ', this.address)
|
|
||||||
},
|
|
||||||
methods: {
|
methods: {
|
||||||
computeAccount() {
|
|
||||||
const accounts = getLocalAccounts()
|
|
||||||
const values = accounts ? Object.values(accounts) : []
|
|
||||||
let array = []
|
|
||||||
for (let i = 0; i < values.length; i += 1) {
|
|
||||||
const addrs = values[i].address.filter(x => x.chain === this.$route.params.chain)
|
|
||||||
if (addrs && addrs.length > 0) {
|
|
||||||
array = array.concat(addrs.map(x => ({ value: x.addr, label: values[i].name.concat(' - ', abbrAddress(x.addr)) })))
|
|
||||||
if (!this.selectedAddress) {
|
|
||||||
this.selectedAddress = addrs[0].addr
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.selectedValidator = this.validatorAddress
|
|
||||||
return array
|
|
||||||
},
|
|
||||||
loadBalance() {
|
loadBalance() {
|
||||||
this.account = this.computeAccount()
|
|
||||||
// if (this.account && this.account.length > 0) this.selectedAddress
|
|
||||||
this.$http.getValidatorList().then(v => {
|
|
||||||
this.validators = v
|
|
||||||
})
|
|
||||||
this.$http.getValidatorUnbondedList().then(v => {
|
|
||||||
this.unbundValidators = v
|
|
||||||
})
|
|
||||||
this.$http.getLatestBlock().then(ret => {
|
this.$http.getLatestBlock().then(ret => {
|
||||||
this.chainId = ret.block.header.chain_id
|
this.chainId = ret.block.header.chain_id
|
||||||
const notSynced = timeIn(ret.block.header.time, 10, 'm')
|
const notSynced = timeIn(ret.block.header.time, 10, 'm')
|
||||||
@ -303,11 +272,7 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
handleOk(bvModalEvt) {
|
handleOk(bvModalEvt) {
|
||||||
// console.log('send')
|
|
||||||
// Prevent modal from closing
|
|
||||||
bvModalEvt.preventDefault()
|
bvModalEvt.preventDefault()
|
||||||
// Trigger submit handler
|
|
||||||
// this.handleSubmit()
|
|
||||||
this.$refs.simpleRules.validate().then(ok => {
|
this.$refs.simpleRules.validate().then(ok => {
|
||||||
if (ok) {
|
if (ok) {
|
||||||
this.sendTx().then(ret => {
|
this.sendTx().then(ret => {
|
||||||
@ -365,7 +330,7 @@ export default {
|
|||||||
hash: res.tx_response.txhash,
|
hash: res.tx_response.txhash,
|
||||||
time: new Date(),
|
time: new Date(),
|
||||||
})
|
})
|
||||||
this.$bvModal.hide('delegate-window')
|
this.$bvModal.hide('operation-modal')
|
||||||
this.$toast({
|
this.$toast({
|
||||||
component: ToastificationContent,
|
component: ToastificationContent,
|
||||||
props: {
|
props: {
|
||||||
|
Loading…
Reference in New Issue
Block a user