From df9b26fddeb15d3d81546361aad6e90310a0b1f5 Mon Sep 17 00:00:00 2001 From: Gustavo Cortez Date: Wed, 23 Apr 2014 01:55:00 -0300 Subject: [PATCH 1/2] List of transactions by address associated to wallet --- css/main.css | 18 ++++++++ index.html | 76 +++++++++++++++++++-------------- js/controllers/transactions.js | 11 +++++ js/models/blockchain/Insight.js | 47 +++++++++++++++++++- 4 files changed, 120 insertions(+), 32 deletions(-) diff --git a/css/main.css b/css/main.css index 0df6831d4..6ab5b4587 100644 --- a/css/main.css +++ b/css/main.css @@ -117,6 +117,24 @@ body { font-size: 12px; } +.btransactions .panel { + background: #fff; +} + +.btransactions .txheader { + font-size: 12px; + margin-bottom: 10px; + padding-bottom: 10px; + border-bottom: 1px solid #eee; +} + +.btransactions .txbottom { + margin-top: 10px; + padding-top: 10px; + border-top: 1px solid #eee; + font-size: 12px; +} + .pending table { width: 100%; border: none; diff --git a/index.html b/index.html index bedc3b4ac..b5aef3a5d 100644 --- a/index.html +++ b/index.html @@ -329,39 +329,53 @@
-
diff --git a/js/controllers/transactions.js b/js/controllers/transactions.js index d4356a62a..aee87b56e 100644 --- a/js/controllers/transactions.js +++ b/js/controllers/transactions.js @@ -67,5 +67,16 @@ console.log('[transactions.js.68:txid:] SENTTX CALLBACK',txid); //TODO } }; + $scope.getTransactions = function() { + var w =$rootScope.wallet; + var addresses = w.getAddressesStr(true); + + w.blockchain.getTransactions(addresses, function(txs) { + $scope.blockchain_txs = txs; + $scope.$digest(); + }); + + }; + _updateTxs(); }); diff --git a/js/models/blockchain/Insight.js b/js/models/blockchain/Insight.js index 67097f2ce..0bcca1a72 100644 --- a/js/models/blockchain/Insight.js +++ b/js/models/blockchain/Insight.js @@ -29,6 +29,52 @@ function _asyncForEach(array, fn, callback) { } }; +Insight.prototype.getTransactions = function(addresses, cb) { + var self = this; + + if (!addresses || !addresses.length) return cb([]); + + var txids = []; + var txs = []; + + _asyncForEach(addresses, function(addr, callback) { + var options = { + host: self.host, + port: self.port, + scheme: self.scheme, + method: 'GET', + path: '/api/addr/' + addr, + + headers: { 'Access-Control-Request-Headers' : '' } + }; + + self._request(options, function(err, res) { + var txids_tmp = res.transactions; + for(var i=0; i Date: Wed, 23 Apr 2014 03:37:17 -0300 Subject: [PATCH 2/2] Get transactions of all addresses (the generated and the changes). Do not repeat txids on the front-end --- index.html | 6 +++--- js/controllers/transactions.js | 13 +++++++------ js/models/blockchain/Insight.js | 29 +++++++++++++++++++++++++++-- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/index.html b/index.html index b5aef3a5d..b30118510 100644 --- a/index.html +++ b/index.html @@ -328,10 +328,10 @@ -
+

Last transactions

-
-
+
+
diff --git a/js/controllers/transactions.js b/js/controllers/transactions.js index aee87b56e..a2e8a3697 100644 --- a/js/controllers/transactions.js +++ b/js/controllers/transactions.js @@ -69,13 +69,14 @@ console.log('[transactions.js.68:txid:] SENTTX CALLBACK',txid); //TODO $scope.getTransactions = function() { var w =$rootScope.wallet; - var addresses = w.getAddressesStr(true); + var addresses = w.getAddressesStr(); - w.blockchain.getTransactions(addresses, function(txs) { - $scope.blockchain_txs = txs; - $scope.$digest(); - }); - + if (addresses.length > 0) { + w.blockchain.getTransactions(addresses, function(txs) { + $scope.blockchain_txs = txs; + $rootScope.$digest(); + }); + } }; _updateTxs(); diff --git a/js/models/blockchain/Insight.js b/js/models/blockchain/Insight.js index 0bcca1a72..7fa1b275f 100644 --- a/js/models/blockchain/Insight.js +++ b/js/models/blockchain/Insight.js @@ -27,7 +27,31 @@ function _asyncForEach(array, fn, callback) { } else { callback(); // Done! } -}; +}; + +function removeRepeatedElements(ar){ + var ya=false,v="",aux=[].concat(ar),r=Array(); + for (var i in aux){ // + v=aux[i]; + ya=false; + for (var a in aux){ + if (v==aux[a]){ + if (ya==false){ + ya=true; + } + else{ + aux[a]=""; + } + } + } + } + for (var a in aux){ + if (aux[a]!=""){ + r.push(aux[a]); + } + } + return r; +} Insight.prototype.getTransactions = function(addresses, cb) { var self = this; @@ -56,7 +80,8 @@ Insight.prototype.getTransactions = function(addresses, cb) { callback(); }); }, function() { - _asyncForEach(txids, function(txid, callback2) { + var clean_txids = removeRepeatedElements(txids); + _asyncForEach(clean_txids, function(txid, callback2) { var options = { host: self.host, port: self.port,