From df12c5964cefa844c6cd96c2ce46bf87b8488d53 Mon Sep 17 00:00:00 2001 From: Esteban Ordano Date: Fri, 7 Nov 2014 15:30:00 -0300 Subject: [PATCH] Fixes performance issue with txproposals --- js/models/Wallet.js | 32 +++++++++++++++----------------- js/services/controllerUtils.js | 4 ++-- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/js/models/Wallet.js b/js/models/Wallet.js index 1f961434e..0748fb16f 100644 --- a/js/models/Wallet.js +++ b/js/models/Wallet.js @@ -1303,7 +1303,7 @@ Wallet.prototype._getActionList = function(actions) { * @return {Object[]} each object returned represents a transaction proposal */ Wallet.prototype.getPendingTxProposals = function() { - var that = this; + var self = this; var ret = []; ret.txs = []; var pendingForUs = 0; @@ -1313,24 +1313,22 @@ Wallet.prototype.getPendingTxProposals = function() { _.find(txps, function(txp) { if (txp.isPending) { pendingForUs++; - var tx = txp.builder.build(); - var outs = []; - tx.outs.forEach(function(o) { - var addr = bitcore.Address.fromScriptPubKey(o.getScript(), that.getNetworkName())[0].toString(); - if (!that.addressIsOwn(addr, { - excludeMain: true - })) { - outs.push({ - address: addr, - value: bitcore.util.valueToBigInt(o.getValue()) * satToUnit, - }); - } + var addresses = {}; + var outs = JSON.parse(txp.builder.vanilla.outs); + outs.forEach(function(o) { + if (!self.publicKeyRing.addressToPath[o.Straddress]) { + if (!addresses[o.address]) addresses[o.address] = 0; + addresses[o.address] += (o.amountSatStr || Math.round(o.amount * bitcore.util.COIN)); + }; + }); + txp.outs = []; + _.each(addresses, function(value, address) { + txp.outs.push({address: address, value: value * satToUnit}); }); // extra fields - txp.outs = outs; txp.fee = txp.builder.feeSat * satToUnit; - txp.missingSignatures = tx.countInputMissingSignatures(0); - txp.actionList = that._getActionList(txp.peerActions); + txp.missingSignatures = txp.builder.build().countInputMissingSignatures(0); + txp.actionList = self._getActionList(txp.peerActions); ret.txs.push(txp); } }); @@ -2203,7 +2201,7 @@ Wallet.prototype.addressIsOwn = function(addrStr, opts) { }; -/* +/** * Estimate a tx fee in satoshis given its input count * only for spending all wallet funds */ diff --git a/js/services/controllerUtils.js b/js/services/controllerUtils.js index 610e331ee..d98735cd7 100644 --- a/js/services/controllerUtils.js +++ b/js/services/controllerUtils.js @@ -62,12 +62,12 @@ angular.module('copayApp.services') }; - root.updateTxsAndBalance = _.debounce(function(w) { + root.updateTxsAndBalance = function(w) { root.updateTxs(); root.updateBalance(w, function() { $rootScope.$digest(); }); - }, 3000); + }; root.installWalletHandlers = function($scope, w) {