diff --git a/public/views/modals/inputAmount.html b/public/views/modals/inputAmount.html index f2e0307e3..387a3d812 100644 --- a/public/views/modals/inputAmount.html +++ b/public/views/modals/inputAmount.html @@ -6,9 +6,9 @@

Enter amount

-
- {{alternativeIsoCode}} - {{unitName}} +
+ +
@@ -16,8 +16,8 @@
{{amount || '-'}}
-
{{globalResult}} [{{amountResult || 0}} {{alternativeIsoCode}}]
-
{{globalResult}} [{{alternativeResult || 0}} {{unitName}}]
+
{{globalResult}} [{{amountResult || '0.00'}} {{alternativeIsoCode}}]
+
{{globalResult}} [{{alternativeResult || '0.00'}} {{unitName}}]
diff --git a/src/js/controllers/modals/inputAmount.js b/src/js/controllers/modals/inputAmount.js index 0be9ab6e8..77dd77726 100644 --- a/src/js/controllers/modals/inputAmount.js +++ b/src/js/controllers/modals/inputAmount.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('inputAmountController', function($rootScope, $scope, $filter, platformInfo, lodash, configService, go, rateService) { +angular.module('copayApp.controllers').controller('inputAmountController', function($rootScope, $scope, $filter, profileService, platformInfo, lodash, configService, go, rateService) { var unitToSatoshi; var satToUnit; var unitDecimals; @@ -27,9 +27,12 @@ angular.module('copayApp.controllers').controller('inputAmountController', funct $scope.toggleAlternative = function() { $scope.showAlternativeAmount = !$scope.showAlternativeAmount; - if (isExpression($scope.amount)) { - var decimals = $scope.showAlternativeAmount ? 2 : unitDecimals; - $scope.globalResult = '= ' + evaluate(format($scope.amount)).toFixed(decimals); + if ($scope.amount && isExpression($scope.amount)) { + var amount = evaluate(format($scope.amount)); + if ($scope.showAlternativeAmount) + $scope.globalResult = '= ' + $filter('formatFiatAmount')(amount); + else + $scope.globalResult = '= ' + profileService.formatAmount(amount * unitToSatoshi, true); } }; @@ -40,9 +43,9 @@ angular.module('copayApp.controllers').controller('inputAmountController', funct $scope.pushDigit = function(digit) { checkFontSize(); - if ($scope.amount && $scope.amount.length >= 20) return; + if ($scope.amount && $scope.amount.length >= 19) return; - $scope.amount = $scope.amount + digit; + $scope.amount = ($scope.amount + digit).replace('..', '.'); processAmount($scope.amount); }; @@ -67,11 +70,11 @@ angular.module('copayApp.controllers').controller('inputAmountController', funct }; function isExpression(val) { - var regex = /^\d+(\.?\d?)+$/; + var regex = /^\.?\d+(\.?\d+)?([\/\-\+\*x]\d?\.?\d+)+$/; var match = regex.exec(val); - if (match) return false; - return true; + if (match) return true; + return false; }; $scope.removeDigit = function() { @@ -100,11 +103,13 @@ angular.module('copayApp.controllers').controller('inputAmountController', funct var result = evaluate(formatedValue); if (lodash.isNumber(result)) { - var decimals = $scope.showAlternativeAmount ? 2 : unitDecimals; + if ($scope.showAlternativeAmount) + $scope.globalResult = isExpression(val) ? '= ' + $filter('formatFiatAmount')(result) : ''; + else + $scope.globalResult = isExpression(val) ? '= ' + profileService.formatAmount(result * unitToSatoshi, true) : ''; - $scope.globalResult = isExpression(val) ? '= ' + result.toFixed(decimals) : ''; $scope.amountResult = $filter('formatFiatAmount')(toFiat(result)); - $scope.alternativeResult = $filter('formatFiatAmount')(fromFiat(result)); + $scope.alternativeResult = profileService.formatAmount(fromFiat(result) * unitToSatoshi, true); } }; diff --git a/src/sass/main.scss b/src/sass/main.scss index 0ca43d701..5d6c62692 100644 --- a/src/sass/main.scss +++ b/src/sass/main.scss @@ -588,6 +588,10 @@ ul.manage li { margin-bottom: 10px; } +.m3t { + margin-top: 3px; +} + .m10t { margin-top: 10px; }