const balanceObject = transaction.balances
.filter(b => b.asset.assetId === assetID);
- const filterInput = _.find(transaction.inputs, function(o) { return o.type =='veto'; })
- const filterOutput = _.find(transaction.outputs, function(o) { return o.type =='vote'; })
+ const filterInput = transaction.types.includes('veto')
+ const filterOutput = transaction.types.includes('vote')
if(filterInput){
transaction.type = 'veto'
transaction.pubkey = filterOutput.vote
transaction.vAmount = Num.formatNue(outAmount,8)
transaction.type = 'vote'
- }else if(_.find(transaction.outputs, function(o) { return o.type =='crosschain_output'; })){
+ }else if(transaction.types.includes('out_crosschain')){
transaction.type = 'crossChain'
- transaction.cDirection ='Vapor -> Bytom'
- }else if(_.find(transaction.inputs, function(o) { return o.type =='crosschain_input'; })){
+ if(this.netType === 'vapor'){
+ transaction.cDirection ='Vapor -> Bytom'
+ }else{
+ transaction.cDirection ='Bytom -> Vapor'
+ }
+ }else if(transaction.types.includes('in_crosschain')){
transaction.type = 'crossChain'
- transaction.cDirection ='Bytom -> Vapor'
+ if(this.netType === 'vapor'){
+ transaction.cDirection ='Bytom -> Vapor'
+ }else{
+ transaction.cDirection ='Vapor -> Bytom'
+ }
}
const inputAddresses = transaction.inputs
<v-select :options="assets" v-bind:colorBlack="true" :clearable="false" :value="selectAsset" :onChange="assetChange" label="asset">
<template slot="selected-option" slot-scope="asset">
<div class="asset-option">
- <div>{{asset.symbol || 'Asset'}}</div>
- <div class="color-grey asset-id">{{shortAddress(asset.asset)}}</div>
+ <div>{{asset.asset.symbol || 'Asset'}}</div>
+ <div class="color-grey asset-id">{{shortAddress(asset.asset.assetId)}}</div>
</div>
</template>
<template slot="option" slot-scope="asset">
<div class="asset-option">
- <div>{{asset.symbol || 'Asset'}}</div>
- <div class="color-grey asset-id">{{shortAddress(asset.asset)}}</div>
+ <div>{{asset.asset.symbol || 'Asset'}}</div>
+ <div class="color-grey asset-id">{{shortAddress(asset.asset.assetId)}}</div>
</div>
</template>
</v-select>
import _ from 'lodash';
const currencyInPrice = {
- inCny: 'cny_price',
- inUsd: 'usd_price',
- inBtc:'btc_price'
+ in_cny: 'cnyPrice',
+ in_usd: 'usdPrice',
+ in_btc:'btcPrice',
+ inCny: 'cnyPrice',
+ inUsd: 'usdPrice',
+ inBtc:'btcPrice'
}
export default {
data() {
return {
selectAsset: {
- asset: BTM,
- symbol: "BTM",
- decimals:8
+ asset:{
+ assetId: BTM,
+ symbol: "BTM",
+ decimals:8
+ }
},
show: false,
guid: null,
return this.currentAccount.vpBalances
}
},
- unit() {
- return this.selectAsset.symbol;
- },
+ address(){
+ if(this.transaction.type === 'toVapor'){
+ return this.currentAccount.address
+ }else{
+ return this.currentAccount.vpAddress
+ }
+ },
+ unit() {
+ return this.selectAsset.asset.symbol;
+ },
bytomBalance: function () {
let balance, balances
if(this.transaction.type === 'toVapor'){
}
if(balances && balances.length >0 ){
- if( this.selectAsset.asset === BTM && this.transaction.type === 'toBytom' ){
- const balanceObject = balances.filter(b => b.asset === BTM)[0]
- balance = balanceObject.balance
-
- let vote = 0, lock = 0
-
- const votes = this.currentAccount.votes
-
- if (votes && votes.length > 0) {
- vote = _.sumBy(votes, 'total')
- lock = _.sumBy(votes, 'locked')
- }
-
- balance = Num.formatNue((balance - vote - lock), balanceObject.decimals)
- }else{
-
- const balanceObject = balances.filter(b => b.asset === this.selectAsset.asset)[0]
- balance = Num.formatNue(balanceObject.balance, balanceObject.decimals)
- }
-
+ const balanceObject = balances.filter(b => b.asset.assetId === this.selectAsset.asset.assetId)[0]
+ balance = Num.formatNue(balanceObject.availableBalance, balanceObject.decimals)
}
if(this.transaction.type === 'toVapor'){
}
});
- account.balance(newGuid).then(balances => {
+ account.balance(this.address).then(balances => {
let balance = 0.00
if(balances.length >0 ) {
const balanceObject = balances.filter(b => b.asset === BTM)[0]
- balance = balanceObject.balance / Math.pow(10, balanceObject.decimals)
+ balance = balanceObject.balance
}
this.accountBalance = balance;
}).catch(error => {
return Num.formatCurrency(num, this.currency)
},
assetChange: function (val) {
- if(val.asset !== this.selectAsset.asset){
- this.transaction.asset = val.asset;
- const balances = this.currentAccount.balances
+ if(val.asset.assetId !== this.selectAsset.asset.assetId){
+ this.transaction.asset = val.asset.assetId;
+ const balances = this.assets
let balance = 0.00
if(balances.length >0 ) {
- const balanceObject = balances.filter(b => b.asset === val.asset)[0]
- balance = Num.formatNue(balanceObject.balance, balanceObject.decimals)
+ const balanceObject = balances.filter(b => b.asset.assetId === val.asset.assetId)[0]
+ balance = Num.formatNue(balanceObject.availableBalance, 0)
}
this.accountBalance = balance;
- transaction.asset(val.asset).then(ret => {
+ transaction.asset(val.asset.assetId).then(ret => {
this.selectAsset = Object.assign(ret,val)
this.transaction.cost = Number(ret[currencyInPrice[this.currency]] * this.transaction.amount).toFixed(2);
});
}
},
send: function () {
- if (this.transaction.amount <= 0) {
- this.$dialog.show({
- body: this.$t("transfer.noneBTM")
- });
- return;
- }
-
- let loader = this.$loading.show({
- // Optional parameters
- container: null,
- canCancel: true,
- onCancel: this.onCancel
+ if (this.transaction.amount <= 0) {
+ this.$dialog.show({
+ body: this.$t("transfer.noneBTM")
});
+ return;
+ }
- // Bytom => Vapor
- if(this.transaction.type === 'toVapor'){
- transaction.chainStatus().then((resp)=>{
- const address = resp.federation_address
- account.setupNet(`${this.net}`)
- this.transaction.to = address
- transaction.build(this.account.guid, address, this.transaction.asset, Num.convertToNue(this.transaction.amount,this.selectAsset.decimals), this.transaction.confirmations).then(result => {
- loader.hide();
- if(!this.transaction.fee){
- this.transaction.fee = Number( _.sumBy(result, 'fee'));
- }
- this.$router.push({ name: 'transfer-confirm', params: { account: this.account, transaction: this.transaction, rawData: result,assetAlias: this.selectAsset.symbol, type: this.$route.query.type } })
- }).catch(error => {
- loader.hide();
- this.$dialog.show({
- body: getLang(error.message)
- });
- });
- })
- }
-
- // Vapor => Bytom
- else{
- const address = this.account.address
- account.setupNet(`${this.net}vapor`)
+ let loader = this.$loading.show({
+ // Optional parameters
+ container: null,
+ canCancel: true,
+ onCancel: this.onCancel
+ });
+
+ // Bytom => Vapor
+ if (this.transaction.type === 'toVapor') {
+ transaction.chainStatus().then((resp) => {
+ const address = resp.federationAddress
+ account.setupNet(`${this.net}`)
this.transaction.to = address
- transaction.buildCrossChain(this.account.guid, address, this.transaction.asset, Num.convertToNue(this.transaction.amount,this.selectAsset.decimals), this.transaction.confirmations).then(result => {
- loader.hide();
- if(!this.transaction.fee){
- this.transaction.fee = Number( _.sumBy(result, 'fee') / 100000000);
+ transaction.build(this.address, address, this.transaction.asset, this.transaction.amount, this.transaction.confirmations).then(result => {
+ loader.hide();
+ if (!this.transaction.fee) {
+ this.transaction.fee = Number( _.sumBy(result, 'tx.fee'));
}
- this.$router.push({ name: 'transfer-confirm', params: { account: this.account, transaction: this.transaction, rawData: result, assetAlias: this.selectAsset.symbol, type: this.$route.query.type } })
+ this.$router.push({name: 'transfer-confirm',
+ params: {
+ account: this.account,
+ transaction: this.transaction,
+ rawData: result,
+ assetAlias: this.selectAsset.asset.symbol,
+ type: this.$route.query.type
+ }
+ })
}).catch(error => {
- loader.hide();
- this.$dialog.show({
- body: getLang(error.message)
- });
+ loader.hide();
+ this.$dialog.show({
+ body: getLang(error.message)
+ });
});
- }
+ })
+ }
+ // Vapor => Bytom
+ else {
+ const toAddress = this.account.address
+ account.setupNet(`${this.net}vapor`)
+ this.transaction.to = toAddress
+ transaction.buildCrossChain(this.address, toAddress, this.transaction.asset, this.transaction.amount, this.transaction.confirmations).then(result => {
+ loader.hide();
+ if (!this.transaction.fee) {
+ this.transaction.fee = Number( _.sumBy(result, 'tx.fee'));
+ }
+ this.$router.push({name: 'transfer-confirm',
+ params: {
+ account: this.account,
+ transaction: this.transaction,
+ rawData: result,
+ assetAlias: this.selectAsset.asset.symbol,
+ type: this.$route.query.type
+ }
+ })
+ }).catch(error => {
+ loader.hide();
+ this.$dialog.show({
+ body: getLang(error.message)
+ });
+ });
+ }
}
+
}, mounted() {
//detect injection
if(this.$route.query.type === 'popup'){
this.account = this.currentAccount
}
- const currentAsset = this.currentAccount.balances[0]
+ const currentAsset = this.currentAccount.balances[0]
- if(currentAsset){
- transaction.asset(currentAsset.asset).then(ret => {
- this.selectAsset = Object.assign(ret,currentAsset)
- });
- }
+ if(currentAsset){
+ transaction.asset(currentAsset.asset.assetId).then(ret => {
+ this.selectAsset = Object.assign(ret,currentAsset)
+ });
+ }
}
};
</script>