From a4bc232f3abfa26e53fed2236ad74b13564c27cd Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 31 Aug 2016 13:47:03 -0300 Subject: [PATCH 1/6] update bwc --- app-template/package.json | 2 +- chrome-app/manifest.json | 4 ++-- package.json | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app-template/package.json b/app-template/package.json index 1b9235f8c..0d396c2af 100644 --- a/app-template/package.json +++ b/app-template/package.json @@ -42,7 +42,7 @@ "url": "https://github.com/bitpay/copay/issues" }, "dependencies": { - "bitcore-wallet-client": "4.0.0", + "bitcore-wallet-client": "4.1.0", "coveralls": "^2.11.9", "express": "^4.11.2", "fs": "0.0.2", diff --git a/chrome-app/manifest.json b/chrome-app/manifest.json index e6320e72a..7f7f2324b 100644 --- a/chrome-app/manifest.json +++ b/chrome-app/manifest.json @@ -1,6 +1,6 @@ - { + { "//":"PLEASE! Do not edit this file directly", - "//":" Modify it at app-template/", + "//":" Modify it at app-template/", "manifest_version": 2, "name": "BitPay", diff --git a/package.json b/package.json index 24776e4fc..ef792c82a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ - { + { "//":"PLEASE! Do not edit this file directly", - "//":" Modify it at app-template/", + "//":" Modify it at app-template/", "name": "bitpay", "description": "The BitPay Bitcoin Wallet", @@ -45,7 +45,7 @@ "url": "https://github.com/bitpay/copay/issues" }, "dependencies": { - "bitcore-wallet-client": "4.0.0", + "bitcore-wallet-client": "4.1.0", "coveralls": "^2.11.9", "express": "^4.11.2", "fs": "0.0.2", From 8bc84d397d42fa4695de3806107a397506f9d2c4 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 31 Aug 2016 15:16:00 -0300 Subject: [PATCH 2/6] . --- public/views/activity.html | 2 +- public/views/includes/walletActivity.html | 2 +- public/views/tab-home.html | 14 ++++++-------- src/js/controllers/tab-home.js | 3 ++- src/js/services/profileService.js | 4 +++- src/js/services/walletService.js | 9 ++++++++- 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/public/views/activity.html b/public/views/activity.html index d10d45479..bfbc44076 100644 --- a/public/views/activity.html +++ b/public/views/activity.html @@ -19,7 +19,7 @@
-
+
diff --git a/public/views/includes/walletActivity.html b/public/views/includes/walletActivity.html index 76931d556..149ec0cc5 100644 --- a/public/views/includes/walletActivity.html +++ b/public/views/includes/walletActivity.html @@ -38,5 +38,5 @@ {{x.wallet.name}}

- + diff --git a/public/views/tab-home.html b/public/views/tab-home.html index 0c258b9e6..402f9d6f3 100644 --- a/public/views/tab-home.html +++ b/public/views/tab-home.html @@ -5,9 +5,10 @@ -
-
+
+
Recent Activity +
diff --git a/src/js/controllers/tab-home.js b/src/js/controllers/tab-home.js index b6886b5c2..631f87441 100644 --- a/src/js/controllers/tab-home.js +++ b/src/js/controllers/tab-home.js @@ -35,7 +35,8 @@ angular.module('copayApp.controllers').controller('tabHomeController', }); walletService.getNotifications(wallet, { - timeSpan: timeSpan + timeSpan: timeSpan, + includeOwn: true, }, function(err, n) { if (err) { console.log('[tab-home.js.35:err:]', $log.error(err)); //TODO diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 1d6e5ffdb..61a9f4e9a 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -130,7 +130,9 @@ angular.module('copayApp.services') }); }); - wallet.initialize({}, function(err) { + wallet.initialize({ + notificationIncludeOwn: true, + }, function(err) { if (err) { $log.error('Could not init notifications err:', err); return; diff --git a/src/js/services/walletService.js b/src/js/services/walletService.js index bdfe1a291..7eea001d0 100644 --- a/src/js/services/walletService.js +++ b/src/js/services/walletService.js @@ -981,8 +981,15 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim 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 x.type != 'NewBlock' && x.type != 'BalanceUpdated' && x.type != 'NewOutgoingTxByThirdParty'; + return !ignored[x.type]; }); var idToName = {}; From d14f5306e3a1e98ea645d5be3038721fa0fc45a6 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 31 Aug 2016 15:23:44 -0300 Subject: [PATCH 3/6] include own notifications in ticker --- public/views/includes/walletActivity.html | 11 ++++++++++- src/js/controllers/activity.js | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/public/views/includes/walletActivity.html b/public/views/includes/walletActivity.html index 149ec0cc5..bdd5d7d9b 100644 --- a/public/views/includes/walletActivity.html +++ b/public/views/includes/walletActivity.html @@ -1,5 +1,15 @@ + +
+ Payment Sent +
+ {{x.amountStr}} +
+
+ + +
Payment Received
@@ -39,4 +49,3 @@

- diff --git a/src/js/controllers/activity.js b/src/js/controllers/activity.js index 897f1f21e..60a1f2cdf 100644 --- a/src/js/controllers/activity.js +++ b/src/js/controllers/activity.js @@ -29,7 +29,8 @@ angular.module('copayApp.controllers').controller('activityController', lodash.each($scope.wallets, function(wallet) { walletService.getNotifications(wallet, { - timeSpan: timeSpan + includeOwn: true, + timeSpan: timeSpan, }, function(err, n) { if (err) { console.log('[tab-home.js.35:err:]', $log.error(err)); //TODO From 3080cf05dde9f998926ff86f5c1f79f074eea394 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 31 Aug 2016 15:26:46 -0300 Subject: [PATCH 4/6] better activity --- public/views/includes/walletActivity.html | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/public/views/includes/walletActivity.html b/public/views/includes/walletActivity.html index bdd5d7d9b..c6ed33ba9 100644 --- a/public/views/includes/walletActivity.html +++ b/public/views/includes/walletActivity.html @@ -17,7 +17,6 @@
-
Proposal Deleted @@ -29,13 +28,13 @@
- + {{x.amountStr}} {{x.message}} - + Proposal Accepted From 0c668f3b831655a3d616b3b6b701f98fe05cc72f Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 31 Aug 2016 17:12:36 -0300 Subject: [PATCH 5/6] recent activity --- public/views/includes/walletActivity.html | 1 + src/js/controllers/activity.js | 33 +++------- src/js/controllers/tab-home.js | 31 ++++------ src/js/services/profileService.js | 73 +++++++++++++++++++++-- src/js/services/walletService.js | 34 ----------- 5 files changed, 89 insertions(+), 83 deletions(-) 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(); From e801fc26268ac28166a5bea4c61b30d7059fa058 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 31 Aug 2016 18:12:28 -0300 Subject: [PATCH 6/6] notifications cache and autorefresh --- public/views/tab-home.html | 2 +- src/js/controllers/activity.js | 18 +--- src/js/controllers/tab-home.js | 64 +++++++------ src/js/services/profileService.js | 146 +++++++++++++++++++++++------- src/js/services/walletService.js | 58 ------------ 5 files changed, 154 insertions(+), 134 deletions(-) diff --git a/public/views/tab-home.html b/public/views/tab-home.html index 402f9d6f3..ef9582374 100644 --- a/public/views/tab-home.html +++ b/public/views/tab-home.html @@ -8,7 +8,7 @@

Recent Activity - +
diff --git a/src/js/controllers/activity.js b/src/js/controllers/activity.js index 89f06fafe..6205357c5 100644 --- a/src/js/controllers/activity.js +++ b/src/js/controllers/activity.js @@ -4,17 +4,6 @@ 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.fetchingNotifications = true; @@ -24,7 +13,10 @@ angular.module('copayApp.controllers').controller('activityController', return; } $scope.fetchingNotifications = false; - setNotifications(n); - }) + $scope.notifications = n; + $timeout(function() { + $scope.$apply(); + }, 1); + }); } }); diff --git a/src/js/controllers/tab-home.js b/src/js/controllers/tab-home.js index bcaeb1d75..1421b60f1 100644 --- a/src/js/controllers/tab-home.js +++ b/src/js/controllers/tab-home.js @@ -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, 3); - $scope.notifications = n; - $scope.notificationsMore = notifications.length > 3 ? notifications.length - 3 : null; + $scope.notifications = notifications; $timeout(function() { $scope.$apply(); }, 1); @@ -16,37 +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 = []; - lodash.each($scope.wallets, function(wallet) { + 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.fetchingNotifications = true; - profileService.getNotifications(3, function(err, n) { + walletService.getStatus(wallet, {}, function(err, status) { if (err) { console.log('[tab-home.js.35:err:]', $log.error(err)); //TODO return; } - $scope.fetchingNotifications = false; - setNotifications(n); - }) + 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) { @@ -57,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); + }) }); }; diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 44eff25a9..0efb95b6a 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -1,6 +1,6 @@ 'use strict'; angular.module('copayApp.services') - .factory('profileService', function profileServiceFactory($rootScope, $timeout, $filter, $log, sjcl, lodash, storageService, bwcService, configService, pushNotificationsService, gettext, gettextCatalog, bwcError, uxLanguage, bitcore, platformInfo, $ionicHistory) { + .factory('profileService', function profileServiceFactory($rootScope, $timeout, $filter, $log, sjcl, lodash, storageService, bwcService, configService, pushNotificationsService, gettext, gettextCatalog, bwcError, uxLanguage, platformInfo, $ionicHistory, txFormatService, $state) { var isChromeApp = platformInfo.isChromeApp; @@ -119,6 +119,9 @@ angular.module('copayApp.services') if (wallet.completeHistory) wallet.completeHistory.isValid = false; + if (wallet.cachedActivity) + wallet.cachedActivity.isValid = false; + $rootScope.$emit('bwsEvent', wallet.id, n.type, n); }); @@ -736,6 +739,7 @@ angular.module('copayApp.services') } else {} return lodash.sortBy(ret, [ + function(x) { return x.isComplete(); }, 'createdOn' @@ -747,14 +751,11 @@ angular.module('copayApp.services') storageService.setHideBalanceFlag(walletId, root.wallet[walletId].balanceHidden.toString(), cb); }; - root.getNotifications = function(limit, cb) { + root.getNotifications = function(opts, cb) { + opts = opts || {}; var TIME_STAMP = 60 * 60 * 24 * 7; - - var opts = { - timeSpan: TIME_STAMP, - includeOwn: true, - }; + var MAX = 100; var ignored = { 'NewBlock': 1, @@ -771,36 +772,117 @@ angular.module('copayApp.services') var l = w.length, j = 0, notifications = []; + + + function isActivityCached(wallet) { + return wallet.cachedActivity && wallet.cachedActivity.isValid; + }; + + + function getNotifications(wallet, cb2) { + if (isActivityCached(wallet) && !opts.force) return cb2(); + + wallet.getNotifications({ + timeSpan: TIME_STAMP, + includeOwn: true, + }, function(err, n) { + if (err) return cb2(err); + + wallet.cachedActivity = { + n: n.slice(-MAX), + isValid: true, + }; + + return cb2(); + }); + }; + + function process(notifications) { + if (!notifications) return []; + + var shown = lodash.sortBy(notifications, 'createdOn').reverse(); + + shown = shown.splice(0, opts.limit || MAX); + + lodash.each(shown, function(x) { + x.txpId = x.data ? x.data.txProposalId : null; + x.txid = x.data ? x.data.txid : null; + x.types = [x.type]; + + if (x.data && x.data.amount) + x.amountStr = txFormatService.formatAmountStr(x.data.amount); + + x.action = function() { + // TODO? + $state.go('wallet.details', { + walletId: x.walletId, + txpId: x.txpId, + txid: x.txid, + }); + }; + }); + + // condense + var finale = [], + prev; + + + lodash.each(shown, function(x) { + if (prev && prev.walletId === x.walletId && prev.txpId && prev.txpId === x.txpId && prev.creatorId && prev.creatorId === x.creatorId) { + prev.types.push(x.type); + prev.data = lodash.assign(prev.data, x.data); + prev.txid = prev.txid || x.txid; + prev.amountStr = prev.amountStr || x.amountStr; + prev.creatorName = prev.creatorName || x.creatorName; + } else { + finale.push(x); + prev = x; + } + }); + + // messages... + + var u = bwcService.getUtils(); + lodash.each(finale, function(x) { + if (x.data && x.data.message && x.wallet && x.wallet.credentials.sharedEncryptingKey) { + // TODO TODO TODO => BWC + x.message = u.decryptMessage(x.data.message, x.wallet.credentials.sharedEncryptingKey); + } + }); + + return finale; + }; + lodash.each(w, function(wallet) { - wallet.getNotifications(opts, function(err, n) { + getNotifications(wallet, function(err) { 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; + $log.warn('Error updating notifications:' + err); + } else { + var n = lodash.filter(wallet.cachedActivity.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); } - - 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))); + if (j == l) { + notifications = lodash.sortBy(notifications, 'createdOn'); + notifications = lodash.compact(lodash.flatten(notifications)).slice(0,MAX); + return cb(null, process(notifications)); }; }); }); diff --git a/src/js/services/walletService.js b/src/js/services/walletService.js index 435ead627..fd5a5bfa2 100644 --- a/src/js/services/walletService.js +++ b/src/js/services/walletService.js @@ -1009,64 +1009,6 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim }); }; - root.processNotifications = function(notifications, limit) { - if (!notifications) return []; - - var shown = lodash.sortBy(notifications, 'createdOn').reverse(); - - if (limit) - shown = shown.splice(0, limit); - - lodash.each(shown, function(x) { - x.txpId = x.data ? x.data.txProposalId : null; - x.txid = x.data ? x.data.txid : null; - x.types = [x.type]; - - if (x.data && x.data.amount) - x.amountStr = txFormatService.formatAmountStr(x.data.amount); - - x.action = function() { - // TODO? - $state.go('wallet.details', { - walletId: x.walletId, - txpId: x.txpId, - txid: x.txid, - }); - }; - }); - - // condense - var finale = [], - prev; - - - lodash.each(shown, function(x) { - if (prev && prev.walletId === x.walletId && prev.txpId && prev.txpId === x.txpId && prev.creatorId && prev.creatorId === x.creatorId) { - prev.types.push(x.type); - prev.data = lodash.assign(prev.data, x.data); - prev.txid = prev.txid || x.txid; - prev.amountStr = prev.amountStr || x.amountStr; - prev.creatorName = prev.creatorName || x.creatorName; - } else { - finale.push(x); - prev = x; - } - }); - - // messages... - - var u = bwcService.getUtils(); - lodash.each(finale, function(x) { - if (x.data && x.data.message && x.wallet && x.wallet.credentials.sharedEncryptingKey) { - // TODO TODO TODO => BWC - x.message = u.decryptMessage(x.data.message, x.wallet.credentials.sharedEncryptingKey); - } - }); - - return finale; - }; - - root.setTouchId = function(wallet, enabled, cb) { fingerprintService.check(wallet, function(err) { if (err) return cb(err); {