send max working

This commit is contained in:
Matias Alejo Garcia 2017-06-21 18:29:03 -03:00
commit 54b554d279
No known key found for this signature in database
GPG key ID: 02470DB551277AB3

View file

@ -58,11 +58,14 @@ angular.module('copayApp.controllers').controller('confirmController', function(
$scope.$on("$ionicView.beforeEnter", function(event, data) { $scope.$on("$ionicView.beforeEnter", function(event, data) {
function setWalletSelector(minAmount, cb) { function setWalletSelector(network, minAmount, cb) {
console.log('[confirm.js.38:minAmount:]', minAmount); //TODO
// no min amount? (sendMax) => look for no empty wallets
minAmount = minAmount || 1;
$scope.wallets = profileService.getWallets({ $scope.wallets = profileService.getWallets({
onlyComplete: true, onlyComplete: true,
network: $scope.network network: network
}); });
if (!$scope.wallets || !$scope.wallets.length) { if (!$scope.wallets || !$scope.wallets.length) {
@ -130,7 +133,6 @@ angular.module('copayApp.controllers').controller('confirmController', function(
// Other Scope vars // Other Scope vars
$scope.isCordova = isCordova; $scope.isCordova = isCordova;
$scope.showAddress = false; $scope.showAddress = false;
$scope.insufficientFunds = false;
$scope.paymentExpired = { $scope.paymentExpired = {
value: false value: false
}; };
@ -140,7 +142,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
$scope.walletSelectorTitle = gettextCatalog.getString('Send from'); $scope.walletSelectorTitle = gettextCatalog.getString('Send from');
setWalletSelector(tx.toAmount, function(err) { setWalletSelector(tx.network, tx.toAmount, function(err) {
if (err) { if (err) {
return exitWithError('Could not update wallets'); return exitWithError('Could not update wallets');
} }
@ -154,7 +156,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
}); });
function getSendMaxInfo(tx, cb) { function getSendMaxInfo(tx, wallet, cb) {
if (!tx.sendMax) return cb(); if (!tx.sendMax) return cb();
//ongoingProcess.set('retrievingInputs', true); //ongoingProcess.set('retrievingInputs', true);
@ -224,20 +226,26 @@ angular.module('copayApp.controllers').controller('confirmController', function(
$scope.tx = tx; $scope.tx = tx;
// Amount function refresh() {
tx.amountStr = txFormatService.formatAmountStr(tx.toAmount); $timeout(function() {
console.log('[confirm.js.217:tx:]', tx); //TODO $scope.$apply();
tx.amountValueStr = tx.amountStr.split(' ')[0]; }, 1);
tx.amountUnitStr = tx.amountStr.split(' ')[1]; }
txFormatService.formatAlternativeStr(tx.toAmount, function(v) {
tx.alternativeAmountStr = v;
});
function updateAmount() {
if (!tx.toAmount) return;
// inmediate refresh of know values // Amount
$timeout(function() { tx.amountStr = txFormatService.formatAmountStr(tx.toAmount);
$scope.$apply(); tx.amountValueStr = tx.amountStr.split(' ')[0];
}, 1); tx.amountUnitStr = tx.amountStr.split(' ')[1];
txFormatService.formatAlternativeStr(tx.toAmount, function(v) {
tx.alternativeAmountStr = v;
});
}
updateAmount();
refresh();
feeService.getFeeRate(tx.network, tx.feeLevel, function(err, feeRate) { feeService.getFeeRate(tx.network, tx.feeLevel, function(err, feeRate) {
if (err) return cb(err); if (err) return cb(err);
@ -245,24 +253,27 @@ angular.module('copayApp.controllers').controller('confirmController', function(
tx.feeRate = feeRate; tx.feeRate = feeRate;
tx.feeLevelName = feeService.feeOpts[tx.feeLevel]; tx.feeLevelName = feeService.feeOpts[tx.feeLevel];
getSendMaxInfo(lodash.clone(tx), function(err, sendMaxInfo) { getSendMaxInfo(lodash.clone(tx), wallet, function(err, sendMaxInfo) {
if (err) { if (err) {
var msg = gettextCatalog.getString('Error getting SendMax information'); var msg = gettextCatalog.getString('Error getting SendMax information');
return setSendError(msg); return setSendError(msg);
} }
if (sendMaxInfo) { if (sendMaxInfo) {
if (tx.sendMax && tx.sendMaxInfo.amount == 0) {
$scope.insufficientFunds = true; $log.debug('Send max info', sendMaxInfo);
if (tx.sendMax && sendMaxInfo.amount == 0) {
setNoWallet('Insufficent funds');
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Not enough funds for fee')); popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Not enough funds for fee'));
return cb('no_funds'); return cb('no_funds');
} }
tx.sendMaxInfo = resp; tx.sendMaxInfo = sendMaxInfo;
tx.toAmount = parseFloat((tx.sendMaxInfo.amount * unitToSatoshi).toFixed(0)); tx.toAmount =tx.sendMaxInfo.amount;
updateAmount();
} }
refresh();
// txp already generated for this wallet? // txp already generated for this wallet?
if (tx.txp[wallet.id]) if (tx.txp[wallet.id])
@ -274,7 +285,6 @@ angular.module('copayApp.controllers').controller('confirmController', function(
if (tx.sendMaxInfo) if (tx.sendMaxInfo)
showSendMaxWarning(sendMaxInfo, function(err) {}); showSendMaxWarning(sendMaxInfo, function(err) {});
txp.feeStr = txFormatService.formatAmountStr(txp.fee); txp.feeStr = txFormatService.formatAmountStr(txp.fee);
txFormatService.formatAlternativeStr(txp.fee, function(v) { txFormatService.formatAlternativeStr(txp.fee, function(v) {
txp.alternativeFeeStr = v; txp.alternativeFeeStr = v;
@ -433,8 +443,6 @@ angular.module('copayApp.controllers').controller('confirmController', function(
updateTx(tx, wallet, { updateTx(tx, wallet, {
dryRun: true dryRun: true
}, function(err) { }, function(err) {
if (err) return;
$timeout(function() { $timeout(function() {
$ionicScrollDelegate.resize(); $ionicScrollDelegate.resize();
$scope.$apply(); $scope.$apply();