fix fee service

This commit is contained in:
Javier 2016-11-03 18:27:59 -03:00
commit 9092ee73dd
2 changed files with 17 additions and 17 deletions

View file

@ -22,9 +22,9 @@ angular.module('copayApp.controllers').controller('amountController', function($
$scope.toEmail = data.stateParams.toEmail; $scope.toEmail = data.stateParams.toEmail;
$scope.showAlternativeAmount = !!$scope.cardId || !!$scope.isGiftCard; $scope.showAlternativeAmount = !!$scope.cardId || !!$scope.isGiftCard;
$scope.toColor = data.stateParams.toColor; $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({ $scope.wallets = profileService.getWallets({
network: network network: $scope.network
}); });
$scope.customAmount = data.stateParams.customAmount; $scope.customAmount = data.stateParams.customAmount;
@ -83,7 +83,7 @@ angular.module('copayApp.controllers').controller('amountController', function($
}); });
$scope.getSendMaxInfo = function(wallet) { $scope.getSendMaxInfo = function(wallet) {
feeService.getCurrentFeeValue(function(err, fee) { feeService.getCurrentFeeValue($scope.network, function(err, fee) {
if (err) { if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err.message); popupService.showAlert(gettextCatalog.getString('Error'), err.message);
return; return;

View file

@ -1,6 +1,6 @@
'use strict'; '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 = {}; var root = {};
// Constant fee options to translate // 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'; return configService.getSync().wallet.settings.feeLevel || 'normal';
}; };
root.getCurrentFeeValue = function(wallet, cb) { root.getCurrentFeeValue = function(network, cb) {
network = network || 'livenet';
var feeLevel = root.getCurrentFeeLevel(); var feeLevel = root.getCurrentFeeLevel();
wallet.getFeeLevels(wallet.credentials.network, function(err, levels) { root.getFeeLevels(function(err, levels) {
if (err) if (err) return cb(err);
return cb({
message: 'Could not get dynamic fee'
});
var feeLevelValue = lodash.find(levels, { var feeLevelValue = lodash.find(levels[network], {
level: feeLevel level: feeLevel
}); });
if (!feeLevelValue || feeLevelValue.feePerKB == null)
if (!feeLevelValue || !feeLevelValue.feePerKB)
return cb({ 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; var fee = feeLevelValue.feePerKB;
$log.debug('Dynamic fee: ' + feeLevel + ' ' + fee + ' SAT'); $log.debug('Dynamic fee: ' + feeLevel + ' ' + fee + ' SAT');
return cb(null, fee); return cb(null, fee);
}); });
}; };
root.getFeeLevels = function(cb) { root.getFeeLevels = function(cb) {
var walletClient = bwcService.getClient(); var walletClient = bwcService.getClient();
var unitName = configService.getSync().wallet.settings.unitName; var unitName = configService.getSync().wallet.settings.unitName;
walletClient.getFeeLevels('livenet', function(errLivenet, levelsLivenet) { walletClient.getFeeLevels('livenet', function(errLivenet, levelsLivenet) {
walletClient.getFeeLevels('testnet', function(errTestnet, levelsTestnet) { walletClient.getFeeLevels('testnet', function(errTestnet, levelsTestnet) {
if (errLivenet || errTestnet) $log.debug('Could not get dynamic fee'); if (errLivenet || errTestnet) {
else { return cb(gettextCatalog.getString('Could not get dynamic fee'));
} else {
for (var i = 0; i < 4; i++) { for (var i = 0; i < 4; i++) {
levelsLivenet[i]['feePerKBUnit'] = txFormatService.formatAmount(levelsLivenet[i].feePerKB) + ' ' + unitName; levelsLivenet[i]['feePerKBUnit'] = txFormatService.formatAmount(levelsLivenet[i].feePerKB) + ' ' + unitName;
levelsTestnet[i]['feePerKBUnit'] = txFormatService.formatAmount(levelsTestnet[i].feePerKB) + ' ' + unitName; levelsTestnet[i]['feePerKBUnit'] = txFormatService.formatAmount(levelsTestnet[i].feePerKB) + ' ' + unitName;
} }
} }
return cb({ return cb(null, {
'livenet': levelsLivenet, 'livenet': levelsLivenet,
'testnet': levelsTestnet 'testnet': levelsTestnet
}); });