From 8ef737083a617a471f529947c0f659c7b43305fd Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Wed, 24 Sep 2014 02:13:56 -0300 Subject: [PATCH 1/2] Show alternative currency on the list of transactions --- js/controllers/transactions.js | 15 ++++++++++++++- views/includes/transaction.html | 21 +++++++++++++++++---- views/transactions.html | 21 +++++++++++++++++++-- 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/js/controllers/transactions.js b/js/controllers/transactions.js index 7b51f0135..2f49bf3d6 100644 --- a/js/controllers/transactions.js +++ b/js/controllers/transactions.js @@ -2,7 +2,7 @@ var bitcore = require('bitcore'); angular.module('copayApp.controllers').controller('TransactionsController', - function($scope, $rootScope, $timeout, controllerUtils, notification) { + function($scope, $rootScope, $timeout, controllerUtils, notification, rateService) { var w = $rootScope.wallet; @@ -13,6 +13,7 @@ angular.module('copayApp.controllers').controller('TransactionsController', $scope.txpCurrentPage = 1; $scope.txpItemsPerPage = 4; $scope.blockchain_txs = []; + $scope.alternativeCurrency = []; var satToUnit = 1 / w.settings.unitToSatoshi; @@ -37,6 +38,7 @@ angular.module('copayApp.controllers').controller('TransactionsController', }; var _aggregateItems = function(items) { + var w = $rootScope.wallet; if (!items) return []; var l = items.length; @@ -92,6 +94,10 @@ angular.module('copayApp.controllers').controller('TransactionsController', angular.forEach(tmp, function(v) { v.value = (parseInt(v.valueSat || 0).toFixed(0)) * satToUnit; + rateService.whenAvailable(function() { + var valueSat = v.value * w.settings.unitToSatoshi; + v.valueAlt = rateService.toFiat(valueSat, w.settings.alternativeIsoCode); + }); ret.push(v); }); return ret; @@ -150,4 +156,11 @@ angular.module('copayApp.controllers').controller('TransactionsController', $scope.getTransactions(); } + $scope.amountAlternative = function (amount, txIndex) { + var w = $rootScope.wallet; + rateService.whenAvailable(function() { + var valueSat = amount * w.settings.unitToSatoshi; + $scope.alternativeCurrency[txIndex] = rateService.toFiat(valueSat, w.settings.alternativeIsoCode); + }); + }; }); diff --git a/views/includes/transaction.html b/views/includes/transaction.html index 60918c04c..a24afa6fe 100644 --- a/views/includes/transaction.html +++ b/views/includes/transaction.html @@ -1,8 +1,8 @@ -
+
- + @@ -16,8 +16,21 @@
-

{{out.value | noFractionNumber}} {{$root.wallet.settings.unitName}}

-

{{out.value | noFractionNumber}} {{$root.wallet.settings.unitName}}

+
+ {{out.value |noFractionNumber}} + {{$root.wallet.settings.unitName}} +
+
+ {{out.value |noFractionNumber}} {{$root.wallet.settings.unitName}} +
diff --git a/views/transactions.html b/views/transactions.html index d4bb0aaf6..521e1037a 100644 --- a/views/transactions.html +++ b/views/transactions.html @@ -54,7 +54,16 @@
- {{vin.value| noFractionNumber}} {{$root.wallet.settings.unitName}} + + {{vin.value| noFractionNumber}} {{$root.wallet.settings.unitName}} +

@@ -68,7 +77,15 @@
- {{vout.value| noFractionNumber}} {{$root.wallet.settings.unitName}} + + {{vout.value| noFractionNumber}} {{$root.wallet.settings.unitName}}

From 26148d1f76abec76848e707543e493cdc7e949ad Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Thu, 25 Sep 2014 16:50:15 -0300 Subject: [PATCH 2/2] simple test --- js/controllers/transactions.js | 3 ++- test/unit/controllers/controllersSpec.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/js/controllers/transactions.js b/js/controllers/transactions.js index 2f49bf3d6..914a07137 100644 --- a/js/controllers/transactions.js +++ b/js/controllers/transactions.js @@ -156,11 +156,12 @@ angular.module('copayApp.controllers').controller('TransactionsController', $scope.getTransactions(); } - $scope.amountAlternative = function (amount, txIndex) { + $scope.amountAlternative = function (amount, txIndex, cb) { var w = $rootScope.wallet; rateService.whenAvailable(function() { var valueSat = amount * w.settings.unitToSatoshi; $scope.alternativeCurrency[txIndex] = rateService.toFiat(valueSat, w.settings.alternativeIsoCode); + return cb ? cb() : null; }); }; }); diff --git a/test/unit/controllers/controllersSpec.js b/test/unit/controllers/controllersSpec.js index 4c268e7ab..bb415764c 100644 --- a/test/unit/controllers/controllersSpec.js +++ b/test/unit/controllers/controllersSpec.js @@ -127,6 +127,10 @@ describe("Unit: Controllers", function() { }); })); + it('should exist', function() { + should.exist(transactionsCtrl); + }); + it('should have a TransactionController controller', function() { expect(scope.loading).equal(false); }); @@ -135,6 +139,17 @@ describe("Unit: Controllers", function() { scope.getTransactions(); expect(scope.blockchain_txs).to.be.empty; }); + + it('should call amountAlternative and return a value', function() { + var cb = sinon.spy(); + var s1 = sinon.stub(scope, 'amountAlternative'); + s1.onCall(0).returns(1000); + s1.onCall(1).returns(2000); + expect(s1(100, 0, cb)).equal(1000); + expect(s1(200, 1, cb)).equal(2000); + sinon.assert.callCount(scope.amountAlternative, 2); + s1.restore(); + }); }); describe('Send Controller', function() {