diff --git a/public/views/walletHome.html b/public/views/walletHome.html index be1a58509..3fce9dd1c 100644 --- a/public/views/walletHome.html +++ b/public/views/walletHome.html @@ -426,7 +426,7 @@ Amount
diff --git a/src/js/controllers/walletHome.js b/src/js/controllers/walletHome.js index 3d10eef89..fd5c6c2e3 100644 --- a/src/js/controllers/walletHome.js +++ b/src/js/controllers/walletHome.js @@ -418,6 +418,12 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi return self.setSendError(gettext(msg)); } + if (form.amount.$modelValue * unitToSat > Number.MAX_SAFE_INTEGER) { + var msg = 'Amount too big'; + $log.warn(msg); + return self.setSendError(gettext(msg)); + }; + $timeout(function() { var paypro = self._paypro; var address, amount; diff --git a/src/js/directives/directives.js b/src/js/directives/directives.js index 1638b9859..8051a8fc6 100644 --- a/src/js/directives/directives.js +++ b/src/js/directives/directives.js @@ -16,7 +16,7 @@ function selectText(element) { } } angular.module('copayApp.directives') -.directive('validAddress', ['$rootScope', 'bitcore', 'profileService', + .directive('validAddress', ['$rootScope', 'bitcore', 'profileService', function($rootScope, bitcore, profileService) { return { require: 'ngModel', @@ -94,19 +94,26 @@ angular.module('copayApp.directives') var val = function(value) { var settings = configService.getSync().wallet.settings; var vNum = Number((value * settings.unitToSatoshi).toFixed(0)); - + console.log('[directives.js.96:vNum:]', vNum); //TODO 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('.'); - var str_value = ('' + value).substring(sep_index + 1); - if (sep_index > 0 && str_value.length > decimals) { + if (vNum > Number.MAX_SAFE_INTEGER) { ctrl.$setValidity('validAmount', false); } else { - ctrl.$setValidity('validAmount', true); + var decimals = Number(settings.unitDecimals); + 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); + return; + } else { + ctrl.$setValidity('validAmount', true); + } } } else { ctrl.$setValidity('validAmount', false); @@ -162,21 +169,23 @@ angular.module('copayApp.directives') } } }) - .directive('contact', ['addressbookService', function(addressbookService) { - return { - restrict: 'E', - link: function(scope, element, attrs) { - var addr = attrs.address; - addressbookService.getLabel(addr, function(label) { - if (label) { - element.append(label); - } else { - element.append(addr); - } - }); - } - }; - }]) + .directive('contact', ['addressbookService', + function(addressbookService) { + return { + restrict: 'E', + link: function(scope, element, attrs) { + var addr = attrs.address; + addressbookService.getLabel(addr, function(label) { + if (label) { + element.append(label); + } else { + element.append(addr); + } + }); + } + }; + } + ]) .directive('highlightOnChange', function() { return { restrict: 'A', @@ -317,5 +326,4 @@ angular.module('copayApp.directives') replace: true, templateUrl: 'views/includes/available-balance.html' } - }) -; + });