Adds three levels of dynamic fees
This commit is contained in:
parent
49c606f135
commit
5742dee340
10 changed files with 241 additions and 110 deletions
|
|
@ -1,6 +1,6 @@
|
|||
'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;
|
||||
self.isCordova = isCordova;
|
||||
self.onGoingProcess = {};
|
||||
|
|
@ -278,6 +278,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
}
|
||||
$log.debug('Wallet Status:', walletStatus);
|
||||
self.setPendingTxps(walletStatus.pendingTxps);
|
||||
self.setFees();
|
||||
|
||||
// Status Shortcuts
|
||||
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() {
|
||||
var fc = profileService.focusedClient;
|
||||
$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() {
|
||||
storageService.getRemotePrefsStoredFlag(function(err, val) {
|
||||
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';
|
||||
|
||||
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;
|
||||
$rootScope.hideMenuBar = false;
|
||||
|
|
@ -526,7 +526,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
|
|||
});
|
||||
};
|
||||
|
||||
// Send
|
||||
// Send
|
||||
|
||||
this.canShowAlternative = function() {
|
||||
return $scope.showAlternative;
|
||||
|
|
@ -724,40 +724,47 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
|
|||
address = form.address.$modelValue;
|
||||
amount = parseInt((form.amount.$modelValue * unitToSat).toFixed(0));
|
||||
|
||||
fc.sendTxProposal({
|
||||
toAddress: address,
|
||||
amount: amount,
|
||||
message: comment,
|
||||
payProUrl: paypro ? paypro.url : null,
|
||||
feePerKb: config.feeValue || 10000,
|
||||
}, function(err, txp) {
|
||||
feeService.getCurrentFeeValue(function(err, feePerKb) {
|
||||
if (err) {
|
||||
self.setOngoingProcess();
|
||||
profileService.lockFC();
|
||||
return self.setSendError(err);
|
||||
}
|
||||
|
||||
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();
|
||||
fc.sendTxProposal({
|
||||
toAddress: address,
|
||||
amount: amount,
|
||||
message: comment,
|
||||
payProUrl: paypro ? paypro.url : null,
|
||||
feePerKb: feePerKb,
|
||||
}, function(err, txp) {
|
||||
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);
|
||||
self.setOngoingProcess();
|
||||
profileService.lockFC();
|
||||
return self.setSendError(err);
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue