From fd2cf54eb4c6c2069c4aa4169ed255a4aefcc5e4 Mon Sep 17 00:00:00 2001 From: Yemel Jardi Date: Thu, 3 Jul 2014 13:04:01 -0300 Subject: [PATCH] Hide empty addresses from othe copayers --- index.html | 4 ++-- js/controllers/addresses.js | 3 ++- js/filters.js | 8 ++++++++ js/models/core/PublicKeyRing.js | 16 +++++++++++----- js/models/core/Wallet.js | 2 +- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/index.html b/index.html index c08288641..6c7d97a0d 100644 --- a/index.html +++ b/index.html @@ -389,7 +389,7 @@
- @@ -411,7 +411,7 @@ - + Show all Show less diff --git a/js/controllers/addresses.js b/js/controllers/addresses.js index 3a0f7bacd..a0281e1b1 100644 --- a/js/controllers/addresses.js +++ b/js/controllers/addresses.js @@ -33,7 +33,8 @@ angular.module('copayApp.controllers').controller('AddressesController', $scope.addresses.push({ 'address': addrinfo.addressStr, 'balance': $rootScope.balanceByAddr ? $rootScope.balanceByAddr[addrinfo.addressStr] : 0, - 'isChange': addrinfo.isChange + 'isChange': addrinfo.isChange, + 'owned': addrinfo.owned }); } $scope.selectedAddr = $scope.addresses[0]; diff --git a/js/filters.js b/js/filters.js index 46d56469d..6b0a99ab0 100644 --- a/js/filters.js +++ b/js/filters.js @@ -17,6 +17,14 @@ angular.module('copayApp.filters', []) return false; }; }) + .filter('removeEmpty', function() { + return function(elements) { + // Hide empty addresses from other copayers + return elements.filter(function(e) { + return e.owned || e.balance > 0; + }); + } + }) .filter('limitAddress', function() { return function(elements, showAll) { if (elements.length <= 1 || showAll) { diff --git a/js/models/core/PublicKeyRing.js b/js/models/core/PublicKeyRing.js index b82c76365..90cab98cd 100644 --- a/js/models/core/PublicKeyRing.js +++ b/js/models/core/PublicKeyRing.js @@ -246,18 +246,22 @@ PublicKeyRing.prototype.getCosigner = function(pubKey) { } -PublicKeyRing.prototype.getAddressesInfo = function(opts) { +PublicKeyRing.prototype.getAddressesInfo = function(opts, pubkey) { var ret = []; var self = this; + var cosigner = pubkey && this.getCosigner(pubkey); this.indexes.forEach(function(index) { - ret = ret.concat(self.getAddressesInfoForIndex(index, opts)); + ret = ret.concat(self.getAddressesInfoForIndex(index, opts, cosigner)); }); return ret; } -PublicKeyRing.prototype.getAddressesInfoForIndex = function(index, opts) { +PublicKeyRing.prototype.getAddressesInfoForIndex = function(index, opts, cosigner) { opts = opts || {}; + var isOwned = index.cosigner == Structure.SHARED_INDEX + || index.cosigner == cosigner; + var ret = []; if (!opts.excludeChange) { for (var i = 0; i < index.changeIndex; i++) { @@ -265,7 +269,8 @@ PublicKeyRing.prototype.getAddressesInfoForIndex = function(index, opts) { ret.unshift({ address: a, addressStr: a.toString(), - isChange: true + isChange: true, + owned: isOwned }); } } @@ -276,7 +281,8 @@ PublicKeyRing.prototype.getAddressesInfoForIndex = function(index, opts) { ret.unshift({ address: a, addressStr: a.toString(), - isChange: false + isChange: false, + owned: isOwned }); } } diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index 800ef5d8e..ae9514926 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -588,7 +588,7 @@ Wallet.prototype.getAddressesStr = function(opts) { }; Wallet.prototype.getAddressesInfo = function(opts) { - return this.publicKeyRing.getAddressesInfo(opts); + return this.publicKeyRing.getAddressesInfo(opts, this.publicKey); }; Wallet.prototype.addressIsOwn = function(addrStr, opts) {