isolated scope - wallets filtered from controller

This commit is contained in:
Javier 2016-08-24 19:32:49 -03:00
commit 19419526e4
6 changed files with 55 additions and 67 deletions

View file

@ -147,57 +147,18 @@ angular.module('copayApp.directives')
return {
restrict: 'E',
templateUrl: 'views/includes/wallets.html',
scope: false,
scope: {
wallets: '=wallets'
},
link: function(scope, element, attrs) {
var opts = {};
opts.onlyComplete = attrs.onlyComplete == 'true' ? true : null;
opts.network = attrs.network;
opts.n = attrs.n;
scope.content = {};
scope.content.wallets = [];
scope.content.notAvailable = false;
var wallets = profileService.getWallets(opts);
var minBalance = attrs.minBalance ? parseInt(attrs.minBalance) : 0;
var filteredWallets = [];
var index = 0;
if (minBalance)
filterWallet();
else {
scope.content.wallets = wallets;
scope.$emit('Wallet/Changed', scope.content.wallets[0]);
}
scope.$on("$ionicSlides.sliderInitialized", function(event, data) {
scope.slider = data.slider;
scope.$emit('Wallet/Changed', scope.wallets[0]);
});
scope.$on("$ionicSlides.slideChangeEnd", function(event, data) {
scope.content.index = data.slider.activeIndex;
scope.$emit('Wallet/Changed', scope.content.wallets[scope.content.index]);
scope.$emit('Wallet/Changed', scope.wallets[data.slider.activeIndex]);
});
function filterWallet() {
if (index == wallets.length) {
if (!lodash.isEmpty(filteredWallets)) {
scope.content.wallets = filteredWallets;
scope.$emit('Wallet/Changed', scope.content.wallets[0]);
} else {
scope.content.notAvailable = true;
$log.warn('No wallet available to make the payment');
}
return;
}
walletService.getStatus(wallets[index], {}, function(err, status) {
if (err) $log.error(err);
if (!status.availableBalanceSat) $log.debug('No balance available in: ' + wallets[index].name);
if (status.availableBalanceSat > minBalance) filteredWallets.push(wallets[index]);
index++;
filterWallet();
});
};
}
}
});