diff --git a/src/js/controllers/addresses.js b/src/js/controllers/addresses.js index 26f683e76..c063e172e 100644 --- a/src/js/controllers/addresses.js +++ b/src/js/controllers/addresses.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('addressesController', function($scope, $stateParams, $state, $timeout, $ionicScrollDelegate, configService, popupService, gettextCatalog, ongoingProcess, lodash, profileService, walletService) { +angular.module('copayApp.controllers').controller('addressesController', function($scope, $stateParams, $state, $timeout, $ionicScrollDelegate, configService, popupService, gettextCatalog, ongoingProcess, lodash, profileService, walletService, bwcError) { var UNUSED_ADDRESS_LIMIT = 5; var BALANCE_ADDRESS_LIMIT = 5; var config; @@ -9,36 +9,35 @@ angular.module('copayApp.controllers').controller('addressesController', functio var satToUnit; var unitDecimals; var withBalance; - var noBalance; $scope.showInfo = false; $scope.wallet = profileService.getWallet($stateParams.walletId); function init() { - ongoingProcess.set('extractingWalletInfo', true); + ongoingProcess.set('gettingAddresses', true); walletService.getMainAddresses($scope.wallet, {}, function(err, addresses) { if (err) { - ongoingProcess.set('extractingWalletInfo', false); + ongoingProcess.set('gettingAddresses', false); return popupService.showAlert(gettextCatalog.getString('Error'), err); } var allAddresses = addresses; walletService.getBalance($scope.wallet, {}, function(err, resp) { - ongoingProcess.set('extractingWalletInfo', false); + ongoingProcess.set('gettingAddresses', false); if (err) { return popupService.showAlert(gettextCatalog.getString('Error'), err); } withBalance = resp.byAddress; var idx = lodash.indexBy(withBalance, 'address'); - noBalance = lodash.reject(allAddresses, function(x) { + $scope.noBalance = lodash.reject(allAddresses, function(x) { return idx[x.address]; }); - processPaths(noBalance); + processPaths($scope.noBalance); processPaths(withBalance); - $scope.latestUnused = lodash.slice(noBalance, 0, UNUSED_ADDRESS_LIMIT); + $scope.latestUnused = lodash.slice($scope.noBalance, 0, UNUSED_ADDRESS_LIMIT); $scope.latestWithBalance = lodash.slice(withBalance, 0, BALANCE_ADDRESS_LIMIT); lodash.each(withBalance, function(a) { @@ -46,9 +45,9 @@ angular.module('copayApp.controllers').controller('addressesController', functio }); $scope.viewAll = { - value: noBalance.length > UNUSED_ADDRESS_LIMIT || withBalance.length > BALANCE_ADDRESS_LIMIT + value: $scope.noBalance.length > UNUSED_ADDRESS_LIMIT || withBalance.length > BALANCE_ADDRESS_LIMIT }; - $scope.allAddresses = noBalance.concat(withBalance); + $scope.allAddresses = $scope.noBalance.concat(withBalance); $scope.$digest(); }); }); @@ -60,6 +59,31 @@ angular.module('copayApp.controllers').controller('addressesController', functio }); }; + $scope.newAddress = function() { + ongoingProcess.set('generatingNewAddress', true); + walletService.getAddress($scope.wallet, true, function(err, addr) { + if (err) { + ongoingProcess.set('generatingNewAddress', false); + return popupService.showAlert(gettextCatalog.getString('Error'), bwcError.msg(err)); + } + + walletService.getMainAddresses($scope.wallet, { + limit: 1 + }, function(err, _addr) { + ongoingProcess.set('generatingNewAddress', false); + if (err) return popupService.showAlert(gettextCatalog.getString('Error'), err); + if (addr != _addr[0].address) return popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('New address could not be generated. Please try again.')); + + $scope.viewAll = { + value: [_addr[0]].concat($scope.latestUnused).length > UNUSED_ADDRESS_LIMIT + }; + $scope.noBalance.concat(_addr[0]); + $scope.latestUnused = lodash.slice($scope.noBalance, 0, UNUSED_ADDRESS_LIMIT); + $scope.$digest(); + }); + }); + }; + $scope.viewAllAddresses = function() { $state.go('tabs.receive.allAddresses', { walletId: $scope.wallet.id diff --git a/src/js/services/onGoingProcess.js b/src/js/services/onGoingProcess.js index acede937d..02e007861 100644 --- a/src/js/services/onGoingProcess.js +++ b/src/js/services/onGoingProcess.js @@ -34,6 +34,8 @@ angular.module('copayApp.services').factory('ongoingProcess', function($log, $ti 'validatingWords': gettext('Validating recovery phrase...'), 'loadingTxInfo': gettext('Loading transaction info...'), 'sendingFeedback': gettext('Sending feedback...'), + 'generatingNewAddress': gettext('Generating new address...'), + 'gettingAddresses': gettext('Getting addresses...'), }; root.clear = function() { diff --git a/src/sass/views/addresses.scss b/src/sass/views/addresses.scss index 00af459d0..ac82961f4 100644 --- a/src/sass/views/addresses.scss +++ b/src/sass/views/addresses.scss @@ -70,7 +70,7 @@ } i { font-size: 35px; - margin-right: 5px; + margin-right: 2px; } } .item-note { diff --git a/www/views/addresses.html b/www/views/addresses.html index b80a1a686..da3df420e 100644 --- a/www/views/addresses.html +++ b/www/views/addresses.html @@ -24,8 +24,8 @@
-
- Unused Addresses +
+ Unused Addresses ({{noBalance.length}})
@@ -42,13 +42,15 @@ Not unused addresses available
-
- Addresses With Balance -
+
+
+ Addresses With Balance +
-
- {{w.address}} -
{{w.balanceStr}}
+
+ {{w.address}} +
{{w.balanceStr}}
+