fix amount validation
This commit is contained in:
parent
f244462250
commit
08fb478195
3 changed files with 39 additions and 25 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
}
|
||||
})
|
||||
;
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue