better fee service

This commit is contained in:
Matias Alejo Garcia 2017-06-21 17:09:33 -03:00
parent 442e64c20c
commit 5745340400
No known key found for this signature in database
GPG Key ID: 02470DB551277AB3
6 changed files with 77 additions and 82 deletions

View File

@ -34,6 +34,28 @@ angular.module('copayApp.controllers').controller('confirmController', function(
$ionicConfig.views.swipeBackEnabled(false); $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) { $scope.$on("$ionicView.beforeEnter", function(event, data) {
function setWalletSelector(minAmount, cb) { function setWalletSelector(minAmount, cb) {
@ -44,12 +66,8 @@ angular.module('copayApp.controllers').controller('confirmController', function(
}); });
if (!$scope.wallets || !$scope.wallets.length) { if (!$scope.wallets || !$scope.wallets.length) {
$scope.noMatchingWallet = true; setNoWallet('No wallets available');
$log.warn('No ' + $scope.network + ' wallets to make the payment'); return cb();
$timeout(function() {
$scope.$apply();
});
return;
} }
var filteredWallets = []; var filteredWallets = [];
@ -77,8 +95,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
return cb('Could not update any wallet'); return cb('Could not update any wallet');
if (lodash.isEmpty(filteredWallets)) { if (lodash.isEmpty(filteredWallets)) {
$scope.insufficientFunds = true; setNoWallet('Insufficent funds');
$log.warn('No wallet available to make the payment');
} }
$scope.wallets = lodash.clone(filteredWallets); $scope.wallets = lodash.clone(filteredWallets);
return cb(); return cb();
@ -114,7 +131,6 @@ angular.module('copayApp.controllers').controller('confirmController', function(
$scope.isCordova = isCordova; $scope.isCordova = isCordova;
$scope.showAddress = false; $scope.showAddress = false;
$scope.insufficientFunds = false; $scope.insufficientFunds = false;
$scope.noMatchingWallet = false;
$scope.paymentExpired = { $scope.paymentExpired = {
value: false value: false
}; };
@ -122,29 +138,16 @@ angular.module('copayApp.controllers').controller('confirmController', function(
value: null value: null
}; };
$scope.walletSelectorTitle = gettextCatalog.getString('Send from'); $scope.walletSelectorTitle = gettextCatalog.getString('Send from');
console.log('[confirm.js.126:tx:]', tx); //TODO
setWalletSelector(tx.toAmount, function(err) { setWalletSelector(tx.toAmount, function(err) {
if (err) { if (err) {
$log.debug('Error updating wallets:' + err); return exitWithError('Could not update wallets');
popupService.showAlert(gettextCatalog.getString('Could not update wallets'), bwcError.msg(err), function() {
$ionicHistory.nextViewOptions({
disableAnimate: true,
historyRoot: true
});
$ionicHistory.clearHistory();
$state.go('tabs.send');
});
} }
$log.debug('Wallet selector is setup');
if ($scope.wallets.length > 1) { if ($scope.wallets.length > 1) {
$scope.showWalletSelector(); $scope.showWalletSelector();
} else { } else if ($scope.wallets.length) {
setWallet($scope.wallets[0], tx); 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 showSendMaxWarning(sendMaxInfo) {
function verifyExcludedUtxos() { function verifyExcludedUtxos() {
@ -353,7 +347,6 @@ angular.module('copayApp.controllers').controller('confirmController', function(
}; };
function setSendMaxValues(data) { function setSendMaxValues(data) {
resetView();
$scope.amountStr = txFormatService.formatAmountStr(data.amount, true); $scope.amountStr = txFormatService.formatAmountStr(data.amount, true);
$scope.displayAmount = getDisplayAmount($scope.amountStr); $scope.displayAmount = getDisplayAmount($scope.amountStr);
$scope.displayUnit = getDisplayUnit($scope.amountStr); $scope.displayUnit = getDisplayUnit($scope.amountStr);
@ -488,7 +481,6 @@ angular.module('copayApp.controllers').controller('confirmController', function(
ongoingProcess.set('creatingTx', true, onSendStatusChange); ongoingProcess.set('creatingTx', true, onSendStatusChange);
getTxp(lodash.clone(tx), wallet, false, function(err, txp) { getTxp(lodash.clone(tx), wallet, false, function(err, txp) {
console.log('[confirm.js.490:txp:]',txp); //TODO
ongoingProcess.set('creatingTx', false, onSendStatusChange); ongoingProcess.set('creatingTx', false, onSendStatusChange);
if (err) return; if (err) return;
@ -534,8 +526,6 @@ console.log('[confirm.js.490:txp:]',txp); //TODO
}); });
return; return;
} }
console.log('[confirm.js.541]'); //TODO
publishAndSign(); publishAndSign();
}); });
}); });
@ -585,27 +575,33 @@ console.log('[confirm.js.541]'); //TODO
$scope.chooseFeeLevel = function(tx, wallet) { $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', { $ionicModal.fromTemplateUrl('views/modals/chooseFeeLevel.html', {
scope: $scope, scope: scope,
}).then(function(modal) { }).then(function(modal) {
$scope.chooseFeeLevelModal = modal; scope.chooseFeeLevelModal = modal;
$scope.openModal(); scope.openModal();
}); });
$scope.openModal = function() { scope.openModal = function() {
$scope.chooseFeeLevelModal.show(); scope.chooseFeeLevelModal.show();
}; };
$scope.hideModal = function(customFeeLevel) {
scope.hideModal = function(customFeeLevel) {
$log.debug('Custom fee level choosen:' + customFeeLevel + ' was:' + tx.feeLevel); $log.debug('Custom fee level choosen:' + customFeeLevel + ' was:' + tx.feeLevel);
if (tx.feeLevel == customFeeLevel) if (tx.feeLevel == customFeeLevel)
$scope.chooseFeeLevelModal.hide(); scope.chooseFeeLevelModal.hide();
tx.feeLevel = customFeeLevel; tx.feeLevel = customFeeLevel;
updateTx(tx, wallet, { updateTx(tx, wallet, {
clearCache: true, clearCache: true,
dryRun: true, dryRun: true,
}, function() { }, function() {
$scope.chooseFeeLevelModal.hide(); scope.chooseFeeLevelModal.hide();
}); });
}; };
}; };

View File

@ -2,13 +2,14 @@
angular.module('copayApp.controllers').controller('preferencesFeeController', function($scope, $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) { var network;
if ($scope.customFeeLevel) { $scope.save = function(newFee) {
$scope.currentFeeLevel = newFee; $scope.currentFeeLevel = newFee;
updateCurrentValues(); updateCurrentValues();
if ($scope.noSave)
return; return;
}
var opts = { var opts = {
wallet: { wallet: {
@ -20,8 +21,6 @@ angular.module('copayApp.controllers').controller('preferencesFeeController', fu
configService.set(opts, function(err) { configService.set(opts, function(err) {
if (err) $log.debug(err); if (err) $log.debug(err);
$scope.currentFeeLevel = newFee;
updateCurrentValues();
$timeout(function() { $timeout(function() {
$scope.$apply(); $scope.$apply();
}); });
@ -33,8 +32,10 @@ angular.module('copayApp.controllers').controller('preferencesFeeController', fu
}); });
$scope.init = function() { $scope.init = function() {
$scope.network = $scope.network || 'livenet';
$scope.feeOpts = feeService.feeOpts; $scope.feeOpts = feeService.feeOpts;
$scope.currentFeeLevel = $scope.customFeeLevel ? $scope.customFeeLevel : feeService.getCurrentFeeLevel(); $scope.currentFeeLevel = $scope.feeLevel || feeService.getCurrentFeeLevel();
$scope.loadingFee = true; $scope.loadingFee = true;
feeService.getFeeLevels(function(err, levels) { feeService.getFeeLevels(function(err, levels) {
$scope.loadingFee = false; $scope.loadingFee = false;
@ -51,16 +52,19 @@ angular.module('copayApp.controllers').controller('preferencesFeeController', fu
var updateCurrentValues = function() { var updateCurrentValues = function() {
if (lodash.isEmpty($scope.feeLevels) || lodash.isEmpty($scope.currentFeeLevel)) return; 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 level: $scope.currentFeeLevel
}); });
if (lodash.isEmpty(feeLevelValue)) {
if (lodash.isEmpty(value)) {
$scope.feePerSatByte = null; $scope.feePerSatByte = null;
$scope.avgConfirmationTime = null; $scope.avgConfirmationTime = null;
return; 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() { $scope.chooseNewFee = function() {

View File

@ -8,9 +8,7 @@ angular.module('copayApp.directives')
transclude: true, transclude: true,
scope: { scope: {
sendStatus: '=clickSendStatus', sendStatus: '=clickSendStatus',
hasWalletChosen: '=hasWalletChosen', isDisabled: '=isDisabled',
insufficientFunds: '=insufficientFunds',
noMatchingWallet: '=noMatchingWallet'
}, },
link: function(scope, element, attrs) { link: function(scope, element, attrs) {
scope.$watch('sendStatus', function() { scope.$watch('sendStatus', function() {

View File

@ -7,7 +7,7 @@
</ion-nav-back-button> </ion-nav-back-button>
</ion-nav-bar> </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="list">
<div class="item head"> <div class="item head">
<div class="sending-label"> <div class="sending-label">
@ -61,7 +61,7 @@
<span ng-if="tx.toName && showAddress">{{tx.toAddress}}</span> <span ng-if="tx.toName && showAddress">{{tx.toAddress}}</span>
</div> </div>
</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> <span class="label" translate>From</span>
<div class="wallet" ng-if="wallet"> <div class="wallet" ng-if="wallet">
<i class="icon big-icon-svg"> <i class="icon big-icon-svg">
@ -77,26 +77,23 @@
</div> </div>
<i class="icon bp-arrow-right"></i> <i class="icon bp-arrow-right"></i>
</a> </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="label">{{'Fee:' | translate}} {{tx.feeLevelName | translate}}</span>
<span class="m10l">{{tx.txp[wallet.id].feeStr || '...'}}</span> <span class="m10l">{{tx.txp[wallet.id].feeStr || '...'}}</span>
<span class="item-note m10l"> <span class="item-note m10l">
<span>{{tx.txp[wallet.id].alternativeFeeStr || '...'}}&nbsp;<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 || '...'}}&nbsp;<span class="fee-rate" ng-if="tx.txp[wallet.id].feeRatePerStr" translate>- {{tx.txp[wallet.id].feeRatePerStr}} of the transaction</span></span>
</span> </span>
<i class="icon bp-arrow-right"></i> <i class="icon bp-arrow-right"></i>
</div> </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="label" translate>Add Memo</span>
<span class="item-note m10l"> <span class="item-note m10l">
{{tx.description}} {{tx.description}}
</span> </span>
<i class="icon bp-arrow-right"></i> <i class="icon bp-arrow-right"></i>
</a> </a>
<div class="text-center" ng-show="noMatchingWallet"> <div class="text-center" ng-show="!wallet">
<span class="badge badge-energized" translate>No wallets available</span> <span class="badge badge-energized">{{noWalletMessage}}</span>
</div>
<div class="text-center" ng-show="insufficientFunds">
<span class="badge badge-energized" translate>Insufficient funds</span>
</div> </div>
</div> </div>
</div> </div>
@ -105,18 +102,14 @@
ng-click="approve(tx, wallet, statusChangeHandler)" ng-click="approve(tx, wallet, statusChangeHandler)"
ng-if="!isCordova" ng-if="!isCordova"
click-send-status="sendStatus" click-send-status="sendStatus"
has-wallet-chosen="wallet" is-disabled="!wallet">
insufficient-funds="insufficientFunds"
no-matching-wallet="noMatchingWallet">
{{buttonText}} {{buttonText}}
</click-to-accept> </click-to-accept>
<slide-to-accept <slide-to-accept
ng-if="isCordova && (wallet && !insufficientFunds && !noMatchingWallet)" ng-if="isCordova && wallet"
slide-on-confirm="onConfirm()" slide-on-confirm="onConfirm()"
slide-send-status="sendStatus" slide-send-status="sendStatus"
has-wallet-chosen="wallet" is-disabled="!wallet">
insufficient-funds="insufficientFunds"
no-matching-wallet="noMatchingWallet">
{{buttonText}} {{buttonText}}
</slide-to-accept> </slide-to-accept>
<slide-to-accept-success <slide-to-accept-success

View File

@ -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"> <span ng-if="!sendStatus">
<ng-transclude></ng-transclude> <ng-transclude></ng-transclude>
</span> </span>

View File

@ -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"> <ion-header-bar align-title="center" class="bar-royal">
<button class="button button-clear" ng-click="hideModal()"> <button class="button button-clear" ng-click="hideModal()">
Close Close
@ -7,7 +7,7 @@
{{'Bitcoin Network Fee Policy'|translate}} {{'Bitcoin Network Fee Policy'|translate}}
</div> </div>
</ion-header-bar> </ion-header-bar>
<ion-content> <ion-content ng-init="init(network)">
<div class="settings-explanation"> <div class="settings-explanation">
<div class="estimates"> <div class="estimates">
<div> <div>
@ -20,6 +20,7 @@
<span class="fee-rate" ng-if="feePerSatByte">{{feePerSatByte}} satoshis/byte</span> <span class="fee-rate" ng-if="feePerSatByte">{{feePerSatByte}} satoshis/byte</span>
<span ng-if="loadingFee">...</span> <span ng-if="loadingFee">...</span>
</div> </div>
<div ng-if="network!='livenet'">[{{network}}]</span>
</div> </div>
</div> </div>
<div class="fee-policies"> <div class="fee-policies">
@ -28,7 +29,10 @@
</ion-radio> </ion-radio>
</div> </div>
<div class="m20t"> <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> </div>
</ion-content> </ion-content>
</ion-modal-view> </ion-modal-view>