diff --git a/js/controllers/addresses.js b/js/controllers/addresses.js index 03f6f5408..3432ef8c5 100644 --- a/js/controllers/addresses.js +++ b/js/controllers/addresses.js @@ -3,6 +3,7 @@ angular.module('copayApp.controllers').controller('AddressesController', function($scope, $rootScope, $timeout, $modal, controllerUtils) { $scope.loading = false; + $scope.showAll = false; var w = $rootScope.wallet; $scope.newAddr = function() { @@ -16,7 +17,7 @@ angular.module('copayApp.controllers').controller('AddressesController', }; $scope.openAddressModal = function(address) { - var ModalInstanceCtrl = function ($scope, $modalInstance, address) { + var ModalInstanceCtrl = function($scope, $modalInstance, address) { $scope.address = address; $scope.isMobile = !!window.cordova; @@ -25,7 +26,7 @@ angular.module('copayApp.controllers').controller('AddressesController', window.plugins.toast.showShortBottom('Copied to clipboard'); } - $scope.cancel = function () { + $scope.cancel = function() { $modalInstance.dismiss('cancel'); }; }; @@ -35,19 +36,47 @@ angular.module('copayApp.controllers').controller('AddressesController', windowClass: 'tiny', controller: ModalInstanceCtrl, resolve: { - address: function() { return address; } + address: function() { + return address; + } } }); }; $rootScope.$watch('addrInfos', function() { + if ($rootScope.updatingBalance) return; $scope.addressList(); }); + $scope.toggleShowAll = function() { + $scope.showAll = !$scope.showAll; + $scope.addressList(); + }; + + $scope.limitAddress = function(elements) { + + elements = elements.sort(function(a, b) { + return (+a.isChange - +b.isChange); + }); + + if (elements.length <= 1 || $scope.showAll) { + return elements; + } + + // Show last 3 non-change addresses plus those with balance + var addrs = elements.filter(function(e, i) { + return (!e.isChange && i < 3) || (e.balance && e.balance > 0); + }); + + return addrs; + }; + $scope.addressList = function() { $scope.addresses = []; - var addrInfos = $rootScope.addrInfos; - if (addrInfos) { + + if ($rootScope.addrInfos) { + var addrInfos = $rootScope.addrInfos; + $scope.addrLength = addrInfos.length; for (var i = 0; i < addrInfos.length; i++) { var addrinfo = addrInfos[i]; $scope.addresses.push({ @@ -57,7 +86,8 @@ angular.module('copayApp.controllers').controller('AddressesController', 'owned': addrinfo.owned }); } + $scope.addresses = $scope.limitAddress($scope.addresses); } - } + }; } ); diff --git a/js/filters.js b/js/filters.js index 9cd467bbf..2c562663c 100644 --- a/js/filters.js +++ b/js/filters.js @@ -26,62 +26,45 @@ angular.module('copayApp.filters', []) }); } }) - .filter('limitAddress', function() { - return function(elements, showAll) { - elements = elements.sort(function(a, b) { - return (+b.owned) - (+a.owned); - }); - if (elements.length <= 1 || showAll) { - return elements; - } +.filter('noFractionNumber', ['$filter', '$locale', '$rootScope', + function(filter, locale, $rootScope) { + var numberFilter = filter('number'); + var formats = locale.NUMBER_FORMATS; + return function(amount, n) { + if (typeof(n) === 'undefined' && !$rootScope.wallet) return amount; - // Show last 3 non-change addresses plus those with balance - var addrs = elements.filter(function(e, i) { - return (!e.isChange && i < 3) || (e.balance && e.balance > 0); - }); - - return addrs; - }; - }) - .filter('noFractionNumber', ['$filter', '$locale', '$rootScope', - function(filter, locale, $rootScope) { - var numberFilter = filter('number'); - var formats = locale.NUMBER_FORMATS; - return function(amount, n) { - if (typeof(n) === 'undefined' && !$rootScope.wallet) return amount; - - var fractionSize = (typeof(n) !== 'undefined') ? - n : $rootScope.wallet.settings.unitToSatoshi.toString().length - 1; - var value = numberFilter(amount, fractionSize); - var sep = value.indexOf(formats.DECIMAL_SEP); - var group = value.indexOf(formats.GROUP_SEP); - if (amount >= 0) { - if (group > 0) { - if (sep < 0) { - return value; - } - var intValue = value.substring(0, sep); - var floatValue = parseFloat(value.substring(sep)); - if (floatValue === 0) { - floatValue = ''; - } else { - if (floatValue % 1 === 0) { - floatValue = floatValue.toFixed(0); - } - floatValue = floatValue.toString().substring(1); - } - var finalValue = intValue + floatValue; - return finalValue; - } else { - value = parseFloat(value); - if (value % 1 === 0) { - value = value.toFixed(0); - } + var fractionSize = (typeof(n) !== 'undefined') ? + n : $rootScope.wallet.settings.unitToSatoshi.toString().length - 1; + var value = numberFilter(amount, fractionSize); + var sep = value.indexOf(formats.DECIMAL_SEP); + var group = value.indexOf(formats.GROUP_SEP); + if (amount >= 0) { + if (group > 0) { + if (sep < 0) { return value; } + var intValue = value.substring(0, sep); + var floatValue = parseFloat(value.substring(sep)); + if (floatValue === 0) { + floatValue = ''; + } else { + if (floatValue % 1 === 0) { + floatValue = floatValue.toFixed(0); + } + floatValue = floatValue.toString().substring(1); + } + var finalValue = intValue + floatValue; + return finalValue; + } else { + value = parseFloat(value); + if (value % 1 === 0) { + value = value.toFixed(0); + } + return value; } - return 0; - }; - } - ]); + } + return 0; + }; + } +]); diff --git a/js/models/PublicKeyRing.js b/js/models/PublicKeyRing.js index 84a08ed16..9512986ed 100644 --- a/js/models/PublicKeyRing.js +++ b/js/models/PublicKeyRing.js @@ -45,6 +45,7 @@ function PublicKeyRing(opts) { this.copayerIds = []; this.copayersBackup = opts.copayersBackup || []; this.addressToPath = {}; + }; /** @@ -322,6 +323,8 @@ PublicKeyRing.prototype.getRedeemScript = function(index, isChange, copayerIndex return script; }; + + /** * @desc * Get the address for a multisig based on the given params. @@ -462,9 +465,11 @@ PublicKeyRing.prototype.getAddressesInfo = function(opts, pubkey) { var ret = []; var self = this; var copayerIndex = pubkey && this.getCosigner(pubkey); + this.indexes.forEach(function(index) { ret = ret.concat(self.getAddressesInfoForIndex(index, opts, copayerIndex)); }); + return ret; }; @@ -489,7 +494,6 @@ PublicKeyRing.prototype.getAddressesInfo = function(opts, pubkey) { */ PublicKeyRing.prototype.getAddressesInfoForIndex = function(index, opts, copayerIndex) { opts = opts || {}; - var isOwned = index.copayerIndex === HDPath.SHARED_INDEX || index.copayerIndex === copayerIndex; var ret = []; var appendAddressInfo = function(address, isChange) { diff --git a/js/services/controllerUtils.js b/js/services/controllerUtils.js index 5200b4e1c..7b70f660c 100644 --- a/js/services/controllerUtils.js +++ b/js/services/controllerUtils.js @@ -136,6 +136,7 @@ angular.module('copayApp.services') }); w.on('close', root.onErrorDigest); w.on('locked', root.onErrorDigest.bind(this)); + }; root.setupRootVariables = function() { @@ -159,6 +160,7 @@ angular.module('copayApp.services') root.updateAddressList(); notification.enableHtml5Mode(); // for chrome: if support, enable it w.netStart(); + }; // TODO movie this to wallet @@ -281,5 +283,7 @@ angular.module('copayApp.services') }); } + + return root; }); diff --git a/test/unit/filters/filtersSpec.js b/test/unit/filters/filtersSpec.js index 1f2e52809..45607ba63 100644 --- a/test/unit/filters/filtersSpec.js +++ b/test/unit/filters/filtersSpec.js @@ -15,68 +15,7 @@ describe('Unit: Testing Filters', function() { alternativeIsoCode: 'LOL' }; - describe('limitAddress', function() { - it('should handle emtpy list', inject(function($filter) { - var limitAddress = $filter('limitAddress'); - expect(limitAddress([], false)).to.be.empty; - })); - - it('should honor show all', inject(function($filter) { - var limitAddress = $filter('limitAddress'); - var addresses = [{}, {}, {}, {}, {}]; - expect(limitAddress(addresses, true).length).to.equal(5); - expect(limitAddress([{}], false).length).to.equal(1); - })); - - it('should filter correctly', inject(function($filter) { - var limitAddress = $filter('limitAddress'); - var addresses = [{ - isChange: true, - balance: 0 - }, { - isChange: false, - balance: 0 - }, { - isChange: true, - balance: 0 - }, { - isChange: false, - balance: 0 - }, { - isChange: true, - balance: 0 - }, { - isChange: false, - balance: 0 - }, { - isChange: true, - balance: 0 - }, { - isChange: false, - balance: 0 - }]; - expect(limitAddress(addresses, false).length).to.equal(1); - - addresses[0].isChange = false; - expect(limitAddress(addresses, false).length).to.equal(2); - - addresses[2].isChange = false; - expect(limitAddress(addresses, false).length).to.equal(3); - - addresses[3].isChange = false; - expect(limitAddress(addresses, false).length).to.equal(3); - - addresses[0].balance = 20; - expect(limitAddress(addresses, false).length).to.equal(3); - - addresses[0].balance = 20; - expect(limitAddress(addresses, false).length).to.equal(3); - - addresses[7].balance = 20; - expect(limitAddress(addresses, false).length).to.equal(4); - })); - }); describe('removeEmpty addresses', function() { it('should work with empty lists', inject(function($filter) { diff --git a/views/addresses.html b/views/addresses.html index 011e817bc..688f3d628 100644 --- a/views/addresses.html +++ b/views/addresses.html @@ -4,10 +4,12 @@ Addresses - +
+ +
-
-
+
+
@@ -22,7 +24,7 @@
- +

{{addr.balance || 0|noFractionNumber}} {{$root.wallet.settings.unitName}}

@@ -50,8 +52,7 @@
- - + Show all Show less