From 8a40f169c04bf161a6b1c4ae68ead81a46a123e8 Mon Sep 17 00:00:00 2001 From: Gustavo Cortez Date: Tue, 3 Jun 2014 16:54:09 -0300 Subject: [PATCH 1/4] Simplification and fixes when getting transaction list (controller) from insight and look&feel of tx list --- css/main.css | 7 +-- index.html | 64 ++++++++++++----------- js/controllers/transactions.js | 96 ++++++++++++++++++++++++++++------ js/filters.js | 17 ------ 4 files changed, 114 insertions(+), 70 deletions(-) diff --git a/css/main.css b/css/main.css index 86982e233..74820a339 100644 --- a/css/main.css +++ b/css/main.css @@ -305,12 +305,7 @@ hr { margin: 2.25rem 0;} .tx-copayers { overflow: hidden; - padding: 0.5rem; -} - -.tx-copayers { - overflow: hidden; - padding: 0.5rem; + padding: 10px; } .box-copayers { diff --git a/index.html b/index.html index b5189afe5..8161deb3a 100644 --- a/index.html +++ b/index.html @@ -517,15 +517,18 @@
-

Last transactions

- Show - Hide +

Last transactions + + Show + Hide + +

No transactions yet.
-
+
- {{btx.firstSeenTs * 1000 | amCalendar}} -
-
-
-
-
-
-

{{vin.addr}}

- {{vin.value}} -
-
-
- -
-
-
-
-
-
-

{{addr}}

-
-
-
- {{vout.value}} -
+
+ first seen at + +
+
+ mined at +
-
+
+
+
+
+ {{vin.value}} +

{{vin.addr}}

+
+
+
+ +
+
+
+ {{vout.value}} +

{{vout.addr}}

+
+
+
+
+
Fees: {{btx.fees}}
Confirmations: {{btx.confirmations || 0}}
diff --git a/js/controllers/transactions.js b/js/controllers/transactions.js index ede169280..c0d9e9434 100644 --- a/js/controllers/transactions.js +++ b/js/controllers/transactions.js @@ -10,6 +10,9 @@ angular.module('copay.transactions').controller('TransactionsController', $scope.txpCurrentPage = 1; $scope.txpItemsPerPage = 4; + + var COIN = 100000000; + $scope.blockchain_txs = []; $scope.update = function () { $scope.loading = false; @@ -30,22 +33,71 @@ angular.module('copay.transactions').controller('TransactionsController', }, 10); }; + var _aggregateItems = function(items) { + if (!items) return []; + + var l = items.length; + + var ret = []; + var tmp = {}; + var u = 0; + + for(var i=0; i < l; i++) { + + var notAddr = false; + // non standard input + if (items[i].scriptSig && !items[i].addr) { + items[i].addr = 'Unparsed address [' + u++ + ']'; + items[i].notAddr = true; + notAddr = true; + } + + // non standard output + if (items[i].scriptPubKey && !items[i].scriptPubKey.addresses) { + items[i].scriptPubKey.addresses = ['Unparsed address [' + u++ + ']']; + items[i].notAddr = true; + notAddr = true; + } + + // multiple addr at output + if (items[i].scriptPubKey && items[i].scriptPubKey.addresses.length > 1) { + items[i].addr = items[i].scriptPubKey.addresses.join(','); + ret.push(items[i]); + continue; + } + + var addr = items[i].addr || (items[i].scriptPubKey && items[i].scriptPubKey.addresses[0]); + + if (!tmp[addr]) { + tmp[addr] = {}; + tmp[addr].valueSat = 0; + tmp[addr].count = 0; + tmp[addr].addr = addr; + tmp[addr].items = []; + } + tmp[addr].isSpent = items[i].spentTxId; + + tmp[addr].doubleSpentTxID = tmp[addr].doubleSpentTxID || items[i].doubleSpentTxID; + tmp[addr].doubleSpentIndex = tmp[addr].doubleSpentIndex || items[i].doubleSpentIndex; + tmp[addr].unconfirmedInput += items[i].unconfirmedInput; + tmp[addr].dbError = tmp[addr].dbError || items[i].dbError; + tmp[addr].valueSat += Math.round(items[i].value * COIN); + tmp[addr].items.push(items[i]); + tmp[addr].notAddr = notAddr; + tmp[addr].count++; + } + + angular.forEach(tmp, function(v) { + v.value = v.value || parseInt(v.valueSat) / COIN; + ret.push(v); + }); + return ret; + }; + $scope.toogleLast = function () { - $scope.loading = true; $scope.lastShowed = !$scope.lastShowed; if ($scope.lastShowed) { - $scope.getTransactions(function(txs){ - $timeout(function() { - $scope.loading = false; - $scope.blockchain_txs = txs; - $scope.$digest(); - }, 10); - }); - } else { - $timeout(function(){ - $scope.loading = false; - $rootScope.$digest(); - }, 10); + $scope.getTransactions(); } }; @@ -87,16 +139,26 @@ angular.module('copay.transactions').controller('TransactionsController', }); }; - $scope.getTransactions = function(cb) { - var w =$rootScope.wallet; + $scope.getTransactions = function() { + var w = $rootScope.wallet; + $scope.loading = true; if (w) { console.log('### Querying last transactions...'); //TODO var addresses = w.getAddressesStr(); if (addresses.length > 0) { - return w.blockchain.getTransactions(addresses, cb); + $scope.blockchain_txs = []; + w.blockchain.getTransactions(addresses, function(txs) { + $timeout(function() { + for (var i=0; i Date: Wed, 4 Jun 2014 10:57:15 -0300 Subject: [PATCH 2/4] Fixed UI. Now aligned with other buttons --- index.html | 11 +++++------ js/controllers/transactions.js | 6 ++++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index 3b74ebfa3..88641b2bb 100644 --- a/index.html +++ b/index.html @@ -517,12 +517,11 @@
-

Last transactions - - Show - Hide - -

+

Last transactions

+
No transactions yet. diff --git a/js/controllers/transactions.js b/js/controllers/transactions.js index f51d1613a..92410a34b 100644 --- a/js/controllers/transactions.js +++ b/js/controllers/transactions.js @@ -158,6 +158,12 @@ angular.module('copayApp.controllers').controller('TransactionsController', }, 10); }); } + else { + $timeout(function() { + $scope.loading = false; + $scope.lastShowed = false; + }, 1); + } } }; From dbdd3c3500f071609d187be2466dfc865fc56080 Mon Sep 17 00:00:00 2001 From: Gustavo Cortez Date: Wed, 4 Jun 2014 11:24:49 -0300 Subject: [PATCH 3/4] Refactory ControllerSpect for test is now more clear. A simple test for transactions. --- test/unit/controllers/controllersSpec.js | 80 +++++++++++------------- 1 file changed, 36 insertions(+), 44 deletions(-) diff --git a/test/unit/controllers/controllersSpec.js b/test/unit/controllers/controllersSpec.js index 75d45e881..f437c1ed8 100644 --- a/test/unit/controllers/controllersSpec.js +++ b/test/unit/controllers/controllersSpec.js @@ -3,59 +3,51 @@ // describe("Unit: Testing Controllers", function() { - beforeEach(module('notifications')); - beforeEach(module('copayApp.services')); - beforeEach(module('copayApp.controllers')); + var scope; - var scope, addressCtrl; -// + beforeEach(module('notifications')); + beforeEach(module('copayApp.services')); + beforeEach(module('copayApp.controllers')); + + describe('Address Controller', function() { + var addressCtrl; beforeEach(inject(function($controller, $rootScope) { scope = $rootScope.$new(); addressCtrl = $controller('AddressesController', { $scope: scope, }); })); - + it('should have a AddressesController controller', function() { + expect(scope.loading).equal(false); + }); - it('should have a AddressesController controller', function() { - expect(scope.loading).equal(false); - }); + it('selectedAddr should modify scope', function() { + expect(scope.selectedAddress).equal(undefined); + scope.selectAddress('hola'); + expect(scope.selectedAddr).equal('hola'); + }); - it('selectedAddr should modify scope', function() { - expect(scope.selectedAddress).equal(undefined); - scope.selectAddress('hola'); - expect(scope.selectedAddr).equal('hola'); - }); + }); -// -// it('should have a BackupController controller', function() { -// expect(copayApp.Backupcontroller).not.to.equal(null); -// }); -// -// it('should have a HeaderController controller', function() { -// expect(copayApp.HeaderController).not.to.equal(null); -// }); -// -// it('should have a SendController controller', function() { -// expect(copayApp.SendController).not.to.equal(null); -// }); -// -// it('should have a SetupController controller', function() { -// expect(copayApp.SetupController).not.to.equal(null); -// }); -// -// it('should have a SigninController controller', function() { -// expect(copayApp.SigninController).not.to.equal(null); -// console.log('[controllersSpec.js.30:copayApp:]',copayApp); //TODO -// }); -// -// it('should have a TransactionsController controller', function() { -// expect(copayApp.TransactionsController).not.to.equal(null); -// }); -// -// beforeEach(angular.mock.module('copay.walletFactory')); -// it('should display a link to create a new wallet if no wallets in localStorage', inject(function(walletFactory) { -// expect(walletFactory.storage.getWalletIds()).to.be.empty; -// })); + describe('Transactions Controller', function() { + var transactionCtrl; + beforeEach(inject(function($controller, $rootScope) { + scope = $rootScope.$new(); + transactionsCtrl = $controller('TransactionsController', { + $scope: scope, + }); + })); + + it('should have a TransactionController controller', function() { + expect(scope.loading).equal(false); + }); + + it('should return an empty array of tx', function() { + scope.getTransactions(); + expect(scope.blockchain_txs).to.be.empty; + console.log('asdfasdf', scope.blockchain_txs); + }); + + }); }); From 72b4d75e78c1fbb5e4b475f6f43fbe4d32751a6e Mon Sep 17 00:00:00 2001 From: Gustavo Cortez Date: Wed, 4 Jun 2014 11:25:58 -0300 Subject: [PATCH 4/4] Removed console.log --- test/unit/controllers/controllersSpec.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/unit/controllers/controllersSpec.js b/test/unit/controllers/controllersSpec.js index f437c1ed8..0209a1cbc 100644 --- a/test/unit/controllers/controllersSpec.js +++ b/test/unit/controllers/controllersSpec.js @@ -43,11 +43,9 @@ describe("Unit: Testing Controllers", function() { expect(scope.loading).equal(false); }); - it('should return an empty array of tx', function() { + it('should return an empty array of tx from insight', function() { scope.getTransactions(); expect(scope.blockchain_txs).to.be.empty; - console.log('asdfasdf', scope.blockchain_txs); }); - }); });