Merge pull request #6684 from cmgustavo/bug/send-max-fee-levels

Bug/send max fee levels
This commit is contained in:
Matias Alejo Garcia 2017-09-04 09:40:58 -03:00 committed by GitHub
commit 8ed3bb5f6e
3 changed files with 31 additions and 16 deletions

View file

@ -309,7 +309,7 @@ angular.module('copayApp.controllers').controller('amountController', function($
if (a) { if (a) {
$scope.alternativeAmount = txFormatService.formatAmount(a * unitToSatoshi, true); $scope.alternativeAmount = txFormatService.formatAmount(a * unitToSatoshi, true);
} else { } else {
$scope.alternativeAmount = 'N/A'; //TODO $scope.alternativeAmount = 'N/A'; //TODO
$scope.allowSend = false; $scope.allowSend = false;
} }
} else { } else {
@ -369,7 +369,7 @@ angular.module('copayApp.controllers').controller('amountController', function($
id: _id, id: _id,
amount: $scope.useSendMax ? null : _amount, amount: $scope.useSendMax ? null : _amount,
currency: unit.id.toUpperCase(), currency: unit.id.toUpperCase(),
coin: coin, coin: $scope.useSendMax ? null : coin,
useSendMax: $scope.useSendMax useSendMax: $scope.useSendMax
}); });
} else { } else {
@ -388,7 +388,7 @@ angular.module('copayApp.controllers').controller('amountController', function($
toName: $scope.toName, toName: $scope.toName,
toEmail: $scope.toEmail, toEmail: $scope.toEmail,
toColor: $scope.toColor, toColor: $scope.toColor,
coin: coin, coin: $scope.useSendMax ? null : coin,
useSendMax: $scope.useSendMax useSendMax: $scope.useSendMax
}); });
} }

View file

@ -28,7 +28,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
function refresh() { function refresh() {
$timeout(function() { $timeout(function() {
$scope.$apply(); $scope.$apply();
}, 1); }, 10);
} }
@ -119,11 +119,6 @@ angular.module('copayApp.controllers').controller('confirmController', function(
}); });
}; };
// TODO: Default fee level for BCH
if (data.stateParams.coin == 'bch') {
configFeeLevel = 'normal';
}
// Setup $scope // Setup $scope
// Grab stateParams // Grab stateParams
@ -147,6 +142,8 @@ angular.module('copayApp.controllers').controller('confirmController', function(
txp: {}, txp: {},
}; };
if (tx.coin && tx.coin == 'bch') tx.feeLevel = 'normal';
// Other Scope vars // Other Scope vars
$scope.isCordova = isCordova; $scope.isCordova = isCordova;
$scope.isWindowsPhoneApp = isWindowsPhoneApp; $scope.isWindowsPhoneApp = isWindowsPhoneApp;
@ -230,6 +227,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
}; };
function updateTx(tx, wallet, opts, cb) { function updateTx(tx, wallet, opts, cb) {
ongoingProcess.set('calculatingFee', true);
if (opts.clearCache) { if (opts.clearCache) {
tx.txp = {}; tx.txp = {};
@ -253,19 +251,23 @@ angular.module('copayApp.controllers').controller('confirmController', function(
refresh(); refresh();
// End of quick refresh, before wallet is selected. // End of quick refresh, before wallet is selected.
if (!wallet) return cb(); if (!wallet) {
ongoingProcess.set('calculatingFee', false);
return cb();
}
feeService.getFeeRate(wallet.coin, tx.network, tx.feeLevel, function(err, feeRate) { feeService.getFeeRate(wallet.coin, tx.network, tx.feeLevel, function(err, feeRate) {
if (err) return cb(err); if (err) {
ongoingProcess.set('calculatingFee', false);
return cb(err);
}
if (!usingCustomFee) tx.feeRate = feeRate; if (!usingCustomFee) tx.feeRate = feeRate;
tx.feeLevelName = feeService.feeOpts[tx.feeLevel]; tx.feeLevelName = feeService.feeOpts[tx.feeLevel];
if (!wallet)
return cb();
getSendMaxInfo(lodash.clone(tx), wallet, function(err, sendMaxInfo) { getSendMaxInfo(lodash.clone(tx), wallet, function(err, sendMaxInfo) {
if (err) { if (err) {
ongoingProcess.set('calculatingFee', false);
var msg = gettextCatalog.getString('Error getting SendMax information'); var msg = gettextCatalog.getString('Error getting SendMax information');
return setSendError(msg); return setSendError(msg);
} }
@ -275,6 +277,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
$log.debug('Send max info', sendMaxInfo); $log.debug('Send max info', sendMaxInfo);
if (tx.sendMax && sendMaxInfo.amount == 0) { if (tx.sendMax && sendMaxInfo.amount == 0) {
ongoingProcess.set('calculatingFee', false);
setNoWallet(gettextCatalog.getString('Insufficient funds')); setNoWallet(gettextCatalog.getString('Insufficient funds'));
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Not enough funds for fee')); popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Not enough funds for fee'));
return cb('no_funds'); return cb('no_funds');
@ -283,17 +286,22 @@ angular.module('copayApp.controllers').controller('confirmController', function(
tx.sendMaxInfo = sendMaxInfo; tx.sendMaxInfo = sendMaxInfo;
tx.toAmount = tx.sendMaxInfo.amount; tx.toAmount = tx.sendMaxInfo.amount;
updateAmount(); updateAmount();
ongoingProcess.set('calculatingFee', false);
showSendMaxWarning(wallet, sendMaxInfo); showSendMaxWarning(wallet, sendMaxInfo);
} }
// txp already generated for this wallet? // txp already generated for this wallet?
if (tx.txp[wallet.id]) { if (tx.txp[wallet.id]) {
ongoingProcess.set('calculatingFee', false);
refresh(); refresh();
return cb(); return cb();
} }
getTxp(lodash.clone(tx), wallet, opts.dryRun, function(err, txp) { getTxp(lodash.clone(tx), wallet, opts.dryRun, function(err, txp) {
if (err) return cb(err); ongoingProcess.set('calculatingFee', false);
if (err) {
return cb(err);
}
txp.feeStr = txFormatService.formatAmountStr(wallet.coin, txp.fee); txp.feeStr = txFormatService.formatAmountStr(wallet.coin, txp.fee);
txFormatService.formatAlternativeStr(wallet.coin, txp.fee, function(v) { txFormatService.formatAlternativeStr(wallet.coin, txp.fee, function(v) {
@ -425,6 +433,11 @@ angular.module('copayApp.controllers').controller('confirmController', function(
$scope.wallet = wallet; $scope.wallet = wallet;
// If select another wallet
tx.coin = wallet.coin;
tx.feeLevel = wallet.coin == 'bch' ? 'normal' : configFeeLevel;
usingCustomFee = null;
setButtonText(wallet.credentials.m > 1, !!tx.paypro); setButtonText(wallet.credentials.m > 1, !!tx.paypro);
if (tx.paypro) if (tx.paypro)

View file

@ -17,6 +17,7 @@ angular.module('copayApp.services').factory('feeService', function($log, $timeou
var cache = { var cache = {
updateTs: 0, updateTs: 0,
coin: ''
}; };
root.getCurrentFeeLevel = function() { root.getCurrentFeeLevel = function() {
@ -60,7 +61,7 @@ angular.module('copayApp.services').factory('feeService', function($log, $timeou
root.getFeeLevels = function(coin, cb) { root.getFeeLevels = function(coin, cb) {
coin = coin || 'btc'; coin = coin || 'btc';
if (cache.updateTs > Date.now() - CACHE_TIME_TS * 1000) { if (cache.coin == coin && cache.updateTs > Date.now() - CACHE_TIME_TS * 1000) {
return cb(null, cache.data, true); return cb(null, cache.data, true);
} }
@ -73,6 +74,7 @@ angular.module('copayApp.services').factory('feeService', function($log, $timeou
} }
cache.updateTs = Date.now(); cache.updateTs = Date.now();
cache.coin = coin;
cache.data = { cache.data = {
'livenet': levelsLivenet, 'livenet': levelsLivenet,
'testnet': levelsTestnet 'testnet': levelsTestnet