Merge pull request #24 from bitpay/feat/notif2

Feat/notif2
This commit is contained in:
Gustavo Maximiliano Cortez 2016-08-31 18:23:48 -03:00 committed by GitHub
commit 46f8c3a3ac
10 changed files with 228 additions and 185 deletions

View file

@ -4,43 +4,19 @@ angular.module('copayApp.controllers').controller('activityController',
function($rootScope, $timeout, $scope, $state, lodash, profileService, walletService, configService, txFormatService, $ionicModal, $log, platformInfo) {
var self = this;
var setNotifications = function(notifications) {
var n = walletService.processNotifications(notifications);
$scope.notifications = n;
$timeout(function() {
$scope.$apply();
}, 1);
};
$scope.init = function() {
$scope.wallets = profileService.getWallets();
var i = $scope.wallets.length,
j = 0;
var timeSpan = 60 * 60 * 24 * 7;
var notifications = [];
$scope.fetchingNotifications = true;
lodash.each($scope.wallets, function(wallet) {
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)));
};
});
profileService.getNotifications(50, function(err, n) {
if (err) {
console.log('[tab-home.js.35:err:]', $log.error(err)); //TODO
return;
}
$scope.fetchingNotifications = false;
$scope.notifications = n;
$timeout(function() {
$scope.$apply();
}, 1);
});
}
});

View file

@ -4,9 +4,7 @@ angular.module('copayApp.controllers').controller('tabHomeController',
function($rootScope, $timeout, $scope, $state, lodash, profileService, walletService, configService, txFormatService, $ionicModal, $log, platformInfo, storageService) {
var setNotifications = function(notifications) {
var n = walletService.processNotifications(notifications, 5);
$scope.notifications = n;
$scope.notificationsMore = notifications.length > 5 ? notifications.length - 5 : null;
$scope.notifications = notifications;
$timeout(function() {
$scope.$apply();
}, 1);
@ -16,41 +14,35 @@ angular.module('copayApp.controllers').controller('tabHomeController',
$scope.wallets = profileService.getWallets();
if (lodash.isEmpty($scope.wallets)) return;
$timeout(function() {
var i = $scope.wallets.length;
var j = 0;
var timeSpan = 60 * 60 * 24 * 7;
var notifications = [];
var i = $scope.wallets.length;
var j = 0;
var timeSpan = 60 * 60 * 24 * 7;
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)));
};
});
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;
});
$scope.$digest();
}, 100);
});
$scope.fetchingNotifications = true;
profileService.getNotifications({
limit: 3
}, function(err, n) {
if (err) {
console.log('[tab-home.js.35:err:]', $log.error(err)); //TODO
return;
}
$scope.fetchingNotifications = false;
setNotifications(n);
})
};
$scope.updateWallet = function(wallet) {
@ -61,9 +53,17 @@ angular.module('copayApp.controllers').controller('tabHomeController',
return;
}
wallet.status = status;
$timeout(function() {
$scope.$apply();
}, 1);
profileService.getNotifications({
limit: 3
}, function(err, n) {
console.log('[tab-home.js.57]', n); //TODO
if (err) {
console.log('[tab-home.js.35:err:]', $log.error(err)); //TODO
return;
}
setNotifications(n);
})
});
};