17 .transferType input[type=radio] {
22 .transferType input[type="radio"]:checked+label{
24 background: linear-gradient(90deg, #227AF1 100%, #035BD4 0%);;
26 .transferType input[type="radio"]:checked+label .cross-icon{
27 background-image: url('../../assets/img/icon/crosschain-toV.svg');
30 .transferType div:last-child input[type="radio"]:checked+label{
32 background: linear-gradient(91deg, #4B4B4B 0.27%, #1C1C1C 99.68%);
35 .transferType div:last-child input[type="radio"]:checked+label .cross-icon{
36 background-image: url('../../assets/img/icon/crosschain-toB.svg');
39 .transferType div:last-child .choice{
40 border-radius: 0px 40px 40px 0px;
47 white-space: pre-wrap;
50 background: rgba(0, 0, 0, 0.04);
51 border-radius: 40px 0px 0px 40px;
55 background-color: #f7f7f7;
78 background: rgba(255,255,255,0.1);
88 text-transform: uppercase;
91 .asset-option .asset-id{
98 background: rgba(247,247,247,1);
101 border-bottom: 1px solid #E0E0E0;
105 background-image: url('../../assets/img/icon/crosschain-default.svg');
116 <div class="warp-chlid bg-white">
117 <section class="header bg-header">
118 <i class="iconfont icon-back" @click="close"></i>
119 <p>{{ $t('crossChain.title') }}</p>
122 <section class="transferType">
124 <input type="radio" id="typeChoice1"
125 value="toVapor" v-model="transaction.type">
126 <label class="choice" for="typeChoice1"> <div class="cross-icon"></div><div>{{$t('crossChain.toVapor')}}</div></label>
130 <input type="radio" id="typeChoice2"
131 value="toBytom" v-model="transaction.type">
132 <label class="choice" for="typeChoice2"><div class="cross-icon"></div><div>{{$t('crossChain.toBytom')}}</div></label>
137 <section class="form-container">
138 <div class="form-item">
139 <label class="form-item-label">{{ $t('crossChain.asset') }}</label>
140 <div class="form-item-content" >
141 <v-select :options="assets" v-bind:colorBlack="true" :clearable="false" :value="selectAsset" :onChange="assetChange" label="asset">
142 <template slot="selected-option" slot-scope="asset">
143 <div class="asset-option">
144 <div>{{asset.symbol || 'Asset'}}</div>
145 <div class="color-grey asset-id">{{shortAddress(asset.asset)}}</div>
148 <template slot="option" slot-scope="asset">
149 <div class="asset-option">
150 <div>{{asset.symbol || 'Asset'}}</div>
151 <div class="color-grey asset-id">{{shortAddress(asset.asset)}}</div>
159 <div class="separator bg-gray"></div>
160 <section class="form-container">
162 <div class="form-item">
163 <label class="form-item-label">
164 {{ $t('transfer.quantity') }}
166 <small class="float-right" style="margin-right: 8px;">{{formatCurrency(transaction.cost||0) }}</small>
168 <div class="form-item-content" style=" display: flex;">
169 <input type="number" v-model="transaction.amount" :placeholder="bytomBalance">
170 <span class="color-grey" style="width: 40px; font-size: 15px;position: absolute;right: 0;">{{unit}}</span>
172 <p class="small color-grey">{{$t('crossChain.amountHint')}}</p>
175 <a class="btn btn-primary" @click="send">{{ $t('transfer.send') }}</a>
181 import address from "@/utils/address";
182 import account from "@/models/account";
183 import transaction from "@/models/transaction";
184 import getLang from "@/assets/language/sdk";
185 import Confirm from "./transferConfirm";
186 import { BTM } from "@/utils/constants";
187 import { mapActions, mapGetters, mapState } from 'vuex'
188 import { Number as Num } from "@/utils/Number"
189 import _ from 'lodash';
191 const currencyInPrice = {
211 accountBalance: 0.00,
212 fee: this.$t("transfer.feeType"),
213 feeTypeOptions: [this.$t("transfer.feeType")],
226 if(this.transaction.type === 'toVapor'){
227 return this.currentAccount.balances
229 return this.currentAccount.vpBalances
233 return this.selectAsset.symbol;
235 bytomBalance: function () {
236 let balance, balances
237 if(this.transaction.type === 'toVapor'){
238 balances = this.currentAccount.balances
239 }else if(this.transaction.type === 'toBytom') {
240 balances = this.currentAccount.vpBalances
243 if(balances && balances.length >0 ){
244 if( this.selectAsset.asset === BTM && this.transaction.type === 'toBytom' ){
245 const balanceObject = balances.filter(b => b.asset === BTM)[0]
246 balance = balanceObject.balance
248 let vote = 0, lock = 0
250 const votes = this.currentAccount.votes
252 if (votes && votes.length > 0) {
253 vote = _.sumBy(votes, 'total')
254 lock = _.sumBy(votes, 'locked')
257 balance = Num.formatNue((balance - vote - lock), balanceObject.decimals)
260 const balanceObject = balances.filter(b => b.asset === this.selectAsset.asset)[0]
261 balance = Num.formatNue(balanceObject.balance, balanceObject.decimals)
266 if(this.transaction.type === 'toVapor'){
267 return `Bytom${this.$t("crossChain.amountPlaceHolder")}${(balance != null && balance != 0) ? balance : '0.00'}`
269 return `Vapor${this.$t("crossChain.amountPlaceHolder")}${(balance != null && balance != 0) ? balance : '0.00'}`
284 "transaction.amount": function (newAmount) {
285 this.transaction.cost = Number(this.selectAsset[currencyInPrice[this.currency]] * newAmount).toFixed(2);
287 account: function (newAccount) {
288 this.guid = newAccount.guid;
290 guid: function (newGuid) {
291 this.accountList.forEach(account => {
292 if (account.guid == newGuid.guid) {
293 this.account = account;
298 account.balance(newGuid).then(balances => {
300 if(balances.length >0 ) {
301 const balanceObject = balances.filter(b => b.asset === BTM)[0]
302 balance = balanceObject.balance / Math.pow(10, balanceObject.decimals)
304 this.accountBalance = balance;
311 shortAddress: function (add) {
312 return address.short(add)
316 this.transaction.to = "";
317 this.transaction.amount = "";
318 account.setupNet(`${this.net}${this.netType}`);
319 if(this.$route.query.type == 'popup'){
323 formatCurrency: function (num) {
324 return Num.formatCurrency(num, this.currency)
326 assetChange: function (val) {
327 if(val.asset !== this.selectAsset.asset){
328 this.transaction.asset = val.asset;
329 const balances = this.currentAccount.balances
331 if(balances.length >0 ) {
332 const balanceObject = balances.filter(b => b.asset === val.asset)[0]
333 balance = Num.formatNue(balanceObject.balance, balanceObject.decimals)
335 this.accountBalance = balance;
336 transaction.asset(val.asset).then(ret => {
337 this.selectAsset = Object.assign(ret,val)
338 this.transaction.cost = Number(ret[currencyInPrice[this.currency]] * this.transaction.amount).toFixed(2);
343 if (this.transaction.amount <= 0) {
345 body: this.$t("transfer.noneBTM")
350 let loader = this.$loading.show({
351 // Optional parameters
354 onCancel: this.onCancel
358 if(this.transaction.type === 'toVapor'){
359 transaction.chainStatus().then((resp)=>{
360 const address = resp.federation_address
361 account.setupNet(`${this.net}`)
362 this.transaction.to = address
363 transaction.build(this.account.guid, address, this.transaction.asset, Num.convertToNue(this.transaction.amount,this.selectAsset.decimals), this.transaction.confirmations).then(result => {
365 if(!this.transaction.fee){
366 this.transaction.fee = Number( _.sumBy(result, 'fee'));
368 this.$router.push({ name: 'transfer-confirm', params: { account: this.account, transaction: this.transaction, rawData: result,assetAlias: this.selectAsset.symbol, type: this.$route.query.type } })
372 body: getLang(error.message)
380 const address = this.account.address
381 account.setupNet(`${this.net}vapor`)
382 this.transaction.to = address
383 transaction.buildCrossChain(this.account.guid, address, this.transaction.asset, Num.convertToNue(this.transaction.amount,this.selectAsset.decimals), this.transaction.confirmations).then(result => {
385 if(!this.transaction.fee){
386 this.transaction.fee = Number( _.sumBy(result, 'fee') / 100000000);
388 this.$router.push({ name: 'transfer-confirm', params: { account: this.account, transaction: this.transaction, rawData: result, assetAlias: this.selectAsset.symbol, type: this.$route.query.type } })
392 body: getLang(error.message)
400 if(this.$route.query.type === 'popup'){
401 if (this.$route.query.from != undefined) {
402 this.guid = this.$route.query.from
403 this.account = this.accountList.filter(e => e.guid === this.guid)[0]
406 if (this.$route.query.asset != undefined) {
407 this.transaction.asset= this.$route.query.asset
409 if (this.$route.query.to != undefined) {
410 this.transaction.to = this.$route.query.to
412 if (this.$route.query.amount != undefined) {
413 this.transaction.amount = this.$route.query.amount
415 if (this.$route.query.gas != undefined) {
416 this.transaction.fee = this.$route.query.gas
418 if(this.$route.query.confirmations != undefined) {
419 this.transaction.confirmations = this.$route.query.confirmations
422 this.account = this.currentAccount
425 const currentAsset = this.currentAccount.balances[0]
428 transaction.asset(currentAsset.asset).then(ret => {
429 this.selectAsset = Object.assign(ret,currentAsset)