Adds three levels of dynamic fees
This commit is contained in:
parent
49c606f135
commit
5742dee340
10 changed files with 241 additions and 110 deletions
|
|
@ -17,7 +17,7 @@
|
||||||
"ng-lodash": "~0.2.0",
|
"ng-lodash": "~0.2.0",
|
||||||
"angular-moment": "~0.10.1",
|
"angular-moment": "~0.10.1",
|
||||||
"moment": "~2.10.3",
|
"moment": "~2.10.3",
|
||||||
"angular-bitcore-wallet-client": "^0.0.26",
|
"angular-bitcore-wallet-client": "^0.0.28",
|
||||||
"angular-ui-router": "~0.2.13",
|
"angular-ui-router": "~0.2.13",
|
||||||
"qrcode-decoder-js": "*",
|
"qrcode-decoder-js": "*",
|
||||||
"fastclick": "*",
|
"fastclick": "*",
|
||||||
|
|
|
||||||
42
public/views/modals/fee.html
Normal file
42
public/views/modals/fee.html
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
<nav class="tab-bar">
|
||||||
|
<section class="left-small">
|
||||||
|
<a ng-click="cancel()" class="p10">
|
||||||
|
<span class="text-close" translate>Close</span>
|
||||||
|
</a>
|
||||||
|
</section>
|
||||||
|
<section class="middle tab-bar-section">
|
||||||
|
<h1 class="title ellipsis" ng-style="{'color':color}" translate>
|
||||||
|
Bitcoin Network Fee Policy
|
||||||
|
</h1>
|
||||||
|
</section>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="modal-content fix-modals-touch" ng-controller="preferencesFeeController as prefFee">
|
||||||
|
<ul class="no-bullet m0 size-14">
|
||||||
|
<h4 class="title m0" translate>Fee level [{{network}}]</h4>
|
||||||
|
<li ng-repeat="fee in (network == 'livenet' ? feeLevels.livenet : feeLevels.testnet)" ng-click="save(fee.level)" class="line-b p20">
|
||||||
|
<span ng-show="fee.level == 'priority'" translate>Priority</span>
|
||||||
|
<span ng-show="fee.level == 'normal'" translate>Normal</span>
|
||||||
|
<span ng-show="fee.level == 'economy'" translate>Economy</span>
|
||||||
|
<span class="size-12 text-light" translate>{{fee.feePerKBUnit}} per kB</span>
|
||||||
|
<i class="fi-check size-16 right" ng-show="currentFeeLevel == fee.level"></i>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<div class="row column m20t">
|
||||||
|
<div class="text-gray size-12 text-center" ng-repeat="fee in (network == 'livenet' ? feeLevels.livenet :
|
||||||
|
feeLevels.testnet)" ng-if="fee.level == currentFeeLevel">
|
||||||
|
<span translate>Average confirmation time: {{fee.nbBlocks * 10}} minutes</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row column m20t">
|
||||||
|
<div class="text-gray size-12 text-center" translate>
|
||||||
|
Bitcoin transactions may include a fee collected by miners on the network. The higher the fee, the greater the incentive a miner has to include that transaction in a block.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="extra-margin-bottom"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
@ -77,13 +77,6 @@
|
||||||
{{preferences.selectedAlternative.name}}
|
{{preferences.selectedAlternative.name}}
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
<li class="line-b p20" ng-click="$root.go('preferencesFee')">
|
|
||||||
<span translate>Bitcoin Network Fee Policy</span>
|
|
||||||
<span class="right text-gray">
|
|
||||||
<i class="icon-arrow-right3 size-24 right"></i>
|
|
||||||
{{preferences.feeName|translate}}
|
|
||||||
</span>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
|
|
||||||
<li class="line-b p20" ng-click="$root.go('preferencesBwsUrl')">
|
<li class="line-b p20" ng-click="$root.go('preferencesBwsUrl')">
|
||||||
|
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
<div
|
|
||||||
class="topbar-container"
|
|
||||||
ng-include="'views/includes/topbar.html'"
|
|
||||||
ng-init="titleSection='Bitcoin Network Fee Policy'; goBackToState = 'preferences'; noColor = true">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div class="content preferences" ng-controller="preferencesFeeController as prefFee">
|
|
||||||
<div ng-repeat="fee in prefFee.feeOpts" ng-click="prefFee.save(fee)" class="line-b p20 size-14">
|
|
||||||
<span ng-if="fee.red" style="color:red">{{fee.name|translate}} (<span translate>{{fee.value}} bits per kB</span>)</span>
|
|
||||||
<span ng-if="!fee.red">{{fee.name|translate}} (<span translate>{{fee.value}} bits per kB</span>)</span>
|
|
||||||
<i class="fi-check size-16 right" ng-show="prefFee.feeName == fee.name"></i>
|
|
||||||
</div>
|
|
||||||
<div class="row column m20t">
|
|
||||||
<div class="text-gray size-12 text-center m20b" translate>
|
|
||||||
Bitcoin transactions may include a fee collected by miners on the network. The higher the fee, the greater the incentive a miner has to include that transaction in a block. The ‘Emergency’ level should only be used when there is a network congestion.
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="extra-margin-bottom"></div>
|
|
||||||
|
|
@ -398,6 +398,17 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="text-right size-12 m10b">
|
||||||
|
<span ng-repeat="fee in (index.network == 'livenet' ? index.feeLevels.livenet : index.feeLevels.testnet)"
|
||||||
|
ng-show="index.currentFeeLevel == fee.level">
|
||||||
|
<span translate>Fee</span>:
|
||||||
|
<span class="text-light" translate>{{fee.feePerKBUnit}} per kB</span>
|
||||||
|
(<span translate>Average confirmation time: {{fee.nbBlocks * 10}} minutes</span>)
|
||||||
|
</span>
|
||||||
|
<a href ng-click="home.openFeeModal(index.feeLevels, index.currentFeeLevel)" translate>Change</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="large-12 columns">
|
<div class="large-12 columns">
|
||||||
<label for="comment"><span translate>Note</span>
|
<label for="comment"><span translate>Note</span>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, lodash, go, profileService, configService, isCordova, rateService, storageService, addressService, gettextCatalog, gettext, amMoment, nodeWebkit, addonManager) {
|
angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, lodash, go, profileService, configService, isCordova, rateService, storageService, addressService, gettextCatalog, gettext, amMoment, nodeWebkit, addonManager, feeService) {
|
||||||
var self = this;
|
var self = this;
|
||||||
self.isCordova = isCordova;
|
self.isCordova = isCordova;
|
||||||
self.onGoingProcess = {};
|
self.onGoingProcess = {};
|
||||||
|
|
@ -278,6 +278,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
}
|
}
|
||||||
$log.debug('Wallet Status:', walletStatus);
|
$log.debug('Wallet Status:', walletStatus);
|
||||||
self.setPendingTxps(walletStatus.pendingTxps);
|
self.setPendingTxps(walletStatus.pendingTxps);
|
||||||
|
self.setFees();
|
||||||
|
|
||||||
// Status Shortcuts
|
// Status Shortcuts
|
||||||
self.walletName = walletStatus.wallet.name;
|
self.walletName = walletStatus.wallet.name;
|
||||||
|
|
@ -305,6 +306,22 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
self.setCurrentFeeLevel = function(level) {
|
||||||
|
self.currentFeeLevel = level || configService.getSync().wallet.settings.feeLevel || 'priority';
|
||||||
|
};
|
||||||
|
|
||||||
|
self.setFees = function() {
|
||||||
|
var fc = profileService.focusedClient;
|
||||||
|
if (!fc) return;
|
||||||
|
$timeout(function() {
|
||||||
|
feeService.getFeeLevels(function(levels) {
|
||||||
|
self.feeLevels = levels;
|
||||||
|
self.setCurrentFeeLevel();
|
||||||
|
$rootScope.$apply();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
self.updateBalance = function() {
|
self.updateBalance = function() {
|
||||||
var fc = profileService.focusedClient;
|
var fc = profileService.focusedClient;
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
|
|
@ -801,6 +818,10 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$rootScope.$on('Local/FeeLevelUpdated', function(event, level) {
|
||||||
|
self.setCurrentFeeLevel(level);
|
||||||
|
});
|
||||||
|
|
||||||
$rootScope.$on('Local/ProfileBound', function() {
|
$rootScope.$on('Local/ProfileBound', function() {
|
||||||
storageService.getRemotePrefsStoredFlag(function(err, val) {
|
storageService.getRemotePrefsStoredFlag(function(err, val) {
|
||||||
if (err || val) return;
|
if (err || val) return;
|
||||||
|
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('preferencesFeeController',
|
|
||||||
function($rootScope, $scope, configService, go, gettext) {
|
|
||||||
var config = configService.getSync();
|
|
||||||
this.feeName = config.wallet.settings.feeName || 'Priority';
|
|
||||||
this.feeOpts = [{
|
|
||||||
name: gettext('Priority'),
|
|
||||||
value: 100,
|
|
||||||
}, {
|
|
||||||
name: gettext('Normal'),
|
|
||||||
value: 50,
|
|
||||||
}, {
|
|
||||||
name: gettext('Economy'),
|
|
||||||
value: 10,
|
|
||||||
}, {
|
|
||||||
name: gettext('Emergency'),
|
|
||||||
red: true,
|
|
||||||
value: 500,
|
|
||||||
}, ];
|
|
||||||
|
|
||||||
this.save = function(newFee) {
|
|
||||||
var opts = {
|
|
||||||
wallet: {
|
|
||||||
settings: {
|
|
||||||
feeName: newFee.name,
|
|
||||||
feeValue: newFee.value * 100,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
this.feeName = newFee.name;
|
|
||||||
|
|
||||||
configService.set(opts, function(err) {
|
|
||||||
if (err) console.log(err);
|
|
||||||
});
|
|
||||||
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('walletHomeController', function($scope, $rootScope, $timeout, $filter, $modal, $log, notification, txStatus, isCordova, profileService, lodash, configService, rateService, storageService, bitcore, isChromeApp, gettext, gettextCatalog, nodeWebkit, addressService) {
|
angular.module('copayApp.controllers').controller('walletHomeController', function($scope, $rootScope, $timeout, $filter, $modal, $log, notification, txStatus, isCordova, profileService, lodash, configService, rateService, storageService, bitcore, isChromeApp, gettext, gettextCatalog, nodeWebkit, addressService, feeService) {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
$rootScope.hideMenuBar = false;
|
$rootScope.hideMenuBar = false;
|
||||||
|
|
@ -724,40 +724,47 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
|
||||||
address = form.address.$modelValue;
|
address = form.address.$modelValue;
|
||||||
amount = parseInt((form.amount.$modelValue * unitToSat).toFixed(0));
|
amount = parseInt((form.amount.$modelValue * unitToSat).toFixed(0));
|
||||||
|
|
||||||
fc.sendTxProposal({
|
feeService.getCurrentFeeValue(function(err, feePerKb) {
|
||||||
toAddress: address,
|
|
||||||
amount: amount,
|
|
||||||
message: comment,
|
|
||||||
payProUrl: paypro ? paypro.url : null,
|
|
||||||
feePerKb: config.feeValue || 10000,
|
|
||||||
}, function(err, txp) {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
self.setOngoingProcess();
|
self.setOngoingProcess();
|
||||||
profileService.lockFC();
|
profileService.lockFC();
|
||||||
return self.setSendError(err);
|
return self.setSendError(err);
|
||||||
}
|
}
|
||||||
|
fc.sendTxProposal({
|
||||||
if (!fc.canSign()) {
|
toAddress: address,
|
||||||
$log.info('No signing proposal: No private key')
|
amount: amount,
|
||||||
self.setOngoingProcess();
|
message: comment,
|
||||||
self.resetForm();
|
payProUrl: paypro ? paypro.url : null,
|
||||||
txStatus.notify(txp, function() {
|
feePerKb: feePerKb,
|
||||||
return $scope.$emit('Local/TxProposalAction');
|
}, function(err, txp) {
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.signAndBroadcast(txp, function(err) {
|
|
||||||
self.setOngoingProcess();
|
|
||||||
profileService.lockFC();
|
|
||||||
self.resetForm();
|
|
||||||
if (err) {
|
if (err) {
|
||||||
self.error = err.message ? err.message : gettext('The payment was created but could not be completed. Please try again from home screen');
|
self.setOngoingProcess();
|
||||||
$scope.$emit('Local/TxProposalAction');
|
profileService.lockFC();
|
||||||
$timeout(function() {
|
return self.setSendError(err);
|
||||||
$scope.$digest();
|
|
||||||
}, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!fc.canSign()) {
|
||||||
|
$log.info('No signing proposal: No private key')
|
||||||
|
self.setOngoingProcess();
|
||||||
|
self.resetForm();
|
||||||
|
txStatus.notify(txp, function() {
|
||||||
|
return $scope.$emit('Local/TxProposalAction');
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.signAndBroadcast(txp, function(err) {
|
||||||
|
self.setOngoingProcess();
|
||||||
|
profileService.lockFC();
|
||||||
|
self.resetForm();
|
||||||
|
if (err) {
|
||||||
|
self.error = err.message ? err.message : gettext('The payment was created but could not be completed. Please try again from home screen');
|
||||||
|
$scope.$emit('Local/TxProposalAction');
|
||||||
|
$timeout(function() {
|
||||||
|
$scope.$digest();
|
||||||
|
}, 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|
@ -970,6 +977,47 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.openFeeModal = function(feeLevels, currentFeeLevel) {
|
||||||
|
var fc = profileService.focusedClient;
|
||||||
|
|
||||||
|
var ModalInstanceCtrl = function($scope, $modalInstance) {
|
||||||
|
$scope.feeLevels = feeLevels;
|
||||||
|
$scope.currentFeeLevel = currentFeeLevel
|
||||||
|
$scope.network = fc.credentials.network;
|
||||||
|
$scope.color = fc.backgroundColor;
|
||||||
|
|
||||||
|
$scope.save = function(level) {
|
||||||
|
var opts = {
|
||||||
|
wallet: {
|
||||||
|
settings: {
|
||||||
|
feeLevel: level
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
$scope.currentFeeLevel = level;
|
||||||
|
$rootScope.$emit('Local/FeeLevelUpdated', level);
|
||||||
|
|
||||||
|
configService.set(opts, function(err) {
|
||||||
|
if (err) $log.debug(err);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.cancel = function() {
|
||||||
|
$modalInstance.dismiss('cancel');
|
||||||
|
};
|
||||||
|
};
|
||||||
|
var modalInstance = $modal.open({
|
||||||
|
templateUrl: 'views/modals/fee.html',
|
||||||
|
windowClass: 'full animated slideInUp',
|
||||||
|
controller: ModalInstanceCtrl
|
||||||
|
});
|
||||||
|
|
||||||
|
modalInstance.result.finally(function() {
|
||||||
|
var m = angular.element(document.getElementsByClassName('reveal-modal'));
|
||||||
|
m.addClass('slideOutDown');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// History
|
// History
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -252,17 +252,6 @@ angular
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.state('preferencesFee', {
|
|
||||||
url: '/preferencesFee',
|
|
||||||
templateUrl: 'views/preferencesFee.html',
|
|
||||||
walletShouldBeComplete: true,
|
|
||||||
needProfile: true,
|
|
||||||
views: {
|
|
||||||
'main': {
|
|
||||||
templateUrl: 'views/preferencesFee.html'
|
|
||||||
},
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
.state('preferencesAdvanced', {
|
.state('preferencesAdvanced', {
|
||||||
url: '/preferencesAdvanced',
|
url: '/preferencesAdvanced',
|
||||||
|
|
@ -469,7 +458,6 @@ angular
|
||||||
delete: 13,
|
delete: 13,
|
||||||
preferencesLanguage: 12,
|
preferencesLanguage: 12,
|
||||||
preferencesUnit: 12,
|
preferencesUnit: 12,
|
||||||
preferencesFee: 12,
|
|
||||||
preferencesAltCurrency: 12,
|
preferencesAltCurrency: 12,
|
||||||
preferencesBwsUrl: 12,
|
preferencesBwsUrl: 12,
|
||||||
preferencesAlias: 12,
|
preferencesAlias: 12,
|
||||||
|
|
|
||||||
88
src/js/services/feeService.js
Normal file
88
src/js/services/feeService.js
Normal file
|
|
@ -0,0 +1,88 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
angular.module('copayApp.services').factory('feeService', function($log, lodash, profileService, configService, gettext) {
|
||||||
|
var root = {};
|
||||||
|
|
||||||
|
root.feeStaticOpts = [{
|
||||||
|
name: gettext('Priority'),
|
||||||
|
level: 'priority',
|
||||||
|
feePerKB: 10000,
|
||||||
|
nbBlocks: 1
|
||||||
|
}, {
|
||||||
|
name: gettext('Normal'),
|
||||||
|
level: 'normal',
|
||||||
|
feePerKB: 5000,
|
||||||
|
nbBlocks: 4
|
||||||
|
}, {
|
||||||
|
name: gettext('Economy'),
|
||||||
|
level: 'economy',
|
||||||
|
feePerKB: 1000,
|
||||||
|
nbBlocks: 12
|
||||||
|
}];
|
||||||
|
|
||||||
|
root.getCurrentFeeValue = function(cb) {
|
||||||
|
var fc = profileService.focusedClient;
|
||||||
|
var config = configService.getSync().wallet.settings;
|
||||||
|
var feeLevel = config.feeLevel || 'priority';
|
||||||
|
// static fee
|
||||||
|
var fee = 10000;
|
||||||
|
fc.getFeeLevels(fc.credentials.network, function(err, levels) {
|
||||||
|
if (err) {
|
||||||
|
return cb({message: 'Error getting dynamic fee'})
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (var i = 0; i < 3; i++) {
|
||||||
|
if (levels[i].level == feeLevel) {
|
||||||
|
fee = levels[i].feePerKB;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$log.debug('Dynamic fee for ' + feeLevel + ': ' + fee);
|
||||||
|
return cb(null, fee);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
var checkCompatibility = function(config) {
|
||||||
|
if (config.feeName && !config.feeLevel) {
|
||||||
|
// Migrate to new dynamic fee values
|
||||||
|
var level = config.feeName.toLowerCase();
|
||||||
|
if (level == 'emergency') level = 'priority';
|
||||||
|
|
||||||
|
var opts = {
|
||||||
|
wallet: {
|
||||||
|
settings: {
|
||||||
|
feeLevel: level
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
configService.set(opts, function(err) {
|
||||||
|
if (err) $log.debug(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
root.getFeeLevels = function(cb) {
|
||||||
|
var fc = profileService.focusedClient;
|
||||||
|
var config = configService.getSync().wallet.settings;
|
||||||
|
var unitName = config.unitName;
|
||||||
|
checkCompatibility(config);
|
||||||
|
|
||||||
|
fc.getFeeLevels('livenet', function(errLivenet, levelsLivenet) {
|
||||||
|
fc.getFeeLevels('testnet', function(errTestnet, levelsTestnet) {
|
||||||
|
if (errLivenet || errTestnet) $log.error('Error getting dynamic fee');
|
||||||
|
|
||||||
|
for (var i = 0; i < 3; i++) {
|
||||||
|
levelsLivenet[i]['feePerKBUnit'] = profileService.formatAmount(levelsLivenet[i].feePerKB) + ' ' + unitName;
|
||||||
|
levelsTestnet[i]['feePerKBUnit'] = profileService.formatAmount(levelsTestnet[i].feePerKB) + ' ' + unitName;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cb({
|
||||||
|
'livenet': levelsLivenet,
|
||||||
|
'testnet': levelsTestnet
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return root;
|
||||||
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue