mirror of https://github.com/BTCPrivate/copay.git
Merge pull request #3716 from cmgustavo/bug/send_all_fee
Bug/send all fee
This commit is contained in:
commit
c70c8947ec
|
@ -106,7 +106,7 @@
|
|||
Please, enter the code below
|
||||
</p>
|
||||
<form name="sellForm"
|
||||
ng-submit="sell.createTx(index.glideraToken, index.glideraPermissions, twoFaCode, index.feeRateToSendMax)" novalidate>
|
||||
ng-submit="sell.createTx(index.glideraToken, index.glideraPermissions, twoFaCode)" novalidate>
|
||||
<input type="number" ng-model="twoFaCode" required>
|
||||
<input class="button black expand round"
|
||||
ng-style="{'background-color':index.backgroundColor}"
|
||||
|
|
|
@ -387,8 +387,8 @@
|
|||
<h4 class="title m0">
|
||||
<available-balance></available-balance>
|
||||
<a
|
||||
ng-if="index.feeToSendMaxStr && index.availableBalanceSat > 0 && !home.blockUx && !home.lockAmount"
|
||||
ng-click="home.sendAll(index.availableMaxBalance, index.feeToSendMaxStr)"
|
||||
ng-show="!home.lockedCurrentFeePerKb && index.feeToSendMaxStr && index.availableBalanceSat > 0 && !home.blockUx && !home.lockAmount"
|
||||
ng-click="home.sendAll()"
|
||||
translate> Send All
|
||||
</a>
|
||||
</h4>
|
||||
|
@ -403,7 +403,7 @@
|
|||
</div>
|
||||
<div class="row m20t">
|
||||
<div class="large-12 large-centered columns">
|
||||
<form name="sendForm" ng-submit="home.submitForm(index.feeRateToSendMax)" ng-disabled="home.blockUx || home.onGoingProcess" novalidate>
|
||||
<form name="sendForm" ng-submit="home.submitForm()" ng-disabled="home.blockUx || home.onGoingProcess" novalidate>
|
||||
|
||||
<div ng-hide="home._paypro || home.hideAddress">
|
||||
<div class="row collapse">
|
||||
|
|
|
@ -371,14 +371,15 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
});
|
||||
};
|
||||
|
||||
self.setSpendUnconfirmed = function() {
|
||||
self.spendUnconfirmed = configService.getSync().wallet.spendUnconfirmed;
|
||||
self.setSpendUnconfirmed = function(spendUnconfirmed) {
|
||||
self.spendUnconfirmed = spendUnconfirmed || configService.getSync().wallet.spendUnconfirmed;
|
||||
};
|
||||
|
||||
self.setSendMax = function() {
|
||||
self.setFeeAndSendMax = function(cb) {
|
||||
|
||||
self.feeToSendMaxStr = null;
|
||||
self.feeRateToSendMax = null;
|
||||
self.availableMaxBalance = null;
|
||||
self.currentFeePerKb = null;
|
||||
|
||||
// Set Send max
|
||||
if (self.currentFeeLevel && self.totalBytesToSendMax) {
|
||||
|
@ -386,12 +387,14 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
|
||||
// KB to send max
|
||||
var feeToSendMaxSat = parseInt(((self.totalBytesToSendMax * feePerKb) / 1000.).toFixed(0));
|
||||
self.feeRateToSendMax = feePerKb;
|
||||
self.currentFeePerKb = feePerKb;
|
||||
|
||||
if (self.availableBalanceSat > feeToSendMaxSat) {
|
||||
self.availableMaxBalance = strip((self.availableBalanceSat - feeToSendMaxSat) * self.satToUnit);
|
||||
self.feeToSendMaxStr = profileService.formatAmount(feeToSendMaxSat) + ' ' + self.unitName;
|
||||
}
|
||||
|
||||
if (cb) return cb(self.currentFeePerKb, self.availableMaxBalance, self.feeToSendMaxStr);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -399,7 +402,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
|
||||
self.setCurrentFeeLevel = function(level) {
|
||||
self.currentFeeLevel = level || configService.getSync().wallet.settings.feeLevel || 'normal';
|
||||
self.setSendMax();
|
||||
self.setFeeAndSendMax();
|
||||
};
|
||||
|
||||
|
||||
|
@ -612,16 +615,18 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
// Address with Balance
|
||||
self.balanceByAddress = balance.byAddress;
|
||||
|
||||
// SAT
|
||||
// Spend unconfirmed funds
|
||||
if (self.spendUnconfirmed) {
|
||||
self.totalBalanceSat = balance.totalAmount;
|
||||
self.lockedBalanceSat = balance.lockedAmount;
|
||||
self.availableBalanceSat = balance.availableAmount;
|
||||
self.totalBytesToSendMax = balance.totalBytesToSendMax;
|
||||
self.pendingAmount = null;
|
||||
} else {
|
||||
self.totalBalanceSat = balance.totalConfirmedAmount;
|
||||
self.lockedBalanceSat = balance.lockedConfirmedAmount;
|
||||
self.availableBalanceSat = balance.availableConfirmedAmount;
|
||||
self.totalBytesToSendMax = balance.totalBytesToSendConfirmedMax;
|
||||
self.pendingAmount = balance.totalAmount - balance.totalConfirmedAmount;
|
||||
}
|
||||
|
||||
|
@ -644,8 +649,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
self.alternativeName = config.alternativeName;
|
||||
self.alternativeIsoCode = config.alternativeIsoCode;
|
||||
|
||||
// Other
|
||||
self.totalBytesToSendMax = balance.totalBytesToSendMax;
|
||||
// Set fee level and max value to send all
|
||||
self.setCurrentFeeLevel();
|
||||
|
||||
// Check address
|
||||
|
@ -1186,8 +1190,8 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
});
|
||||
});
|
||||
|
||||
$rootScope.$on('Local/SpendUnconfirmedUpdated', function(event) {
|
||||
self.setSpendUnconfirmed();
|
||||
$rootScope.$on('Local/SpendUnconfirmedUpdated', function(event, spendUnconfirmed) {
|
||||
self.setSpendUnconfirmed(spendUnconfirmed);
|
||||
self.updateAll();
|
||||
});
|
||||
|
||||
|
@ -1195,6 +1199,10 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
self.setCurrentFeeLevel(level);
|
||||
});
|
||||
|
||||
$rootScope.$on('Local/SetFeeSendMax', function(event, cb) {
|
||||
self.setFeeAndSendMax(cb);
|
||||
});
|
||||
|
||||
$rootScope.$on('Local/ProfileBound', function() {
|
||||
storageService.getRemotePrefsStoredFlag(function(err, val) {
|
||||
if (err || val) return;
|
||||
|
@ -1450,4 +1458,5 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
$rootScope.$apply();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -24,7 +24,7 @@ angular.module('copayApp.controllers').controller('preferencesGlobalController',
|
|||
}
|
||||
};
|
||||
configService.set(opts, function(err) {
|
||||
$rootScope.$emit('Local/SpendUnconfirmedUpdated');
|
||||
$rootScope.$emit('Local/SpendUnconfirmedUpdated', newVal);
|
||||
if (err) $log.debug(err);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('sellGlideraController',
|
||||
function($scope, $timeout, $log, $modal, configService, profileService, addressService, glideraService, bwsError, lodash, isChromeApp, animationService) {
|
||||
function($scope, $timeout, $log, $modal, configService, profileService, addressService, feeService, glideraService, bwsError, lodash, isChromeApp, animationService) {
|
||||
|
||||
var self = this;
|
||||
var config = configService.getSync();
|
||||
|
@ -11,6 +11,7 @@ angular.module('copayApp.controllers').controller('sellGlideraController',
|
|||
this.error = null;
|
||||
this.loading = null;
|
||||
this.currentSpendUnconfirmed = config.wallet.spendUnconfirmed;
|
||||
this.currentFeeLevel = config.wallet.settings.feeLevel || 'normal';
|
||||
var fc;
|
||||
|
||||
var otherWallets = function(testnet) {
|
||||
|
@ -122,7 +123,7 @@ angular.module('copayApp.controllers').controller('sellGlideraController',
|
|||
}, 100);
|
||||
};
|
||||
|
||||
this.createTx = function(token, permissions, twoFaCode, currentFeePerKb) {
|
||||
this.createTx = function(token, permissions, twoFaCode) {
|
||||
var self = this;
|
||||
self.error = null;
|
||||
|
||||
|
@ -142,62 +143,65 @@ angular.module('copayApp.controllers').controller('sellGlideraController',
|
|||
}
|
||||
var amount = parseInt((self.sellPrice.qty * 100000000).toFixed(0));
|
||||
|
||||
fc.sendTxProposal({
|
||||
toAddress: sellAddress,
|
||||
amount: amount,
|
||||
message: 'Glidera transaction',
|
||||
customData: {'glideraToken': token},
|
||||
payProUrl: null,
|
||||
feePerKb: currentFeePerKb,
|
||||
excludeUnconfirmedUtxos: self.currentSpendUnconfirmed ? false : true
|
||||
}, function(err, txp) {
|
||||
if (err) {
|
||||
profileService.lockFC();
|
||||
$log.error(err);
|
||||
$timeout(function() {
|
||||
self.loading = null;
|
||||
self.error = bwsError.msg(err, 'Error');
|
||||
}, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!fc.canSign()) {
|
||||
self.loading = null;
|
||||
$log.info('No signing proposal: No private key');
|
||||
return;
|
||||
}
|
||||
|
||||
_signTx(txp, function(err, txp, rawTx) {
|
||||
profileService.lockFC();
|
||||
feeService.getCurrentFeeValue(self.currentFeeLevel, function(err, feePerKb) {
|
||||
if (err) $log.debug(err);
|
||||
fc.sendTxProposal({
|
||||
toAddress: sellAddress,
|
||||
amount: amount,
|
||||
message: 'Glidera transaction',
|
||||
customData: {'glideraToken': token},
|
||||
payProUrl: null,
|
||||
feePerKb: feePerKb,
|
||||
excludeUnconfirmedUtxos: self.currentSpendUnconfirmed ? false : true
|
||||
}, function(err, txp) {
|
||||
if (err) {
|
||||
self.loading = null;
|
||||
self.error = err;
|
||||
$scope.$apply();
|
||||
}
|
||||
else {
|
||||
var data = {
|
||||
refundAddress: refundAddress,
|
||||
signedTransaction: rawTx,
|
||||
priceUuid: self.sellPrice.priceUuid,
|
||||
useCurrentPrice: self.sellPrice.priceUuid ? false : true,
|
||||
ip: null
|
||||
};
|
||||
glideraService.sell(token, twoFaCode, data, function(err, data) {
|
||||
profileService.lockFC();
|
||||
$log.error(err);
|
||||
$timeout(function() {
|
||||
self.loading = null;
|
||||
if (err) {
|
||||
self.error = err;
|
||||
fc.removeTxProposal(txp, function(err, txpb) {
|
||||
$timeout(function() {
|
||||
$scope.$emit('Local/GlideraError');
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
else {
|
||||
self.success = data;
|
||||
$scope.$emit('Local/GlideraTx');
|
||||
}
|
||||
});
|
||||
self.error = bwsError.msg(err, 'Error');
|
||||
}, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!fc.canSign()) {
|
||||
self.loading = null;
|
||||
$log.info('No signing proposal: No private key');
|
||||
return;
|
||||
}
|
||||
|
||||
_signTx(txp, function(err, txp, rawTx) {
|
||||
profileService.lockFC();
|
||||
if (err) {
|
||||
self.loading = null;
|
||||
self.error = err;
|
||||
$scope.$apply();
|
||||
}
|
||||
else {
|
||||
var data = {
|
||||
refundAddress: refundAddress,
|
||||
signedTransaction: rawTx,
|
||||
priceUuid: self.sellPrice.priceUuid,
|
||||
useCurrentPrice: self.sellPrice.priceUuid ? false : true,
|
||||
ip: null
|
||||
};
|
||||
glideraService.sell(token, twoFaCode, data, function(err, data) {
|
||||
self.loading = null;
|
||||
if (err) {
|
||||
self.error = err;
|
||||
fc.removeTxProposal(txp, function(err, txpb) {
|
||||
$timeout(function() {
|
||||
$scope.$emit('Local/GlideraError');
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
else {
|
||||
self.success = data;
|
||||
$scope.$emit('Local/GlideraTx');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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,10 +827,11 @@ 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;
|
||||
var currentFeeLevel = walletSettings.feeLevel || 'normal';
|
||||
|
||||
if (isCordova && this.isWindowsPhoneApp) {
|
||||
this.hideAddress = false;
|
||||
|
@ -859,6 +861,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(currentFeeLevel, cb);
|
||||
}
|
||||
};
|
||||
|
||||
self.setOngoingProcess(gettext('Creating transaction'));
|
||||
$timeout(function() {
|
||||
var paypro = self._paypro;
|
||||
|
@ -878,40 +888,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 +1009,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 +1271,30 @@ 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
|
||||
});
|
||||
|
||||
confirmDialog.show(msg, function(confirmed) {
|
||||
if (confirmed) {
|
||||
self._doSendAll(amount);
|
||||
self.error = null;
|
||||
self.setOngoingProcess(gettext('Getting fee'));
|
||||
$rootScope.$emit('Local/SetFeeSendMax', function(currentFeePerKb, availableMaxBalance, feeToSendMaxStr) {
|
||||
self.setOngoingProcess();
|
||||
if (lodash.isNull(currentFeePerKb)) {
|
||||
self.error = gettext('Could not calculate fee');
|
||||
$scope.$apply();
|
||||
return;
|
||||
}
|
||||
self.lockedCurrentFeePerKb = currentFeePerKb;
|
||||
var msg = gettextCatalog.getString("{{fee}} will be deducted for bitcoin networking fees", {
|
||||
fee: feeToSendMaxStr
|
||||
});
|
||||
|
||||
$scope.$apply();
|
||||
confirmDialog.show(msg, function(confirmed) {
|
||||
if (confirmed) {
|
||||
self._doSendAll(availableMaxBalance);
|
||||
} else {
|
||||
self.resetForm();
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue