From 8b2265d767dde339c3cd33db5a94b10f125d2572 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Fri, 1 Sep 2017 14:32:49 -0300 Subject: [PATCH 1/3] Fix sendMax, support bch. Fee levels cache for bch --- src/js/controllers/confirm.js | 44 ++++++++++++++++++++++------------- src/js/services/feeService.js | 4 +++- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/js/controllers/confirm.js b/src/js/controllers/confirm.js index 45605f719..c65f057a0 100644 --- a/src/js/controllers/confirm.js +++ b/src/js/controllers/confirm.js @@ -28,7 +28,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( function refresh() { $timeout(function() { $scope.$apply(); - }, 1); + }, 10); } @@ -69,7 +69,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( $scope.$on("$ionicView.beforeEnter", function(event, data) { - function setWalletSelector(coin, network, minAmount, cb) { + function setWalletSelector(coin, network, minAmount, sendMax, cb) { // no min amount? (sendMax) => look for no empty wallets minAmount = minAmount || 1; @@ -77,7 +77,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( $scope.wallets = profileService.getWallets({ onlyComplete: true, network: network, - coin: coin + coin: sendMax ? null : coin }); if (!$scope.wallets || !$scope.wallets.length) { @@ -119,11 +119,6 @@ angular.module('copayApp.controllers').controller('confirmController', function( }); }; - // TODO: Default fee level for BCH - if (data.stateParams.coin == 'bch') { - configFeeLevel = 'normal'; - } - // Setup $scope // Grab stateParams @@ -134,7 +129,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( description: data.stateParams.description, paypro: data.stateParams.paypro, - feeLevel: configFeeLevel, + feeLevel: data.stateParams.coin == 'bch' ? 'normal' : configFeeLevel, spendUnconfirmed: walletConfig.spendUnconfirmed, // Vanity tx info (not in the real tx) @@ -154,7 +149,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( $scope.walletSelectorTitle = gettextCatalog.getString('Send from'); - setWalletSelector(tx.coin, tx.network, tx.toAmount, function(err) { + setWalletSelector(tx.coin, tx.network, tx.toAmount, tx.sendMax, function(err) { if (err) { return exitWithError('Could not update wallets'); } @@ -230,6 +225,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( }; function updateTx(tx, wallet, opts, cb) { + ongoingProcess.set('calculatingFee', true); if (opts.clearCache) { tx.txp = {}; @@ -253,19 +249,23 @@ angular.module('copayApp.controllers').controller('confirmController', function( refresh(); // End of quick refresh, before wallet is selected. - if (!wallet) return cb(); + if (!wallet) { + ongoingProcess.set('calculatingFee', false); + return cb(); + } feeService.getFeeRate(wallet.coin, tx.network, tx.feeLevel, function(err, feeRate) { - if (err) return cb(err); + if (err) { + ongoingProcess.set('calculatingFee', false); + return cb(err); + } if (!usingCustomFee) tx.feeRate = feeRate; tx.feeLevelName = feeService.feeOpts[tx.feeLevel]; - if (!wallet) - return cb(); - getSendMaxInfo(lodash.clone(tx), wallet, function(err, sendMaxInfo) { if (err) { + ongoingProcess.set('calculatingFee', false); var msg = gettextCatalog.getString('Error getting SendMax information'); return setSendError(msg); } @@ -275,6 +275,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( $log.debug('Send max info', sendMaxInfo); if (tx.sendMax && sendMaxInfo.amount == 0) { + ongoingProcess.set('calculatingFee', false); setNoWallet(gettextCatalog.getString('Insufficient funds')); popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Not enough funds for fee')); return cb('no_funds'); @@ -283,17 +284,23 @@ angular.module('copayApp.controllers').controller('confirmController', function( tx.sendMaxInfo = sendMaxInfo; tx.toAmount = tx.sendMaxInfo.amount; updateAmount(); + ongoingProcess.set('calculatingFee', false); showSendMaxWarning(wallet, sendMaxInfo); } // txp already generated for this wallet? if (tx.txp[wallet.id]) { +console.log('[confirm.js:292] Ya existe la tx',tx); //TODO/ + ongoingProcess.set('calculatingFee', false); refresh(); return cb(); } getTxp(lodash.clone(tx), wallet, opts.dryRun, function(err, txp) { - if (err) return cb(err); + ongoingProcess.set('calculatingFee', false); + if (err) { + return cb(err); + } txp.feeStr = txFormatService.formatAmountStr(wallet.coin, txp.fee); txFormatService.formatAlternativeStr(wallet.coin, txp.fee, function(v) { @@ -425,6 +432,11 @@ angular.module('copayApp.controllers').controller('confirmController', function( $scope.wallet = wallet; + // If select another wallet + tx.coin = wallet.coin; + tx.feeLevel = wallet.coin == 'bch' ? 'normal' : configFeeLevel; + usingCustomFee = null; + setButtonText(wallet.credentials.m > 1, !!tx.paypro); if (tx.paypro) diff --git a/src/js/services/feeService.js b/src/js/services/feeService.js index 2109d7ea0..37cd8ab58 100644 --- a/src/js/services/feeService.js +++ b/src/js/services/feeService.js @@ -17,6 +17,7 @@ angular.module('copayApp.services').factory('feeService', function($log, $timeou var cache = { updateTs: 0, + coin: '' }; root.getCurrentFeeLevel = function() { @@ -60,7 +61,7 @@ angular.module('copayApp.services').factory('feeService', function($log, $timeou root.getFeeLevels = function(coin, cb) { coin = coin || 'btc'; - if (cache.updateTs > Date.now() - CACHE_TIME_TS * 1000) { + if (cache.coin == coin && cache.updateTs > Date.now() - CACHE_TIME_TS * 1000) { return cb(null, cache.data, true); } @@ -73,6 +74,7 @@ angular.module('copayApp.services').factory('feeService', function($log, $timeou } cache.updateTs = Date.now(); + cache.coin = coin; cache.data = { 'livenet': levelsLivenet, 'testnet': levelsTestnet From 7601005d5d1756d453e9c96d540a31feb1a8c426 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Fri, 1 Sep 2017 14:33:50 -0300 Subject: [PATCH 2/3] Removes console log --- src/js/controllers/confirm.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/js/controllers/confirm.js b/src/js/controllers/confirm.js index c65f057a0..d8cd299b3 100644 --- a/src/js/controllers/confirm.js +++ b/src/js/controllers/confirm.js @@ -290,7 +290,6 @@ angular.module('copayApp.controllers').controller('confirmController', function( // txp already generated for this wallet? if (tx.txp[wallet.id]) { -console.log('[confirm.js:292] Ya existe la tx',tx); //TODO/ ongoingProcess.set('calculatingFee', false); refresh(); return cb(); From 9f9bb1b728b35f7184d8bc5a0054d10d805efda5 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Fri, 1 Sep 2017 15:26:12 -0300 Subject: [PATCH 3/3] Ref amount-confirm sendMax --- src/js/controllers/amount.js | 6 +++--- src/js/controllers/confirm.js | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/js/controllers/amount.js b/src/js/controllers/amount.js index dee20cde1..c1b105068 100644 --- a/src/js/controllers/amount.js +++ b/src/js/controllers/amount.js @@ -309,7 +309,7 @@ angular.module('copayApp.controllers').controller('amountController', function($ if (a) { $scope.alternativeAmount = txFormatService.formatAmount(a * unitToSatoshi, true); } else { - $scope.alternativeAmount = 'N/A'; //TODO + $scope.alternativeAmount = 'N/A'; //TODO $scope.allowSend = false; } } else { @@ -369,7 +369,7 @@ angular.module('copayApp.controllers').controller('amountController', function($ id: _id, amount: $scope.useSendMax ? null : _amount, currency: unit.id.toUpperCase(), - coin: coin, + coin: $scope.useSendMax ? null : coin, useSendMax: $scope.useSendMax }); } else { @@ -388,7 +388,7 @@ angular.module('copayApp.controllers').controller('amountController', function($ toName: $scope.toName, toEmail: $scope.toEmail, toColor: $scope.toColor, - coin: coin, + coin: $scope.useSendMax ? null : coin, useSendMax: $scope.useSendMax }); } diff --git a/src/js/controllers/confirm.js b/src/js/controllers/confirm.js index d8cd299b3..2129e0352 100644 --- a/src/js/controllers/confirm.js +++ b/src/js/controllers/confirm.js @@ -69,7 +69,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( $scope.$on("$ionicView.beforeEnter", function(event, data) { - function setWalletSelector(coin, network, minAmount, sendMax, cb) { + function setWalletSelector(coin, network, minAmount, cb) { // no min amount? (sendMax) => look for no empty wallets minAmount = minAmount || 1; @@ -77,7 +77,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( $scope.wallets = profileService.getWallets({ onlyComplete: true, network: network, - coin: sendMax ? null : coin + coin: coin }); if (!$scope.wallets || !$scope.wallets.length) { @@ -129,7 +129,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( description: data.stateParams.description, paypro: data.stateParams.paypro, - feeLevel: data.stateParams.coin == 'bch' ? 'normal' : configFeeLevel, + feeLevel: configFeeLevel, spendUnconfirmed: walletConfig.spendUnconfirmed, // Vanity tx info (not in the real tx) @@ -142,6 +142,8 @@ angular.module('copayApp.controllers').controller('confirmController', function( txp: {}, }; + if (tx.coin && tx.coin == 'bch') tx.feeLevel = 'normal'; + // Other Scope vars $scope.isCordova = isCordova; $scope.isWindowsPhoneApp = isWindowsPhoneApp; @@ -149,7 +151,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( $scope.walletSelectorTitle = gettextCatalog.getString('Send from'); - setWalletSelector(tx.coin, tx.network, tx.toAmount, tx.sendMax, function(err) { + setWalletSelector(tx.coin, tx.network, tx.toAmount, function(err) { if (err) { return exitWithError('Could not update wallets'); }