This commit is contained in:
Matias Alejo Garcia 2016-08-24 17:54:01 -03:00
commit 7229adf08a
No known key found for this signature in database
GPG key ID: 02470DB551277AB3
8 changed files with 335 additions and 64 deletions

View file

@ -4,27 +4,58 @@ angular.module('copayApp.controllers').controller('tabHomeController',
function($rootScope, $timeout, $scope, $state, lodash, profileService, walletService, configService, txFormatService, $ionicModal, $log, platformInfo) {
var self = this;
self.setWallets = function() {
$scope.wallets = profileService.getWallets();
var setNotifications = function(notifications) {
var n = walletService.processNotifications(notifications, 5);
$scope.notifications = n;
$scope.notificationsMore = notifications.length > 5 ? notifications.length - 5 : null;
$timeout(function() {
$scope.$apply();
}, 1);
};
self.updateAllWallets = function() {
$scope.wallets = profileService.getWallets();
var i = $scope.wallets.length;
var i = $scope.wallets.length, j =0;
// var timeSpan = 60 * 60 * 24 * 7;
var timeSpan = 60 * 60 * 24 * 1;
var notifications = [];
$scope.fetchingNotifications = true;
lodash.each($scope.wallets, function(wallet) {
walletService.getStatus(wallet, {}, function(err, status) {
if (err) {
console.log('[tab-home.js.35:err:]', $log.error(err)); //TODO
return;
}
}
wallet.status = status;
});
walletService.getNotifications(wallet, {
timeSpan: timeSpan
}, function(err, n) {
if (err) {
console.log('[tab-home.js.35:err:]', $log.error(err)); //TODO
return;
}
notifications.push(n);
if (++j == i) {
$scope.fetchingNotifications = false;
setNotifications(lodash.compact(lodash.flatten(notifications)));
};
});
});
}
self.updateWallet = function(wallet) {
$log.debug('Updating wallet:' + wallet.name)
walletService.getStatus(wallet, {}, function(err, status) {
if (err) {
@ -32,7 +63,7 @@ angular.module('copayApp.controllers').controller('tabHomeController',
return;
}
wallet.status = status;
$timeout(function(){
$timeout(function() {
$scope.$apply();
}, 1);
});
@ -55,7 +86,7 @@ angular.module('copayApp.controllers').controller('tabHomeController',
];
$scope.$on('$destroy', function() {
lodash.each(listeners, function(x){
lodash.each(listeners, function(x) {
x();
});
});