From 6586a4b69650b4d381a944509a90b8bf4e29aba7 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Fri, 30 Jan 2015 11:09:07 -0300 Subject: [PATCH] Remove unnused variable. Added tests to check amount validation --- js/controllers/send.js | 6 +----- test/unit/controllers/controllersSpec.js | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/js/controllers/send.js b/js/controllers/send.js index 7ebb4147e..98887129f 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -5,8 +5,6 @@ var preconditions = require('preconditions').singleton(); angular.module('copayApp.controllers').controller('SendController', function($scope, $rootScope, $window, $timeout, $modal, $filter, notification, isMobile, rateService, txStatus, isCordova) { - var satToUnit; - $scope.init = function() { var w = $rootScope.wallet; preconditions.checkState(w); @@ -23,8 +21,6 @@ angular.module('copayApp.controllers').controller('SendController', $scope.loading = false; $scope.error = $scope.success = null; - satToUnit = 1 / w.settings.unitToSatoshi; - $scope.alternativeName = w.settings.alternativeName; $scope.alternativeIsoCode = w.settings.alternativeIsoCode; @@ -101,7 +97,7 @@ angular.module('copayApp.controllers').controller('SendController', this.__alternative = newValue; if (typeof(newValue) === 'number' && $scope.isRateAvailable) { this._amount = parseFloat( - (rateService.fromFiat(newValue, $scope.alternativeIsoCode) * satToUnit).toFixed(w.settings.unitDecimals), 10); + (rateService.fromFiat(newValue, $scope.alternativeIsoCode) * 1 / w.settings.unitToSatoshi).toFixed(w.settings.unitDecimals), 10); } else { this._amount = 0; } diff --git a/test/unit/controllers/controllersSpec.js b/test/unit/controllers/controllersSpec.js index abf95dada..b002832fe 100644 --- a/test/unit/controllers/controllersSpec.js +++ b/test/unit/controllers/controllersSpec.js @@ -273,7 +273,7 @@ describe("Unit: Controllers", function() { var element2 = angular.element( '
' + '' + - '' + + '' + '' + '' + '
' @@ -390,6 +390,27 @@ describe("Unit: Controllers", function() { done(); }); }); + + it('receive from uri using bits', inject(function() { + sendForm.address.$setViewValue('bitcoin:mxf5psDyA8EQVzb2MZ7MkDWiXuAuWWCRMB?amount=1.018085'); + expect(sendForm.amount.$modelValue).to.equal(1018085); + sendForm.address.$setViewValue('bitcoin:mxf5psDyA8EQVzb2MZ7MkDWiXuAuWWCRMB?amount=1.01808500'); + expect(sendForm.amount.$modelValue).to.equal(1018085); + sendForm.address.$setViewValue('bitcoin:mxf5psDyA8EQVzb2MZ7MkDWiXuAuWWCRMB?amount=0.29133585'); + expect(sendForm.amount.$modelValue).to.equal(291335.85); + })); + + it('receive from uri using BTC', inject(function($rootScope) { + var old = $rootScope.wallet.settings.unitToSatoshi; + $rootScope.wallet.settings.unitToSatoshi = 100000000; + sendForm.address.$setViewValue('bitcoin:mxf5psDyA8EQVzb2MZ7MkDWiXuAuWWCRMB?amount=1.018085'); + expect(sendForm.amount.$modelValue).to.equal(1.018085); + sendForm.address.$setViewValue('bitcoin:mxf5psDyA8EQVzb2MZ7MkDWiXuAuWWCRMB?amount=1.01808500'); + expect(sendForm.amount.$modelValue).to.equal(1.018085); + sendForm.address.$setViewValue('bitcoin:mxf5psDyA8EQVzb2MZ7MkDWiXuAuWWCRMB?amount=0.29133585'); + expect(sendForm.amount.$modelValue).to.equal(0.29133585); + $rootScope.wallet.settings.unitToSatoshi = old; + })); }); describe("Unit: Version Controller", function() {