replace send all to send max (#4010)

* fix prevent submit

* replace send all to send max

* fix params and errors

* add warnings in case to exclude utxos

* remove unnecessaries parameters and variables

* verify exclude utxos before checking amount

* bump bwc dependency to v2.2.1

* fix message text
This commit is contained in:
Javier Donadío 2016-04-13 14:05:36 -03:00 committed by Matias Alejo Garcia
parent 5666649a2d
commit b011df787c
2 changed files with 62 additions and 27 deletions

View File

@ -390,11 +390,11 @@
<available-balance></available-balance> <available-balance></available-balance>
<span <span
ng-show="home.lockedCurrentFeePerKb || home.blockUx || home.lockAmount" ng-show="home.lockedCurrentFeePerKb || home.blockUx || home.lockAmount"
class="text-gray" translate>Send All</span> class="text-gray" translate>Send Max</span>
<a <a
ng-show="index.availableBalanceSat > 0 && !home.lockedCurrentFeePerKb && !home.blockUx && !home.lockAmount" ng-show="index.availableBalanceSat > 0 && !home.lockedCurrentFeePerKb && !home.blockUx && !home.lockAmount"
ng-click="home.sendAll(index.totalBytesToSendMax, index.availableBalanceSat)" ng-click="home.sendMax(index.availableBalanceSat)"
translate> Send All translate>Send Max
</a> </a>
<div ng-show="!home.paymentExpired && home._paypro"> <div ng-show="!home.paymentExpired && home._paypro">
<span translate>Payment expires</span> <span translate>Payment expires</span>

View File

@ -1243,46 +1243,81 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
return actions.hasOwnProperty('create'); return actions.hasOwnProperty('create');
}; };
this._doSendAll = function(amount) { this._doSendMax = function(amount) {
this.setForm(null, amount, null); this.setForm(null, amount, null);
}; };
this.sendAll = function(totalBytesToSendMax, availableBalanceSat) { this.sendMax = function(availableBalanceSat) {
if (availableBalanceSat == 0) {
this.error = gettext("Cannot create transaction. Insufficient funds");
return;
}
var self = this; var self = this;
var availableMaxBalance; var fc = profileService.focusedClient;
var feeToSendMaxStr;
this.error = null; this.error = null;
this.setOngoingProcess(gettextCatalog.getString('Calculating fee')); this.setOngoingProcess(gettextCatalog.getString('Calculating fee'));
feeService.getCurrentFeeValue(function(err, feePerKb) { feeService.getCurrentFeeValue(function(err, feePerKb) {
if (err || !lodash.isNumber(feePerKb)) {
self.setOngoingProcess(); self.setOngoingProcess();
if (err || lodash.isNull(feePerKb)) {
self.error = gettext('Could not get fee value'); self.error = gettext('Could not get fee value');
return; return;
} }
var feeToSendMaxSat = parseInt(((totalBytesToSendMax * feePerKb) / 1000.).toFixed(0)); var opts = {};
if (availableBalanceSat > feeToSendMaxSat) { opts.feePerKb = feePerKb;
self.lockedCurrentFeePerKb = feePerKb; opts.returnInputs = true;
availableMaxBalance = strip((availableBalanceSat - feeToSendMaxSat) * self.satToUnit); var config = configService.getSync();
feeToSendMaxStr = profileService.formatAmount(feeToSendMaxSat) + ' ' + self.unitName; opts.excludeUnconfirmedUtxos = !config.wallet.spendUnconfirmed;
} else { self.setOngoingProcess(gettextCatalog.getString('Retrieving inputs information'));
self.error = gettext('Not enought funds for fee');
fc.getSendMaxInfo(opts, function(err, resp) {
self.setOngoingProcess();
if (err) {
self.error = err;
$scope.$apply();
return;
}
if (resp.amount == 0) {
self.error = gettext("Not enought funds for fee");
$scope.$apply();
return; return;
} }
var msg = gettextCatalog.getString("{{fee}} will be deducted for bitcoin networking fees", { var msg = gettextCatalog.getString("{{fee}} will be deducted for bitcoin networking fees", {
fee: feeToSendMaxStr fee: profileService.formatAmount(resp.fee) + ' ' + self.unitName
}); });
$scope.$apply(); var warningMsg = verifyExcludedUtxos();
if (!lodash.isEmpty(warningMsg))
msg += '. \n' + warningMsg;
confirmDialog.show(msg, function(confirmed) { confirmDialog.show(msg, function(confirmed) {
if (confirmed) { if (confirmed) {
self._doSendAll(availableMaxBalance); self._doSendMax(resp.amount * self.satToUnit);
} else { } else {
self.resetForm(); self.resetForm();
} }
}); });
function verifyExcludedUtxos() {
var warningMsg = [];
if (resp.utxosBelowFee > 0) {
warningMsg.push(gettextCatalog.getString("Note: a total of {{amountBelowFeeStr}} were excluded. These funds come from UTXOs smaller than the network fee provided.", {
amountBelowFeeStr: profileService.formatAmount(resp.amountBelowFee) + ' ' + self.unitName
}));
}
if (resp.utxosAboveMaxSize > 0) {
warningMsg.push(gettextCatalog.getString("Note: a total of {{amountAboveMaxSizeStr}} were excluded. The maximum size allowed for a transaction was exceeded", {
amountAboveMaxSizeStr: profileService.formatAmount(resp.amountAboveMaxSize) + ' ' + self.unitName
}));
}
return warningMsg.join('\n');
}
});
}); });
}; };