Merge pull request #1550 from cmgustavo/bug/10-amount
Bug/Invalid-amount
This commit is contained in:
commit
02b85870df
4 changed files with 48 additions and 38 deletions
|
|
@ -48,32 +48,37 @@ angular.module('copayApp.directives')
|
|||
};
|
||||
}
|
||||
])
|
||||
.directive('enoughAmount', ['$rootScope',
|
||||
function($rootScope) {
|
||||
.directive('validAmount', ['$rootScope', '$locale',
|
||||
function($rootScope, locale) {
|
||||
var w = $rootScope.wallet;
|
||||
preconditions.checkState(w);
|
||||
preconditions.checkState(w.settings.unitToSatoshi);
|
||||
var formats = locale.NUMBER_FORMATS;
|
||||
|
||||
var feeSat = Number(bitcore.TransactionBuilder.FEE_PER_1000B_SAT);
|
||||
return {
|
||||
require: 'ngModel',
|
||||
link: function(scope, element, attrs, ctrl) {
|
||||
var val = function(value) {
|
||||
var availableBalanceNum = Number(($rootScope.availableBalance * w.settings.unitToSatoshi).toFixed(0));
|
||||
var vNum = Number((value * w.settings.unitToSatoshi).toFixed(0));
|
||||
|
||||
if (typeof value == 'undefined') {
|
||||
ctrl.$pristine = true;
|
||||
}
|
||||
|
||||
if (typeof vNum == "number" && vNum > 0) {
|
||||
vNum = vNum + feeSat;
|
||||
if (availableBalanceNum < vNum || isNaN(availableBalanceNum)) {
|
||||
ctrl.$setValidity('enoughAmount', false);
|
||||
scope.notEnoughAmount = true;
|
||||
var decimals = Number(w.settings.unitDecimals);
|
||||
var sep_index = ('' + value).indexOf(formats.DECIMAL_SEP);
|
||||
var str_value = ('' + value).substring(sep_index+1);
|
||||
if (sep_index > 0 && str_value.length > decimals) {
|
||||
ctrl.$setValidity('validAmount', false);
|
||||
scope.notValidAmount = true;
|
||||
} else {
|
||||
ctrl.$setValidity('enoughAmount', true);
|
||||
scope.notEnoughAmount = null;
|
||||
ctrl.$setValidity('validAmount', true);
|
||||
scope.notValidAmount = null;
|
||||
}
|
||||
} else {
|
||||
ctrl.$setValidity('enoughAmount', false);
|
||||
scope.notEnoughAmount = null;
|
||||
ctrl.$setValidity('validAmount', false);
|
||||
scope.notValidAmount = null;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2206,7 +2206,7 @@ Wallet.prototype.createTx = function(toAddress, amountSatStr, comment, opts, cb)
|
|||
|
||||
var ntxid = self.createTxSync(toAddress, amountSatStr, comment, safeUnspent, opts);
|
||||
if (!ntxid) {
|
||||
return cb(new Error('Error creating TX'));
|
||||
return cb(new Error('Error creating the Transaction'));
|
||||
}
|
||||
|
||||
self.sendIndexes();
|
||||
|
|
@ -2241,12 +2241,19 @@ Wallet.prototype.createTxSync = function(toAddress, amountSatStr, comment, utxos
|
|||
opts[k] = Wallet.builderOpts[k];
|
||||
}
|
||||
|
||||
var b = new Builder(opts)
|
||||
var b;
|
||||
|
||||
try {
|
||||
b = new Builder(opts)
|
||||
.setUnspent(utxos)
|
||||
.setOutputs([{
|
||||
address: toAddress,
|
||||
amountSatStr: amountSatStr,
|
||||
}]);
|
||||
} catch (e) {
|
||||
log.debug(e.message);
|
||||
return;
|
||||
};
|
||||
|
||||
var selectedUtxos = b.getSelectedUnspent();
|
||||
var inputChainPaths = selectedUtxos.map(function(utxo) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue