diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js
index 51290d830..886800109 100644
--- a/src/js/controllers/index.js
+++ b/src/js/controllers/index.js
@@ -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();
});
});
+
});
diff --git a/src/js/controllers/preferencesGlobal.js b/src/js/controllers/preferencesGlobal.js
index a3733882b..741d37963 100644
--- a/src/js/controllers/preferencesGlobal.js
+++ b/src/js/controllers/preferencesGlobal.js
@@ -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);
});
});
diff --git a/src/js/controllers/sellGlidera.js b/src/js/controllers/sellGlidera.js
index 4904d4c21..616892aa7 100644
--- a/src/js/controllers/sellGlidera.js
+++ b/src/js/controllers/sellGlidera.js
@@ -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');
+ }
+ });
+ }
+ });
});
});
});
diff --git a/src/js/controllers/walletHome.js b/src/js/controllers/walletHome.js
index f911b7e34..c2bccb017 100644
--- a/src/js/controllers/walletHome.js
+++ b/src/js/controllers/walletHome.js
@@ -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
- });
+ 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
+ });
- confirmDialog.show(msg, function(confirmed) {
- if (confirmed) {
- self._doSendAll(amount);
- }
+ $scope.$apply();
+ confirmDialog.show(msg, function(confirmed) {
+ if (confirmed) {
+ self._doSendAll(availableMaxBalance);
+ } else {
+ self.resetForm();
+ }
+ });
});
};