use new fee level only for the current transaction created
This commit is contained in:
parent
f681122fd6
commit
6521bbdcb4
9 changed files with 147 additions and 96 deletions
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $interval, $filter, $timeout, $ionicScrollDelegate, gettextCatalog, walletService, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, profileService, bitcore, txFormatService, ongoingProcess, $ionicModal, popupService, $ionicHistory, $ionicConfig, payproService, feeService, bwcError) {
|
||||
var cachedTxp = {};
|
||||
var feeLevel;
|
||||
var feePerKb;
|
||||
var toAmount;
|
||||
var isChromeApp = platformInfo.isChromeApp;
|
||||
var countDown = null;
|
||||
|
|
@ -37,17 +39,23 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
|||
$scope.remainingTimeStr = {
|
||||
value: null
|
||||
};
|
||||
|
||||
var config = configService.getSync().wallet;
|
||||
var feeLevel = config.settings && config.settings.feeLevel ? config.settings.feeLevel : 'normal';
|
||||
$scope.feeLevel = feeService.feeOpts[feeLevel];
|
||||
$scope.network = (new bitcore.Address($scope.toAddress)).network.name;
|
||||
setFee();
|
||||
resetValues();
|
||||
if (!$scope.wallet) setwallets();
|
||||
else useSelectedWallet();
|
||||
setwallets();
|
||||
applyButtonText();
|
||||
});
|
||||
|
||||
function setFee(customFeeLevel, cb) {
|
||||
feeService.getCurrentFeeValue($scope.network, customFeeLevel, function(err, feePerKb) {
|
||||
var config = configService.getSync().wallet;
|
||||
var configFeeLevel = (config.settings && config.settings.feeLevel) ? config.settings.feeLevel : 'normal';
|
||||
feePerKb = feePerKb;
|
||||
feeLevel = customFeeLevel ? customFeeLevel : configFeeLevel;
|
||||
$scope.feeLevel = feeService.feeOpts[feeLevel];
|
||||
if (cb) return cb();
|
||||
});
|
||||
}
|
||||
|
||||
function useSelectedWallet() {
|
||||
if (!$scope.useSendMax) displayValues();
|
||||
|
|
@ -170,78 +178,69 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
|||
|
||||
$scope.getSendMaxInfo = function() {
|
||||
resetValues();
|
||||
var config = configService.getSync().wallet;
|
||||
|
||||
ongoingProcess.set('gettingFeeLevels', true);
|
||||
feeService.getCurrentFeeValue($scope.network, function(err, feePerKb) {
|
||||
ongoingProcess.set('gettingFeeLevels', false);
|
||||
ongoingProcess.set('retrievingInputs', true);
|
||||
walletService.getSendMaxInfo($scope.wallet, {
|
||||
feePerKb: feePerKb,
|
||||
excludeUnconfirmedUtxos: !config.spendUnconfirmed,
|
||||
returnInputs: true,
|
||||
}, function(err, resp) {
|
||||
ongoingProcess.set('retrievingInputs', false);
|
||||
if (err) {
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), err.message);
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), err);
|
||||
return;
|
||||
}
|
||||
var config = configService.getSync().wallet;
|
||||
|
||||
ongoingProcess.set('retrievingInputs', true);
|
||||
walletService.getSendMaxInfo($scope.wallet, {
|
||||
if (resp.amount == 0) {
|
||||
$scope.insufficientFunds = true;
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Not enough funds for fee'));
|
||||
return;
|
||||
}
|
||||
|
||||
$scope.sendMaxInfo = {
|
||||
sendMax: true,
|
||||
amount: resp.amount,
|
||||
inputs: resp.inputs,
|
||||
fee: resp.fee,
|
||||
feePerKb: feePerKb,
|
||||
excludeUnconfirmedUtxos: !config.spendUnconfirmed,
|
||||
returnInputs: true,
|
||||
}, function(err, resp) {
|
||||
ongoingProcess.set('retrievingInputs', false);
|
||||
if (err) {
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), err);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
if (resp.amount == 0) {
|
||||
$scope.insufficientFunds = true;
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Not enough funds for fee'));
|
||||
return;
|
||||
}
|
||||
cachedSendMax[$scope.wallet.id] = $scope.sendMaxInfo;
|
||||
|
||||
$scope.sendMaxInfo = {
|
||||
sendMax: true,
|
||||
amount: resp.amount,
|
||||
inputs: resp.inputs,
|
||||
fee: resp.fee,
|
||||
feePerKb: feePerKb,
|
||||
};
|
||||
|
||||
cachedSendMax[$scope.wallet.id] = $scope.sendMaxInfo;
|
||||
|
||||
var msg = gettextCatalog.getString("{{fee}} will be deducted for bitcoin networking fees.", {
|
||||
fee: txFormatService.formatAmountStr(resp.fee)
|
||||
});
|
||||
var warningMsg = verifyExcludedUtxos();
|
||||
|
||||
if (!lodash.isEmpty(warningMsg))
|
||||
msg += '\n' + warningMsg;
|
||||
|
||||
popupService.showAlert(null, msg, function() {
|
||||
setSendMaxValues(resp);
|
||||
|
||||
createTx($scope.wallet, true, function(err, txp) {
|
||||
if (err) return;
|
||||
cachedTxp[$scope.wallet.id] = txp;
|
||||
apply(txp);
|
||||
});
|
||||
});
|
||||
|
||||
function verifyExcludedUtxos() {
|
||||
var warningMsg = [];
|
||||
if (resp.utxosBelowFee > 0) {
|
||||
warningMsg.push(gettextCatalog.getString("A total of {{amountBelowFeeStr}} were excluded. These funds come from UTXOs smaller than the network fee provided.", {
|
||||
amountBelowFeeStr: txFormatService.formatAmountStr(resp.amountBelowFee)
|
||||
}));
|
||||
}
|
||||
|
||||
if (resp.utxosAboveMaxSize > 0) {
|
||||
warningMsg.push(gettextCatalog.getString("A total of {{amountAboveMaxSizeStr}} were excluded. The maximum size allowed for a transaction was exceeded.", {
|
||||
amountAboveMaxSizeStr: txFormatService.formatAmountStr(resp.amountAboveMaxSize)
|
||||
}));
|
||||
}
|
||||
return warningMsg.join('\n');
|
||||
};
|
||||
var msg = gettextCatalog.getString("{{fee}} will be deducted for bitcoin networking fees.", {
|
||||
fee: txFormatService.formatAmountStr(resp.fee)
|
||||
});
|
||||
var warningMsg = verifyExcludedUtxos();
|
||||
|
||||
if (!lodash.isEmpty(warningMsg))
|
||||
msg += '\n' + warningMsg;
|
||||
|
||||
popupService.showAlert(null, msg, function() {
|
||||
setSendMaxValues(resp);
|
||||
|
||||
createTx($scope.wallet, true, function(err, txp) {
|
||||
if (err) return;
|
||||
cachedTxp[$scope.wallet.id] = txp;
|
||||
apply(txp);
|
||||
});
|
||||
});
|
||||
|
||||
function verifyExcludedUtxos() {
|
||||
var warningMsg = [];
|
||||
if (resp.utxosBelowFee > 0) {
|
||||
warningMsg.push(gettextCatalog.getString("A total of {{amountBelowFeeStr}} were excluded. These funds come from UTXOs smaller than the network fee provided.", {
|
||||
amountBelowFeeStr: txFormatService.formatAmountStr(resp.amountBelowFee)
|
||||
}));
|
||||
}
|
||||
|
||||
if (resp.utxosAboveMaxSize > 0) {
|
||||
warningMsg.push(gettextCatalog.getString("A total of {{amountAboveMaxSizeStr}} were excluded. The maximum size allowed for a transaction was exceeded.", {
|
||||
amountAboveMaxSizeStr: txFormatService.formatAmountStr(resp.amountAboveMaxSize)
|
||||
}));
|
||||
}
|
||||
return warningMsg.join('\n');
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -433,7 +432,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
|||
txp.inputs = $scope.sendMaxInfo.inputs;
|
||||
txp.fee = $scope.sendMaxInfo.fee;
|
||||
} else
|
||||
txp.feeLevel = config.settings && config.settings.feeLevel ? config.settings.feeLevel : 'normal';
|
||||
txp.feeLevel = feeLevel;
|
||||
|
||||
txp.message = description;
|
||||
|
||||
|
|
@ -583,8 +582,29 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
|||
};
|
||||
|
||||
$scope.chooseFeeLevel = function() {
|
||||
cachedTxp = {};
|
||||
$state.go('tabs.send.confirm.fee');
|
||||
|
||||
$scope.customFeeLevel = feeLevel;
|
||||
$ionicModal.fromTemplateUrl('views/modals/chooseFeeLevel.html', {
|
||||
scope: $scope,
|
||||
}).then(function(modal) {
|
||||
$scope.chooseFeeLevelModal = modal;
|
||||
$scope.openModal();
|
||||
});
|
||||
$scope.openModal = function() {
|
||||
$scope.chooseFeeLevelModal.show();
|
||||
};
|
||||
$scope.hideModal = function(customFeeLevel) {
|
||||
if (customFeeLevel) {
|
||||
cachedTxp = {};
|
||||
ongoingProcess.set('gettingFeeLevels', true);
|
||||
setFee(customFeeLevel, function() {
|
||||
ongoingProcess.set('gettingFeeLevels', false);
|
||||
resetValues();
|
||||
if ($scope.wallet) useSelectedWallet();
|
||||
})
|
||||
}
|
||||
$scope.chooseFeeLevelModal.hide();
|
||||
};
|
||||
};
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ angular.module('copayApp.controllers').controller('paperWalletController',
|
|||
$scope.wallet.buildTxFromPrivateKey($scope.privateKey, destinationAddress, null, function(err, testTx) {
|
||||
if (err) return cb(err);
|
||||
var rawTxLength = testTx.serialize().length;
|
||||
feeService.getCurrentFeeValue('livenet', function(err, feePerKB) {
|
||||
feeService.getCurrentFeeValue('livenet', null, function(err, feePerKB) {
|
||||
var opts = {};
|
||||
opts.fee = Math.round((feePerKB * rawTxLength) / 2000);
|
||||
$scope.wallet.buildTxFromPrivateKey($scope.privateKey, destinationAddress, opts, function(err, tx) {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,15 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('preferencesFeeController', function($scope, $rootScope, $timeout, $ionicHistory, lodash, gettextCatalog, configService, feeService, ongoingProcess, popupService) {
|
||||
angular.module('copayApp.controllers').controller('preferencesFeeController', function($scope, $timeout, $ionicHistory, lodash, gettextCatalog, configService, feeService, ongoingProcess, popupService) {
|
||||
|
||||
$scope.save = function(newFee) {
|
||||
|
||||
if ($scope.customFeeLevel) {
|
||||
$scope.currentFeeLevel = newFee;
|
||||
updateCurrentValues();
|
||||
return;
|
||||
}
|
||||
|
||||
var opts = {
|
||||
wallet: {
|
||||
settings: {
|
||||
|
|
@ -21,18 +28,13 @@ angular.module('copayApp.controllers').controller('preferencesFeeController', fu
|
|||
});
|
||||
};
|
||||
|
||||
function hideTabs() {
|
||||
$timeout(function() {
|
||||
$rootScope.hideTabs = 'tabs-item-hide';
|
||||
$rootScope.$apply();
|
||||
});
|
||||
};
|
||||
|
||||
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
||||
$scope.init();
|
||||
});
|
||||
|
||||
if ($ionicHistory.backView() && ($ionicHistory.backView().stateName == 'tabs.send.confirm')) hideTabs();
|
||||
$scope.init = function() {
|
||||
$scope.feeOpts = feeService.feeOpts;
|
||||
$scope.currentFeeLevel = feeService.getCurrentFeeLevel();
|
||||
$scope.currentFeeLevel = $scope.customFeeLevel ? $scope.customFeeLevel : feeService.getCurrentFeeLevel();
|
||||
$scope.loadingFee = true;
|
||||
feeService.getFeeLevels(function(err, levels) {
|
||||
$scope.loadingFee = false;
|
||||
|
|
@ -45,7 +47,7 @@ angular.module('copayApp.controllers').controller('preferencesFeeController', fu
|
|||
updateCurrentValues();
|
||||
$scope.$apply();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
var updateCurrentValues = function() {
|
||||
if (lodash.isEmpty($scope.feeLevels) || lodash.isEmpty($scope.currentFeeLevel)) return;
|
||||
|
|
@ -60,4 +62,8 @@ angular.module('copayApp.controllers').controller('preferencesFeeController', fu
|
|||
$scope.feePerSatByte = (feeLevelValue.feePerKB / 1000).toFixed();
|
||||
$scope.avgConfirmationTime = feeLevelValue.nbBlocks * 10;
|
||||
};
|
||||
|
||||
$scope.chooseNewFee = function() {
|
||||
$scope.hideModal($scope.currentFeeLevel);
|
||||
};
|
||||
});
|
||||
|
|
|
|||
|
|
@ -295,15 +295,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
paypro: null
|
||||
}
|
||||
})
|
||||
.state('tabs.send.confirm.fee', {
|
||||
url: '/fee',
|
||||
views: {
|
||||
'tab-send@tabs': {
|
||||
controller: 'preferencesFeeController',
|
||||
templateUrl: 'views/preferencesFee.html'
|
||||
}
|
||||
}
|
||||
})
|
||||
.state('tabs.send.addressbook', {
|
||||
url: '/addressbook/add/:fromSendTab/:addressbookEntry',
|
||||
views: {
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@ angular.module('copayApp.services').factory('feeService', function($log, $stateP
|
|||
return configService.getSync().wallet.settings.feeLevel || 'normal';
|
||||
};
|
||||
|
||||
root.getCurrentFeeValue = function(network, cb) {
|
||||
root.getCurrentFeeValue = function(network, customFeeLevel, cb) {
|
||||
network = network || 'livenet';
|
||||
var feeLevel = root.getCurrentFeeLevel();
|
||||
var feeLevel = customFeeLevel || root.getCurrentFeeLevel();
|
||||
|
||||
root.getFeeLevels(function(err, levels) {
|
||||
if (err) return cb(err);
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ angular.module('copayApp.services').factory('ongoingProcess', function($log, $ti
|
|||
} else {
|
||||
|
||||
var tmpl;
|
||||
if (isWP) tmpl = '<div>' + showName +'</div>';
|
||||
if (isWP) tmpl = '<div>' + showName + '</div>';
|
||||
else tmpl = '<div class="item-icon-left">' + showName + '<ion-spinner class="spinner-stable" icon="lines"></ion-spinner></div>';
|
||||
$ionicLoading.show({
|
||||
template: tmpl
|
||||
|
|
@ -95,8 +95,8 @@ angular.module('copayApp.services').factory('ongoingProcess', function($log, $ti
|
|||
if (isCordova && !isWP) {
|
||||
window.plugins.spinnerDialog.hide();
|
||||
} else {
|
||||
$ionicLoading.hide();
|
||||
}
|
||||
$ionicLoading.hide();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@ angular.module('copayApp.services').service('sendMaxService', function(feeServic
|
|||
*
|
||||
*/
|
||||
this.getInfo = function(wallet, cb) {
|
||||
feeService.getCurrentFeeValue(wallet.credentials.network, function(err, feePerKb) {
|
||||
feeService.getCurrentFeeValue(wallet.credentials.network, null, function(err, feePerKb) {
|
||||
if (err) return cb(err);
|
||||
|
||||
|
||||
var config = configService.getSync().wallet;
|
||||
|
||||
walletService.getSendMaxInfo(wallet, {
|
||||
|
|
|
|||
34
www/views/modals/chooseFeeLevel.html
Normal file
34
www/views/modals/chooseFeeLevel.html
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<ion-modal-view id="settings-fee" class="settings" ng-controller="preferencesFeeController" ng-init="init()">
|
||||
<ion-header-bar align-title="center" class="bar-royal">
|
||||
<button class="button button-clear" ng-click="hideModal()">
|
||||
Close
|
||||
</button>
|
||||
<div class="title">
|
||||
{{'Bitcoin Network Fee Policy'|translate}}
|
||||
</div>
|
||||
</ion-header-bar>
|
||||
<ion-content>
|
||||
<div class="settings-explanation">
|
||||
<div class="estimates">
|
||||
<div>
|
||||
<span translate>Average confirmation time</span>:
|
||||
<span class="fee-minutes" ng-if="avgConfirmationTime">{{avgConfirmationTime | amDurationFormat: 'minute'}}</span>
|
||||
<span ng-if="loadingFee">...</span>
|
||||
</div>
|
||||
<div>
|
||||
<span translate>Current fee rate for this policy</span>:
|
||||
<span class="fee-rate" ng-if="feePerSatByte">{{feePerSatByte}} sat/byte</span>
|
||||
<span ng-if="loadingFee">...</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="fee-policies">
|
||||
<ion-radio ng-repeat="(fee, level) in feeOpts" ng-value="fee" ng-model="currentFeeLevel" ng-click="save(fee)">
|
||||
{{level|translate}}
|
||||
</ion-radio>
|
||||
</div>
|
||||
<div class="m20t">
|
||||
<button class="button button-standard button-primary" ng-click="chooseNewFee()" translate>Save</button>
|
||||
</div>
|
||||
</ion-content>
|
||||
</ion-modal-view>
|
||||
|
|
@ -18,7 +18,7 @@
|
|||
</div>
|
||||
<div>
|
||||
<span translate>Current fee rate for this policy</span>:
|
||||
<span class="fee-rate" ng-if="feePerSatByte">{{feePerSatByte}} sat/Byte</span>
|
||||
<span class="fee-rate" ng-if="feePerSatByte">{{feePerSatByte}} sat/byte</span>
|
||||
<span ng-if="loadingFee">...</span>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue