diff --git a/js/controllers/history.js b/js/controllers/history.js index 81dd8bcef..2779705f9 100644 --- a/js/controllers/history.js +++ b/js/controllers/history.js @@ -147,7 +147,8 @@ angular.module('copayApp.controllers').controller('HistoryController', _.each(res, function(r) { var tx = index[r.ts]; tx.alternativeAmount = $filter('noFractionNumber')( - (r.rate != null ? tx.amountSat * rateService.SAT_TO_BTC * r.rate : null); + (r.rate != null ? tx.amountSat * rateService.SAT_TO_BTC * r.rate : null)) + ; }); setTimeout(function() { $scope.$digest(); diff --git a/js/controllers/profile.js b/js/controllers/profile.js index 2b9bb0cd4..92238910c 100644 --- a/js/controllers/profile.js +++ b/js/controllers/profile.js @@ -1,5 +1,5 @@ 'use strict'; -angular.module('copayApp.controllers').controller('ProfileController', function($scope, $rootScope, $location, $modal, backupService) { +angular.module('copayApp.controllers').controller('ProfileController', function($scope, $rootScope, $location, $modal, backupService, identityService) { $scope.username = $rootScope.iden.getName(); $scope.isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0; @@ -16,10 +16,11 @@ angular.module('copayApp.controllers').controller('ProfileController', function( $scope.deleteWallet = function(w) { if (!w) return; - $scope.loading = w.id; - - identityService.deleteWallet(w.id,function() { + identityService.deleteWallet(w, function(err) { $scope.loading = false; + if (err) { + log.warn(err); + } }); }; diff --git a/js/services/balanceService.js b/js/services/balanceService.js index 05a23ac3d..c2be78dcb 100644 --- a/js/services/balanceService.js +++ b/js/services/balanceService.js @@ -19,6 +19,7 @@ angular.module('copayApp.services') var r = {}; r.totalBalance = $filter('noFractionNumber')(balanceSat * satToUnit); r.totalBalanceBTC = (balanceSat / COIN); + var availableBalanceNr = safeBalanceSat * satToUnit; r.availableBalance = $filter('noFractionNumber')(safeBalanceSat * satToUnit); r.availableBalanceBTC = (safeBalanceSat / COIN); r.safeUnspentCount = safeUnspentCount; @@ -29,7 +30,7 @@ angular.module('copayApp.services') if (r.safeUnspentCount) { var estimatedFee = copay.Wallet.estimatedFee(r.safeUnspentCount); - r.topAmount = (((r.availableBalance * w.settings.unitToSatoshi).toFixed(0) - estimatedFee) / w.settings.unitToSatoshi); + r.topAmount = (((availableBalanceNr * w.settings.unitToSatoshi).toFixed(0) - estimatedFee) / w.settings.unitToSatoshi); } var balanceByAddr = {}; diff --git a/js/services/identityService.js b/js/services/identityService.js index ee7f924b0..6fb1cd0aa 100644 --- a/js/services/identityService.js +++ b/js/services/identityService.js @@ -87,8 +87,8 @@ angular.module('copayApp.services') }); }; - root.deleteWallet = function($scope, iden, w) { - $rootScope.iden.deleteWallet(w.id); + root.deleteWallet = function(w, cb) { + $rootScope.iden.deleteWallet(w.id, cb); }; root.isFocused = function(wid) { diff --git a/test/unit/controllers/controllersSpec.js b/test/unit/controllers/controllersSpec.js index f3b80e1ff..d770e3544 100644 --- a/test/unit/controllers/controllersSpec.js +++ b/test/unit/controllers/controllersSpec.js @@ -15,6 +15,8 @@ saveAs = function(blob, filename) { describe("Unit: Controllers", function() { config.plugins.LocalStorage = true; config.plugins.GoogleDrive = null; + config.plugins.InsightStorage = null; + config.plugins.EncryptedInsightStorage= null; var anAddr = 'mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy'; var anAmount = 1000; @@ -254,13 +256,13 @@ describe("Unit: Controllers", function() { sendForm.amount.$setViewValue(anAmount); sendForm.comment.$setViewValue(aComment); - scope.loadTxs = sinon.spy(); + scope.updateTxs = sinon.spy(); var w = scope.wallet; scope.submitForm(sendForm); sinon.assert.callCount(w.spend, 1); sinon.assert.callCount(w.broadcastTx, 0); - sinon.assert.callCount(scope.loadTxs, 1); + sinon.assert.callCount(scope.updateTxs, 1); var spendArgs = w.spend.getCall(0).args[0]; spendArgs.toAddress.should.equal(anAddr); spendArgs.amountSat.should.equal(anAmount * scope.wallet.settings.unitToSatoshi); @@ -275,7 +277,7 @@ describe("Unit: Controllers", function() { sendForm.amount.$setViewValue(100); sendForm.address.$setViewValue(anAddr); - scope.loadTxs = sinon.spy(); + scope.updateTxs = sinon.spy(); scope.submitForm(sendForm); var w = scope.wallet; w.spend.getCall(0).args[0].amountSat.should.equal(100 * scope.wallet.settings.unitToSatoshi); @@ -602,9 +604,10 @@ describe("Unit: Controllers", function() { it('Delete a wallet', function() { var w = scope.wallet; - scope.deleteWallet(w); - scope.$digest(); - expect(scope.wallet).equal(null); + scope.deleteWallet(w, function() { + scope.$digest(); + expect(scope.wallet).equal(null); + }); }); }); diff --git a/test/unit/services/servicesSpec.js b/test/unit/services/servicesSpec.js index 41ad2b35b..3abe1efaf 100644 --- a/test/unit/services/servicesSpec.js +++ b/test/unit/services/servicesSpec.js @@ -65,49 +65,34 @@ describe("Angular services", function() { - describe("Unit: controllerUtils", function() { + describe("Unit: balanceService", function() { - it('should updateBalance in bits', inject(function(controllerUtils, $rootScope) { + it('should updateBalance in bits', inject(function(balanceService, $rootScope) { var w = $rootScope.wallet; - - expect(controllerUtils.updateBalance).not.to.equal(null); + expect(balanceService.update).not.to.equal(null); var Waddr = Object.keys($rootScope.wallet.balanceByAddr)[0]; var a = {}; a[Waddr] = 200; w.getBalance = sinon.stub().yields(null, 100000001, a, 90000002, 5); - var orig =controllerUtils.isFocusedWallet; - controllerUtils.isFocusedWallet = sinon.stub().returns(true); - //retuns values in DEFAULT UNIT(bits) - controllerUtils.updateBalance(null, function() { + balanceService.update(w, function() { + var b = w.balanceInfo; + expect(b.totalBalanceBTC).to.be.equal(1.00000001); + expect(b.availableBalanceBTC).to.be.equal(0.90000002); + expect(b.lockedBalanceBTC).to.be.equal(0.09999999); + expect(b.totalBalance).to.be.equal('1,000,000.01'); + expect(b.availableBalance).to.be.equal('900,000.02'); + expect(b.lockedBalance).to.be.equal(99999.99); - expect($rootScope.totalBalanceBTC).to.be.equal(1.00000001); - expect($rootScope.availableBalanceBTC).to.be.equal(0.90000002); - expect($rootScope.lockedBalanceBTC).to.be.equal(0.09999999); - - expect($rootScope.totalBalance).to.be.equal(1000000.01); - expect($rootScope.availableBalance).to.be.equal(900000.02); - expect($rootScope.lockedBalance).to.be.equal(99999.99); - - expect($rootScope.balanceByAddr[Waddr]).to.equal(2); - expect($rootScope.safeUnspentCount).to.equal(5); - expect($rootScope.topAmount).to.equal(899800.02); - }); - - controllerUtils.isFocusedWallet = orig; + expect(b.balanceByAddr[Waddr]).to.equal(2); + expect(b.safeUnspentCount).to.equal(5); + expect(b.topAmount).to.equal(899800.02); + },false); })); - it('should set the rootScope', inject(function(controllerUtils, $rootScope) { - controllerUtils.setupGlobalVariables(function() { - expect($rootScope.txAlertCount).to.be.equal(0); - expect($rootScope.insightError).to.be.equal(0); - expect($rootScope.isCollapsed).to.be.equal(0); - expect($rootScope.unitName).to.be.equal('bits'); - }); - })); }); describe("Unit: Notification Service", function() {