From 5ead443c2405af41ced8d2bc36617fb26052524b Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Thu, 10 Nov 2016 13:47:57 -0300 Subject: [PATCH] Fix recent transactions. Show the latest transactions within 24 hours --- src/js/controllers/activity.js | 36 ++----------- src/js/controllers/tab-home.js | 90 +++++++++---------------------- src/js/controllers/tx-details.js | 8 +-- src/js/services/profileService.js | 41 +++++++------- www/views/activity.html | 6 +-- www/views/tab-home.html | 4 -- 6 files changed, 57 insertions(+), 128 deletions(-) diff --git a/src/js/controllers/activity.js b/src/js/controllers/activity.js index 29721ca3b..9ea9a31e9 100644 --- a/src/js/controllers/activity.js +++ b/src/js/controllers/activity.js @@ -26,7 +26,10 @@ angular.module('copayApp.controllers').controller('activityController', $scope.openNotificationModal = function(n) { if (n.txid) { - openTxModal(n); + $state.transitionTo('tabs.wallet.tx-details', { + txid: n.txid, + walletId: n.walletId + }); } else { var txp = lodash.find($scope.txps, { id: n.txpId @@ -46,35 +49,4 @@ angular.module('copayApp.controllers').controller('activityController', } } }; - - var openTxModal = function(n) { - var wallet = profileService.getWallet(n.walletId); - - ongoingProcess.set('loadingTxInfo', true); - walletService.getTx(wallet, n.txid, function(err, tx) { - ongoingProcess.set('loadingTxInfo', false); - - if (err) { - $log.error(err); - return popupService.showAlert(gettextCatalog.getString('Error'), err); - } - - if (!tx) { - $log.warn('No tx found'); - return popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Transaction not found')); - } - - $scope.wallet = wallet; - $scope.btx = lodash.cloneDeep(tx); - $state.transitionTo('tabs.wallet.tx-details', { - txid: $scope.btx.txid, - walletId: $scope.walletId - }); - - walletService.getTxNote(wallet, n.txid, function(err, note) { - if (err) $log.warn('Could not fetch transaction note: ' + err); - $scope.btx.note = note; - }); - }); - }; }); diff --git a/src/js/controllers/tab-home.js b/src/js/controllers/tab-home.js index 656949602..08d136573 100644 --- a/src/js/controllers/tab-home.js +++ b/src/js/controllers/tab-home.js @@ -43,7 +43,10 @@ angular.module('copayApp.controllers').controller('tabHomeController', wallet = profileService.getWallet(n.walletId); if (n.txid) { - openTxModal(n); + $state.transitionTo('tabs.wallet.tx-details', { + txid: n.txid, + walletId: n.walletId + }); } else { var txp = lodash.find($scope.txps, { id: n.txpId @@ -65,37 +68,6 @@ angular.module('copayApp.controllers').controller('tabHomeController', } }; - var openTxModal = function(n) { - wallet = profileService.getWallet(n.walletId); - - ongoingProcess.set('loadingTxInfo', true); - walletService.getTx(wallet, n.txid, function(err, tx) { - ongoingProcess.set('loadingTxInfo', false); - - if (err) { - $log.error(err); - return popupService.showAlert(gettextCatalog.getString('Error'), err); - } - - if (!tx) { - $log.warn('No tx found'); - return popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Transaction not found')); - } - - $scope.wallet = wallet; - $scope.btx = lodash.cloneDeep(tx); - $state.transitionTo('tabs.wallet.tx-details', { - txid: $scope.btx.txid, - walletId: $scope.walletId - }); - - walletService.getTxNote(wallet, n.txid, function(err, note) { - if (err) $log.warn('Could not fetch transaction note: ' + err); - $scope.btx.note = note; - }); - }); - }; - $scope.openWallet = function(wallet) { if (!wallet.isComplete()) { return $state.go('tabs.copayers', { @@ -117,6 +89,7 @@ angular.module('copayApp.controllers').controller('tabHomeController', $scope.txpsN = n; $timeout(function() { $ionicScrollDelegate.resize(); + $scope.$apply(); }, 100); }) }; @@ -141,25 +114,6 @@ angular.module('copayApp.controllers').controller('tabHomeController', } }); }); - - if (!$scope.recentTransactionsEnabled) return; - $scope.fetchingNotifications = true; - profileService.getNotifications({ - limit: 3 - }, function(err, n) { - if (err) { - $log.error(err); - return; - } - $scope.fetchingNotifications = false; - $scope.notifications = n; - - $timeout(function() { - $ionicScrollDelegate.resize(); - $scope.$apply(); - }, 100); - - }) }; var updateWallet = function(wallet) { @@ -171,20 +125,22 @@ angular.module('copayApp.controllers').controller('tabHomeController', } wallet.status = status; updateTxps(); + }); + }; - if (!$scope.recentTransactionsEnabled) return; - - $scope.fetchingNotifications = true; - profileService.getNotifications({ - limit: 3 - }, function(err, notifications) { - $scope.fetchingNotifications = false; - if (err) { - $log.error(err); - return; - } - $scope.notifications = notifications; - }); + var getNotifications = function() { + profileService.getNotifications({ + limit: 3 + }, function(err, n) { + if (err) { + $log.error(err); + return; + } + $scope.notifications = n; + $timeout(function() { + $ionicScrollDelegate.resize(); + $scope.$apply(); + }, 100); }); }; @@ -242,7 +198,7 @@ angular.module('copayApp.controllers').controller('tabHomeController', updateAllWallets(); }; - $scope.$on("$ionicView.enter", function(event, data) { + $scope.$on("$ionicView.beforeEnter", function(event, data) { updateAllWallets(); addressbookService.list(function(err, ab) { @@ -254,11 +210,13 @@ angular.module('copayApp.controllers').controller('tabHomeController', $rootScope.$on('bwsEvent', function(e, walletId, type, n) { var wallet = profileService.getWallet(walletId); updateWallet(wallet); + if ($scope.recentTransactionsEnabled) getNotifications(); }), $rootScope.$on('Local/TxAction', function(e, walletId) { $log.debug('Got action for wallet ' + walletId); var wallet = profileService.getWallet(walletId); updateWallet(wallet); + if ($scope.recentTransactionsEnabled) getNotifications(); }) ]; @@ -279,6 +237,8 @@ angular.module('copayApp.controllers').controller('tabHomeController', $scope.nextStepEnabled = buyAndSellEnabled || amazonEnabled || bitpayCardEnabled; $scope.recentTransactionsEnabled = config.recentTransactions.enabled; + if ($scope.recentTransactionsEnabled) getNotifications(); + if ($scope.bitpayCardEnabled) bitpayCardCache(); $timeout(function() { $ionicScrollDelegate.resize(); diff --git a/src/js/controllers/tx-details.js b/src/js/controllers/tx-details.js index c84304700..1b6beb58b 100644 --- a/src/js/controllers/tx-details.js +++ b/src/js/controllers/tx-details.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('txDetailsController', function($log, $ionicHistory, $scope, $stateParams, walletService, lodash, gettextCatalog, profileService, externalLinkService, popupService) { +angular.module('copayApp.controllers').controller('txDetailsController', function($log, $ionicHistory, $scope, walletService, lodash, gettextCatalog, profileService, configService, externalLinkService, popupService, ongoingProcess) { $scope.$on("$ionicView.beforeEnter", function(event, data) { $scope.title = gettextCatalog.getString('Transaction'); @@ -9,11 +9,13 @@ angular.module('copayApp.controllers').controller('txDetailsController', functio $scope.copayerId = $scope.wallet.credentials.copayerId; $scope.isShared = $scope.wallet.credentials.n > 1; - walletService.getTx($scope.wallet, $stateParams.txid, function(err, tx) { + ongoingProcess.set('loadingTxInfo', true); + walletService.getTx($scope.wallet, data.stateParams.txid, function(err, tx) { + ongoingProcess.set('loadingTxInfo', false); if (err) { $log.warn('Could not get tx'); $ionicHistory.goBack(); - return; + return popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Transaction not found')); } $scope.btx = tx; if ($scope.btx.action != 'invalid') { diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 4c65a3f48..8d660cb16 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -795,7 +795,7 @@ angular.module('copayApp.services') root.getNotifications = function(opts, cb) { opts = opts || {}; - var TIME_STAMP = 60 * 60 * 24 * 7; + var TIME_STAMP = 60 * 60 * 24; var MAX = 100; var typeFilter = { @@ -861,26 +861,25 @@ angular.module('copayApp.services') var finale = shown; // GROUPING DISABLED! - // var finale = [], - // prev; - // - // - // // Item grouping... DISABLED. - // - // // REMOVE (if we want 1-to-1 notification) ???? - // 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; - // } - // }); - // + var finale = [], + prev; + + + // Item grouping... DISABLED. + + // REMOVE (if we want 1-to-1 notification) ???? + 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; + } + }); var u = bwcService.getUtils(); lodash.each(finale, function(x) { diff --git a/www/views/activity.html b/www/views/activity.html index fb84142dc..8586e97e9 100644 --- a/www/views/activity.html +++ b/www/views/activity.html @@ -1,7 +1,7 @@ - {{'Recent Activity'|translate}} + {{'Recent Transactions'|translate}} @@ -11,7 +11,7 @@
-
Updating activity. Please stand by
+
Updating... Please stand by
@@ -22,7 +22,7 @@
- No recent activity + No recent transactions
diff --git a/www/views/tab-home.html b/www/views/tab-home.html index 1b4c611f1..41bd57b63 100644 --- a/www/views/tab-home.html +++ b/www/views/tab-home.html @@ -47,10 +47,6 @@ Recent Transactions - - -
Updating activity...
-