list available and unavailable wallets properly

This commit is contained in:
JDonadio 2017-09-20 17:24:45 -03:00
commit 5867edfa26
No known key found for this signature in database
GPG key ID: EC1F4E04B2BFA730
2 changed files with 76 additions and 15 deletions

View file

@ -45,19 +45,57 @@ angular.module('copayApp.controllers').controller('cashScanController',
return !xPubKeyIndex[w.credentials.xPubKey];
});
// Filter out non BIP44 wallets
var wallets = lodash.filter(walletsBTC, function(w) {
return w.credentials.derivationStrategy == 'BIP44'
});
var availableWallets = [];
var nonEligibleWallets = [];
$scope.wallets = wallets;
$scope.nonBIP44Wallets = lodash.filter(walletsBTC, function(w) {
function addToNonEligibleWallets(wallets) {
if (!wallets) return;
lodash.each(wallets, function(w) {
nonEligibleWallets.push(w);
});
};
// Filter out non BIP44 wallets
var nonBIP44Wallets = lodash.filter(walletsBTC, function(w) {
return w.credentials.derivationStrategy != 'BIP44';
});
var i = wallets.length;
if (!lodash.isEmpty(nonBIP44Wallets)) {
availableWallets = lodash.filter(walletsBTC, function(w) {
return w.credentials.derivationStrategy == 'BIP44';
});
addToNonEligibleWallets(nonBIP44Wallets);
}
// Filter out read only wallets
var readOnlyWallets = lodash.filter(availableWallets, function(w) {
return !w.canSign();
});
if (!lodash.isEmpty(readOnlyWallets)) {
availableWallets = lodash.filter(availableWallets, function(w) {
return w.canSign();
});
addToNonEligibleWallets(readOnlyWallets);
}
// Filter out non backed up wallets
$scope.nonBackedUpWallets = lodash.filter(availableWallets, function(w) {
return w.needsBackup;
});
if (!lodash.isEmpty($scope.nonBackedUpWallets)) {
availableWallets = lodash.filter(availableWallets, function(w) {
return !w.needsBackup;
});
}
$scope.nonEligibleWallets = nonEligibleWallets;
$scope.availableWallets = availableWallets;
var i = availableWallets.length;
var j = 0;
lodash.each(wallets, function(wallet) {
lodash.each(availableWallets, function(wallet) {
walletService.getBalance(wallet, {
coin: 'bch'
}, function(err, balance) {