Merge pull request #4471 from matiu/bug/validation
fix amount validation
This commit is contained in:
commit
6357bf0f55
3 changed files with 38 additions and 25 deletions
|
|
@ -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>
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ function selectText(element) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
angular.module('copayApp.directives')
|
angular.module('copayApp.directives')
|
||||||
.directive('validAddress', ['$rootScope', 'bitcore', 'profileService',
|
.directive('validAddress', ['$rootScope', 'bitcore', 'profileService',
|
||||||
function($rootScope, bitcore, profileService) {
|
function($rootScope, bitcore, profileService) {
|
||||||
return {
|
return {
|
||||||
require: 'ngModel',
|
require: 'ngModel',
|
||||||
|
|
@ -94,19 +94,25 @@ 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) {
|
||||||
var decimals = Number(settings.unitDecimals);
|
if (vNum > Number.MAX_SAFE_INTEGER) {
|
||||||
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);
|
ctrl.$setValidity('validAmount', false);
|
||||||
} else {
|
} 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 {
|
} else {
|
||||||
ctrl.$setValidity('validAmount', false);
|
ctrl.$setValidity('validAmount', false);
|
||||||
|
|
@ -162,21 +168,23 @@ angular.module('copayApp.directives')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.directive('contact', ['addressbookService', function(addressbookService) {
|
.directive('contact', ['addressbookService',
|
||||||
return {
|
function(addressbookService) {
|
||||||
restrict: 'E',
|
return {
|
||||||
link: function(scope, element, attrs) {
|
restrict: 'E',
|
||||||
var addr = attrs.address;
|
link: function(scope, element, attrs) {
|
||||||
addressbookService.getLabel(addr, function(label) {
|
var addr = attrs.address;
|
||||||
if (label) {
|
addressbookService.getLabel(addr, function(label) {
|
||||||
element.append(label);
|
if (label) {
|
||||||
} else {
|
element.append(label);
|
||||||
element.append(addr);
|
} else {
|
||||||
}
|
element.append(addr);
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
};
|
}
|
||||||
}])
|
};
|
||||||
|
}
|
||||||
|
])
|
||||||
.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'
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
;
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue