From 8882ca8e874af3e3b73706336638a299ca81def6 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Wed, 16 Dec 2015 16:15:40 -0300 Subject: [PATCH 1/3] Fixes proposals with multiple outputs with only one output --- src/js/services/txFormatService.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/js/services/txFormatService.js b/src/js/services/txFormatService.js index d94d9bf92..15032794d 100644 --- a/src/js/services/txFormatService.js +++ b/src/js/services/txFormatService.js @@ -24,8 +24,8 @@ angular.module('copayApp.services').factory('txFormatService', function(profileS root.processTx = function(tx) { if (!tx) return; - var outputs = tx.outputs ? tx.outputs.length : 0; - if (outputs > 1 && tx.action != 'received') { + var outputs = lodash.isArray(tx.outputs) ? tx.outputs.length : 0; + if (outputs && tx.action != 'received') { tx.hasMultiplesOutputs = true; tx.recipientCount = outputs; tx.amount = lodash.reduce(tx.outputs, function(total, o) { From 804c37bffa4575ae99b5477ab645e651a836c890 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Wed, 16 Dec 2015 16:22:40 -0300 Subject: [PATCH 2/3] Adds example. Refactory --- src/js/controllers/index.js | 19 +++++++++++++++++++ src/js/services/txFormatService.js | 5 ++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index 4a70af0d9..575b29eae 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -495,6 +495,25 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.pendingTxProposalsCountForUs = 0; var now = Math.floor(Date.now() / 1000); + /* Uncomment to test multiple outputs */ + /* + var txp = { + message: 'test multi-output', + fee: 1000, + createdOn: new Date() / 1000, + outputs: [] + }; + function addOutput(n) { + txp.outputs.push({ + amount: 600, + toAddress: '2N8bhEwbKtMvR2jqMRcTCQqzHP6zXGToXcK', + message: 'output #' + (Number(n) + 1) + }); + }; + lodash.times(150, addOutput); + txps.push(txp); + */ + lodash.each(txps, function(tx) { tx = txFormatService.processTx(tx); diff --git a/src/js/services/txFormatService.js b/src/js/services/txFormatService.js index 15032794d..8a78249f5 100644 --- a/src/js/services/txFormatService.js +++ b/src/js/services/txFormatService.js @@ -24,10 +24,9 @@ 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 (lodash.isArray(tx.outputs) && tx.action != 'received') { tx.hasMultiplesOutputs = true; - tx.recipientCount = outputs; + tx.recipientCount = tx.outputs.length; tx.amount = lodash.reduce(tx.outputs, function(total, o) { o.amountStr = formatAmountStr(o.amount); o.alternativeAmountStr = formatAlternativeStr(o.amount); From 8c90f6f346c04f1174c3eeaddf110171f90f9a09 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Wed, 16 Dec 2015 16:40:02 -0300 Subject: [PATCH 3/3] Check if array is empty --- src/js/services/txFormatService.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/services/txFormatService.js b/src/js/services/txFormatService.js index 8a78249f5..1061ede76 100644 --- a/src/js/services/txFormatService.js +++ b/src/js/services/txFormatService.js @@ -24,7 +24,7 @@ angular.module('copayApp.services').factory('txFormatService', function(profileS root.processTx = function(tx) { if (!tx) return; - if (lodash.isArray(tx.outputs) && tx.action != 'received') { + if (lodash.isArray(tx.outputs) && tx.outputs.length > 0 && tx.action != 'received') { tx.hasMultiplesOutputs = true; tx.recipientCount = tx.outputs.length; tx.amount = lodash.reduce(tx.outputs, function(total, o) {