From a661b5bc5823415c269284e23e8d82c4a89b5e94 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 11 Oct 2016 18:13:46 -0300 Subject: [PATCH] updates hasFunds --- src/js/controllers/tab-send.js | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/js/controllers/tab-send.js b/src/js/controllers/tab-send.js index d57a3b52c..381cb5cd9 100644 --- a/src/js/controllers/tab-send.js +++ b/src/js/controllers/tab-send.js @@ -6,7 +6,6 @@ angular.module('copayApp.controllers').controller('tabSendController', function( var CONTACTS_SHOW_LIMIT; var currentContactsPage; - $scope.hasFunds = false; var updateList = function() { CONTACTS_SHOW_LIMIT = 10; @@ -105,11 +104,43 @@ angular.module('copayApp.controllers').controller('tabSendController', function( }); }; + + var updateHasFunds = function() { + $scope.hasFunds = null; + + var wallets = profileService.getWallets({ + onlyComplete: true, + }); + + if (!wallets || !wallets.length) { + $scope.hasFunds = false; + } + + var index = 0; + lodash.each(wallets, function(w) { + walletService.getStatus(w, {}, function(err, status) { + ++index; + if (err || !status) { + $log.error(err); + return; + } + + if (status.availableBalanceSat) { + $scope.hasFunds = true; + } + if (index == wallets.length) { + $scope.hasFunds = $scope.hasFunds || false; + } + }); + }); + }; + $scope.$on("$ionicView.beforeEnter", function(event, data) { $scope.formData = { search: null }; updateList(); + updateHasFunds(); }); });