diff --git a/js/controllers/send.js b/js/controllers/send.js index 86fc09017..c82ed9280 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -8,13 +8,19 @@ angular.module('copayApp.controllers').controller('SendController', var satToUnit = 1 / config.unitToSatoshi; $scope.defaultFee = bitcore.TransactionBuilder.FEE_PER_1000B_SAT * satToUnit; $scope.unitToBtc = config.unitToSatoshi / bitcore.util.COIN; + $scope.unitToSatoshi = config.unitToSatoshi; $scope.minAmount = config.limits.minAmountSatoshi * satToUnit; - this.alternativeName = config.alternativeName; - this.alternativeIsoCode = config.alternativeIsoCode; - this.rateService = rateService; + $scope.alternativeName = config.alternativeName; + $scope.alternativeIsoCode = config.alternativeIsoCode; - $scope.amount = 0; + $scope.isRateAvailable = false; + $scope.rateService = rateService; + + rateService.whenAvailable(function() { + $scope.isRateAvailable = true; + $scope.$digest(); + }); /** * Setting the two related amounts as properties prevents an infinite @@ -26,12 +32,13 @@ angular.module('copayApp.controllers').controller('SendController', return this._alternative; }, set: function (newValue) { + newValue = -(-newValue) || 0; this._alternative = newValue; - if (typeof(newValue) === 'number') { + if ($scope.isRateAvailable) { this._amount = Number.parseFloat( (rateService.fromFiat(newValue, config.alternativeIsoCode) * satToUnit ).toFixed(config.unitDecimals), 10); - } + }; }, enumerable: true, configurable: true @@ -42,12 +49,13 @@ angular.module('copayApp.controllers').controller('SendController', return this._amount; }, set: function (newValue) { + newValue = -(-newValue) || 0; this._amount = newValue; - if (newValue) { + if ($scope.isRateAvailable) { this._alternative = Number.parseFloat( (rateService.toFiat(newValue * config.unitToSatoshi, config.alternativeIsoCode) ).toFixed(2), 10); - } + }; }, enumerable: true, configurable: true diff --git a/test/unit/controllers/controllersSpec.js b/test/unit/controllers/controllersSpec.js index aeb7a5006..f4ec299e6 100644 --- a/test/unit/controllers/controllersSpec.js +++ b/test/unit/controllers/controllersSpec.js @@ -135,8 +135,9 @@ describe("Unit: Controllers", function() { } }); })); - beforeEach(angular.mock.inject(function($compile, $rootScope, $controller) { + beforeEach(angular.mock.inject(function($compile, $rootScope, $controller, rateService) { scope = $rootScope.$new(); + scope.rateService = rateService; $rootScope.wallet = new FakeWallet(walletConfig); config.alternativeName = 'lol currency'; config.alternativeIsoCode = 'LOL'; @@ -254,7 +255,7 @@ describe("Unit: Controllers", function() { }); it('should convert bits amount to fiat', function(done) { - sendCtrl.rateService.whenAvailable(function() { + scope.rateService.whenAvailable(function() { sendForm.amount.$setViewValue(1e6); scope.$digest(); expect(scope.alternative).to.equal(2); @@ -262,7 +263,7 @@ describe("Unit: Controllers", function() { }); }); it('should convert fiat to bits amount', function(done) { - sendCtrl.rateService.whenAvailable(function() { + scope.rateService.whenAvailable(function() { sendForm.alternative.$setViewValue(2); scope.$digest(); expect(scope.amount).to.equal(1e6); diff --git a/views/send.html b/views/send.html index 2c93546a9..cb06736e9 100644 --- a/views/send.html +++ b/views/send.html @@ -1,4 +1,4 @@ -
+

Send Proposals

@@ -85,17 +85,17 @@
- +
- {{ctrl.alternativeIsoCode}} + {{alternativeIsoCode}}
@@ -135,6 +135,9 @@
Total amount for this transaction:

{{amount + defaultFee |noFractionNumber}} {{$root.unitName}} + + {{ rateService.toFiat((amount + defaultFee) * unitToSatoshi, alternativeIsoCode) | noFractionNumber: 2 }} {{ alternativeIsoCode }} + {{ ((amount + defaultFee) * unitToBtc)|noFractionNumber:8}} BTC
Including fee of {{defaultFee|noFractionNumber}} {{$root.unitName}}