From 0fbde7199627ee1877f3827aa071773d28ecade9 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sat, 15 Oct 2016 09:41:35 -0300 Subject: [PATCH 1/4] add "Cache" for hasFunds --- src/js/controllers/tab-send.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/js/controllers/tab-send.js b/src/js/controllers/tab-send.js index 4409eb698..926e017b8 100644 --- a/src/js/controllers/tab-send.js +++ b/src/js/controllers/tab-send.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('tabSendController', function($scope, $log, $timeout, $ionicScrollDelegate, addressbookService, profileService, lodash, $state, walletService, incomingData, popupService) { +angular.module('copayApp.controllers').controller('tabSendController', function($scope, $log, $timeout, $ionicScrollDelegate, addressbookService, profileService, lodash, $state, walletService, incomingData, popupService, $rootScope) { var originalList; var CONTACTS_SHOW_LIMIT; @@ -113,6 +113,9 @@ angular.module('copayApp.controllers').controller('tabSendController', function( var updateHasFunds = function() { $scope.hasFunds = true; + if ($rootScope.everHasFunds) + return; + var wallets = profileService.getWallets({ onlyComplete: true, }); @@ -134,6 +137,9 @@ angular.module('copayApp.controllers').controller('tabSendController', function( return; } walletsTotalBalance = walletsTotalBalance + status.availableBalanceSat; + if (walletsTotalBalance>0) { + $rootScope.everHasFunds = true; + } if (index == wallets.length && walletsTotalBalance == 0) { $scope.hasFunds = false; $timeout(function() { From 934409433e13b3444c1c5758e279ae8fc4191294 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sat, 15 Oct 2016 09:45:44 -0300 Subject: [PATCH 2/4] format --- src/js/controllers/tab-send.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/js/controllers/tab-send.js b/src/js/controllers/tab-send.js index 926e017b8..5334efc50 100644 --- a/src/js/controllers/tab-send.js +++ b/src/js/controllers/tab-send.js @@ -113,8 +113,9 @@ angular.module('copayApp.controllers').controller('tabSendController', function( var updateHasFunds = function() { $scope.hasFunds = true; - if ($rootScope.everHasFunds) + if ($rootScope.everHasFunds) { return; + } var wallets = profileService.getWallets({ onlyComplete: true, @@ -137,7 +138,7 @@ angular.module('copayApp.controllers').controller('tabSendController', function( return; } walletsTotalBalance = walletsTotalBalance + status.availableBalanceSat; - if (walletsTotalBalance>0) { + if (walletsTotalBalance > 0) { $rootScope.everHasFunds = true; } if (index == wallets.length && walletsTotalBalance == 0) { From 41b8c7f0647de840497285a6e48897256239cf95 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sat, 15 Oct 2016 09:47:52 -0300 Subject: [PATCH 3/4] format2 --- src/js/controllers/tab-send.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/js/controllers/tab-send.js b/src/js/controllers/tab-send.js index 5334efc50..b216891ca 100644 --- a/src/js/controllers/tab-send.js +++ b/src/js/controllers/tab-send.js @@ -113,7 +113,7 @@ angular.module('copayApp.controllers').controller('tabSendController', function( var updateHasFunds = function() { $scope.hasFunds = true; - if ($rootScope.everHasFunds) { + if ($rootScope.everHadFunds) { return; } @@ -139,7 +139,7 @@ angular.module('copayApp.controllers').controller('tabSendController', function( } walletsTotalBalance = walletsTotalBalance + status.availableBalanceSat; if (walletsTotalBalance > 0) { - $rootScope.everHasFunds = true; + $rootScope.everHadFunds = true; } if (index == wallets.length && walletsTotalBalance == 0) { $scope.hasFunds = false; From f49bc5f24cbfcd58335b4e5f4fe3cab2e4b7d597 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sat, 15 Oct 2016 10:03:45 -0300 Subject: [PATCH 4/4] no flicker --- src/js/controllers/tab-send.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/js/controllers/tab-send.js b/src/js/controllers/tab-send.js index b216891ca..0ea31438b 100644 --- a/src/js/controllers/tab-send.js +++ b/src/js/controllers/tab-send.js @@ -109,27 +109,26 @@ angular.module('copayApp.controllers').controller('tabSendController', function( }); }; - var updateHasFunds = function() { - $scope.hasFunds = true; - if ($rootScope.everHadFunds) { + if ($rootScope.everHasFunds) { + $scope.hasFunds = true; return; } + $scope.hasFunds = false; + var wallets = profileService.getWallets({ onlyComplete: true, }); if (!wallets || !wallets.length) { - $scope.hasFunds = false; - $timeout(function() { + return $timeout(function() { $scope.$apply(); }); } var index = 0; - var walletsTotalBalance = 0; lodash.each(wallets, function(w) { walletService.getStatus(w, {}, function(err, status) { ++index; @@ -137,12 +136,13 @@ angular.module('copayApp.controllers').controller('tabSendController', function( $log.error(err); return; } - walletsTotalBalance = walletsTotalBalance + status.availableBalanceSat; - if (walletsTotalBalance > 0) { - $rootScope.everHadFunds = true; + + if (status.availableBalanceSat > 0) { + $scope.hasFunds = true; + $rootScope.everHasFunds = true; } - if (index == wallets.length && walletsTotalBalance == 0) { - $scope.hasFunds = false; + + if (index == wallets.length) { $timeout(function() { $scope.$apply(); });