custom fee feature

This commit is contained in:
Gabriel Bazán 2017-07-07 10:26:31 -03:00
commit 3fca4b90d3
6 changed files with 96 additions and 32 deletions

View file

@ -202,7 +202,9 @@ angular.module('copayApp.controllers').controller('confirmController', function(
txp.inputs = tx.sendMaxInfo.inputs;
txp.fee = tx.sendMaxInfo.fee;
} else {
txp.feeLevel = tx.feeLevel;
if (tx.feeLevel == 'custom') {
txp.feePerKb = tx.feeRate;
} else txp.feeLevel = tx.feeLevel;
}
txp.message = tx.description;
@ -245,12 +247,12 @@ angular.module('copayApp.controllers').controller('confirmController', function(
refresh();
// End of quick refresh, before wallet is selected.
if (!wallet)return cb();
if (!wallet) return cb();
feeService.getFeeRate(tx.network, tx.feeLevel, function(err, feeRate) {
if (err) return cb(err);
tx.feeRate = feeRate;
if (tx.feeLevel != 'custom') tx.feeRate = feeRate;
tx.feeLevelName = feeService.feeOpts[tx.feeLevel];
if (!wallet)
@ -294,8 +296,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
var per = (txp.fee / (txp.amount + txp.fee) * 100);
txp.feeRatePerStr = per.toFixed(2) + '%';
txp.feeToHigh = per > FEE_TOO_HIGH_LIMIT_PER;
txp.feeToHigh = per > FEE_TOO_HIGH_LIMIT_PER;
tx.txp[wallet.id] = txp;
$log.debug('Confirm. TX Fully Updated for wallet:' + wallet.id, tx);
@ -558,9 +559,12 @@ angular.module('copayApp.controllers').controller('confirmController', function(
scope.network = tx.network;
scope.feeLevel = tx.feeLevel;
scope.noSave = true;
if (tx.feeLevel == 'custom') scope.feePerSatByte = (tx.feeRate / 1000).toFixed();
$ionicModal.fromTemplateUrl('views/modals/chooseFeeLevel.html', {
scope: scope,
backdropClickToClose: false,
hardwareBackButtonClose: false
}).then(function(modal) {
scope.chooseFeeLevelModal = modal;
scope.openModal();
@ -569,18 +573,19 @@ angular.module('copayApp.controllers').controller('confirmController', function(
scope.chooseFeeLevelModal.show();
};
scope.hideModal = function(customFeeLevel) {
scope.hideModal = function(newFeeLevel, customFeePerKBValue) {
scope.chooseFeeLevelModal.hide();
$log.debug('Custom fee level choosen:' + customFeeLevel + ' was:' + tx.feeLevel);
if (tx.feeLevel == customFeeLevel)
return;
$log.debug('New fee level choosen:' + newFeeLevel + ' was:' + tx.feeLevel);
if (tx.feeLevel == newFeeLevel && !customFeePerKBValue) return;
tx.feeLevel = newFeeLevel;
if (customFeePerKBValue) tx.feeRate = parseInt(customFeePerKBValue);
tx.feeLevel = customFeeLevel;
updateTx(tx, wallet, {
clearCache: true,
dryRun: true,
}, function() {
});
dryRun: true
}, function() {});
};
};

View file

@ -2,14 +2,14 @@
angular.module('copayApp.controllers').controller('preferencesFeeController', function($scope, $timeout, $ionicHistory, lodash, gettextCatalog, configService, feeService, ongoingProcess, popupService) {
var network;
$scope.save = function(newFee) {
$scope.currentFeeLevel = newFee;
updateCurrentValues();
if ($scope.noSave)
return;
$scope.currentFeeLevel = newFee;
if ($scope.currentFeeLevel != 'custom') updateCurrentValues();
else showCustomFeePrompt();
if ($scope.noSave) return;
var opts = {
wallet: {
@ -32,7 +32,6 @@ angular.module('copayApp.controllers').controller('preferencesFeeController', fu
});
$scope.init = function() {
$scope.network = $scope.network || 'livenet';
$scope.feeOpts = feeService.feeOpts;
$scope.currentFeeLevel = $scope.feeLevel || feeService.getCurrentFeeLevel();
@ -60,16 +59,56 @@ angular.module('copayApp.controllers').controller('preferencesFeeController', fu
});
if (lodash.isEmpty(value)) {
$scope.feePerSatByte = null;
$scope.feePerSatByte = $scope.currentFeeLevel == 'custom' ? $scope.feePerSatByte : null;
$scope.avgConfirmationTime = null;
setMinWarning();
setMaxWarning();
return;
}
$scope.feePerSatByte = (value.feePerKB / 1000).toFixed();
$scope.avgConfirmationTime = value.nbBlocks * 10;
$scope.invalidCustomFeeEntered = false;
setMinWarning();
setMaxWarning();
};
$scope.chooseNewFee = function() {
$scope.hideModal($scope.currentFeeLevel);
$scope.hideModal($scope.currentFeeLevel, $scope.customFeePerKB);
};
var showCustomFeePrompt = function() {
$scope.invalidCustomFeeEntered = true;
$scope.showMaxWarning = false;
popupService.showPrompt(null, gettextCatalog.getString('Custom Fee'), null, function(text) {
if (!text || !parseInt(text)) return;
$scope.feePerSatByte = parseInt(text);
$scope.customFeePerKB = ($scope.feePerSatByte * 1000).toFixed();
setMaxWarning();
setMinWarning();
});
};
$scope.getMinimumRecommeded = function() {
var value = lodash.find($scope.feeLevels[$scope.network], {
level: 'superEconomy'
});
return parseInt((value.feePerKB / 1000).toFixed());
};
var setMinWarning = function() {
if (parseInt($scope.feePerSatByte) < $scope.getMinimumRecommeded()) $scope.showMinWarning = true;
else $scope.showMinWarning = false;
};
var setMaxWarning = function() {
if (parseInt($scope.feePerSatByte) > 1000) {
$scope.showMaxWarning = true;
$scope.invalidCustomFeeEntered = true;
} else {
$scope.showMaxWarning = false;
$scope.invalidCustomFeeEntered = false;
}
};
});

View file

@ -11,7 +11,8 @@ angular.module('copayApp.services').factory('feeService', function($log, $timeou
priority: gettext('Priority'),
normal: gettext('Normal'),
economy: gettext('Economy'),
superEconomy: gettext('Super Economy')
superEconomy: gettext('Super Economy'),
custom: gettext('Custom')
};
var cache = {
@ -24,6 +25,9 @@ angular.module('copayApp.services').factory('feeService', function($log, $timeou
root.getFeeRate = function(network, feeLevel, cb) {
if (feeLevel == 'custom') return cb();
network = network || 'livenet';
root.getFeeLevels(function(err, levels, fromCache) {

View file

@ -25,6 +25,12 @@
background-color: #fff;
font-size:0.9em;
color: $v-mid-gray;
.text {
padding-left: 30px;
}
.icon {
position: absolute;
}
}
&-explanation, &-button-group {
padding: 0 1rem;
@ -162,6 +168,7 @@
#settings-fee {
.estimates {
min-height: 6rem;
font-size: 15px;
color: $v-dark-gray;
margin-bottom: .5rem;