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.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;

View file

@ -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
});