diff --git a/src/js/controllers/addresses.js b/src/js/controllers/addresses.js index 303919044..251388134 100644 --- a/src/js/controllers/addresses.js +++ b/src/js/controllers/addresses.js @@ -1,7 +1,8 @@ 'use strict'; angular.module('copayApp.controllers').controller('addressesController', function($scope, $stateParams, $timeout, $ionicScrollDelegate, configService, popupService, gettextCatalog, ongoingProcess, lodash, profileService, walletService) { - var ADDRESS_LIMIT = 5; + var UNUSED_ADDRESS_LIMIT = 5; + var BALANCE_ADDRESS_LIMIT = 5; var config; var unitName; var unitToSatoshi; @@ -16,28 +17,47 @@ angular.module('copayApp.controllers').controller('addressesController', functio satToUnit = 1 / unitToSatoshi; unitName = config.unitName; unitDecimals = config.unitDecimals; + init(); + }); - // $scope.unusedAddresses = getUnusedAddreses(); No backend support TODO - $scope.unusedAddresses = [{ - createdOn: 1479138140, - address: "0m9sad00810m0m1d2192d9u12d9", - path: 'xpub/0/1' - }]; - + function init() { ongoingProcess.set('extractingWalletInfo', true); - walletService.getBalance($scope.wallet, {}, function(err, resp) { - ongoingProcess.set('extractingWalletInfo', false); + walletService.getMainAddresses($scope.wallet, {}, function(err, addresses) { if (err) { + ongoingProcess.set('extractingWalletInfo', false); return popupService.showAlert(gettextCatalog.getString('Error'), err); } - $scope.addresses = lodash.slice(resp.byAddress, 0, ADDRESS_LIMIT); - lodash.each($scope.addresses, function(a) { - a.balanceStr = (a.amount * satToUnit).toFixed(unitDecimals) + ' ' + unitName; + $scope.allAddresses = addresses; + + walletService.getBalance($scope.wallet, {}, function(err, resp) { + ongoingProcess.set('extractingWalletInfo', false); + if (err) { + return popupService.showAlert(gettextCatalog.getString('Error'), err); + } + + var withBalance = resp.byAddress; + var idx = lodash.indexBy(withBalance, 'address'); + var noBalance = lodash.reject($scope.allAddresses, function(x) { + return idx[x.address]; + }); + lodash.each(noBalance, function(n) { + n.path = n.path.replace(/^m/g, 'xpub'); + }); + $scope.unused = lodash.slice(noBalance, 0, UNUSED_ADDRESS_LIMIT); + $scope.withBalance = lodash.slice(withBalance, 0, BALANCE_ADDRESS_LIMIT); + + lodash.each($scope.withBalance, function(a) { + a.balanceStr = (a.amount * satToUnit).toFixed(unitDecimals) + ' ' + unitName; + }); + + $scope.viewAll = { + value: noBalance.length > UNUSED_ADDRESS_LIMIT || withBalance.length > BALANCE_ADDRESS_LIMIT + }; + $scope.$digest(); }); - $scope.$digest(); }); - }); + }; $scope.showInformation = function() { $timeout(function() { diff --git a/src/js/services/walletService.js b/src/js/services/walletService.js index 07efbb1b9..83e83a6a5 100644 --- a/src/js/services/walletService.js +++ b/src/js/services/walletService.js @@ -773,10 +773,9 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim }); }; - root.getMainAddresses = function(wallet, limit, cb) { - var opts = {}; + root.getMainAddresses = function(wallet, opts, cb) { + opts = opts || {}; opts.reverse = true; - if (limit) opts.limit = limit; wallet.getMainAddresses(opts, function(err, addresses) { if (err) return cb(err); diff --git a/src/sass/views/addresses.scss b/src/sass/views/addresses.scss index 441c3e413..130c66c36 100644 --- a/src/sass/views/addresses.scss +++ b/src/sass/views/addresses.scss @@ -14,6 +14,11 @@ font-size: 15px; color: $mid-gray; margin: 1rem 0; + a { + font-weight: bold; + cursor: pointer; + cursor: hand; + } } &-description-disabled { color: cadetblue; @@ -35,32 +40,34 @@ } } - a { - font-weight: bold; - } - .addr-list { .item { color: $dark-gray; padding-top: 1.3rem; padding-bottom: 1.3rem; - &.has-addr-value { padding-top: .65rem; padding-bottom: .65rem; } - &.item-divider { color: $mid-gray; padding-bottom: .5rem; font-size: .9rem; } - - .icon { - color: $light-gray; + &.view-all { + margin: 20px 0px 20px 0px; + cursor: pointer; + cursor: hand; + i { + font-size: 35px; + margin-right: 5px; + color: #434CBE; + } + a { + font-weight: bold; + } } } - .item-note { color: $light-gray; } diff --git a/www/views/addresses.html b/www/views/addresses.html index 9b4a4c715..8aba73dab 100644 --- a/www/views/addresses.html +++ b/www/views/addresses.html @@ -29,16 +29,16 @@ -
-
- {{uAddress.address}} +
+
+ {{u.address}}
- {{uAddress.path}} {{uAddress.createdOn * 1000 | amDateFormat:'MMMM Do YYYY, hh:mm a'}} + {{u.path}} {{u.createdOn * 1000 | amDateFormat:'MMMM Do YYYY, hh:mm a'}}
-
+
Not unused addresses available
@@ -46,9 +46,14 @@ Addresses With Balance
-
- {{addr.address}} -
{{addr.balanceStr}}
+
+ {{w.address}} +
{{w.balanceStr}}
+
+ +