diff --git a/js/controllers/homeWallet.js b/js/controllers/homeWallet.js index 788e937b8..2c86559da 100644 --- a/js/controllers/homeWallet.js +++ b/js/controllers/homeWallet.js @@ -2,15 +2,6 @@ angular.module('copayApp.controllers').controller('HomeWalletController', function($scope, $rootScope) { $scope.init = function() { - $rootScope.title = 'Home'; - $scope.addr = _.last($rootScope.wallet.getReceiveAddresses()); - - // This is necesarry, since wallet can change in homeWallet, without running init() again. - $rootScope.$watch('wallet', function() { - if ($rootScope.wallet && $rootScope.wallet.isComplete()) { - $scope.addr = _.last($rootScope.wallet.getReceiveAddresses()); - } - }); }; }); diff --git a/js/controllers/receive.js b/js/controllers/receive.js index 6481d09b3..660a02417 100644 --- a/js/controllers/receive.js +++ b/js/controllers/receive.js @@ -2,9 +2,6 @@ angular.module('copayApp.controllers').controller('ReceiveController', function($scope, $rootScope, $timeout, $modal) { - $rootScope.title = 'Receive'; - $scope.loading = false; - $scope.showAll = false; $scope.newAddr = function() { var w = $rootScope.wallet; @@ -16,6 +13,25 @@ angular.module('copayApp.controllers').controller('ReceiveController', }, 1); }; + $scope.init = function() { + $rootScope.title = 'Receive'; + $scope.showAll = false; + + var w = $rootScope.wallet; + var lastAddr = _.first(w.getAddressesOrderer()); + var balance = w.balanceInfo.balanceByAddr; + + if (balance[lastAddr]>0) + $scope.loading = true; + + while (balance && balance[lastAddr] > 0) { + $scope.newAddr(); + lastAddr = w.generateAddress(null); + }; + $scope.loading = false; + $scope.addr = lastAddr; + }; + $scope.openAddressModal = function(address) { var ModalInstanceCtrl = function($scope, $modalInstance, address) { $scope.address = address; @@ -43,26 +59,30 @@ angular.module('copayApp.controllers').controller('ReceiveController', }; $scope.setAddressList = function() { - var w = $rootScope.wallet; - var balance = w.balanceInfo.balanceByAddr; + if ($scope.showAll) { + var w = $rootScope.wallet; + var balance = w.balanceInfo.balanceByAddr; - var addresses = w.getAddressesOrderer(); - if (addresses) { - $scope.addrLength = addresses.length; + var addresses = w.getAddressesOrderer(); + if (addresses) { + $scope.addrLength = addresses.length; - if (!$scope.showAll) - addresses = addresses.slice(0,3); + if (!$scope.showAll) + addresses = addresses.slice(0, 3); - var list = []; - _.each(addresses, function(address, index){ - list.push({ - 'index': index, - 'address': address, - 'balance': balance ? balance[address] : null, - 'isChange': w.addressIsChange(address), + var list = []; + _.each(addresses, function(address, index) { + list.push({ + 'index': index, + 'address': address, + 'balance': balance ? balance[address] : null, + 'isChange': w.addressIsChange(address), + }); }); - }); - $scope.addresses = list; + $scope.addresses = list; + } + } else { + $scope.addresses = []; } }; } diff --git a/test/unit/controllers/controllersSpec.js b/test/unit/controllers/controllersSpec.js index 571a907ef..7c0314fa1 100644 --- a/test/unit/controllers/controllersSpec.js +++ b/test/unit/controllers/controllersSpec.js @@ -145,9 +145,6 @@ describe("Unit: Controllers", function() { }); })); - it('should have a ReceiveController controller', function() { - expect(scope.loading).equal(false); - }); }); describe('History Controller', function() { diff --git a/views/homeWallet.html b/views/homeWallet.html index 798473247..a0c3cff12 100644 --- a/views/homeWallet.html +++ b/views/homeWallet.html @@ -1,63 +1,57 @@