Refactor processTx
This commit is contained in:
parent
9cc275af5f
commit
df09e07ded
1 changed files with 18 additions and 13 deletions
|
|
@ -24,20 +24,25 @@ angular.module('copayApp.services').factory('txFormatService', function(profileS
|
||||||
root.processTx = function(tx) {
|
root.processTx = function(tx) {
|
||||||
if (!tx) return;
|
if (!tx) return;
|
||||||
|
|
||||||
var outputs = lodash.isArray(tx.outputs) ? tx.outputs.length : 0;
|
// New transaction output format
|
||||||
if (outputs && tx.action != 'received') {
|
if (tx.outputs) {
|
||||||
if (outputs > 1) {
|
|
||||||
tx.hasMultiplesOutputs = true;
|
var outputsNr = tx.outputs.length;
|
||||||
tx.recipientCount = outputs;
|
|
||||||
}
|
if (tx.action != 'received') {
|
||||||
tx.amount = lodash.reduce(tx.outputs, function(total, o) {
|
if (outputsNr > 1) {
|
||||||
o.amountStr = formatAmountStr(o.amount);
|
tx.recipientCount = outputsNr;
|
||||||
o.alternativeAmountStr = formatAlternativeStr(o.amount);
|
tx.hasMultiplesOutputs = true;
|
||||||
return total + o.amount;
|
}
|
||||||
}, 0);
|
tx.amount = lodash.reduce(tx.outputs, function(total, o) {
|
||||||
}
|
o.amountStr = formatAmountStr(o.amount);
|
||||||
|
o.alternativeAmountStr = formatAlternativeStr(o.amount);
|
||||||
|
return total + o.amount;
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
tx.toAddress = tx.outputs[0].toAddress;
|
||||||
|
}
|
||||||
|
|
||||||
tx.toAddress = tx.outputs[0].toAddress; // Get first address for single transactions
|
|
||||||
tx.amountStr = formatAmountStr(tx.amount);
|
tx.amountStr = formatAmountStr(tx.amount);
|
||||||
tx.alternativeAmountStr = formatAlternativeStr(tx.amount);
|
tx.alternativeAmountStr = formatAlternativeStr(tx.amount);
|
||||||
tx.feeStr = formatFeeStr(tx.fee || tx.fees);
|
tx.feeStr = formatFeeStr(tx.fee || tx.fees);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue