From 805eebb7528f6a9c1a9759191984c52d485c962f Mon Sep 17 00:00:00 2001 From: Gregg Zigler Date: Wed, 1 Jul 2015 15:36:44 -0700 Subject: [PATCH] handle multiple outputs in transaction proposal --- public/views/includes/output.html | 20 +++++++++++ public/views/includes/transaction.html | 12 +++++-- public/views/modals/txp-details.html | 9 ++++- src/js/controllers/index.js | 50 ++++++++++++++++++++++---- 4 files changed, 82 insertions(+), 9 deletions(-) create mode 100644 public/views/includes/output.html diff --git a/public/views/includes/output.html b/public/views/includes/output.html new file mode 100644 index 000000000..ee51e0605 --- /dev/null +++ b/public/views/includes/output.html @@ -0,0 +1,20 @@ +
+ +
diff --git a/public/views/includes/transaction.html b/public/views/includes/transaction.html index 4b0a2b47a..f964a4f7f 100644 --- a/public/views/includes/transaction.html +++ b/public/views/includes/transaction.html @@ -16,8 +16,16 @@ {{tx.merchant.domain}} {{tx.merchant.domain}} - - {{tx.toAddress}} + + {{tx.outputs[0].toAddress.substring(0, 16)+'...'}} + and + {{tx.outputs.length - 1}} + more + + + + {{tx.toAddress}} +
{{tx.message}} diff --git a/public/views/modals/txp-details.html b/public/views/modals/txp-details.html index debb853af..82a4f1f14 100644 --- a/public/views/modals/txp-details.html +++ b/public/views/modals/txp-details.html @@ -16,7 +16,8 @@
+
+
+
+
+
diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index 53a9b5703..2260e92c5 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -429,15 +429,53 @@ angular.module('copayApp.controllers').controller('indexController', function($r var config = configService.getSync().wallet.settings; self.pendingTxProposalsCountForUs = 0; lodash.each(txps, function(tx) { - var amount = tx.amount * self.satToUnit; - tx.amountStr = profileService.formatAmount(tx.amount) + ' ' + config.unitName; + // gregg hack test data + if (!tx.outputs) { + tx.outputs = [ + { toAddress: '2MzCXF7QW4ArgiwDTh12qU3ymWNZzNsrbLo', amount: 123456, message: 'Bitography, Inc.' }, + { toAddress: '2N9JWQkJxbpbW6M4sVaz2Yvn4yczTZgZZh6', amount: 76543, message: 'Chipotle @ Buckhead' }, + { toAddress: '2NFvpdtduhJzQaJcsx3Hf1oJ1U4ouUfLiFG', amount: 543210, message: 'Grand Decentral' } + ]; + } + // gregg hack test data + + function formatAmount(obj) { + var amount = obj.amount * self.satToUnit; + obj.amountStr = profileService.formatAmount(obj.amount) + ' ' + config.unitName; + obj.alternativeAmount = rateService.toFiat(obj.amount, config.alternativeIsoCode) ? rateService.toFiat(obj.amount, config.alternativeIsoCode).toFixed(2) : 'N/A'; + obj.alternativeAmountStr = obj.alternativeAmount + " " + config.alternativeIsoCode; + }; + + if (tx.outputs) { + if (tx.outputs.length === 1) { + tx.amount = tx.outputs[0].amount; + tx.toAddress = tx.outputs[0].toAddress; + tx.message += (' ' + tx.outputs[0].message); + delete tx.outputs; + } else { + tx.amount = lodash.reduce(tx.outputs, function(total, o) { + return total + o.amount; + }, 0); + var cumAmount = 0; + var cumPercent = 0; + var sorted = lodash.sortBy(tx.outputs, function(o) { + return -1 * o.amount; // descending order + }); + tx.outputs = lodash.transform(sorted, function(outputs, o) { + cumAmount += o.amount; + cumPercent += 100 * (o.amount / tx.amount); + o.cumAmount = cumAmount; + o.cumPercent = cumPercent; + formatAmount(o); + outputs.push(o); + }, []); + } + } + formatAmount(tx); + tx.feeStr = profileService.formatAmount(tx.fee) + ' ' + config.unitName; - tx.alternativeAmount = rateService.toFiat(tx.amount, config.alternativeIsoCode) ? rateService.toFiat(tx.amount, config.alternativeIsoCode).toFixed(2) : 'N/A'; - tx.alternativeAmountStr = tx.alternativeAmount + " " + config.alternativeIsoCode; tx.alternativeIsoCode = config.alternativeIsoCode; - - var action = lodash.find(tx.actions, { copayerId: self.copayerId });