Fix fee for send all
This commit is contained in:
parent
08a15ae52b
commit
66b7fa8f7a
5 changed files with 134 additions and 106 deletions
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('walletHomeController', function($scope, $rootScope, $timeout, $filter, $modal, $log, notification, txStatus, isCordova, profileService, lodash, configService, rateService, storageService, bitcore, isChromeApp, gettext, gettextCatalog, nodeWebkit, addressService, ledger, bwsError, confirmDialog, txFormatService, animationService, addressbookService, go) {
|
||||
angular.module('copayApp.controllers').controller('walletHomeController', function($scope, $rootScope, $timeout, $filter, $modal, $log, notification, txStatus, isCordova, profileService, lodash, configService, rateService, storageService, bitcore, isChromeApp, gettext, gettextCatalog, nodeWebkit, addressService, ledger, bwsError, confirmDialog, txFormatService, animationService, addressbookService, go, feeService) {
|
||||
|
||||
var self = this;
|
||||
$rootScope.hideMenuBar = false;
|
||||
|
|
@ -26,6 +26,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
|
|||
this.showScanner = false;
|
||||
this.isMobile = isMobile.any();
|
||||
this.addr = {};
|
||||
this.lockedCurrentFeePerKb = null;
|
||||
|
||||
var disableScannerListener = $rootScope.$on('dataScanned', function(event, data) {
|
||||
self.setForm(data);
|
||||
|
|
@ -826,7 +827,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
|
|||
};
|
||||
};
|
||||
|
||||
this.submitForm = function(currentFeePerKb) {
|
||||
this.submitForm = function() {
|
||||
var fc = profileService.focusedClient;
|
||||
var unitToSat = this.unitToSatoshi;
|
||||
var currentSpendUnconfirmed = configWallet.spendUnconfirmed;
|
||||
|
|
@ -859,6 +860,14 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
|
|||
return self.setSendError(gettext(msg));
|
||||
}
|
||||
|
||||
var getFee = function(cb) {
|
||||
if (self.lockedCurrentFeePerKb) {
|
||||
cb(null, self.lockedCurrentFeePerKb);
|
||||
} else {
|
||||
feeService.getCurrentFeeValue(self.currentFeeLevel, cb);
|
||||
}
|
||||
};
|
||||
|
||||
self.setOngoingProcess(gettext('Creating transaction'));
|
||||
$timeout(function() {
|
||||
var paypro = self._paypro;
|
||||
|
|
@ -878,40 +887,43 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
|
|||
return;
|
||||
}
|
||||
|
||||
fc.sendTxProposal({
|
||||
toAddress: address,
|
||||
amount: amount,
|
||||
message: comment,
|
||||
payProUrl: paypro ? paypro.url : null,
|
||||
feePerKb: currentFeePerKb,
|
||||
excludeUnconfirmedUtxos: currentSpendUnconfirmed ? false : true
|
||||
}, function(err, txp) {
|
||||
if (err) {
|
||||
self.setOngoingProcess();
|
||||
profileService.lockFC();
|
||||
return self.setSendError(err);
|
||||
}
|
||||
|
||||
if (!fc.canSign() && !fc.isPrivKeyExternal()) {
|
||||
$log.info('No signing proposal: No private key')
|
||||
self.setOngoingProcess();
|
||||
self.resetForm();
|
||||
txStatus.notify(txp, function() {
|
||||
return $scope.$emit('Local/TxProposalAction');
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
self.signAndBroadcast(txp, function(err) {
|
||||
self.setOngoingProcess();
|
||||
self.resetForm();
|
||||
getFee(function(err, feePerKb) {
|
||||
if (err) $log.debug(err);
|
||||
fc.sendTxProposal({
|
||||
toAddress: address,
|
||||
amount: amount,
|
||||
message: comment,
|
||||
payProUrl: paypro ? paypro.url : null,
|
||||
feePerKb: feePerKb,
|
||||
excludeUnconfirmedUtxos: currentSpendUnconfirmed ? false : true
|
||||
}, function(err, txp) {
|
||||
if (err) {
|
||||
self.error = err.message ? err.message : gettext('The payment was created but could not be completed. Please try again from home screen');
|
||||
$scope.$emit('Local/TxProposalAction');
|
||||
$timeout(function() {
|
||||
$scope.$digest();
|
||||
}, 1);
|
||||
} else go.walletHome();
|
||||
self.setOngoingProcess();
|
||||
profileService.lockFC();
|
||||
return self.setSendError(err);
|
||||
}
|
||||
|
||||
if (!fc.canSign() && !fc.isPrivKeyExternal()) {
|
||||
$log.info('No signing proposal: No private key')
|
||||
self.setOngoingProcess();
|
||||
self.resetForm();
|
||||
txStatus.notify(txp, function() {
|
||||
return $scope.$emit('Local/TxProposalAction');
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
self.signAndBroadcast(txp, function(err) {
|
||||
self.setOngoingProcess();
|
||||
self.resetForm();
|
||||
if (err) {
|
||||
self.error = err.message ? err.message : gettext('The payment was created but could not be completed. Please try again from home screen');
|
||||
$scope.$emit('Local/TxProposalAction');
|
||||
$timeout(function() {
|
||||
$scope.$digest();
|
||||
}, 1);
|
||||
} else go.walletHome();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -996,6 +1008,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
|
|||
this.resetForm = function() {
|
||||
this.resetError();
|
||||
this._paypro = null;
|
||||
this.lockedCurrentFeePerKb = null;
|
||||
|
||||
this.lockAddress = false;
|
||||
this.lockAmount = false;
|
||||
|
|
@ -1257,16 +1270,19 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
|
|||
this.setForm(null, amount, null);
|
||||
};
|
||||
|
||||
this.sendAll = function(amount, feeStr) {
|
||||
this.sendAll = function() {
|
||||
var self = this;
|
||||
var msg = gettextCatalog.getString("{{fee}} will be deducted for bitcoin networking fees", {
|
||||
fee: feeStr
|
||||
});
|
||||
$rootScope.$emit('Local/SetFeeSendMax', function(currentFeePerKb, availableMaxBalance, feeToSendMaxStr) {
|
||||
self.lockedCurrentFeePerKb = currentFeePerKb;
|
||||
var msg = gettextCatalog.getString("{{fee}} will be deducted for bitcoin networking fees", {
|
||||
fee: feeToSendMaxStr
|
||||
});
|
||||
|
||||
confirmDialog.show(msg, function(confirmed) {
|
||||
if (confirmed) {
|
||||
self._doSendAll(amount);
|
||||
}
|
||||
confirmDialog.show(msg, function(confirmed) {
|
||||
if (confirmed) {
|
||||
self._doSendAll(availableMaxBalance);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue