fix wallet selector - use fee instead of feePerKb

This commit is contained in:
Javier 2016-11-29 11:05:55 -03:00
commit e82cc38c8d
2 changed files with 22 additions and 17 deletions

View file

@ -23,6 +23,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
giftCardUUID = data.stateParams.giftCardUUID; giftCardUUID = data.stateParams.giftCardUUID;
toAmount = data.stateParams.toAmount; toAmount = data.stateParams.toAmount;
cachedSendMax = {};
$scope.useSendMax = data.stateParams.useSendMax == 'true' ? true : false; $scope.useSendMax = data.stateParams.useSendMax == 'true' ? true : false;
$scope.isWallet = data.stateParams.isWallet; $scope.isWallet = data.stateParams.isWallet;
$scope.cardId = data.stateParams.cardId; $scope.cardId = data.stateParams.cardId;
@ -44,9 +45,6 @@ angular.module('copayApp.controllers').controller('confirmController', function(
$scope.feeLevel = config.settings && config.settings.feeLevel ? config.settings.feeLevel : 'normal'; $scope.feeLevel = config.settings && config.settings.feeLevel ? config.settings.feeLevel : 'normal';
$scope.network = (new bitcore.Address($scope.toAddress)).network.name; $scope.network = (new bitcore.Address($scope.toAddress)).network.name;
setwallets(); setwallets();
if ($scope.useSendMax) $scope.showWalletSelector();
else initConfirm();
}); });
function setwallets() { function setwallets() {
@ -56,11 +54,8 @@ angular.module('copayApp.controllers').controller('confirmController', function(
n: $scope.isGiftCard ? true : false n: $scope.isGiftCard ? true : false
}); });
if (!$scope.wallets || !$scope.wallets.length) { if (!$scope.wallets || !$scope.wallets.length)
$scope.noMatchingWallet = true; $scope.noMatchingWallet = true;
} else {
$scope.wallet = $scope.wallets[0];
}
var filteredWallets = []; var filteredWallets = [];
var index = 0; var index = 0;
@ -82,17 +77,18 @@ angular.module('copayApp.controllers').controller('confirmController', function(
if (++index == $scope.wallets.length) { if (++index == $scope.wallets.length) {
if (!lodash.isEmpty(filteredWallets)) { if (!lodash.isEmpty(filteredWallets)) {
$scope.wallets = lodash.clone(filteredWallets); $scope.wallets = lodash.clone(filteredWallets);
if (!$scope.useSendMax) setWallet($scope.wallets[0]); if ($scope.useSendMax) $scope.showWalletSelector();
else initConfirm();
} else { } else {
if (!enoughFunds) $scope.insufficientFunds = true; if (!enoughFunds) $scope.insufficientFunds = true;
$log.warn('No wallet available to make the payment'); $log.warn('No wallet available to make the payment');
} }
$timeout(function() {
$scope.$apply();
});
} }
}); });
}); });
$timeout(function() {
$scope.$apply();
});
}; };
var initConfirm = function() { var initConfirm = function() {
@ -107,13 +103,18 @@ angular.module('copayApp.controllers').controller('confirmController', function(
if ($scope.paypro) _paymentTimeControl($scope.paypro.expires); if ($scope.paypro) _paymentTimeControl($scope.paypro.expires);
$scope.showWalletSelector();
$timeout(function() { $timeout(function() {
$scope.$apply(); $scope.$apply();
}); });
}; };
function resetValues() {
$scope.displayAmount = $scope.displayUnit = $scope.fee = $scope.alternativeAmountStr = $scope.insufficientFunds = $scope.noMatchingWallet = null;
};
$scope.getSendMaxInfo = function() { $scope.getSendMaxInfo = function() {
$scope.displayAmount = $scope.displayUnit = $scope.fee = $scope.alternativeAmountStr = null; resetValues();
ongoingProcess.set('gettingFeeLevels', true); ongoingProcess.set('gettingFeeLevels', true);
feeService.getCurrentFeeValue($scope.network, function(err, feePerKb) { feeService.getCurrentFeeValue($scope.network, function(err, feePerKb) {
@ -192,6 +193,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
}; };
function setSendMaxValues(data) { function setSendMaxValues(data) {
resetValues();
var config = configService.getSync().wallet; var config = configService.getSync().wallet;
var unitName = config.settings.unitName; var unitName = config.settings.unitName;
var unitToSatoshi = config.settings.unitToSatoshi; var unitToSatoshi = config.settings.unitToSatoshi;
@ -205,6 +207,9 @@ angular.module('copayApp.controllers').controller('confirmController', function(
txFormatService.formatAlternativeStr(data.amount, function(v) { txFormatService.formatAlternativeStr(data.amount, function(v) {
$scope.alternativeAmountStr = v; $scope.alternativeAmountStr = v;
}); });
$timeout(function() {
$scope.$apply();
});
}; };
$scope.$on('accepted', function(event) { $scope.$on('accepted', function(event) {
@ -212,7 +217,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
}); });
$scope.showWalletSelector = function() { $scope.showWalletSelector = function() {
if ($scope.insufficientFunds || $scope.noMatchingWallet) return; if (!$scope.useSendMax && ($scope.insufficientFunds || $scope.noMatchingWallet)) return;
$scope.showWallets = true; $scope.showWallets = true;
}; };
@ -239,7 +244,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
if (typeof res != 'undefined') $scope.description = res; if (typeof res != 'undefined') $scope.description = res;
$timeout(function() { $timeout(function() {
$scope.$apply(); $scope.$apply();
}, 100); });
}); });
}; };
@ -316,7 +321,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
$timeout(function() { $timeout(function() {
$scope.$apply(); $scope.$apply();
}); });
popupService.showAlert(gettextCatalog.getString('Error at confirm:'), msg); popupService.showAlert(gettextCatalog.getString('Error at confirm'), msg);
}; };
function apply(txp) { function apply(txp) {
@ -362,7 +367,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
if ($scope.sendMaxInfo) { if ($scope.sendMaxInfo) {
txp.inputs = $scope.sendMaxInfo.inputs; txp.inputs = $scope.sendMaxInfo.inputs;
txp.feePerKb = $scope.sendMaxInfo.feePerKb; txp.fee = $scope.sendMaxInfo.fee;
} else } else
txp.feeLevel = config.settings && config.settings.feeLevel ? config.settings.feeLevel : 'normal'; txp.feeLevel = config.settings && config.settings.feeLevel ? config.settings.feeLevel : 'normal';

View file

@ -50,7 +50,7 @@
<span ng-if="tx.hasMultiplesOutputs" translate>Multiple recipients</span> --> <span ng-if="tx.hasMultiplesOutputs" translate>Multiple recipients</span> -->
</span> </span>
</div> </div>
<a class="item item-icon-right" ng-hide="insufficientFunds || noMatchingWallet" ng-click="showWalletSelector()"> <a class="item item-icon-right" ng-hide="!useSendMax && (insufficientFunds || noMatchingWallet)" ng-click="showWalletSelector()">
<span class="label" translate>From</span> <span class="label" translate>From</span>
<div class="wallet"> <div class="wallet">
<i class="icon big-icon-svg"> <i class="icon big-icon-svg">