From c64bf07ae381441abd05cbc78a553573d40eab02 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Thu, 5 Jun 2014 14:55:19 -0300 Subject: [PATCH] fix safeUnspents report --- config.js | 4 ++-- index.html | 2 +- js/controllers/header.js | 5 +++-- js/models/core/TxProposals.js | 10 ++++++---- js/models/core/Wallet.js | 5 +++-- js/services/controllerUtils.js | 6 ++++-- 6 files changed, 19 insertions(+), 13 deletions(-) diff --git a/config.js b/config.js index 19ec917b5..cfabaaa7e 100644 --- a/config.js +++ b/config.js @@ -23,12 +23,12 @@ var defaultConfig = { // Use this to connect to bitpay's PeerJS server key: 'satoshirocks', host: '162.242.219.26', - port: 80, + port: 10000, path: '/', // other PeerJS config maxPeers: 15, - debug: 3, + debug: 1, // Network encryption config sjclParams: { diff --git a/index.html b/index.html index 76b2720d4..703cb0589 100644 --- a/index.html +++ b/index.html @@ -82,7 +82,7 @@ -
+
Having troubles connecting to Insight server. Check diff --git a/js/controllers/header.js b/js/controllers/header.js index 757b67958..36b37459f 100644 --- a/js/controllers/header.js +++ b/js/controllers/header.js @@ -35,14 +35,15 @@ angular.module('copayApp.controllers').controller('HeaderController', // Initialize alert notification (not show when init wallet) $rootScope.txAlertCount = 0; - $rootScope.insightError = -1; + $rootScope.insightError = 0; $rootScope.$watch('insightError', function(status) { - if (status === 0) { + if (status === -1) { $rootScope.$flashMessage = { type: 'success', message: 'Networking Restored :)', }; + $rootScope.insightError = 0; } }); diff --git a/js/models/core/TxProposals.js b/js/models/core/TxProposals.js index 11cb2de56..10c2e1308 100644 --- a/js/models/core/TxProposals.js +++ b/js/models/core/TxProposals.js @@ -231,15 +231,17 @@ TxProposals.prototype.getTxProposal = function(ntxid, copayers) { return i; }; +//returns the unspent txid-vout used in PENDING Txs TxProposals.prototype.getUsedUnspent = function(maxRejectCount) { - var ret = []; + var ret = {}; for(var i in this.txps) { var u = this.txps[i].builder.getSelectedUnspent(); - if (this.getTxProposal(i).rejectCount>maxRejectCount) + var p = this.getTxProposal(i); + if (p.rejectCount>maxRejectCount || p.sentTxid) continue; - for (var j in u){ - ret.push(u[j].txid); + for (var j in u) { + ret[u[j].txid + ',' + u[j].vout]=1; } } return ret; diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index 6e7dca714..82448ef07 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -596,8 +596,9 @@ Wallet.prototype.getUnspent = function(cb) { var uu = self.txProposals.getUsedUnspent(maxRejectCount); for (var i in unspentList) { - if (uu.indexOf(unspentList[i].txid) === -1) - safeUnspendList.push(unspentList[i]); + var u=unspentList[i]; + if (! uu[u.txid +','+u.vout]) + safeUnspendList.push(u); } return cb(null, safeUnspendList, unspentList); diff --git a/js/services/controllerUtils.js b/js/services/controllerUtils.js index 898400ae2..516fdfee1 100644 --- a/js/services/controllerUtils.js +++ b/js/services/controllerUtils.js @@ -174,7 +174,6 @@ angular.module('copayApp.services') }; root._setCommError = function(e) { - // first error ever? if ($rootScope.insightError<0) $rootScope.insightError=0; $rootScope.insightError++; @@ -182,7 +181,10 @@ angular.module('copayApp.services') root._clearCommError = function(e) { - $rootScope.insightError=0; + if ($rootScope.insightError>0) + $rootScope.insightError=-1; + else + $rootScope.insightError=0; }; root.setSocketHandlers = function() {