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"
},
"dependencies": {
"bitcore-wallet-client": "2.2.2",
"bitcore-wallet-client": "2.3.0",
"express": "^4.11.2",
"fs": "0.0.2",
"grunt": "^0.4.5",

View File

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

View File

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