diff --git a/src/js/controllers/modals/feeLevels.js b/src/js/controllers/modals/feeLevels.js new file mode 100644 index 000000000..5ee92fe33 --- /dev/null +++ b/src/js/controllers/modals/feeLevels.js @@ -0,0 +1,108 @@ +'use strict'; + +angular.module('copayApp.controllers').controller('feeLevelsController', function($scope, $timeout, $log, lodash, gettextCatalog, configService, feeService, ongoingProcess, popupService) { + + var MAX_RECOMMENDED_FEE = 1000; + + var showErrorAndClose = function(title, msg) { + title = title || gettextCatalog.getString('Error'); + $log.error(msg); + popupService.showAlert(title, msg, function() { + $scope.chooseFeeLevelModal.hide(); + }); + + }; + + var getMinRecommended = function() { + var value = lodash.find($scope.feeLevels[$scope.network], { + level: 'superEconomy' + }); + return parseInt((value.feePerKB / 1000).toFixed()); + }; + + var getMaxRecommended = function() { + return MAX_RECOMMENDED_FEE; + }; + + $scope.ok = function() { + $scope.customFeePerKB = $scope.customFeePerKB ? ($scope.customSatPerByte.value * 1000).toFixed() : null; + $scope.hideModal($scope.feeLevel, $scope.customFeePerKB); + }; + + $scope.setFeesRecommended = function() { + $scope.maxFeeRecommended = getMaxRecommended(); + $scope.minFeeRecommended = getMinRecommended(); + }; + + $scope.checkFees = function(feePerSatByte) { + if (parseInt(feePerSatByte) < $scope.minFeeRecommended) $scope.showMinWarning = true; + else $scope.showMinWarning = false; + + if (parseInt(feePerSatByte) > $scope.maxFeeRecommended) $scope.showMaxWarning = true; + else $scope.showMaxWarning = false; + }; + + $scope.updateFeeRate = function() { + var value = lodash.find($scope.feeLevels[$scope.network], { + level: $scope.feeLevel + }); + + // If no custom fee + if (value) { + $scope.customFeePerKB = null; + $scope.feePerSatByte = (value.feePerKB / 1000).toFixed(); + $scope.avgConfirmationTime = value.nbBlocks * 10; + } else { + $scope.avgConfirmationTime = null; + $scope.customSatPerByte = { value: parseInt($scope.feePerSatByte) }; + $scope.customFeePerKB = ($scope.feePerSatByte * 1000).toFixed(); + } + + // Warnings + $scope.setFeesRecommended(); + $scope.checkFees($scope.feePerSatByte); + + $timeout(function() { + $scope.$apply(); + }); + }; + + $scope.$watch( + "selectedFee.value", + function ( newValue, oldValue ) { + if (newValue != oldValue) { + $log.debug('New fee level: ' + newValue); + $scope.feeLevel = $scope.selectedFee.value; + $scope.updateFeeRate(); + } + } + ); + + // From parent controller + // $scope.network + // $scope.feeLevel + // + // IF usingCustomFee + // $scope.customFeePerKB + // $scope.feePerSatByte + + if (lodash.isEmpty($scope.feeLevel)) showErrorAndClose(null, gettextCatalog.getString('Fee level is not defined') ); + $scope.selectedFee = { value: $scope.feeLevel }; + + $scope.feeOpts = feeService.feeOpts; + $scope.loadingFee = true; + feeService.getFeeLevels(function(err, levels) { + $scope.loadingFee = false; + if (err || lodash.isEmpty(levels)) { + showErrorAndClose(null, err); + return; + } + if (lodash.isEmpty(levels)) { + showErrorAndClose(null, gettextCatalog.getString('Could not get fee levels')); + return; + } + $scope.feeLevels = levels; + $scope.updateFeeRate(); + }); + +}); diff --git a/src/sass/views/includes/modals/choose-fee-level.scss b/src/sass/views/includes/modals/choose-fee-level.scss new file mode 100644 index 000000000..cd5eb05af --- /dev/null +++ b/src/sass/views/includes/modals/choose-fee-level.scss @@ -0,0 +1,43 @@ +#choose-fee-level { + @extend .deflash-blue; + .selected-fee-level { + text-align: center; + background: #f2f2f2; + font-size: 11px; + height: 120px; + padding-top: 25px; + .row { + padding: 0; + } + .separator { + border-left: 1px solid #d9d9df; + height: 75%; + } + .value { + font-size: 20px; + margin-bottom: 10px; + } + .rate .list { + margin-bottom: 0; + } + .unit { + color: #9c9c9c; + background: #f2f2f2; + height: 50px; + position: absolute; + right: 0; + padding: 12px 10px 0 10px; + } + } + .warning-fee { + color: $v-warning-color; + font-size: 12px; + text-align: left; + } + .box-notification { + margin: 0; + padding: 1px; + text-align: center; + } + +}