mirror of https://github.com/BTCPrivate/copay.git
better fee service
This commit is contained in:
parent
442e64c20c
commit
5745340400
|
@ -34,6 +34,28 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
|||
$ionicConfig.views.swipeBackEnabled(false);
|
||||
});
|
||||
|
||||
|
||||
function exitWithError(err) {
|
||||
$log.info('Error setting wallet selector:' + err);
|
||||
popupService.showAlert(gettextCatalog.getString(), bwcError.msg(err), function() {
|
||||
$ionicHistory.nextViewOptions({
|
||||
disableAnimate: true,
|
||||
historyRoot: true
|
||||
});
|
||||
$ionicHistory.clearHistory();
|
||||
$state.go('tabs.send');
|
||||
});
|
||||
};
|
||||
|
||||
function setNoWallet(msg) {
|
||||
$scope.wallet = null;
|
||||
$scope.noWalletMessage = gettextCatalog.getString(msg);
|
||||
$log.warn('Not ready to make the payment:' + msg);
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
});
|
||||
};
|
||||
|
||||
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
||||
|
||||
function setWalletSelector(minAmount, cb) {
|
||||
|
@ -44,12 +66,8 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
|||
});
|
||||
|
||||
if (!$scope.wallets || !$scope.wallets.length) {
|
||||
$scope.noMatchingWallet = true;
|
||||
$log.warn('No ' + $scope.network + ' wallets to make the payment');
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
});
|
||||
return;
|
||||
setNoWallet('No wallets available');
|
||||
return cb();
|
||||
}
|
||||
|
||||
var filteredWallets = [];
|
||||
|
@ -77,8 +95,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
|||
return cb('Could not update any wallet');
|
||||
|
||||
if (lodash.isEmpty(filteredWallets)) {
|
||||
$scope.insufficientFunds = true;
|
||||
$log.warn('No wallet available to make the payment');
|
||||
setNoWallet('Insufficent funds');
|
||||
}
|
||||
$scope.wallets = lodash.clone(filteredWallets);
|
||||
return cb();
|
||||
|
@ -114,7 +131,6 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
|||
$scope.isCordova = isCordova;
|
||||
$scope.showAddress = false;
|
||||
$scope.insufficientFunds = false;
|
||||
$scope.noMatchingWallet = false;
|
||||
$scope.paymentExpired = {
|
||||
value: false
|
||||
};
|
||||
|
@ -122,29 +138,16 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
|||
value: null
|
||||
};
|
||||
|
||||
|
||||
$scope.walletSelectorTitle = gettextCatalog.getString('Send from');
|
||||
|
||||
console.log('[confirm.js.126:tx:]', tx); //TODO
|
||||
|
||||
setWalletSelector(tx.toAmount, function(err) {
|
||||
if (err) {
|
||||
$log.debug('Error updating wallets:' + err);
|
||||
popupService.showAlert(gettextCatalog.getString('Could not update wallets'), bwcError.msg(err), function() {
|
||||
$ionicHistory.nextViewOptions({
|
||||
disableAnimate: true,
|
||||
historyRoot: true
|
||||
});
|
||||
$ionicHistory.clearHistory();
|
||||
$state.go('tabs.send');
|
||||
});
|
||||
return exitWithError('Could not update wallets');
|
||||
}
|
||||
|
||||
$log.debug('Wallet selector is setup');
|
||||
|
||||
if ($scope.wallets.length > 1) {
|
||||
$scope.showWalletSelector();
|
||||
} else {
|
||||
} else if ($scope.wallets.length) {
|
||||
setWallet($scope.wallets[0], tx);
|
||||
}
|
||||
});
|
||||
|
@ -314,15 +317,6 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
|||
};
|
||||
|
||||
|
||||
function resetView() {
|
||||
$scope.displayAmount = $scope.displayUnit = $scope.fee = $scope.feeFiat = $scope.feeRateStr = $scope.alternativeAmountStr = $scope.insufficientFunds = $scope.noMatchingWallet = null;
|
||||
$scope.showAddress = false;
|
||||
|
||||
console.log('[confirm.js.213] RESET'); //TODO
|
||||
};
|
||||
|
||||
|
||||
|
||||
function showSendMaxWarning(sendMaxInfo) {
|
||||
|
||||
function verifyExcludedUtxos() {
|
||||
|
@ -353,7 +347,6 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
|||
};
|
||||
|
||||
function setSendMaxValues(data) {
|
||||
resetView();
|
||||
$scope.amountStr = txFormatService.formatAmountStr(data.amount, true);
|
||||
$scope.displayAmount = getDisplayAmount($scope.amountStr);
|
||||
$scope.displayUnit = getDisplayUnit($scope.amountStr);
|
||||
|
@ -488,7 +481,6 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
|||
|
||||
ongoingProcess.set('creatingTx', true, onSendStatusChange);
|
||||
getTxp(lodash.clone(tx), wallet, false, function(err, txp) {
|
||||
console.log('[confirm.js.490:txp:]',txp); //TODO
|
||||
ongoingProcess.set('creatingTx', false, onSendStatusChange);
|
||||
if (err) return;
|
||||
|
||||
|
@ -534,8 +526,6 @@ console.log('[confirm.js.490:txp:]',txp); //TODO
|
|||
});
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('[confirm.js.541]'); //TODO
|
||||
publishAndSign();
|
||||
});
|
||||
});
|
||||
|
@ -585,27 +575,33 @@ console.log('[confirm.js.541]'); //TODO
|
|||
|
||||
$scope.chooseFeeLevel = function(tx, wallet) {
|
||||
|
||||
$scope.customFeeLevel = tx.feeLevel;
|
||||
|
||||
var scope = $rootScope.$new(true);
|
||||
scope.network = tx.network;
|
||||
scope.feeLevel = tx.feeLevel;
|
||||
scope.noSave = true;
|
||||
|
||||
$ionicModal.fromTemplateUrl('views/modals/chooseFeeLevel.html', {
|
||||
scope: $scope,
|
||||
scope: scope,
|
||||
}).then(function(modal) {
|
||||
$scope.chooseFeeLevelModal = modal;
|
||||
$scope.openModal();
|
||||
scope.chooseFeeLevelModal = modal;
|
||||
scope.openModal();
|
||||
});
|
||||
$scope.openModal = function() {
|
||||
$scope.chooseFeeLevelModal.show();
|
||||
scope.openModal = function() {
|
||||
scope.chooseFeeLevelModal.show();
|
||||
};
|
||||
$scope.hideModal = function(customFeeLevel) {
|
||||
|
||||
scope.hideModal = function(customFeeLevel) {
|
||||
$log.debug('Custom fee level choosen:' + customFeeLevel + ' was:' + tx.feeLevel);
|
||||
if (tx.feeLevel == customFeeLevel)
|
||||
$scope.chooseFeeLevelModal.hide();
|
||||
scope.chooseFeeLevelModal.hide();
|
||||
|
||||
tx.feeLevel = customFeeLevel;
|
||||
updateTx(tx, wallet, {
|
||||
clearCache: true,
|
||||
dryRun: true,
|
||||
}, function() {
|
||||
$scope.chooseFeeLevelModal.hide();
|
||||
scope.chooseFeeLevelModal.hide();
|
||||
});
|
||||
};
|
||||
};
|
||||
|
|
|
@ -2,13 +2,14 @@
|
|||
|
||||
angular.module('copayApp.controllers').controller('preferencesFeeController', function($scope, $timeout, $ionicHistory, lodash, gettextCatalog, configService, feeService, ongoingProcess, popupService) {
|
||||
|
||||
$scope.save = function(newFee) {
|
||||
var network;
|
||||
|
||||
if ($scope.customFeeLevel) {
|
||||
$scope.save = function(newFee) {
|
||||
$scope.currentFeeLevel = newFee;
|
||||
updateCurrentValues();
|
||||
|
||||
if ($scope.noSave)
|
||||
return;
|
||||
}
|
||||
|
||||
var opts = {
|
||||
wallet: {
|
||||
|
@ -20,8 +21,6 @@ angular.module('copayApp.controllers').controller('preferencesFeeController', fu
|
|||
|
||||
configService.set(opts, function(err) {
|
||||
if (err) $log.debug(err);
|
||||
$scope.currentFeeLevel = newFee;
|
||||
updateCurrentValues();
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
});
|
||||
|
@ -33,8 +32,10 @@ angular.module('copayApp.controllers').controller('preferencesFeeController', fu
|
|||
});
|
||||
|
||||
$scope.init = function() {
|
||||
|
||||
$scope.network = $scope.network || 'livenet';
|
||||
$scope.feeOpts = feeService.feeOpts;
|
||||
$scope.currentFeeLevel = $scope.customFeeLevel ? $scope.customFeeLevel : feeService.getCurrentFeeLevel();
|
||||
$scope.currentFeeLevel = $scope.feeLevel || feeService.getCurrentFeeLevel();
|
||||
$scope.loadingFee = true;
|
||||
feeService.getFeeLevels(function(err, levels) {
|
||||
$scope.loadingFee = false;
|
||||
|
@ -51,16 +52,19 @@ angular.module('copayApp.controllers').controller('preferencesFeeController', fu
|
|||
|
||||
var updateCurrentValues = function() {
|
||||
if (lodash.isEmpty($scope.feeLevels) || lodash.isEmpty($scope.currentFeeLevel)) return;
|
||||
var feeLevelValue = lodash.find($scope.feeLevels['livenet'], {
|
||||
|
||||
var value = lodash.find($scope.feeLevels[$scope.network], {
|
||||
level: $scope.currentFeeLevel
|
||||
});
|
||||
if (lodash.isEmpty(feeLevelValue)) {
|
||||
|
||||
if (lodash.isEmpty(value)) {
|
||||
$scope.feePerSatByte = null;
|
||||
$scope.avgConfirmationTime = null;
|
||||
return;
|
||||
}
|
||||
$scope.feePerSatByte = (feeLevelValue.feePerKB / 1000).toFixed();
|
||||
$scope.avgConfirmationTime = feeLevelValue.nbBlocks * 10;
|
||||
|
||||
$scope.feePerSatByte = (value.feePerKB / 1000).toFixed();
|
||||
$scope.avgConfirmationTime = value.nbBlocks * 10;
|
||||
};
|
||||
|
||||
$scope.chooseNewFee = function() {
|
||||
|
|
|
@ -8,9 +8,7 @@ angular.module('copayApp.directives')
|
|||
transclude: true,
|
||||
scope: {
|
||||
sendStatus: '=clickSendStatus',
|
||||
hasWalletChosen: '=hasWalletChosen',
|
||||
insufficientFunds: '=insufficientFunds',
|
||||
noMatchingWallet: '=noMatchingWallet'
|
||||
isDisabled: '=isDisabled',
|
||||
},
|
||||
link: function(scope, element, attrs) {
|
||||
scope.$watch('sendStatus', function() {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
</ion-nav-back-button>
|
||||
</ion-nav-bar>
|
||||
|
||||
<ion-content ng-class="{'add-bottom-for-cta': !insufficientFunds && !noMatchingWallet}">
|
||||
<ion-content ng-class="{'add-bottom-for-cta': !wallet}">
|
||||
<div class="list">
|
||||
<div class="item head">
|
||||
<div class="sending-label">
|
||||
|
@ -61,7 +61,7 @@
|
|||
<span ng-if="tx.toName && showAddress">{{tx.toAddress}}</span>
|
||||
</div>
|
||||
</div>
|
||||
<a class="item item-icon-right" ng-hide="!tx.sendMax && (insufficientFunds || noMatchingWallet)" ng-click="showWalletSelector()">
|
||||
<a class="item item-icon-right" ng-hide="!tx.sendMax ||!wallet" ng-click="showWalletSelector()">
|
||||
<span class="label" translate>From</span>
|
||||
<div class="wallet" ng-if="wallet">
|
||||
<i class="icon big-icon-svg">
|
||||
|
@ -77,26 +77,23 @@
|
|||
</div>
|
||||
<i class="icon bp-arrow-right"></i>
|
||||
</a>
|
||||
<div class="item item-icon-right" ng-if="!insufficientFunds && !noMatchingWallet" ng-click="chooseFeeLevel(tx, wallet)">
|
||||
<div class="item item-icon-right" ng-if="wallet" ng-click="chooseFeeLevel(tx, wallet)">
|
||||
<span class="label">{{'Fee:' | translate}} {{tx.feeLevelName | translate}}</span>
|
||||
<span class="m10l">{{tx.txp[wallet.id].feeStr || '...'}}</span>
|
||||
<span class="item-note m10l">
|
||||
<span>{{tx.txp[wallet.id].alternativeFeeStr || '...'}} <span class="fee-rate" ng-if="tx.feeRatePerStr" translate>- {{tx.txp[wallet.id].feeRatePerStr}} of the transaction</span></span>
|
||||
<span>{{tx.txp[wallet.id].alternativeFeeStr || '...'}} <span class="fee-rate" ng-if="tx.txp[wallet.id].feeRatePerStr" translate>- {{tx.txp[wallet.id].feeRatePerStr}} of the transaction</span></span>
|
||||
</span>
|
||||
<i class="icon bp-arrow-right"></i>
|
||||
</div>
|
||||
<a class="item item-icon-right" ng-if="!insufficientFunds && !noMatchingWallet" ng-click="showDescriptionPopup(tx)">
|
||||
<a class="item item-icon-right" ng-if="wallet" ng-click="showDescriptionPopup(tx)">
|
||||
<span class="label" translate>Add Memo</span>
|
||||
<span class="item-note m10l">
|
||||
{{tx.description}}
|
||||
</span>
|
||||
<i class="icon bp-arrow-right"></i>
|
||||
</a>
|
||||
<div class="text-center" ng-show="noMatchingWallet">
|
||||
<span class="badge badge-energized" translate>No wallets available</span>
|
||||
</div>
|
||||
<div class="text-center" ng-show="insufficientFunds">
|
||||
<span class="badge badge-energized" translate>Insufficient funds</span>
|
||||
<div class="text-center" ng-show="!wallet">
|
||||
<span class="badge badge-energized">{{noWalletMessage}}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -105,18 +102,14 @@
|
|||
ng-click="approve(tx, wallet, statusChangeHandler)"
|
||||
ng-if="!isCordova"
|
||||
click-send-status="sendStatus"
|
||||
has-wallet-chosen="wallet"
|
||||
insufficient-funds="insufficientFunds"
|
||||
no-matching-wallet="noMatchingWallet">
|
||||
is-disabled="!wallet">
|
||||
{{buttonText}}
|
||||
</click-to-accept>
|
||||
<slide-to-accept
|
||||
ng-if="isCordova && (wallet && !insufficientFunds && !noMatchingWallet)"
|
||||
ng-if="isCordova && wallet"
|
||||
slide-on-confirm="onConfirm()"
|
||||
slide-send-status="sendStatus"
|
||||
has-wallet-chosen="wallet"
|
||||
insufficient-funds="insufficientFunds"
|
||||
no-matching-wallet="noMatchingWallet">
|
||||
is-disabled="!wallet">
|
||||
{{buttonText}}
|
||||
</slide-to-accept>
|
||||
<slide-to-accept-success
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<button ng-disabled="!hasWalletChosen || insufficientFunds || noMatchingWallet" class="click-to-accept__button button button-standard button-primary" ng-class="{disable: sendStatus}">
|
||||
<button ng-disabled="isDisabled" class="click-to-accept__button button button-standard button-primary" ng-class="{disable: sendStatus}">
|
||||
<span ng-if="!sendStatus">
|
||||
<ng-transclude></ng-transclude>
|
||||
</span>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<ion-modal-view id="settings-fee" class="settings" ng-controller="preferencesFeeController" ng-init="init()">
|
||||
<ion-modal-view id="settings-fee" class="settings" ng-controller="preferencesFeeController" >
|
||||
<ion-header-bar align-title="center" class="bar-royal">
|
||||
<button class="button button-clear" ng-click="hideModal()">
|
||||
Close
|
||||
|
@ -7,7 +7,7 @@
|
|||
{{'Bitcoin Network Fee Policy'|translate}}
|
||||
</div>
|
||||
</ion-header-bar>
|
||||
<ion-content>
|
||||
<ion-content ng-init="init(network)">
|
||||
<div class="settings-explanation">
|
||||
<div class="estimates">
|
||||
<div>
|
||||
|
@ -20,6 +20,7 @@
|
|||
<span class="fee-rate" ng-if="feePerSatByte">{{feePerSatByte}} satoshis/byte</span>
|
||||
<span ng-if="loadingFee">...</span>
|
||||
</div>
|
||||
<div ng-if="network!='livenet'">[{{network}}]</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="fee-policies">
|
||||
|
@ -28,7 +29,10 @@
|
|||
</ion-radio>
|
||||
</div>
|
||||
<div class="m20t">
|
||||
<button class="button button-standard button-primary" ng-click="chooseNewFee()" translate>Save</button>
|
||||
<button class="button button-standard button-primary" ng-click="chooseNewFee()" >
|
||||
<span translate ng-if="!noSave">Save</span>
|
||||
<span translate ng-if="noSave">OK</span>
|
||||
</button>
|
||||
</div>
|
||||
</ion-content>
|
||||
</ion-modal-view>
|
||||
|
|
Loading…
Reference in New Issue