diff --git a/src/js/controllers/amount.js b/src/js/controllers/amount.js index dee20cde1..c1b105068 100644 --- a/src/js/controllers/amount.js +++ b/src/js/controllers/amount.js @@ -309,7 +309,7 @@ angular.module('copayApp.controllers').controller('amountController', function($ if (a) { $scope.alternativeAmount = txFormatService.formatAmount(a * unitToSatoshi, true); } else { - $scope.alternativeAmount = 'N/A'; //TODO + $scope.alternativeAmount = 'N/A'; //TODO $scope.allowSend = false; } } else { @@ -369,7 +369,7 @@ angular.module('copayApp.controllers').controller('amountController', function($ id: _id, amount: $scope.useSendMax ? null : _amount, currency: unit.id.toUpperCase(), - coin: coin, + coin: $scope.useSendMax ? null : coin, useSendMax: $scope.useSendMax }); } else { @@ -388,7 +388,7 @@ angular.module('copayApp.controllers').controller('amountController', function($ toName: $scope.toName, toEmail: $scope.toEmail, toColor: $scope.toColor, - coin: coin, + coin: $scope.useSendMax ? null : coin, useSendMax: $scope.useSendMax }); } diff --git a/src/js/controllers/confirm.js b/src/js/controllers/confirm.js index 45605f719..2129e0352 100644 --- a/src/js/controllers/confirm.js +++ b/src/js/controllers/confirm.js @@ -28,7 +28,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( function refresh() { $timeout(function() { $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 // Grab stateParams @@ -147,6 +142,8 @@ angular.module('copayApp.controllers').controller('confirmController', function( txp: {}, }; + if (tx.coin && tx.coin == 'bch') tx.feeLevel = 'normal'; + // Other Scope vars $scope.isCordova = isCordova; $scope.isWindowsPhoneApp = isWindowsPhoneApp; @@ -230,6 +227,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( }; function updateTx(tx, wallet, opts, cb) { + ongoingProcess.set('calculatingFee', true); if (opts.clearCache) { tx.txp = {}; @@ -253,19 +251,23 @@ angular.module('copayApp.controllers').controller('confirmController', function( refresh(); // 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) { - if (err) return cb(err); + if (err) { + ongoingProcess.set('calculatingFee', false); + return cb(err); + } if (!usingCustomFee) tx.feeRate = feeRate; tx.feeLevelName = feeService.feeOpts[tx.feeLevel]; - if (!wallet) - return cb(); - getSendMaxInfo(lodash.clone(tx), wallet, function(err, sendMaxInfo) { if (err) { + ongoingProcess.set('calculatingFee', false); var msg = gettextCatalog.getString('Error getting SendMax information'); return setSendError(msg); } @@ -275,6 +277,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( $log.debug('Send max info', sendMaxInfo); if (tx.sendMax && sendMaxInfo.amount == 0) { + ongoingProcess.set('calculatingFee', false); setNoWallet(gettextCatalog.getString('Insufficient funds')); popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Not enough funds for fee')); return cb('no_funds'); @@ -283,17 +286,22 @@ angular.module('copayApp.controllers').controller('confirmController', function( tx.sendMaxInfo = sendMaxInfo; tx.toAmount = tx.sendMaxInfo.amount; updateAmount(); + ongoingProcess.set('calculatingFee', false); showSendMaxWarning(wallet, sendMaxInfo); } // txp already generated for this wallet? if (tx.txp[wallet.id]) { + ongoingProcess.set('calculatingFee', false); refresh(); return cb(); } 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); txFormatService.formatAlternativeStr(wallet.coin, txp.fee, function(v) { @@ -425,6 +433,11 @@ angular.module('copayApp.controllers').controller('confirmController', function( $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); if (tx.paypro) diff --git a/src/js/services/feeService.js b/src/js/services/feeService.js index 2109d7ea0..37cd8ab58 100644 --- a/src/js/services/feeService.js +++ b/src/js/services/feeService.js @@ -17,6 +17,7 @@ angular.module('copayApp.services').factory('feeService', function($log, $timeou var cache = { updateTs: 0, + coin: '' }; root.getCurrentFeeLevel = function() { @@ -60,7 +61,7 @@ angular.module('copayApp.services').factory('feeService', function($log, $timeou root.getFeeLevels = function(coin, cb) { 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); } @@ -73,6 +74,7 @@ angular.module('copayApp.services').factory('feeService', function($log, $timeou } cache.updateTs = Date.now(); + cache.coin = coin; cache.data = { 'livenet': levelsLivenet, 'testnet': levelsTestnet