1 <style lang="scss" scoped>
13 .form-item-content input, input.form-item-content {
16 border-bottom: 0.5px solid #EBEBEB;
21 .form-item-content input:focus,
22 input.form-item-content:focus,
23 input.form-item-content:active
26 border-bottom: 0.5px solid #004EE4;
32 justify-content: space-between;
36 border-bottom: 0.5px solid #EBEBEB;
74 color: rgba(0, 0, 0, 0.36);
100 <div class="warp-child bg-grey">
101 <section class="header">
102 <BackButton :small="true" :back="close"/>
103 <h1 class="color-black">
104 <div class="welcome-title">{{ $t('main.send') }}</div>
108 <section class="bg-shadow-white form">
111 <div class="form-item">
112 <label class="form-item-label">{{ $t('transfer.asset') }}</label>
113 <div class="form-item-content currency" @click="$router.push({ name: 'asset-selection' })">
114 <div class="symbol color-black">
115 <img :src="img(unit)" alt="" class="c-icon">
117 <div class="uppercase">
123 <div class=" text-align-right">
124 <div class="color-grey-36 uppercase assetId">{{ shortAddress(selectAsset.assetId) }} <i class="iconfont iconarrow_1"></i></div>
130 <div class="form-item">
131 <label class="form-item-label">{{ $t('transfer.address') }}</label>
132 <input class="form-item-content"
133 :placeholder="netType=='vapor'? $t('transfer.vaporAddress'): $t('transfer.bytomAddress')"
138 v-model="$v.transaction.to.$model"
141 <div class="form-item">
142 <label class="form-item-label" for="tx-amount">
143 {{ unit+$t('transfer.quantity') }}
145 <small class="float-right color-grey-36" style="margin-right: 8px; margin-top: 8px;">
146 {{ `${$t('transfer.available')} ${currentBalance} ${unit}` }}
150 <div class="form-item-content amount-input">
157 v-model="$v.transaction.amount.$model"
158 @keypress="limitAmount"
161 <div class="max" @click="max()">Max</div>
162 <span class="color-grey-36">≈ {{formatCurrency(transaction.cost||0)}}</span>
169 <label >{{ $t('transfer.fee') }}</label>
170 <div>{{ transaction.fee }} BTM</div>
175 <a :class="['btn', netType ==='vapor'?'btn-vapor':'btn-bytom']" @click="validate">{{ $t('transfer.send') }}</a>
178 <modal-passwd ref="modalPasswd" @confirm="send"></modal-passwd>
183 import address from "@/utils/address";
184 import transaction from "@/models/transaction";
185 import getLang from "@/assets/language/sdk";
186 import Confirm from "./transferConfirm";
187 import { BTM } from "@/utils/constants";
188 import { Number as Num } from "@/utils/Number"
189 import { mapActions, mapGetters, mapState } from 'vuex'
190 import * as Actions from '@/store/constants';
191 import _ from 'lodash'
192 import { required } from "vuelidate/lib/validators";
193 import BigNumber from "bignumber.js"
196 const currencyInPrice = {
224 assetId: "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
242 if(this.netType === 'vapor'){
243 if(!this.currentAccount.vpBalances ||this.currentAccount.vpBalances.length == 0){
244 return [this.selectAsset]
246 return this.currentAccount.vpBalances.map(b=>b.asset)
249 if(!this.currentAccount.balances ||this.currentAccount.balances.length == 0){
250 return [this.selectAsset]
252 return this.currentAccount.balances.map(b=>b.asset)
257 const assetId = this.selectAsset.assetId
260 if(this.netType === 'vapor'){
261 balances = this.currentAccount.vpBalances
263 balances = this.currentAccount.balances
266 const balance = balances.find(b => b.asset.assetId === assetId)
267 return balance? balance.availableBalance:0;
270 return this.selectAsset.symbol;
284 "transaction.amount": function (newAmount) {
285 const singlePrice = this.selectAsset[currencyInPrice[this.currency]]||this.selectAsset[this.currency]||0
286 this.transaction.cost = Number( singlePrice * newAmount).toFixed(2);
291 this.transaction.fee = '0.00000000'
294 account: function (newAccount) {
295 if (newAccount.guid == undefined){
299 this.guid = newAccount.guid;
300 this.address = this.netType === 'vapor'? newAccount.vpAddress: newAccount.address;
304 estimateFee: function(){
305 const asset_amount={}
306 asset_amount[this.selectAsset.assetId] = this.transaction.amount || 0;
308 transaction.estimateFee(this.address, asset_amount).then( (resp) =>{
309 this.transaction.fee = resp.fee
312 img:function (symbol) {
313 const _symbol = symbol.toLowerCase();
314 if(this.netType === 'vapor'){
315 return `https://cdn.blockmeta.com/resources/logo/vapor/${_symbol}.png`
317 return `https://cdn.blockmeta.com/resources/logo/bytom/${_symbol}.png`
320 shortAddress: function (add) {
321 return address.short(add)
323 formatCurrency: function (num) {
324 return Num.formatCurrency(num, this.currency)
326 limitAmount ($event) {
327 // restrict to 2 decimal places
328 const n = new BigNumber(this.transaction.amount)
330 if(this.transaction.amount!=null && this.transaction.amount.indexOf(".")>-1 && (this.transaction.amount.split('.')[1].length > (this.selectAsset.decimals-1))){
331 $event.preventDefault();
335 this.$router.push({name: 'home'});
336 this[Actions.SET_CURRENT_ASSET](undefined)
338 this.transaction.to = "";
339 this.transaction.amount = "";
340 if(this.$route.query.type == 'popup'){
345 this.transaction.amount = this.currentBalance;
347 validate: function () {
349 if (this.$v.$invalid) {
350 const transaction = this.$v.transaction
351 for (let key in Object.keys(transaction)) {
352 const input = Object.keys(transaction)[key];
353 if (input.includes("$")) return false;
355 if (transaction[input].$error) {
359 this.$t("transfer.emptyTo")
364 this.$t("transfer.noneBTM")
368 this.$refs[input].focus();
373 const n = new BigNumber(this.transaction.amount)
374 const to = this.transaction.to
375 if(!address.isValid(to, this.netType)){
377 this.$t("error.BTM0006")
379 this.$refs['to'].focus();
382 else if (n.gt(this.currentBalance)) {
384 this.$t("error.BTM0005")
386 this.$refs['amount'].focus();
390 this.$refs.modalPasswd.open();
393 send: function (password) {
395 let loader = this.$loading.show({
396 // Optional parameters
399 onCancel: this.onCancel
402 this.transaction.asset = this.selectAsset.assetId;
403 transaction.transfer(this.transaction, password, this.address, this).then(result => {
405 this.$router.push('/')
410 getLang(error.message)
415 Actions.SET_CURRENT_ASSET,
420 if(this.$route.query.type === 'popup'){
421 if (this.$route.query.from != undefined) {
422 this.address = this.$route.query.from
423 this.guid = this.currentAccount.guid
424 this.account = this.currentAccount
427 if (this.$route.query.asset != undefined) {
428 currentAssetId = this.$route.query.asset
430 this.transaction.asset= currentAssetId
432 const assets = this.assets
433 this.selectAsset = assets.filter(b => b.assetId === currentAssetId.toLowerCase())[0]
435 if (this.$route.query.to != undefined) {
436 this.transaction.to = this.$route.query.to
438 if (this.$route.query.amount != undefined) {
439 this.transaction.amount = this.$route.query.amount
441 if (this.$route.query.gas != undefined) {
442 this.transaction.fee = this.$route.query.gas
444 if(this.$route.query.confirmations != undefined) {
445 this.transaction.confirmations = this.$route.query.confirmations
448 this.account = this.currentAccount
450 const currentAsset = this.currentAsset || this.selectAsset
451 currentAssetId = currentAsset.assetId
457 transaction.asset(currentAssetId).then(ret => {
458 that.selectAsset = ret
459 if(that.transaction.amount){
460 that.transaction.cost = Number(ret[currencyInPrice[that.currency]] * that.transaction.amount).toFixed(2);