From 93028b9be08c8d05ecd57ad3bdacb2bc563e4f29 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Fri, 7 Aug 2015 11:23:32 -0300 Subject: [PATCH 1/2] Fixes decimal inputs --- public/views/modals/customized-amount.html | 8 ++++---- public/views/walletHome.html | 14 ++++++++++---- src/js/directives/directives.js | 6 +++--- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/public/views/modals/customized-amount.html b/public/views/modals/customized-amount.html index d37f32dd5..8981f5738 100644 --- a/public/views/modals/customized-amount.html +++ b/public/views/modals/customized-amount.html @@ -53,8 +53,8 @@ Amount
- + {{unitName}}
@@ -63,8 +63,8 @@
- + {{ alternativeIsoCode }}
diff --git a/public/views/walletHome.html b/public/views/walletHome.html index a68d4fa86..06a71249e 100644 --- a/public/views/walletHome.html +++ b/public/views/walletHome.html @@ -382,8 +382,11 @@ Amount
- - + + {{home.unitName}}
@@ -391,8 +394,11 @@
- - + + {{ home.alternativeIsoCode }}
diff --git a/src/js/directives/directives.js b/src/js/directives/directives.js index 5696fd116..78376c647 100644 --- a/src/js/directives/directives.js +++ b/src/js/directives/directives.js @@ -87,22 +87,22 @@ angular.module('copayApp.directives') ]) .directive('validAmount', ['configService', '$locale', function(configService, locale) { - var formats = locale.NUMBER_FORMATS; return { require: 'ngModel', link: function(scope, element, attrs, ctrl) { var val = function(value) { + if (value) value = value.replace(/,/g, '.'); var settings = configService.getSync().wallet.settings; var vNum = Number((value * settings.unitToSatoshi).toFixed(0)); - if (typeof value == 'undefined') { + if (typeof value == 'undefined' || value == 0) { ctrl.$pristine = true; } if (typeof vNum == "number" && vNum > 0) { var decimals = Number(settings.unitDecimals); - var sep_index = ('' + value).indexOf(formats.DECIMAL_SEP); + var sep_index = ('' + value).indexOf('.'); var str_value = ('' + value).substring(sep_index + 1); if (sep_index > 0 && str_value.length > decimals) { ctrl.$setValidity('validAmount', false); From ce05318d94c141d8f59170a5ba7c93d57e5b3513 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Fri, 7 Aug 2015 17:21:22 -0300 Subject: [PATCH 2/2] Replaces comma by dot --- public/views/modals/customized-amount.html | 6 ++-- public/views/walletHome.html | 8 +++--- src/js/controllers/walletHome.js | 8 ++++-- src/js/directives/directives.js | 33 ++++++++++++++++++++-- 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/public/views/modals/customized-amount.html b/public/views/modals/customized-amount.html index 8981f5738..a50eb0764 100644 --- a/public/views/modals/customized-amount.html +++ b/public/views/modals/customized-amount.html @@ -55,7 +55,7 @@ @@ -64,8 +64,8 @@
- + ng-model="_customAlternative" valid-alternative required autocomplete="off" pattern="[0-9]+([\.,][0-9]+)*" required> + {{ alternativeIsoCode }}
diff --git a/public/views/walletHome.html b/public/views/walletHome.html index 06a71249e..69df80a74 100644 --- a/public/views/walletHome.html +++ b/public/views/walletHome.html @@ -373,7 +373,7 @@ Not valid - + @@ -385,7 +385,7 @@ + ng-blur="home.formFocus(false)"> {{home.unitName}} @@ -396,8 +396,8 @@
+ ng-model="_alternative" valid-alternative required autocomplete="off" ng-focus="home.formFocus('amount')" + ng-blur="home.formFocus(false)"> {{ home.alternativeIsoCode }}
diff --git a/src/js/controllers/walletHome.js b/src/js/controllers/walletHome.js index 37b14ea88..db32b9769 100644 --- a/src/js/controllers/walletHome.js +++ b/src/js/controllers/walletHome.js @@ -475,6 +475,8 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi $scope.customAlternative = newValue; if (typeof(newValue) === 'number' && $scope.isRateAvailable) { $scope.customAmount = parseFloat((rateService.fromFiat(newValue, $scope.alternativeIsoCode) * satToUnit).toFixed($scope.unitDecimals), 10); + } else { + $scope.customAmount = null; } }, enumerable: true, @@ -491,7 +493,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi if (typeof(newValue) === 'number' && $scope.isRateAvailable) { $scope.customAlternative = parseFloat((rateService.toFiat(newValue * $scope.unitToSatoshi, $scope.alternativeIsoCode)).toFixed(2), 10); } else { - $scope.customAlternative = 0; + $scope.customAlternative = null; } $scope.alternativeAmount = $scope.customAlternative; }, @@ -625,6 +627,8 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi $scope.__alternative = newValue; if (typeof(newValue) === 'number' && self.isRateAvailable) { $scope._amount = parseFloat((rateService.fromFiat(newValue, self.alternativeIsoCode) * satToUnit).toFixed(self.unitDecimals), 10); + } else { + $scope.__amount = null; } }, enumerable: true, @@ -640,7 +644,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi if (typeof(newValue) === 'number' && self.isRateAvailable) { $scope.__alternative = parseFloat((rateService.toFiat(newValue * self.unitToSatoshi, self.alternativeIsoCode)).toFixed(2), 10); } else { - $scope.__alternative = 0; + $scope.__alternative = null; } self.alternativeAmount = $scope.__alternative; self.resetError(); diff --git a/src/js/directives/directives.js b/src/js/directives/directives.js index 78376c647..6ca44a772 100644 --- a/src/js/directives/directives.js +++ b/src/js/directives/directives.js @@ -85,14 +85,14 @@ angular.module('copayApp.directives') }; } ]) - .directive('validAmount', ['configService', '$locale', - function(configService, locale) { + .directive('validAmount', ['configService', + function(configService) { return { require: 'ngModel', link: function(scope, element, attrs, ctrl) { var val = function(value) { - if (value) value = value.replace(/,/g, '.'); + if (value) value = Number(String(value).replace(/,/g, '.')); var settings = configService.getSync().wallet.settings; var vNum = Number((value * settings.unitToSatoshi).toFixed(0)); @@ -120,6 +120,33 @@ angular.module('copayApp.directives') }; } ]) + .directive('validAlternative', [ + function() { + + return { + require: 'ngModel', + link: function(scope, element, attrs, ctrl) { + var val = function(value) { + if (value) value = Number(String(value).replace(/,/g, '.')); + var vNum = Number(value); + + if (typeof value == 'undefined' || value == 0) { + ctrl.$pristine = true; + } + + if (typeof vNum == "number" && vNum > 0) { + ctrl.$setValidity('validAlternative', true); + } else { + ctrl.$setValidity('validAlternative', false); + } + return value; + } + ctrl.$parsers.unshift(val); + ctrl.$formatters.unshift(val); + } + }; + } + ]) .directive('walletSecret', function(bitcore) { return { require: 'ngModel',