diff --git a/public/views/includes/walletActivity.html b/public/views/includes/walletActivity.html index c6ed33ba9..33fe998ce 100644 --- a/public/views/includes/walletActivity.html +++ b/public/views/includes/walletActivity.html @@ -42,6 +42,7 @@
+ {{ x.creatorName}}@ {{x.wallet.name}} diff --git a/src/js/controllers/activity.js b/src/js/controllers/activity.js index 60a1f2cdf..89f06fafe 100644 --- a/src/js/controllers/activity.js +++ b/src/js/controllers/activity.js @@ -17,31 +17,14 @@ angular.module('copayApp.controllers').controller('activityController', $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, { - includeOwn: true, - 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; + setNotifications(n); + }) } }); diff --git a/src/js/controllers/tab-home.js b/src/js/controllers/tab-home.js index 631f87441..bcaeb1d75 100644 --- a/src/js/controllers/tab-home.js +++ b/src/js/controllers/tab-home.js @@ -4,9 +4,9 @@ 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); + var n = walletService.processNotifications(notifications, 3); $scope.notifications = n; - $scope.notificationsMore = notifications.length > 5 ? notifications.length - 5 : null; + $scope.notificationsMore = notifications.length > 3 ? notifications.length - 3 : null; $timeout(function() { $scope.$apply(); }, 1); @@ -22,8 +22,6 @@ angular.module('copayApp.controllers').controller('tabHomeController', var timeSpan = 60 * 60 * 24 * 7; var notifications = []; - $scope.fetchingNotifications = true; - lodash.each($scope.wallets, function(wallet) { walletService.getStatus(wallet, {}, function(err, status) { @@ -34,22 +32,19 @@ angular.module('copayApp.controllers').controller('tabHomeController', wallet.status = status; }); - walletService.getNotifications(wallet, { - timeSpan: timeSpan, - includeOwn: true, - }, 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))); - }; - }); }); + + $scope.fetchingNotifications = true; + profileService.getNotifications(3, function(err, n) { + if (err) { + console.log('[tab-home.js.35:err:]', $log.error(err)); //TODO + return; + } + $scope.fetchingNotifications = false; + setNotifications(n); + }) + $scope.$digest(); }, 100); }; diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 61a9f4e9a..44eff25a9 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -428,8 +428,8 @@ angular.module('copayApp.services') // check if exist if (lodash.find(root.profile.credentials, { - 'walletId': walletData.walletId - })) { + 'walletId': walletData.walletId + })) { return cb(gettext('Cannot join the same wallet more that once')); } } catch (ex) { @@ -735,15 +735,76 @@ angular.module('copayApp.services') }); } else {} - return lodash.sortBy(ret, [function(x) { - return x.isComplete(); - }, 'createdOn']); + return lodash.sortBy(ret, [ + function(x) { + return x.isComplete(); + }, 'createdOn' + ]); }; root.toggleHideBalanceFlag = function(walletId, cb) { root.wallet[walletId].balanceHidden = !root.wallet[walletId].balanceHidden; storageService.setHideBalanceFlag(walletId, root.wallet[walletId].balanceHidden.toString(), cb); - } + }; + + root.getNotifications = function(limit, cb) { + + var TIME_STAMP = 60 * 60 * 24 * 7; + + var opts = { + timeSpan: TIME_STAMP, + includeOwn: true, + }; + + var ignored = { + 'NewBlock': 1, + 'BalanceUpdated': 1, + 'NewOutgoingTxByThirdParty': 1, + 'NewAddress': 1, + 'TxProposalFinallyAccepted': 1, + 'TxProposalFinallyRejected': 1, + }; + + var w = root.getWallets(); + if (lodash.isEmpty(w)) return cb(); + + var l = w.length, + j = 0, + notifications = []; + lodash.each(w, function(wallet) { + wallet.getNotifications(opts, function(err, n) { + j++; + if (err) { + console.log('[tab-home.js.35:err:]', $log.error(err)); //TODO + return; + } + + n = lodash.filter(n, function(x) { + return !ignored[x.type]; + }); + + var idToName = {}; + if (wallet.cachedStatus) { + lodash.each(wallet.cachedStatus.wallet.copayers, function(c) { + idToName[c.id] = c.name; + }); + } + + lodash.each(n, function(x) { + x.wallet = wallet; + if (x.creatorId && wallet.cachedStatus) { + x.creatorName = idToName[x.creatorId]; + }; + }); + + notifications.push(n); + if (++j == l) { + notifications = lodash.sortBy(notifications,'createdOn'); + return cb(null, lodash.compact(lodash.flatten(notifications))); + }; + }); + }); + }; return root; }); diff --git a/src/js/services/walletService.js b/src/js/services/walletService.js index 7eea001d0..435ead627 100644 --- a/src/js/services/walletService.js +++ b/src/js/services/walletService.js @@ -976,40 +976,6 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim }); }; - root.getNotifications = function(wallet, opts, cb) { - - wallet.getNotifications(opts, function(err, notifications) { - if (err) return cb(err); - - var ignored = { - 'NewBlock': 1, - 'BalanceUpdated': 1, - 'NewOutgoingTxByThirdParty': 1, - 'NewAddress': 1, - }; - - notifications = lodash.filter(notifications, function(x) { - return !ignored[x.type]; - }); - - var idToName = {}; - if (wallet.cachedStatus) { - lodash.each(wallet.cachedStatus.wallet.copayers, function(c) { - idToName[c.id] = c.name; - }); - } - - lodash.each(notifications, function(x) { - x.wallet = wallet; - if (x.creatorId && wallet.cachedStatus) { - x.creatorName = idToName[x.creatorId]; - }; - }); - - return cb(null, notifications); - }); - }; - root.getEncodedWalletInfo = function(wallet, cb) { var derivationPath = wallet.credentials.getBaseAddressDerivationPath();