Wallet/src/js/controllers/preferencesFee.js

48 lines
1.4 KiB
JavaScript
Raw Normal View History

'use strict';
2017-01-10 10:23:01 -03:00
angular.module('copayApp.controllers').controller('preferencesFeeController', function($scope, $timeout, $ionicHistory, lodash, gettextCatalog, configService, feeService, ongoingProcess, popupService) {
2016-06-10 18:41:52 -03:00
$scope.save = function(newFee) {
var opts = {
wallet: {
settings: {
2017-01-10 10:23:01 -03:00
feeLevel: newFee
2016-06-10 18:41:52 -03:00
}
}
};
2016-06-10 18:41:52 -03:00
configService.set(opts, function(err) {
if (err) $log.debug(err);
2017-01-10 10:23:01 -03:00
$scope.currentFeeLevel = newFee;
updateCurrentValues();
$timeout(function() {
$scope.$apply();
});
2016-06-10 18:41:52 -03:00
});
};
2017-01-10 10:23:01 -03:00
$scope.$on("$ionicView.beforeEnter", function(event, data) {
$scope.feeOpts = feeService.feeOpts;
$scope.currentFeeLevel = feeService.getCurrentFeeLevel();
2017-01-10 10:23:01 -03:00
$scope.loadingFee = true;
feeService.getFeeLevels(function(err, levels) {
$scope.loadingFee = false;
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err);
return;
}
$scope.feeLevels = levels;
updateCurrentValues();
$scope.$apply();
});
});
2017-01-10 10:23:01 -03:00
var updateCurrentValues = function() {
2017-01-10 10:31:53 -03:00
if (lodash.isEmpty($scope.feeLevels) || lodash.isEmpty($scope.currentFeeLevel)) return;
2017-01-10 10:23:01 -03:00
var feeLevelValue = lodash.find($scope.feeLevels['livenet'], {
level: $scope.currentFeeLevel
});
$scope.feePerKBUnit = feeLevelValue.feePerKBUnit;
$scope.avgConfirmationTime = feeLevelValue.nbBlocks * 10;
};
2016-06-10 18:41:52 -03:00
});