use cached values

This commit is contained in:
Javier 2016-11-25 15:59:44 -03:00
commit 3d4f216b41
2 changed files with 28 additions and 14 deletions

View file

@ -10,6 +10,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
var giftCardAccessKey; var giftCardAccessKey;
var giftCardInvoiceTime; var giftCardInvoiceTime;
var giftCardUUID; var giftCardUUID;
var cachedSendMax = {};
$scope.isCordova = platformInfo.isCordova; $scope.isCordova = platformInfo.isCordova;
$ionicConfig.views.swipeBackEnabled(false); $ionicConfig.views.swipeBackEnabled(false);
@ -22,7 +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;
$scope.useSendMax = data.stateParams.useSendMax; $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;
$scope.toAddress = data.stateParams.toAddress; $scope.toAddress = data.stateParams.toAddress;
@ -116,12 +117,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
popupService.showAlert(gettextCatalog.getString('Error'), err.message); popupService.showAlert(gettextCatalog.getString('Error'), err.message);
return; return;
} }
var config = configService.getSync().wallet; var config = configService.getSync().wallet;
var unitName = config.settings.unitName;
var unitToSatoshi = config.settings.unitToSatoshi;
var satToUnit = 1 / unitToSatoshi;
var unitDecimals = config.settings.unitDecimals;
ongoingProcess.set('retrievingInputs', true); ongoingProcess.set('retrievingInputs', true);
walletService.getSendMaxInfo($scope.wallet, { walletService.getSendMaxInfo($scope.wallet, {
@ -144,11 +140,15 @@ angular.module('copayApp.controllers').controller('confirmController', function(
$scope.sendMaxInfo = { $scope.sendMaxInfo = {
sendMax: true, sendMax: true,
amount: resp.amount,
inputs: resp.inputs, inputs: resp.inputs,
fee: resp.fee, fee: resp.fee,
feePerKb: feePerKb, feePerKb: feePerKb,
}; };
cachedSendMax[$scope.wallet.id] = $scope.sendMaxInfo;
var unitName = config.settings.unitName;
var msg = gettextCatalog.getString("{{fee}} will be deducted for bitcoin networking fees", { var msg = gettextCatalog.getString("{{fee}} will be deducted for bitcoin networking fees", {
fee: txFormatService.formatAmount(resp.fee) + ' ' + unitName fee: txFormatService.formatAmount(resp.fee) + ' ' + unitName
}); });
@ -158,13 +158,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
msg += '. \n' + warningMsg; msg += '. \n' + warningMsg;
popupService.showAlert(null, msg, function() { popupService.showAlert(null, msg, function() {
$scope.displayAmount = txFormatService.formatAmount(resp.amount, true); setSendMaxValues(resp);
$scope.displayUnit = unitName;
$scope.fee = txFormatService.formatAmount($scope.sendMaxInfo.fee) + ' ' + unitName;
toAmount = parseFloat((resp.amount * satToUnit).toFixed(unitDecimals));
txFormatService.formatAlternativeStr(resp.amount, function(v) {
$scope.alternativeAmountStr = v;
});
createTx($scope.wallet, true, function(err, txp) { createTx($scope.wallet, true, function(err, txp) {
if (err) return; if (err) return;
@ -192,6 +186,22 @@ angular.module('copayApp.controllers').controller('confirmController', function(
}); });
}; };
function setSendMaxValues(data) {
var config = configService.getSync().wallet;
var unitName = config.settings.unitName;
var unitToSatoshi = config.settings.unitToSatoshi;
var satToUnit = 1 / unitToSatoshi;
var unitDecimals = config.settings.unitDecimals;
$scope.displayAmount = txFormatService.formatAmount(data.amount, true);
$scope.displayUnit = unitName;
$scope.fee = txFormatService.formatAmount(data.fee) + ' ' + unitName;
toAmount = parseFloat((data.amount * satToUnit).toFixed(unitDecimals));
txFormatService.formatAlternativeStr(data.amount, function(v) {
$scope.alternativeAmountStr = v;
});
};
$scope.$on('accepted', function(event) { $scope.$on('accepted', function(event) {
$scope.approve(); $scope.approve();
}); });
@ -203,6 +213,11 @@ angular.module('copayApp.controllers').controller('confirmController', function(
$scope.onWalletSelect = function(wallet) { $scope.onWalletSelect = function(wallet) {
if ($scope.useSendMax) { if ($scope.useSendMax) {
$scope.wallet = wallet; $scope.wallet = wallet;
if (cachedSendMax[wallet.id]) {
$log.debug('Send max cached for wallet:', wallet.id);
setSendMaxValues(cachedSendMax[wallet.id]);
return;
}
$scope.getSendMaxInfo(); $scope.getSendMaxInfo();
} else } else
setWallet(wallet); setWallet(wallet);

View file

@ -38,7 +38,6 @@
@import "includes/tx-details"; @import "includes/tx-details";
@import "includes/txp-details"; @import "includes/txp-details";
@import "includes/tx-status"; @import "includes/tx-status";
@import "includes/sendMaxSelector";
@import "includes/walletSelector"; @import "includes/walletSelector";
@import "integrations/coinbase"; @import "integrations/coinbase";
@import "integrations/glidera"; @import "integrations/glidera";