diff --git a/src/js/controllers/tab-home.js b/src/js/controllers/tab-home.js index ac2a6b471..dcd495d89 100644 --- a/src/js/controllers/tab-home.js +++ b/src/js/controllers/tab-home.js @@ -242,12 +242,13 @@ angular.module('copayApp.controllers').controller('tabHomeController', var getNotifications = function() { profileService.getNotifications({ limit: 3 - }, function(err, n) { + }, function(err, notifications, total) { if (err) { $log.error(err); return; } - $scope.notifications = n; + $scope.notifications = notifications; + $scope.notificationsN = total; $timeout(function() { $ionicScrollDelegate.resize(); $scope.$apply(); diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index dabffc717..a9416fcf3 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -796,8 +796,8 @@ angular.module('copayApp.services') root.getNotifications = function(opts, cb) { opts = opts || {}; - var TIME_STAMP = 60 * 60 * 6; - var MAX = 100; + var TIME_STAMP = 60 * 60 * 6; + var MAX = 30; var typeFilter = { 'NewOutgoingTx': 1, @@ -925,7 +925,8 @@ angular.module('copayApp.services') if (j == l) { notifications = lodash.sortBy(notifications, 'createdOn'); notifications = lodash.compact(lodash.flatten(notifications)).slice(0, MAX); - return cb(null, process(notifications)); + var total = notifications.length; + return cb(null, process(notifications), total); }; }); }); diff --git a/src/js/services/walletService.js b/src/js/services/walletService.js index 3537a8a71..236b19ee1 100644 --- a/src/js/services/walletService.js +++ b/src/js/services/walletService.js @@ -347,14 +347,16 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim return ret; }; - var updateLocalTxHistory = function(wallet, progressFn, cb) { + var updateLocalTxHistory = function(wallet, opts, cb) { var FIRST_LIMIT = 5; var LIMIT = 50; var requestLimit = FIRST_LIMIT; var walletId = wallet.credentials.walletId; var config = configService.getSync().wallet.settings; - progressFn = progressFn || function() {}; + var opts = opts || {}; + var progressFn = opts.progressFn || function() {}; + var foundLimitTx = false; var fixTxsUnit = function(txs) { if (!txs || !txs[0] || !txs[0].amountStr) return; @@ -387,17 +389,17 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim progressFn(txsFromLocal, 0); wallet.completeHistory = txsFromLocal; - function getNewTxs(newTxs, skip, cb) { + function getNewTxs(newTxs, skip, next) { getTxsFromServer(wallet, skip, endingTxid, requestLimit, function(err, res, shouldContinue) { if (err) { $log.warn(bwcError.msg(err, 'Server Error')); //TODO if (err instanceof errors.CONNECTION_ERROR || (err.message && err.message.match(/5../))) { $log.info('Retrying history download in 5 secs...'); return $timeout(function() { - return getNewTxs(newTxs, skip, cb); + return getNewTxs(newTxs, skip, next); }, 5000); }; - return cb(err); + return next(err); } newTxs = newTxs.concat(processNewTxs(wallet, lodash.compact(res))); @@ -408,13 +410,29 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim $log.debug('Syncing TXs. Got:' + newTxs.length + ' Skip:' + skip, ' EndingTxid:', endingTxid, ' Continue:', shouldContinue); + // TODO Dirty + // do not sync all history, just looking for a single TX. + if (opts.limitTx) { + + foundLimitTx = lodash.find(newTxs, { + txid: opts.limitTx, + }); + + if (foundLimitTx) { + $log.debug('Found limitTX: ' + opts.limitTx); + return next(null, newTxs); + } + } + // + + if (!shouldContinue) { $log.debug('Finished Sync: New / soft confirmed Txs: ' + newTxs.length); - return cb(null, newTxs); + return next(null, newTxs); } requestLimit = LIMIT; - getNewTxs(newTxs, skip, cb); + getNewTxs(newTxs, skip, next); }); }; @@ -451,6 +469,14 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim } updateNotes(function() { + + // + if (foundLimitTx) { + $log.debug('Tx history read until limitTx: ' + opts.limitTx); + return cb(null, newHistory); + } + // + var historyToSave = JSON.stringify(newHistory); lodash.each(txs, function(tx) { @@ -506,7 +532,9 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim finish(); } else { - root.getTxHistory(wallet, {}, function(err, txHistory) { + root.getTxHistory(wallet, { + limitTx: txid + }, function(err, txHistory) { if (err) return cb(err); tx = lodash.find(txHistory, { @@ -538,9 +566,13 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim $log.debug('Updating Transaction History'); - updateLocalTxHistory(wallet, opts.progressFn, function(err) { + updateLocalTxHistory(wallet, opts, function(err, txs) { if (err) return cb(err); + if (opts.limitTx) { + return cb(err, txs); + } + wallet.completeHistory.isValid = true; return cb(err, wallet.completeHistory); }); diff --git a/src/sass/views/tab-home.scss b/src/sass/views/tab-home.scss index 692224cf2..6fd937188 100644 --- a/src/sass/views/tab-home.scss +++ b/src/sass/views/tab-home.scss @@ -135,4 +135,8 @@ position: absolute; } } + + .badge { + top:11px; + } } diff --git a/www/views/activity.html b/www/views/activity.html index 8586e97e9..720ffb4e3 100644 --- a/www/views/activity.html +++ b/www/views/activity.html @@ -10,7 +10,7 @@
- +
Updating... Please stand by
diff --git a/www/views/tab-home.html b/www/views/tab-home.html index 04bedc98d..909c332d4 100644 --- a/www/views/tab-home.html +++ b/www/views/tab-home.html @@ -47,6 +47,7 @@ Recent Transactions + {{notificationsN}}