Fix send max opts (#4152)

* fix send max opts

* improve setForm call
This commit is contained in:
Javier Donadío 2016-04-29 11:25:30 -03:00 committed by Gustavo Maximiliano Cortez
parent 85716f72f3
commit 8ffb01a355
3 changed files with 36 additions and 22 deletions

View File

@ -42,7 +42,7 @@
"url": "https://github.com/bitpay/copay/issues" "url": "https://github.com/bitpay/copay/issues"
}, },
"dependencies": { "dependencies": {
"bitcore-wallet-client": "2.2.2", "bitcore-wallet-client": "2.3.0",
"express": "^4.11.2", "express": "^4.11.2",
"fs": "0.0.2", "fs": "0.0.2",
"grunt": "^0.4.5", "grunt": "^0.4.5",

View File

@ -24,6 +24,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
ret.isMobile = isMobile.any(); ret.isMobile = isMobile.any();
ret.isWindowsPhoneApp = isMobile.Windows() && isCordova; ret.isWindowsPhoneApp = isMobile.Windows() && isCordova;
ret.countDown = null; ret.countDown = null;
ret.sendMaxInfo = {};
var vanillaScope = ret; var vanillaScope = ret;
var disableScannerListener = $rootScope.$on('dataScanned', function(event, data) { var disableScannerListener = $rootScope.$on('dataScanned', function(event, data) {
@ -909,14 +910,21 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
'message': comment 'message': comment
}); });
var opts = { var opts = {};
toAddress: address,
amount: amount, if (self.sendMaxInfo) {
outputs: outputs, opts.sendMax = true;
message: comment, opts.inputs = self.sendMaxInfo.inputs;
payProUrl: paypro ? paypro.url : null, opts.fee = self.sendMaxInfo.fee;
lockedCurrentFeePerKb: self.lockedCurrentFeePerKb }else {
}; opts.amount = amount;
}
opts.toAddress = address;
opts.outputs = outputs;
opts.message = comment;
opts.payProUrl = paypro ? paypro.url : null;
opts.lockedCurrentFeePerKb = self.lockedCurrentFeePerKb;
self.setOngoingProcess(gettextCatalog.getString('Creating transaction')); self.setOngoingProcess(gettextCatalog.getString('Creating transaction'));
txService.createTx(opts, function(err, txp) { txService.createTx(opts, function(err, txp) {
@ -1004,6 +1012,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
this.resetForm = function() { this.resetForm = function() {
this.resetError(); this.resetError();
this.sendMaxInfo = {};
if (this.countDown) $interval.cancel(this.countDown); if (this.countDown) $interval.cancel(this.countDown);
this._paypro = null; this._paypro = null;
this.lockedCurrentFeePerKb = null; this.lockedCurrentFeePerKb = null;
@ -1246,10 +1255,6 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
return actions.hasOwnProperty('create'); return actions.hasOwnProperty('create');
}; };
this._doSendMax = function(amount) {
this.setForm(null, amount, null);
};
this.sendMax = function(availableBalanceSat) { this.sendMax = function(availableBalanceSat) {
if (availableBalanceSat == 0) { if (availableBalanceSat == 0) {
this.error = gettext("Cannot create transaction. Insufficient funds"); this.error = gettext("Cannot create transaction. Insufficient funds");
@ -1300,7 +1305,9 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
confirmDialog.show(msg, function(confirmed) { confirmDialog.show(msg, function(confirmed) {
if (confirmed) { if (confirmed) {
self._doSendMax(parseFloat((resp.amount * self.satToUnit).toFixed(self.unitDecimals))); self.sendMaxInfo = resp;
var amount = parseFloat((resp.amount * self.satToUnit).toFixed(self.unitDecimals));
self.setForm(null, amount, null);
} else { } else {
self.resetForm(); self.resetForm();
} }

View File

@ -91,7 +91,7 @@ angular.module('copayApp.services').factory('txService', function($rootScope, pr
}); });
}); });
}; };
root.removeTx = function(txp, opts, cb) { root.removeTx = function(txp, opts, cb) {
opts = opts || {}; opts = opts || {};
@ -106,7 +106,7 @@ angular.module('copayApp.services').factory('txService', function($rootScope, pr
opts = opts || {}; opts = opts || {};
var fc = opts.selectedClient || profileService.focusedClient; var fc = opts.selectedClient || profileService.focusedClient;
var currentSpendUnconfirmed = configService.getSync().wallet.spendUnconfirmed; var currentSpendUnconfirmed = configService.getSync().wallet.spendUnconfirmed;
var getFee = function(cb) { var getFee = function(cb) {
if (opts.lockedCurrentFeePerKb) { if (opts.lockedCurrentFeePerKb) {
cb(null, opts.lockedCurrentFeePerKb); cb(null, opts.lockedCurrentFeePerKb);
@ -115,16 +115,23 @@ angular.module('copayApp.services').factory('txService', function($rootScope, pr
} }
}; };
getFee(function(err, feePerKb) { if (opts.sendMax) {
if (err) return cb(err);
opts.feePerKb = feePerKb;
opts.excludeUnconfirmedUtxos = currentSpendUnconfirmed ? false : true;
fc.createTxProposal(opts, function(err, txp) { fc.createTxProposal(opts, function(err, txp) {
if (err) return cb(err); if (err) return cb(err);
else return cb(null, txp); else return cb(null, txp);
}); });
}); }else {
getFee(function(err, feePerKb) {
if (err) return cb(err);
opts.feePerKb = feePerKb;
opts.excludeUnconfirmedUtxos = currentSpendUnconfirmed ? false : true;
fc.createTxProposal(opts, function(err, txp) {
if (err) return cb(err);
else return cb(null, txp);
});
});
}
}; };
root.publishTx = function(txp, opts, cb) { root.publishTx = function(txp, opts, cb) {