Merge pull request #4471 from matiu/bug/validation

fix amount validation
This commit is contained in:
Gustavo Maximiliano Cortez 2016-06-21 13:10:29 -03:00 committed by GitHub
commit 6357bf0f55
3 changed files with 38 additions and 25 deletions

View file

@ -426,7 +426,7 @@
<span translate>Amount</span> <span translate>Amount</span>
</label> </label>
<div class="input"> <div class="input">
<input type="number" id="amount" ng-disabled=" home.lockAmount" name="amount" ng-attr-placeholder="{{'Amount in'|translate}} {{home.unitName}}" ng-minlength="0.00000001" ng-maxlength="10000000000" ng-model="_amount" valid-amount required autocomplete="off" ng-focus="home.formFocus('amount')" ng-blur="home.formFocus(false)"> <input type="number" id="amount" ng-disabled=" home.lockAmount" name="amount" ng-attr-placeholder="{{'Amount in'|translate}} {{home.unitName}}" ng-model="_amount" valid-amount required autocomplete="off" ng-focus="home.formFocus('amount')" ng-blur="home.formFocus(false)">
<input type="number" id="alternative" name="alternative" ng-model="_alternative" style="display:none"> <input type="number" id="alternative" name="alternative" ng-model="_alternative" style="display:none">
<a class="postfix button" ng-style="{'background-color':index.backgroundColor}" ng-click="home.showAlternative()">{{home.unitName}}</a> <a class="postfix button" ng-style="{'background-color':index.backgroundColor}" ng-click="home.showAlternative()">{{home.unitName}}</a>
</div> </div>

View file

@ -418,6 +418,12 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
return self.setSendError(gettext(msg)); 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() { $timeout(function() {
var paypro = self._paypro; var paypro = self._paypro;
var address, amount; var address, amount;

View file

@ -94,20 +94,26 @@ angular.module('copayApp.directives')
var val = function(value) { var val = function(value) {
var settings = configService.getSync().wallet.settings; var settings = configService.getSync().wallet.settings;
var vNum = Number((value * settings.unitToSatoshi).toFixed(0)); var vNum = Number((value * settings.unitToSatoshi).toFixed(0));
if (typeof value == 'undefined' || value == 0) { if (typeof value == 'undefined' || value == 0) {
ctrl.$pristine = true; ctrl.$pristine = true;
} }
if (typeof vNum == "number" && vNum > 0) { if (typeof vNum == "number" && vNum > 0) {
if (vNum > Number.MAX_SAFE_INTEGER) {
ctrl.$setValidity('validAmount', false);
} else {
var decimals = Number(settings.unitDecimals); var decimals = Number(settings.unitDecimals);
var sep_index = ('' + value).indexOf('.'); var sep_index = ('' + value).indexOf('.');
var str_value = ('' + value).substring(sep_index + 1); var str_value = ('' + value).substring(sep_index + 1);
if (sep_index > 0 && str_value.length > decimals) { if (sep_index >= 0 && str_value.length > decimals) {
ctrl.$setValidity('validAmount', false); ctrl.$setValidity('validAmount', false);
return;
} else { } else {
ctrl.$setValidity('validAmount', true); ctrl.$setValidity('validAmount', true);
} }
}
} else { } else {
ctrl.$setValidity('validAmount', false); ctrl.$setValidity('validAmount', false);
} }
@ -162,7 +168,8 @@ angular.module('copayApp.directives')
} }
} }
}) })
.directive('contact', ['addressbookService', function(addressbookService) { .directive('contact', ['addressbookService',
function(addressbookService) {
return { return {
restrict: 'E', restrict: 'E',
link: function(scope, element, attrs) { link: function(scope, element, attrs) {
@ -176,7 +183,8 @@ angular.module('copayApp.directives')
}); });
} }
}; };
}]) }
])
.directive('highlightOnChange', function() { .directive('highlightOnChange', function() {
return { return {
restrict: 'A', restrict: 'A',
@ -317,5 +325,4 @@ angular.module('copayApp.directives')
replace: true, replace: true,
templateUrl: 'views/includes/available-balance.html' templateUrl: 'views/includes/available-balance.html'
} }
}) });
;