2021-08-25 07:45:40 +00:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<b-modal
|
|
|
|
id="transfer-window"
|
|
|
|
centered
|
|
|
|
size="md"
|
|
|
|
title="Transfer Tokens"
|
2021-09-14 14:06:14 +00:00
|
|
|
ok-title="Send"
|
2021-08-25 07:45:40 +00:00
|
|
|
hide-header-close
|
|
|
|
scrollable
|
2021-09-06 07:30:17 +00:00
|
|
|
:ok-disabled="!address"
|
2021-08-25 07:45:40 +00:00
|
|
|
@hidden="resetModal"
|
|
|
|
@ok="handleOk"
|
|
|
|
@show="loadBalance"
|
|
|
|
>
|
|
|
|
<validation-observer ref="simpleRules">
|
|
|
|
<b-form>
|
|
|
|
<b-row>
|
|
|
|
<b-col v-if="account">
|
|
|
|
<b-form-group
|
|
|
|
label="Sender"
|
|
|
|
label-for="Account"
|
|
|
|
>
|
|
|
|
<b-input-group class="mb-25">
|
|
|
|
<b-input-group-prepend is-text>
|
|
|
|
<b-avatar
|
|
|
|
:src="account.logo"
|
|
|
|
size="18"
|
|
|
|
variant="light-primary"
|
|
|
|
rounded
|
|
|
|
/>
|
|
|
|
</b-input-group-prepend>
|
|
|
|
<b-form-input
|
|
|
|
:value="account.addr"
|
|
|
|
readonly
|
|
|
|
/>
|
|
|
|
</b-input-group>
|
|
|
|
</b-form-group>
|
|
|
|
</b-col>
|
|
|
|
</b-row>
|
|
|
|
<b-row>
|
|
|
|
<b-col>
|
|
|
|
<b-form-group
|
|
|
|
label="Recipient"
|
|
|
|
label-for="Recipient"
|
|
|
|
>
|
|
|
|
<validation-provider
|
|
|
|
#default="{ errors }"
|
|
|
|
rules="required"
|
|
|
|
name="recipient"
|
|
|
|
>
|
|
|
|
<b-input-group class="mb-25">
|
|
|
|
<b-form-input
|
|
|
|
id="Recipient"
|
|
|
|
v-model="recipient"
|
|
|
|
:state="errors.length > 0 ? false:null"
|
|
|
|
/>
|
|
|
|
</b-input-group>
|
|
|
|
<small class="text-danger">{{ errors[0] }}</small>
|
|
|
|
</validation-provider>
|
|
|
|
</b-form-group>
|
|
|
|
</b-col>
|
|
|
|
</b-row>
|
|
|
|
<b-row>
|
|
|
|
<b-col>
|
|
|
|
<b-form-group
|
|
|
|
label="Available Token"
|
|
|
|
label-for="Token"
|
|
|
|
>
|
|
|
|
<validation-provider
|
|
|
|
#default="{ errors }"
|
|
|
|
rules="required"
|
|
|
|
name="Token"
|
|
|
|
>
|
|
|
|
<b-form-select
|
|
|
|
v-model="token"
|
|
|
|
>
|
|
|
|
<b-form-select-option
|
|
|
|
v-for="item in balance"
|
|
|
|
:key="item.denom"
|
|
|
|
:value="item.denom"
|
|
|
|
>
|
|
|
|
{{ format(item) }}
|
|
|
|
</b-form-select-option>
|
|
|
|
</b-form-select>
|
|
|
|
<small class="text-danger">{{ errors[0] }}</small>
|
|
|
|
</validation-provider>
|
|
|
|
</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 class="mb-25">
|
|
|
|
<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>
|
2021-09-14 14:06:14 +00:00
|
|
|
{{ printDenom() }}
|
2021-08-25 07:45:40 +00:00
|
|
|
</b-input-group-append>
|
|
|
|
</b-input-group>
|
|
|
|
<small class="text-danger">{{ errors[0] }}</small>
|
|
|
|
</validation-provider>
|
|
|
|
</b-form-group>
|
|
|
|
</b-col>
|
|
|
|
</b-row>
|
|
|
|
<b-row>
|
|
|
|
<b-col>
|
|
|
|
<b-form-group
|
|
|
|
label="Fee"
|
|
|
|
label-for="Fee"
|
|
|
|
>
|
2021-09-15 11:49:57 +00:00
|
|
|
<validation-provider
|
|
|
|
v-slot="{ errors }"
|
|
|
|
rules="required|integer"
|
|
|
|
name="fee"
|
|
|
|
>
|
|
|
|
<b-input-group>
|
2021-08-26 13:50:56 +00:00
|
|
|
<b-form-input v-model="fee" />
|
2021-09-15 11:49:57 +00:00
|
|
|
<b-input-group-append>
|
|
|
|
<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>
|
2021-08-25 07:45:40 +00:00
|
|
|
</b-form-group>
|
|
|
|
</b-col>
|
|
|
|
</b-row>
|
2021-09-15 11:49:57 +00:00
|
|
|
<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">
|
2021-08-25 07:45:40 +00:00
|
|
|
<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"
|
2021-09-15 11:49:57 +00:00
|
|
|
class="d-none d-md-block"
|
2021-08-25 07:45:40 +00:00
|
|
|
>
|
|
|
|
Keplr
|
|
|
|
</b-form-radio>
|
2021-09-10 12:13:31 +00:00
|
|
|
<b-form-radio
|
2021-08-25 07:45:40 +00:00
|
|
|
v-model="wallet"
|
|
|
|
name="wallet"
|
|
|
|
value="ledgerUSB"
|
|
|
|
>
|
2021-09-15 11:49:57 +00:00
|
|
|
<small>Ledger(USB)</small>
|
2021-08-25 07:45:40 +00:00
|
|
|
</b-form-radio>
|
|
|
|
<b-form-radio
|
|
|
|
v-model="wallet"
|
|
|
|
name="wallet"
|
|
|
|
value="ledgerBle"
|
2021-09-15 11:49:57 +00:00
|
|
|
class="mr-0"
|
2021-08-25 07:45:40 +00:00
|
|
|
>
|
2021-09-15 11:49:57 +00:00
|
|
|
<small>Ledger(Bluetooth)</small>
|
2021-09-10 12:13:31 +00:00
|
|
|
</b-form-radio>
|
2021-08-25 07:45:40 +00:00
|
|
|
</b-form-radio-group>
|
|
|
|
<small class="text-danger">{{ errors[0] }}</small>
|
|
|
|
</validation-provider>
|
|
|
|
</b-form-group>
|
|
|
|
</b-col>
|
|
|
|
</b-row>
|
|
|
|
</b-form>
|
|
|
|
</validation-observer>
|
|
|
|
{{ error }}
|
|
|
|
</b-modal>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import { ValidationProvider, ValidationObserver } from 'vee-validate'
|
|
|
|
import {
|
|
|
|
BModal, BRow, BCol, BInputGroup, BInputGroupAppend, BFormInput, BAvatar, BFormGroup, BFormSelect, BFormSelectOption,
|
2021-09-15 11:49:57 +00:00
|
|
|
BForm, BFormRadioGroup, BFormRadio, BInputGroupPrepend, BFormCheckbox,
|
2021-08-25 07:45:40 +00:00
|
|
|
} from 'bootstrap-vue'
|
|
|
|
import {
|
|
|
|
required, email, url, between, alpha, integer, password, min, digits, alphaDash, length,
|
|
|
|
} from '@validations'
|
|
|
|
import {
|
2021-09-14 14:06:14 +00:00
|
|
|
formatToken, formatTokenDenom, getLocalAccounts, getLocalChains, setLocalTxHistory, sign, timeIn,
|
2021-08-25 07:45:40 +00:00
|
|
|
} from '@/libs/data'
|
|
|
|
import { Cosmos } from '@cosmostation/cosmosjs'
|
|
|
|
import ToastificationContent from '@core/components/toastification/ToastificationContent.vue'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'TransforDialogue',
|
|
|
|
components: {
|
|
|
|
BModal,
|
|
|
|
BRow,
|
|
|
|
BCol,
|
|
|
|
BForm,
|
|
|
|
BInputGroup,
|
|
|
|
BInputGroupAppend,
|
|
|
|
BInputGroupPrepend,
|
|
|
|
BFormInput,
|
|
|
|
BAvatar,
|
|
|
|
BFormGroup,
|
|
|
|
BFormSelect,
|
|
|
|
BFormSelectOption,
|
|
|
|
BFormRadioGroup,
|
|
|
|
BFormRadio,
|
2021-09-15 11:49:57 +00:00
|
|
|
BFormCheckbox,
|
2021-08-25 07:45:40 +00:00
|
|
|
|
|
|
|
ValidationProvider,
|
|
|
|
ValidationObserver,
|
|
|
|
// eslint-disable-next-line vue/no-unused-components
|
|
|
|
ToastificationContent,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
address: {
|
|
|
|
type: String,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
chainId: '',
|
|
|
|
selectedChain: '',
|
|
|
|
balance: [],
|
|
|
|
token: '',
|
|
|
|
amount: null,
|
|
|
|
memo: '',
|
|
|
|
recipient: null,
|
2021-09-10 12:13:31 +00:00
|
|
|
fee: '800',
|
2021-08-25 07:45:40 +00:00
|
|
|
feeDenom: '',
|
2021-09-15 11:49:57 +00:00
|
|
|
wallet: 'ledgerUSB',
|
2021-08-25 07:45:40 +00:00
|
|
|
error: null,
|
|
|
|
sequence: 1,
|
|
|
|
accountNumber: 0,
|
2021-09-04 03:02:12 +00:00
|
|
|
account: [],
|
2021-09-14 14:06:14 +00:00
|
|
|
IBCDenom: {},
|
2021-09-15 11:49:57 +00:00
|
|
|
gas: '200000',
|
|
|
|
advance: false,
|
2021-08-25 07:45:40 +00:00
|
|
|
|
|
|
|
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: {
|
2021-09-14 14:06:14 +00:00
|
|
|
printDenom() {
|
|
|
|
return formatTokenDenom(this.IBCDenom[this.token] || this.token)
|
|
|
|
},
|
2021-08-25 07:45:40 +00:00
|
|
|
computeAccount() {
|
|
|
|
const accounts = getLocalAccounts()
|
|
|
|
const chains = getLocalChains()
|
|
|
|
const values = Object.values(accounts)
|
|
|
|
for (let i = 0; i < values.length; i += 1) {
|
|
|
|
const addr = values[i].address.find(x => x.addr === this.address)
|
|
|
|
if (addr) {
|
|
|
|
this.selectedChain = chains[addr.chain]
|
|
|
|
return addr
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null
|
|
|
|
},
|
|
|
|
loadBalance() {
|
2021-09-04 03:02:12 +00:00
|
|
|
this.account = this.computeAccount()
|
|
|
|
if (this.account && this.account.length > 0) this.address = this.account[0].addr
|
2021-08-25 07:45:40 +00:00
|
|
|
if (this.address) {
|
2021-09-14 14:06:14 +00:00
|
|
|
this.$http.getBankBalances(this.address, this.selectedChain).then(res => {
|
2021-08-25 07:45:40 +00:00
|
|
|
if (res && res.length > 0) {
|
|
|
|
this.balance = res
|
|
|
|
this.token = this.balance[0].denom
|
2021-09-04 03:02:12 +00:00
|
|
|
this.feeDenom = this.balance.find(x => !x.denom.startsWith('ibc')).denom
|
2021-09-14 14:06:14 +00:00
|
|
|
this.balance.filter(i => i.denom.startsWith('ibc')).forEach(x => {
|
|
|
|
if (!this.IBCDenom[x.denom]) {
|
|
|
|
this.$http.getIBCDenomTrace(x.denom).then(denom => {
|
|
|
|
this.IBCDenom[x.denom] = denom.denom_trace.base_denom
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2021-08-25 07:45:40 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
this.$http.getLatestBlock(this.selectedChain).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'
|
|
|
|
} else {
|
|
|
|
this.error = null
|
|
|
|
}
|
|
|
|
})
|
|
|
|
this.$http.getAuthAccount(this.address, this.selectedChain).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.send().then(ret => {
|
|
|
|
// console.log(ret)
|
|
|
|
this.error = ret
|
|
|
|
})
|
|
|
|
},
|
|
|
|
resetModal() {
|
|
|
|
this.feeDenom = ''
|
|
|
|
this.error = null
|
|
|
|
},
|
|
|
|
format(v) {
|
2021-09-14 14:06:14 +00:00
|
|
|
return formatToken(v, this.IBCDenom)
|
2021-08-25 07:45:40 +00:00
|
|
|
},
|
|
|
|
async sendCosmos() {
|
|
|
|
const cosmos = new Cosmos(this.selectedChain.api, this.chainId)
|
|
|
|
cosmos.getAccounts()
|
|
|
|
},
|
|
|
|
async send() {
|
|
|
|
const txMsgs = [
|
|
|
|
{
|
|
|
|
typeUrl: '/cosmos.bank.v1beta1.MsgSend',
|
|
|
|
value: {
|
|
|
|
fromAddress: this.address,
|
|
|
|
toAddress: this.recipient,
|
|
|
|
amount: [
|
|
|
|
{
|
|
|
|
amount: String((Number(this.amount) * 1000000).toFixed()),
|
|
|
|
denom: this.token,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
const txFee = {
|
|
|
|
amount: [
|
|
|
|
{
|
|
|
|
amount: this.fee,
|
|
|
|
denom: this.feeDenom,
|
|
|
|
},
|
|
|
|
],
|
2021-09-15 11:49:57 +00:00
|
|
|
gas: this.gas,
|
2021-08-25 07:45:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const signerData = {
|
|
|
|
accountNumber: this.accountNumber,
|
2021-09-16 01:54:57 +00:00
|
|
|
sequence: this.sequence,
|
2021-08-25 07:45:40 +00:00
|
|
|
chainId: this.chainId,
|
|
|
|
}
|
|
|
|
|
|
|
|
sign(
|
|
|
|
this.wallet,
|
|
|
|
this.chainId,
|
|
|
|
this.address,
|
|
|
|
txMsgs,
|
|
|
|
txFee,
|
|
|
|
this.memo,
|
|
|
|
signerData,
|
2021-08-27 05:13:41 +00:00
|
|
|
).then(bodyBytes => {
|
2021-08-25 07:45:40 +00:00
|
|
|
this.$http.broadcastTx(bodyBytes, this.selectedChain).then(res => {
|
2021-08-26 13:50:56 +00:00
|
|
|
setLocalTxHistory({ op: 'send', hash: res.txhash, time: new Date() })
|
2021-08-25 07:45:40 +00:00
|
|
|
this.$bvModal.hide('transfer-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>
|