Fix sendMax, support bch. Fee levels cache for bch
This commit is contained in:
parent
1200c9701c
commit
8b2265d767
2 changed files with 31 additions and 17 deletions
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -69,7 +69,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
||||||
|
|
||||||
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
||||||
|
|
||||||
function setWalletSelector(coin, network, minAmount, cb) {
|
function setWalletSelector(coin, network, minAmount, sendMax, cb) {
|
||||||
|
|
||||||
// no min amount? (sendMax) => look for no empty wallets
|
// no min amount? (sendMax) => look for no empty wallets
|
||||||
minAmount = minAmount || 1;
|
minAmount = minAmount || 1;
|
||||||
|
|
@ -77,7 +77,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
||||||
$scope.wallets = profileService.getWallets({
|
$scope.wallets = profileService.getWallets({
|
||||||
onlyComplete: true,
|
onlyComplete: true,
|
||||||
network: network,
|
network: network,
|
||||||
coin: coin
|
coin: sendMax ? null : coin
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!$scope.wallets || !$scope.wallets.length) {
|
if (!$scope.wallets || !$scope.wallets.length) {
|
||||||
|
|
@ -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
|
||||||
|
|
@ -134,7 +129,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
||||||
description: data.stateParams.description,
|
description: data.stateParams.description,
|
||||||
paypro: data.stateParams.paypro,
|
paypro: data.stateParams.paypro,
|
||||||
|
|
||||||
feeLevel: configFeeLevel,
|
feeLevel: data.stateParams.coin == 'bch' ? 'normal' : configFeeLevel,
|
||||||
spendUnconfirmed: walletConfig.spendUnconfirmed,
|
spendUnconfirmed: walletConfig.spendUnconfirmed,
|
||||||
|
|
||||||
// Vanity tx info (not in the real tx)
|
// Vanity tx info (not in the real tx)
|
||||||
|
|
@ -154,7 +149,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
||||||
|
|
||||||
$scope.walletSelectorTitle = gettextCatalog.getString('Send from');
|
$scope.walletSelectorTitle = gettextCatalog.getString('Send from');
|
||||||
|
|
||||||
setWalletSelector(tx.coin, tx.network, tx.toAmount, function(err) {
|
setWalletSelector(tx.coin, tx.network, tx.toAmount, tx.sendMax, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return exitWithError('Could not update wallets');
|
return exitWithError('Could not update wallets');
|
||||||
}
|
}
|
||||||
|
|
@ -230,6 +225,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 +249,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 +275,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 +284,23 @@ 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]) {
|
||||||
|
console.log('[confirm.js:292] Ya existe la tx',tx); //TODO/
|
||||||
|
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 +432,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)
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue