From aa051657101a4ff55b9ce798ced839e1e4a1e66f Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Mon, 16 Jan 2017 16:58:42 -0300 Subject: [PATCH] better send tab without internet --- src/js/controllers/confirm.js | 23 ++++++++++++++++++++--- src/js/controllers/tab-send.js | 20 +++++++++++--------- www/views/tab-send.html | 8 -------- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/js/controllers/confirm.js b/src/js/controllers/confirm.js index 62ddb96ef..0cfd503ab 100644 --- a/src/js/controllers/confirm.js +++ b/src/js/controllers/confirm.js @@ -79,12 +79,14 @@ angular.module('copayApp.controllers').controller('confirmController', function( var filteredWallets = []; var index = 0; var enoughFunds = false; + var walletsUpdated = 0; lodash.each($scope.wallets, function(w) { walletService.getStatus(w, {}, function(err, status) { if (err || !status) { $log.error(err); } else { + walletsUpdated++; w.status = status; if (!status.availableBalanceSat) $log.debug('No balance available in: ' + w.name); if (status.availableBalanceSat > toAmount) { @@ -94,6 +96,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( } if (++index == $scope.wallets.length) { + if (!lodash.isEmpty(filteredWallets)) { $scope.wallets = lodash.clone(filteredWallets); if ($scope.useSendMax) { @@ -105,9 +108,23 @@ angular.module('copayApp.controllers').controller('confirmController', function( } } else initConfirm(); } else { - if (!enoughFunds) $scope.insufficientFunds = true; - displayValues(); - $log.warn('No wallet available to make the payment'); + + // Were we able to update any wallet? + if (walletsUpdated) { + if (!enoughFunds) $scope.insufficientFunds = true; + displayValues(); + $log.warn('No wallet available to make the payment'); + } else { + popupService.showAlert(gettextCatalog.getString('Could not update wallets'), bwcError.msg(err), function() { + $ionicHistory.nextViewOptions({ + disableAnimate: true, + historyRoot: true + }); + $ionicHistory.clearHistory(); + $state.go('tabs.send'); + }); + } + } $timeout(function() { $scope.$apply(); diff --git a/src/js/controllers/tab-send.js b/src/js/controllers/tab-send.js index 4463e5a53..dff61c55d 100644 --- a/src/js/controllers/tab-send.js +++ b/src/js/controllers/tab-send.js @@ -94,8 +94,8 @@ angular.module('copayApp.controllers').controller('tabSendController', function( $timeout(function() { item.getAddress(function(err, addr) { if (err || !addr) { - $log.error(err); - return; + //Error is already formated + return popupService.showAlert(err); } $log.debug('Got toAddress:' + addr + ' | ' + item.name); return $state.transitionTo('tabs.send.amount', { @@ -109,6 +109,10 @@ angular.module('copayApp.controllers').controller('tabSendController', function( }); }; + + // THIS is ONLY to show the 'buy bitcoins' message + // does not has any other function. + var updateHasFunds = function() { if ($rootScope.everHasFunds) { @@ -128,20 +132,18 @@ angular.module('copayApp.controllers').controller('tabSendController', function( }); } - $scope.checkingBalanceError = false; $scope.checkingBalance = true; - var index = 0, - errorShown = 0; + var index = 0; lodash.each(wallets, function(w) { walletService.getStatus(w, {}, function(err, status) { ++index; if (err && !status) { $log.error(err); - if (!errorShown++) popupService.showAlert(bwcError.msg(err, gettextCatalog.getString('Could not update wallet'))); - $scope.checkingBalanceError = true; - return; - + // error updating the wallet. Probably a network error, do not show + // the 'buy bitcoins' message. + + $scope.hasFunds = true; } else if (status.availableBalanceSat > 0) { $scope.hasFunds = true; $rootScope.everHasFunds = true; diff --git a/www/views/tab-send.html b/www/views/tab-send.html index 478863ba0..95ba36942 100644 --- a/www/views/tab-send.html +++ b/www/views/tab-send.html @@ -2,14 +2,6 @@ {{'Send' | translate}} - -
-
- - Could not update wallets -
-
-