Merge pull request #1447 from matiaspando/feature/orderAddressList

Fixes show all/show less button on address list
This commit is contained in:
Gustavo Maximiliano Cortez 2014-09-23 18:01:56 -03:00
commit c091c6c40a
6 changed files with 88 additions and 127 deletions

View file

@ -3,6 +3,7 @@
angular.module('copayApp.controllers').controller('AddressesController', angular.module('copayApp.controllers').controller('AddressesController',
function($scope, $rootScope, $timeout, $modal, controllerUtils) { function($scope, $rootScope, $timeout, $modal, controllerUtils) {
$scope.loading = false; $scope.loading = false;
$scope.showAll = false;
var w = $rootScope.wallet; var w = $rootScope.wallet;
$scope.newAddr = function() { $scope.newAddr = function() {
@ -35,19 +36,47 @@ angular.module('copayApp.controllers').controller('AddressesController',
windowClass: 'tiny', windowClass: 'tiny',
controller: ModalInstanceCtrl, controller: ModalInstanceCtrl,
resolve: { resolve: {
address: function() { return address; } address: function() {
return address;
}
} }
}); });
}; };
$rootScope.$watch('addrInfos', function() { $rootScope.$watch('addrInfos', function() {
if ($rootScope.updatingBalance) return;
$scope.addressList(); $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.addressList = function() {
$scope.addresses = []; $scope.addresses = [];
if ($rootScope.addrInfos) {
var addrInfos = $rootScope.addrInfos; var addrInfos = $rootScope.addrInfos;
if (addrInfos) { $scope.addrLength = addrInfos.length;
for (var i = 0; i < addrInfos.length; i++) { for (var i = 0; i < addrInfos.length; i++) {
var addrinfo = addrInfos[i]; var addrinfo = addrInfos[i];
$scope.addresses.push({ $scope.addresses.push({
@ -57,7 +86,8 @@ angular.module('copayApp.controllers').controller('AddressesController',
'owned': addrinfo.owned 'owned': addrinfo.owned
}); });
} }
$scope.addresses = $scope.limitAddress($scope.addresses);
} }
} };
} }
); );

View file

@ -26,24 +26,7 @@ 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;
}
// 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', .filter('noFractionNumber', ['$filter', '$locale', '$rootScope',
function(filter, locale, $rootScope) { function(filter, locale, $rootScope) {
var numberFilter = filter('number'); var numberFilter = filter('number');

View file

@ -45,6 +45,7 @@ function PublicKeyRing(opts) {
this.copayerIds = []; this.copayerIds = [];
this.copayersBackup = opts.copayersBackup || []; this.copayersBackup = opts.copayersBackup || [];
this.addressToPath = {}; this.addressToPath = {};
}; };
/** /**
@ -322,6 +323,8 @@ PublicKeyRing.prototype.getRedeemScript = function(index, isChange, copayerIndex
return script; return script;
}; };
/** /**
* @desc * @desc
* Get the address for a multisig based on the given params. * Get the address for a multisig based on the given params.
@ -462,9 +465,11 @@ PublicKeyRing.prototype.getAddressesInfo = function(opts, pubkey) {
var ret = []; var ret = [];
var self = this; var self = this;
var copayerIndex = pubkey && this.getCosigner(pubkey); var copayerIndex = pubkey && this.getCosigner(pubkey);
this.indexes.forEach(function(index) { this.indexes.forEach(function(index) {
ret = ret.concat(self.getAddressesInfoForIndex(index, opts, copayerIndex)); ret = ret.concat(self.getAddressesInfoForIndex(index, opts, copayerIndex));
}); });
return ret; return ret;
}; };
@ -489,7 +494,6 @@ PublicKeyRing.prototype.getAddressesInfo = function(opts, pubkey) {
*/ */
PublicKeyRing.prototype.getAddressesInfoForIndex = function(index, opts, copayerIndex) { PublicKeyRing.prototype.getAddressesInfoForIndex = function(index, opts, copayerIndex) {
opts = opts || {}; opts = opts || {};
var isOwned = index.copayerIndex === HDPath.SHARED_INDEX || index.copayerIndex === copayerIndex; var isOwned = index.copayerIndex === HDPath.SHARED_INDEX || index.copayerIndex === copayerIndex;
var ret = []; var ret = [];
var appendAddressInfo = function(address, isChange) { var appendAddressInfo = function(address, isChange) {

View file

@ -136,6 +136,7 @@ angular.module('copayApp.services')
}); });
w.on('close', root.onErrorDigest); w.on('close', root.onErrorDigest);
w.on('locked', root.onErrorDigest.bind(this)); w.on('locked', root.onErrorDigest.bind(this));
}; };
root.setupRootVariables = function() { root.setupRootVariables = function() {
@ -159,6 +160,7 @@ angular.module('copayApp.services')
root.updateAddressList(); root.updateAddressList();
notification.enableHtml5Mode(); // for chrome: if support, enable it notification.enableHtml5Mode(); // for chrome: if support, enable it
w.netStart(); w.netStart();
}; };
// TODO movie this to wallet // TODO movie this to wallet
@ -281,5 +283,7 @@ angular.module('copayApp.services')
}); });
} }
return root; return root;
}); });

View file

@ -15,68 +15,7 @@ describe('Unit: Testing Filters', function() {
alternativeIsoCode: 'LOL' 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() { describe('removeEmpty addresses', function() {
it('should work with empty lists', inject(function($filter) { it('should work with empty lists', inject(function($filter) {

View file

@ -4,10 +4,12 @@
<span translate>Addresses</span> <span translate>Addresses</span>
<span class="button primary small side-bar" ng-click="newAddr()" ng-disabled="loading"><i class="fi-plus"></i></span> <span class="button primary small side-bar" ng-click="newAddr()" ng-disabled="loading"><i class="fi-plus"></i></span>
</h1> </h1>
<div ng-show="!addresses[0]">
<i class="fi-bitcoin-circle icon-rotate spinner"></i>
</div>
<div class="large-12 medium-12" ng-if="!!(addresses|removeEmpty).length"> <div class="large-12 medium-12" ng-if="!!(addresses|removeEmpty).length">
<div class="large-12 medium-12" ng-init="showAll=0"> <div class="large-12 medium-12">
<div class="oh" ng-repeat="addr in addresses|removeEmpty|limitAddress:showAll"> <div class="oh" ng-repeat="addr in addresses|removeEmpty">
<div class="panel radius show-for-large-up"> <div class="panel radius show-for-large-up">
<div class="row collapse"> <div class="row collapse">
<div class="large-7 medium-9 column"> <div class="large-7 medium-9 column">
@ -50,8 +52,7 @@
</div> </div>
</div> </div>
<a class="secondary radius" ng-click="toggleShowAll()" ng-show="addrLength > 3">
<a class="secondary radius" ng-click="showAll=!showAll" ng-show="(addresses|removeEmpty).length != (addresses|removeEmpty|limitAddress).length">
<span translate ng-if="!showAll">Show all</span> <span translate ng-if="!showAll">Show all</span>
<span translate ng-if="showAll">Show less</span> <span translate ng-if="showAll">Show less</span>
</a> </a>