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.asset.symbol || 'Asset'}}</div>
145 <div class="color-grey asset-id">{{shortAddress(asset.asset.assetId)}}</div>
148 <template slot="option" slot-scope="asset">
149 <div class="asset-option">
150 <div>{{asset.asset.symbol || 'Asset'}}</div>
151 <div class="color-grey asset-id">{{shortAddress(asset.asset.assetId)}}</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 = {
216 accountBalance: 0.00,
217 fee: this.$t("transfer.feeType"),
218 feeTypeOptions: [this.$t("transfer.feeType")],
231 if(this.transaction.type === 'toVapor'){
232 return this.currentAccount.balances
234 return this.currentAccount.vpBalances
238 if(this.transaction.type === 'toVapor'){
239 return this.currentAccount.address
241 return this.currentAccount.vpAddress
245 return this.selectAsset.asset.symbol;
247 bytomBalance: function () {
248 let balance, balances
249 if(this.transaction.type === 'toVapor'){
250 balances = this.currentAccount.balances
251 }else if(this.transaction.type === 'toBytom') {
252 balances = this.currentAccount.vpBalances
255 if(balances && balances.length >0 ){
256 const balanceObject = balances.filter(b => b.asset.assetId === this.selectAsset.asset.assetId)[0]
257 balance = Num.formatNue(balanceObject.availableBalance, balanceObject.decimals)
260 if(this.transaction.type === 'toVapor'){
261 return `Bytom${this.$t("crossChain.amountPlaceHolder")}${(balance != null && balance != 0) ? balance : '0.00'}`
263 return `Vapor${this.$t("crossChain.amountPlaceHolder")}${(balance != null && balance != 0) ? balance : '0.00'}`
278 "transaction.amount": function (newAmount) {
279 this.transaction.cost = Number(this.selectAsset[currencyInPrice[this.currency]] * newAmount).toFixed(2);
281 account: function (newAccount) {
282 this.guid = newAccount.guid;
284 guid: function (newGuid) {
285 this.accountList.forEach(account => {
286 if (account.guid == newGuid.guid) {
287 this.account = account;
292 account.balance(this.address).then(balances => {
294 if(balances.length >0 ) {
295 const balanceObject = balances.filter(b => b.asset === BTM)[0]
296 balance = balanceObject.balance
298 this.accountBalance = balance;
305 shortAddress: function (add) {
306 return address.short(add)
310 this.transaction.to = "";
311 this.transaction.amount = "";
312 account.setupNet(`${this.net}${this.netType}`);
313 if(this.$route.query.type == 'popup'){
317 formatCurrency: function (num) {
318 return Num.formatCurrency(num, this.currency)
320 assetChange: function (val) {
321 if(val.asset.assetId !== this.selectAsset.asset.assetId){
322 this.transaction.asset = val.asset.assetId;
323 const balances = this.assets
325 if(balances.length >0 ) {
326 const balanceObject = balances.filter(b => b.asset.assetId === val.asset.assetId)[0]
327 balance = Num.formatNue(balanceObject.availableBalance, 0)
329 this.accountBalance = balance;
330 transaction.asset(val.asset.assetId).then(ret => {
331 this.selectAsset = Object.assign(ret,val)
332 this.transaction.cost = Number(ret[currencyInPrice[this.currency]] * this.transaction.amount).toFixed(2);
337 if (this.transaction.amount <= 0) {
339 body: this.$t("transfer.noneBTM")
344 let loader = this.$loading.show({
345 // Optional parameters
348 onCancel: this.onCancel
352 if (this.transaction.type === 'toVapor') {
353 transaction.chainStatus().then((resp) => {
354 const address = resp.federationAddress
355 account.setupNet(`${this.net}`)
356 this.transaction.to = address
357 transaction.build(this.address, address, this.transaction.asset, this.transaction.amount, this.transaction.confirmations).then(result => {
359 if (!this.transaction.fee) {
360 this.transaction.fee = Number( _.sumBy(result, 'tx.fee'));
362 this.$router.push({name: 'transfer-confirm',
364 account: this.account,
365 transaction: this.transaction,
367 assetAlias: this.selectAsset.asset.symbol,
368 type: this.$route.query.type
374 body: getLang(error.message)
382 const toAddress = this.account.address
383 account.setupNet(`${this.net}vapor`)
384 this.transaction.to = toAddress
385 transaction.buildCrossChain(this.address, toAddress, this.transaction.asset, this.transaction.amount, this.transaction.confirmations).then(result => {
387 if (!this.transaction.fee) {
388 this.transaction.fee = Number( _.sumBy(result, 'tx.fee'));
390 this.$router.push({name: 'transfer-confirm',
392 account: this.account,
393 transaction: this.transaction,
395 assetAlias: this.selectAsset.asset.symbol,
396 type: this.$route.query.type
402 body: getLang(error.message)
410 if(this.$route.query.type === 'popup'){
411 if (this.$route.query.from != undefined) {
412 this.guid = this.$route.query.from
413 this.account = this.accountList.filter(e => e.guid === this.guid)[0]
416 if (this.$route.query.asset != undefined) {
417 this.transaction.asset= this.$route.query.asset
419 if (this.$route.query.to != undefined) {
420 this.transaction.to = this.$route.query.to
422 if (this.$route.query.amount != undefined) {
423 this.transaction.amount = this.$route.query.amount
425 if (this.$route.query.gas != undefined) {
426 this.transaction.fee = this.$route.query.gas
428 if(this.$route.query.confirmations != undefined) {
429 this.transaction.confirmations = this.$route.query.confirmations
432 this.account = this.currentAccount
435 const currentAsset = this.currentAccount.balances[0]
438 transaction.asset(currentAsset.asset.assetId).then(ret => {
439 this.selectAsset = Object.assign(ret,currentAsset)