Merge pull request #3091 from matiu/feat/fix-send-all

fix commit
This commit is contained in:
Gustavo Maximiliano Cortez 2015-08-13 15:07:25 -03:00
commit 89fb17c726
3 changed files with 26 additions and 7 deletions

View File

@ -295,7 +295,7 @@
<a class="right lh" <a class="right lh"
ng-if="index.feeToSendMaxStr && index.availableBalanceSat > 0 && !home.blockUx && !home.lockAmount" ng-if="index.feeToSendMaxStr && index.availableBalanceSat > 0 && !home.blockUx && !home.lockAmount"
ng-click="home.sendAll(index.availableMaxBalance, index.feeToSendMaxStr)" ng-click="home.sendAll(index.availableMaxBalance, index.feeToSendMaxStr, index.feeRateToSendMax)"
translate> Send All translate> Send All
</a> </a>

View File

@ -328,10 +328,12 @@ angular.module('copayApp.controllers').controller('indexController', function($r
// KB to send max // KB to send max
if (self.totalBytesToSendMax) { if (self.totalBytesToSendMax) {
var feeToSendMaxSat = parseInt(((self.totalBytesToSendMax * feePerKb) / 1000.).toFixed(0)); var feeToSendMaxSat = parseInt(((self.totalBytesToSendMax * feePerKb) / 1000.).toFixed(0));
self.feeRateToSendMax = feePerKb;
self.availableMaxBalance = strip((self.availableBalanceSat - feeToSendMaxSat) * self.satToUnit); self.availableMaxBalance = strip((self.availableBalanceSat - feeToSendMaxSat) * self.satToUnit);
self.feeToSendMaxStr = profileService.formatAmount(feeToSendMaxSat) + ' ' + self.unitName; self.feeToSendMaxStr = profileService.formatAmount(feeToSendMaxSat) + ' ' + self.unitName;
} else { } else {
self.feeToSendMaxStr = null; self.feeToSendMaxStr = null;
self.feeRateToSendMax = null;
} }
}); });
} }

View File

@ -722,7 +722,15 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
address = form.address.$modelValue; address = form.address.$modelValue;
amount = parseInt((form.amount.$modelValue * unitToSat).toFixed(0)); amount = parseInt((form.amount.$modelValue * unitToSat).toFixed(0));
feeService.getCurrentFeeValue(self.currentSendFeeLevel, function(err, feePerKb) { var getFee = function(cb) {
if (form.feePerKb) {
cb(null, form.feePerKb);
} else {
feeService.getCurrentFeeValue(self.currentSendFeeLevel, cb);
}
};
getFee(function(err, feePerKb) {
if (err) $log.debug(err); if (err) $log.debug(err);
fc.sendTxProposal({ fc.sendTxProposal({
toAddress: address, toAddress: address,
@ -803,7 +811,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
}); });
}; };
this.setForm = function(to, amount, comment) { this.setForm = function(to, amount, comment, feeRate) {
var form = $scope.sendForm; var form = $scope.sendForm;
if (to) { if (to) {
form.address.$setViewValue(to); form.address.$setViewValue(to);
@ -824,6 +832,10 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
form.comment.$isValid = true; form.comment.$isValid = true;
form.comment.$render(); form.comment.$render();
} }
if (feeRate) {
form.feeRate = feeRate;
}
}; };
@ -841,6 +853,11 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
this._amount = this._address = null; this._amount = this._address = null;
var form = $scope.sendForm; var form = $scope.sendForm;
if (form && form.feeRate) {
form.feeRate = null;
}
if (form && form.amount) { if (form && form.amount) {
form.amount.$pristine = true; form.amount.$pristine = true;
form.amount.$setViewValue(''); form.amount.$setViewValue('');
@ -1042,8 +1059,8 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
return actions.hasOwnProperty('create'); return actions.hasOwnProperty('create');
}; };
this._doSendAll = function(amount) { this._doSendAll = function(amount, feeRate) {
this.setForm(null, amount); this.setForm(null, amount, null, feeRate);
}; };
this.confirmDialog = function(msg, cb) { this.confirmDialog = function(msg, cb) {
@ -1069,7 +1086,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
} }
}; };
this.sendAll = function(amount, feeStr) { this.sendAll = function(amount, feeStr, feeRate) {
var self = this; var self = this;
var msg = gettextCatalog.getString("{{fee}} will be discounted for bitcoin networking fees", { var msg = gettextCatalog.getString("{{fee}} will be discounted for bitcoin networking fees", {
fee: feeStr fee: feeStr
@ -1077,7 +1094,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
this.confirmDialog(msg, function(confirmed) { this.confirmDialog(msg, function(confirmed) {
if (confirmed) if (confirmed)
self._doSendAll(amount); self._doSendAll(amount, feeRate);
}); });
}; };