set send max

This commit is contained in:
Javier 2016-11-23 11:23:19 -03:00
commit 1687669149
11 changed files with 249 additions and 171 deletions

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('amountController', function($rootScope, $scope, $filter, $timeout, $ionicScrollDelegate, gettextCatalog, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, txFormatService, ongoingProcess, bitpayCardService, popupService, bwcError, payproService, amazonService, profileService, bitcore, walletService, feeService) {
angular.module('copayApp.controllers').controller('amountController', function($scope, $filter, $timeout, $ionicScrollDelegate, gettextCatalog, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, txFormatService, ongoingProcess, bitpayCardService, popupService, bwcError, payproService, profileService, bitcore, amazonService) {
var unitToSatoshi;
var satToUnit;
var unitDecimals;
@ -53,8 +53,7 @@ angular.module('copayApp.controllers').controller('amountController', function($
$timeout(function() {
$scope.$apply();
}, 10);
});
});
var config = configService.getSync().wallet.settings;
@ -78,74 +77,22 @@ angular.module('copayApp.controllers').controller('amountController', function($
$timeout(function() {
$ionicScrollDelegate.resize();
}, 10);
});
});
$scope.getSendMaxInfo = function(wallet) {
ongoingProcess.set('gettingFeeLevels', true);
feeService.getCurrentFeeValue($scope.network, function(err, fee) {
ongoingProcess.set('gettingFeeLevels', false);
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err.message);
return;
}
var config = configService.getSync();
ongoingProcess.set('retrivingInputs', true);
walletService.getSendMaxInfo(wallet, {
feePerKb: fee,
excludeUnconfirmedUtxos: !config.wallet.spendUnconfirmed,
returnInputs: true,
}, function(err, resp) {
ongoingProcess.set('retrivingInputs', false);
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err);
return;
}
if (resp.amount == 0) {
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Not enough funds for fee'));
return;
}
var msg = gettextCatalog.getString("{{fee}} will be deducted for bitcoin networking fees", {
fee: txFormatService.formatAmount(resp.fee) + ' ' + $scope.unitName
});
var warningMsg = verifyExcludedUtxos();
if (!lodash.isEmpty(warningMsg))
msg += '. \n' + warningMsg;
popupService.showConfirm(null, msg, 'Ok', gettextCatalog.getString('Cancel'), function(result) {
if (!result) return;
var amount = (resp.amount * satToUnit).toFixed(0);
$scope.amount = amount;
processAmount(amount);
});
function verifyExcludedUtxos() {
var warningMsg = [];
if (resp.utxosBelowFee > 0) {
warningMsg.push(gettextCatalog.getString("A total of {{amountBelowFeeStr}} were excluded. These funds come from UTXOs smaller than the network fee provided.", {
amountBelowFeeStr: txFormatService.formatAmount(resp.amountBelowFee) + ' ' + $scope.unitName
}));
}
if (resp.utxosAboveMaxSize > 0) {
warningMsg.push(gettextCatalog.getString("A total of {{amountAboveMaxSizeStr}} were excluded. The maximum size allowed for a transaction was exceeded", {
amountAboveMaxSizeStr: txFormatService.formatAmount(resp.amountAboveMaxSize) + ' ' + $scope.unitName
}));
}
return warningMsg.join('\n');
};
});
});
$scope.showSendMaxSelector = function() {
$scope.sendMax = true;
};
$scope.showWalletSelector = function() {
$scope.showWallets = true;
$scope.setSendMax = function() {
$state.transitionTo('tabs.send.confirm', {
isWallet: $scope.isWallet,
toAmount: null,
toAddress: $scope.toAddress,
toName: $scope.toName,
toEmail: $scope.toEmail,
useSendMax: true,
});
};
$scope.toggleAlternative = function() {