mainnetvapor: `${networks['mainnet']}/vapor/v3/` ,
}
+
+export const decimalsMap = {
+ mainnet:{
+ '184e1cc4ee4845023888810a79eed7a42c02c544cf2c61ceac05e176d575bd46':6,
+ '25f2069140fa3ff4d6e0dc1d0fcaa11ace01eb721f115f0f1a5a3782db597fb1':6,
+ '78de44ffa1bce37b757c9eae8925b5f199dc4621b412ef0f3f46168865284a93':9,
+ 'bda946b3110fa46fd94346ce3f05f0760f1b9de72e238835bc4d19f9d64f1742':8,
+ 'c4644dd6643475d57ed624f63129ab815f282b61f4bb07646d73423a6e1a1563':6,
+ 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff':8
+ },
+ tesetnet:{
+ '328d60d8192425beeaea53dbbc7900778ec06f4ca2e4499f92aea6ca17645d4c':8,
+ '4483893ef7d9aac788c0e9e49a12398c1d35a2172adb1c8dc551fd169a6f5703':8,
+ '57e5b3a3040e1c0162f64019838fd93b5f33dcde7069fa72aee48a054143443f':8,
+ 'a0889e1080999e59ed552865a1d3ee677202796222141ccc3552041708aad76c':8,
+ 'babb18008ba6cf533fed6bc2bb8e98b3978c324f221aa679ba4c2b558a8fa97d':8,
+ 'd50a426bdaaf1458d161aba4d8c3ebdd095eac7e1bbeb4a0252a3737ccf2d492':8,
+ 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff':8
+ }
+}
</tr>
<div class="divider"></div>
+ <tr class="row">
+ <td class="col label">{{ $t('transfer.types') }}</td>
+ <td class="col value">{{transaction.types}}</td>
+ </tr>
<tr v-for="(amountInput, index) in transaction.amounts" :key="index" class="row">
<td class="col label">{{index ==0 && $t('transfer.transferAmount') }}</td>
<script>
import transaction from "@/models/transaction";
import getLang from "@/assets/language/sdk";
-import { LocalStream } from 'extension-streams';
import {apis} from '@/utils/BrowserApis';
import NotificationService from '../../services/NotificationService'
import { mapActions, mapGetters, mapState } from 'vuex'
import _ from 'lodash';
import account from "@/models/account";
-import { Number as Num } from "@/utils/Number"
-
+import { camelize, removeFromArray } from "@/utils/utils";
+import { decimalsMap } from "@/utils/constants"
+import BigNumber from "bignumber.js"
export default {
args: "",
fee: "",
confirmations:1,
- amounts: []
+ amounts: [],
+ types:[]
},
password:'',
prompt:''
}
}, mounted() {
this.prompt = window.data || apis.extension.getBackgroundPage().notification || null;
-
if(this.prompt.data !== undefined){
- const param = Array.isArray(this.prompt.data)? this.prompt.data[0].tx : this.prompt.data.tx
- if(param.inputs !== undefined){
- this.transaction.input = param.inputs
- }
- if(param.outputs !== undefined){
- this.transaction.output = param.outputs
- }
- if(param.fee !== undefined){
- this.transaction.fee = param.fee
- }
-
- const array = param.inputs.filter(action => action.type ==='spend')
+ const param = Array.isArray(this.prompt.data)? this.prompt.data[0] : this.prompt.data
+ const tx = camelize(param)
+ const rawTransaction = tx.rawTransaction
+ const currentAddress = this.netType === 'vapor'?
+ this.currentAccount.vpAddress:
+ this.currentAccount.address
- if(array.length>0){
account.setupNet(`${this.net}${this.netType}`)
- const promise =
- _(array)
- .groupBy('asset')
- .map((objs, key) => {
- return this.queryAsset(key).then(resp =>{
- return {
- 'asset': key,
- 'alias':resp.alias,
- 'amount':Num.formatNue( _.sumBy(objs, 'amount'), resp.decimals)
- }
- })
+ transaction.decodeTransaction(rawTransaction).then((tx)=>{
+ this.transaction.fee = tx.fee/100000000
+ this.transaction.input = tx.inputs
+ this.transaction.output = tx.outputs
+
+ const inputs = tx.inputs.filter(i => i.address === currentAddress)
+ const outputs = tx.outputs.filter(i => i.address === currentAddress)
+ const inputAsset = inputs.map(i => i.asset);
+ const outputAsset = outputs.map(i => i.asset);
+
+ const asset = _.union(inputAsset, outputAsset)
+
+ let types = ["transfer"]
+ const promise =
+ asset
+ .map((assetId) => {
+ return this.queryAsset(assetId).then(resp =>{
+ const assetInput = inputs.filter(i => i.asset ===assetId)
+ const assetOutput = outputs.filter(o => o.asset ===assetId)
+ const inputAmount = new BigNumber(_.sumBy(assetInput, 'amount'))
+ const outputAmount = new BigNumber(_.sumBy(assetOutput, 'amount'))
+
+ const decimals = decimalsMap[this.net][assetId]
+ const amount = inputAmount.minus(outputAmount).shiftedBy(-decimals)
+
+ return {
+ 'asset': assetId,
+ 'alias': resp.symbol,
+ 'amount': amount.toString()
+ }
+ })
+ })
+
+ let that = this;
+ Promise.all(promise).then(function(output) {
+ that.transaction.amounts = output
})
- let that = this;
- Promise.all(promise).then(function(output) {
- that.transaction.amounts = output
- })
+ const inputType = inputs.map(i => i.type);
+ const outputType = outputs.map(o => o.type);
+ types = _.union(inputType, outputType, types);
- }
+ const remove = ['spend','control'];
+ types = removeFromArray(types, remove);
+ types = types.map(ty => this.$t(`common.${ty}`)).join(', ');
+
+ this.transaction.types = types
+ })
- }
+ }
}
};
</script>