From df09e07ded85e875588db7f823cacfe28c5eded5 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Thu, 11 Feb 2016 13:56:57 -0500 Subject: [PATCH] Refactor processTx --- src/js/services/txFormatService.js | 31 +++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/js/services/txFormatService.js b/src/js/services/txFormatService.js index 7ca66dd5c..9623753e8 100644 --- a/src/js/services/txFormatService.js +++ b/src/js/services/txFormatService.js @@ -24,20 +24,25 @@ angular.module('copayApp.services').factory('txFormatService', function(profileS root.processTx = function(tx) { if (!tx) return; - var outputs = lodash.isArray(tx.outputs) ? tx.outputs.length : 0; - if (outputs && tx.action != 'received') { - if (outputs > 1) { - tx.hasMultiplesOutputs = true; - tx.recipientCount = outputs; - } - tx.amount = lodash.reduce(tx.outputs, function(total, o) { - o.amountStr = formatAmountStr(o.amount); - o.alternativeAmountStr = formatAlternativeStr(o.amount); - return total + o.amount; - }, 0); - } + // New transaction output format + if (tx.outputs) { + + var outputsNr = tx.outputs.length; + + if (tx.action != 'received') { + if (outputsNr > 1) { + tx.recipientCount = outputsNr; + tx.hasMultiplesOutputs = true; + } + 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.alternativeAmountStr = formatAlternativeStr(tx.amount); tx.feeStr = formatFeeStr(tx.fee || tx.fees);