diff --git a/src/js/controllers/amount.js b/src/js/controllers/amount.js index a6fcdd8c3..6efbd0c6b 100644 --- a/src/js/controllers/amount.js +++ b/src/js/controllers/amount.js @@ -22,9 +22,9 @@ angular.module('copayApp.controllers').controller('amountController', function($ $scope.toEmail = data.stateParams.toEmail; $scope.showAlternativeAmount = !!$scope.cardId || !!$scope.isGiftCard; $scope.toColor = data.stateParams.toColor; - var network = (new bitcore.Address($scope.toAddress)).network.name; + $scope.network = (new bitcore.Address($scope.toAddress)).network.name; $scope.wallets = profileService.getWallets({ - network: network + network: $scope.network }); $scope.customAmount = data.stateParams.customAmount; @@ -83,7 +83,7 @@ angular.module('copayApp.controllers').controller('amountController', function($ }); $scope.getSendMaxInfo = function(wallet) { - feeService.getCurrentFeeValue(function(err, fee) { + feeService.getCurrentFeeValue($scope.network, function(err, fee) { if (err) { popupService.showAlert(gettextCatalog.getString('Error'), err.message); return; diff --git a/src/js/services/feeService.js b/src/js/services/feeService.js index be1a57160..1d673129f 100644 --- a/src/js/services/feeService.js +++ b/src/js/services/feeService.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.services').factory('feeService', function($log, $stateParams, bwcService, walletService, configService, gettext, lodash, txFormatService) { +angular.module('copayApp.services').factory('feeService', function($log, $stateParams, bwcService, walletService, configService, gettext, lodash, txFormatService, profileService, gettextCatalog) { var root = {}; // Constant fee options to translate @@ -15,45 +15,45 @@ angular.module('copayApp.services').factory('feeService', function($log, $stateP return configService.getSync().wallet.settings.feeLevel || 'normal'; }; - root.getCurrentFeeValue = function(wallet, cb) { + root.getCurrentFeeValue = function(network, cb) { + network = network || 'livenet'; var feeLevel = root.getCurrentFeeLevel(); - wallet.getFeeLevels(wallet.credentials.network, function(err, levels) { - if (err) - return cb({ - message: 'Could not get dynamic fee' - }); + root.getFeeLevels(function(err, levels) { + if (err) return cb(err); - var feeLevelValue = lodash.find(levels, { + var feeLevelValue = lodash.find(levels[network], { level: feeLevel }); - if (!feeLevelValue || feeLevelValue.feePerKB == null) + + if (!feeLevelValue || !feeLevelValue.feePerKB) return cb({ - message: 'Could not get dynamic fee for level: ' + feeLevel + message: gettextCatalog.getString('Could not get dynamic fee for level: ') + feeLevel }); var fee = feeLevelValue.feePerKB; $log.debug('Dynamic fee: ' + feeLevel + ' ' + fee + ' SAT'); + return cb(null, fee); }); }; root.getFeeLevels = function(cb) { var walletClient = bwcService.getClient(); - var unitName = configService.getSync().wallet.settings.unitName; walletClient.getFeeLevels('livenet', function(errLivenet, levelsLivenet) { walletClient.getFeeLevels('testnet', function(errTestnet, levelsTestnet) { - if (errLivenet || errTestnet) $log.debug('Could not get dynamic fee'); - else { + if (errLivenet || errTestnet) { + return cb(gettextCatalog.getString('Could not get dynamic fee')); + } else { for (var i = 0; i < 4; i++) { levelsLivenet[i]['feePerKBUnit'] = txFormatService.formatAmount(levelsLivenet[i].feePerKB) + ' ' + unitName; levelsTestnet[i]['feePerKBUnit'] = txFormatService.formatAmount(levelsTestnet[i].feePerKB) + ' ' + unitName; } } - return cb({ + return cb(null, { 'livenet': levelsLivenet, 'testnet': levelsTestnet });