code refactor

This commit is contained in:
Gabriel Bazán 2017-07-10 14:19:38 -03:00
parent 7b802b7f9a
commit 3f27c3d231
2 changed files with 17 additions and 8 deletions

View File

@ -22,6 +22,9 @@ angular.module('copayApp.controllers').controller('confirmController', function(
var isCordova = platformInfo.isCordova;
var isWindowsPhoneApp = platformInfo.isCordova && platformInfo.isWP;
//custom fee flag
var usingCustomFee = null;
function refresh() {
$timeout(function() {
$scope.$apply();
@ -202,7 +205,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
txp.inputs = tx.sendMaxInfo.inputs;
txp.fee = tx.sendMaxInfo.fee;
} else {
if (tx.feeLevel == 'custom') {
if (usingCustomFee) {
txp.feePerKb = tx.feeRate;
} else txp.feeLevel = tx.feeLevel;
}
@ -252,7 +255,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
feeService.getFeeRate(tx.network, tx.feeLevel, function(err, feeRate) {
if (err) return cb(err);
if (tx.feeLevel != 'custom') tx.feeRate = feeRate;
if (!usingCustomFee) tx.feeRate = feeRate;
tx.feeLevelName = feeService.feeOpts[tx.feeLevel];
if (!wallet)
@ -559,7 +562,11 @@ 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();
if (usingCustomFee) {
scope.customFeePerKB = tx.feeRate;
scope.feePerSatByte = (tx.feeRate / 1000).toFixed();
}
$ionicModal.fromTemplateUrl('views/modals/chooseFeeLevel.html', {
scope: scope,
@ -573,14 +580,16 @@ angular.module('copayApp.controllers').controller('confirmController', function(
scope.chooseFeeLevelModal.show();
};
scope.hideModal = function(newFeeLevel, customFeePerKBValue) {
scope.hideModal = function(newFeeLevel, customFeePerKB) {
scope.chooseFeeLevelModal.hide();
$log.debug('New fee level choosen:' + newFeeLevel + ' was:' + tx.feeLevel);
if (tx.feeLevel == newFeeLevel && !customFeePerKBValue) return;
usingCustomFee = newFeeLevel == 'custom' ? true : false;
if (tx.feeLevel == newFeeLevel && !usingCustomFee) return;
tx.feeLevel = newFeeLevel;
if (customFeePerKBValue) tx.feeRate = parseInt(customFeePerKBValue);
if (usingCustomFee) tx.feeRate = parseInt(customFeePerKB);
updateTx(tx, wallet, {
clearCache: true,

View File

@ -13,12 +13,12 @@
<div>
<span translate>Average confirmation time</span>:
<span class="fee-minutes" ng-if="avgConfirmationTime && currentFeeLevel != 'custom'">{{avgConfirmationTime | amDurationFormat: 'minute'}}</span>
<span class="fee-minutes" ng-if="currentFeeLevel == 'custom' && !invalidCustomFeeEntered" translate>Could not be estimated</span>
<span class="fee-minutes" ng-if="currentFeeLevel == 'custom' && !invalidCustomFeeEntered && !loadingFee" translate>Could not be estimated</span>
<span ng-if="loadingFee || invalidCustomFeeEntered">...</span>
</div>
<div>
<span translate>Current fee rate for this policy</span>:
<span class="fee-rate" ng-if="feePerSatByte && !invalidCustomFeeEntered">{{feePerSatByte}} satoshis/byte</span>
<span class="fee-rate" ng-if="feePerSatByte && !invalidCustomFeeEntered && !loadingFee">{{feePerSatByte}} satoshis/byte</span>
<span ng-if="loadingFee || invalidCustomFeeEntered">...</span>
</div>
<span ng-if="network!='livenet'">[{{network}}]</span>