364 lines
9.8 KiB
Vue
364 lines
9.8 KiB
Vue
<template>
|
|
<div>
|
|
<b-modal
|
|
id="withdraw-commission-window"
|
|
centered
|
|
size="md"
|
|
title="Withdraw Validator Commission"
|
|
hide-header-close
|
|
scrollable
|
|
|
|
:ok-disabled="!address"
|
|
@hidden="resetModal"
|
|
@ok="handleOk"
|
|
@show="loadBalance"
|
|
>
|
|
<validation-observer ref="simpleRules">
|
|
<b-form>
|
|
<b-row>
|
|
<b-col>
|
|
<b-form-group
|
|
label="Sender"
|
|
label-for="Account"
|
|
>
|
|
<b-input-group class="mb-25">
|
|
<b-form-input
|
|
:value="address"
|
|
readonly
|
|
/>
|
|
</b-input-group>
|
|
</b-form-group>
|
|
</b-col>
|
|
</b-row>
|
|
<b-row>
|
|
<b-col>
|
|
<b-form-group
|
|
label="Fee"
|
|
label-for="Fee"
|
|
>
|
|
<validation-provider
|
|
v-slot="{ errors }"
|
|
rules="required|integer"
|
|
name="fee"
|
|
>
|
|
<b-input-group>
|
|
<b-form-input v-model="fee" />
|
|
<b-input-group-append name="xx">
|
|
<b-form-select
|
|
v-model="feeDenom"
|
|
:options="feeDenoms"
|
|
value-field="denom"
|
|
text-field="denom"
|
|
/>
|
|
</b-input-group-append>
|
|
</b-input-group>
|
|
<small class="text-danger">{{ errors[0] }}</small>
|
|
</validation-provider>
|
|
</b-form-group>
|
|
</b-col>
|
|
<b-col cols="12">
|
|
<b-form-group>
|
|
<b-form-checkbox
|
|
v-model="advance"
|
|
name="advance"
|
|
value="true"
|
|
>
|
|
<small>Advance</small>
|
|
</b-form-checkbox>
|
|
</b-form-group>
|
|
</b-col>
|
|
</b-row>
|
|
<b-row v-if="advance">
|
|
<b-col cols="12">
|
|
<b-form-group
|
|
label="Gas"
|
|
label-for="gas"
|
|
>
|
|
<validation-provider
|
|
v-slot="{ errors }"
|
|
name="gas"
|
|
>
|
|
<b-form-input
|
|
id="gas"
|
|
v-model="gas"
|
|
type="number"
|
|
/>
|
|
<small class="text-danger">{{ errors[0] }}</small>
|
|
</validation-provider>
|
|
</b-form-group>
|
|
</b-col>
|
|
<b-col cols="12">
|
|
<b-form-group
|
|
label="Memo"
|
|
label-for="Memo"
|
|
>
|
|
<validation-provider
|
|
v-slot="{ errors }"
|
|
name="memo"
|
|
>
|
|
<b-form-input
|
|
id="Memo"
|
|
v-model="memo"
|
|
max="2"
|
|
/>
|
|
<small class="text-danger">{{ errors[0] }}</small>
|
|
</validation-provider>
|
|
</b-form-group>
|
|
</b-col>
|
|
</b-row>
|
|
<b-row>
|
|
<b-col>
|
|
<b-form-group
|
|
label="Wallet"
|
|
label-for="wallet"
|
|
>
|
|
<validation-provider
|
|
v-slot="{ errors }"
|
|
rules="required"
|
|
name="wallet"
|
|
>
|
|
<b-form-radio-group
|
|
v-model="wallet"
|
|
stacked
|
|
class="demo-inline-spacing"
|
|
>
|
|
<b-form-radio
|
|
v-model="wallet"
|
|
name="wallet"
|
|
value="keplr"
|
|
class="d-none d-md-block"
|
|
>
|
|
Keplr
|
|
</b-form-radio>
|
|
<b-form-radio
|
|
v-model="wallet"
|
|
name="wallet"
|
|
value="ledgerUSB"
|
|
>
|
|
<small>Ledger(USB)</small>
|
|
</b-form-radio>
|
|
<b-form-radio
|
|
v-model="wallet"
|
|
name="wallet"
|
|
value="ledgerBle"
|
|
class="mr-0"
|
|
>
|
|
<small>Ledger(Bluetooth)</small>
|
|
</b-form-radio>
|
|
</b-form-radio-group>
|
|
<small class="text-danger">{{ errors[0] }}</small>
|
|
</validation-provider>
|
|
</b-form-group>
|
|
</b-col>
|
|
</b-row>
|
|
</b-form>
|
|
</validation-observer>
|
|
<small class="text-danger">{{ error }}</small>
|
|
</b-modal>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import { ValidationProvider, ValidationObserver } from 'vee-validate'
|
|
import {
|
|
BModal, BRow, BCol, BInputGroup, BFormInput, BFormGroup, BFormSelect, BFormCheckbox,
|
|
BForm, BFormRadioGroup, BFormRadio, BInputGroupAppend,
|
|
} from 'bootstrap-vue'
|
|
import {
|
|
required, email, url, between, alpha, integer, password, min, digits, alphaDash, length,
|
|
} from '@validations'
|
|
import {
|
|
formatToken, setLocalTxHistory, sign, timeIn,
|
|
} from '@/libs/data'
|
|
import ToastificationContent from '@core/components/toastification/ToastificationContent.vue'
|
|
|
|
export default {
|
|
name: 'WithdrawCommissionDialogue',
|
|
components: {
|
|
BModal,
|
|
BRow,
|
|
BCol,
|
|
BForm,
|
|
BInputGroup,
|
|
BFormInput,
|
|
BFormGroup,
|
|
BFormSelect,
|
|
BFormRadioGroup,
|
|
BFormRadio,
|
|
BFormCheckbox,
|
|
BInputGroupAppend,
|
|
|
|
ValidationProvider,
|
|
ValidationObserver,
|
|
// eslint-disable-next-line vue/no-unused-components
|
|
ToastificationContent,
|
|
},
|
|
props: {
|
|
address: {
|
|
type: String,
|
|
default: '',
|
|
},
|
|
validatorAddress: {
|
|
type: String,
|
|
default: '',
|
|
},
|
|
},
|
|
data() {
|
|
return {
|
|
chainId: '',
|
|
account: [],
|
|
selectedChain: '',
|
|
balance: [],
|
|
delegations: [],
|
|
memo: '',
|
|
fee: '800',
|
|
feeDenom: '',
|
|
wallet: 'ledgerUSB',
|
|
error: null,
|
|
sequence: 1,
|
|
accountNumber: 0,
|
|
gas: '200000',
|
|
advance: false,
|
|
|
|
required,
|
|
password,
|
|
email,
|
|
min,
|
|
integer,
|
|
url,
|
|
alpha,
|
|
between,
|
|
digits,
|
|
length,
|
|
alphaDash,
|
|
}
|
|
},
|
|
computed: {
|
|
feeDenoms() {
|
|
return this.balance.filter(item => !item.denom.startsWith('ibc'))
|
|
},
|
|
},
|
|
created() {
|
|
// console.log('address: ', this.address)
|
|
},
|
|
methods: {
|
|
|
|
loadBalance() {
|
|
this.$http.getBankBalances(this.address).then(res => {
|
|
if (res && res.length > 0) {
|
|
this.balance = res
|
|
const token = this.balance.find(i => !i.denom.startsWith('ibc'))
|
|
if (token) this.feeDenom = token.denom
|
|
}
|
|
})
|
|
this.$http.getLatestBlock().then(ret => {
|
|
this.chainId = ret.block.header.chain_id
|
|
const notSynced = timeIn(ret.block.header.time, 10, 'm')
|
|
if (notSynced) {
|
|
this.error = 'Client is not synced or blockchain is halted'
|
|
}
|
|
})
|
|
this.$http.getAuthAccount(this.address).then(ret => {
|
|
if (ret.value.base_vesting_account) {
|
|
this.accountNumber = ret.value.base_vesting_account.base_account.account_number
|
|
this.sequence = ret.value.base_vesting_account.base_account.sequence
|
|
if (!this.sequence) this.sequence = 0
|
|
} else {
|
|
this.accountNumber = ret.value.account_number
|
|
this.sequence = ret.value.sequence ? ret.value.sequence : 0
|
|
}
|
|
})
|
|
},
|
|
handleOk(bvModalEvt) {
|
|
// console.log('send')
|
|
// Prevent modal from closing
|
|
bvModalEvt.preventDefault()
|
|
// Trigger submit handler
|
|
// this.handleSubmit()
|
|
this.sendTx().then(ret => {
|
|
// console.log(ret)
|
|
this.error = ret
|
|
})
|
|
},
|
|
resetModal() {
|
|
this.feeDenom = ''
|
|
this.error = null
|
|
},
|
|
format(v) {
|
|
return formatToken(v)
|
|
},
|
|
async sendTx() {
|
|
const txMsgs = [
|
|
{
|
|
typeUrl: '/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward',
|
|
value: {
|
|
delegatorAddress: this.address,
|
|
validatorAddress: this.validatorAddress,
|
|
},
|
|
}, {
|
|
typeUrl: '/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission',
|
|
value: {
|
|
validatorAddress: this.validatorAddress,
|
|
},
|
|
},
|
|
]
|
|
|
|
if (txMsgs.length === 0) {
|
|
this.error = 'No delegation found'
|
|
return ''
|
|
}
|
|
if (!this.accountNumber) {
|
|
this.error = 'Account number should not be empty!'
|
|
return ''
|
|
}
|
|
|
|
const txFee = {
|
|
amount: [
|
|
{
|
|
amount: this.fee,
|
|
denom: this.feeDenom,
|
|
},
|
|
],
|
|
gas: this.gas,
|
|
}
|
|
|
|
const signerData = {
|
|
accountNumber: this.accountNumber,
|
|
sequence: this.sequence,
|
|
chainId: this.chainId,
|
|
}
|
|
|
|
sign(
|
|
this.wallet,
|
|
this.chainId,
|
|
this.address,
|
|
txMsgs,
|
|
txFee,
|
|
this.memo,
|
|
signerData,
|
|
).then(bodyBytes => {
|
|
this.$http.broadcastTx(bodyBytes, this.selectedChain).then(res => {
|
|
setLocalTxHistory({ op: 'withdraw', hash: res.tx_response.txhash, time: new Date() })
|
|
this.$bvModal.hide('withdraw-commission-window')
|
|
this.$toast({
|
|
component: ToastificationContent,
|
|
props: {
|
|
title: 'Transaction sent!',
|
|
icon: 'EditIcon',
|
|
variant: 'success',
|
|
},
|
|
})
|
|
}).catch(e => {
|
|
this.error = e
|
|
})
|
|
}).catch(e => {
|
|
this.error = e
|
|
})
|
|
// Send tokens
|
|
// return client.sendTokens(this.address, this.recipient, sendCoins, this.memo)
|
|
return ''
|
|
},
|
|
},
|
|
}
|
|
</script>
|