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>
</label>
<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">
<a class="postfix button" ng-style="{'background-color':index.backgroundColor}" ng-click="home.showAlternative()">{{home.unitName}}</a>
</div>

View file

@ -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;

View file

@ -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,25 @@ angular.module('copayApp.directives')
var val = function(value) {
var settings = configService.getSync().wallet.settings;
var vNum = Number((value * settings.unitToSatoshi).toFixed(0));
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 +168,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 +325,4 @@ angular.module('copayApp.directives')
replace: true,
templateUrl: 'views/includes/available-balance.html'
}
})
;
});