Merge pull request #5475 from matiu/feat/recent-transactions-badge

Feat/recent transactions badge
This commit is contained in:
Gustavo Maximiliano Cortez 2017-01-18 12:08:14 -03:00 committed by GitHub
commit e59f51b4e1
6 changed files with 54 additions and 15 deletions

View file

@ -242,12 +242,13 @@ angular.module('copayApp.controllers').controller('tabHomeController',
var getNotifications = function() { var getNotifications = function() {
profileService.getNotifications({ profileService.getNotifications({
limit: 3 limit: 3
}, function(err, n) { }, function(err, notifications, total) {
if (err) { if (err) {
$log.error(err); $log.error(err);
return; return;
} }
$scope.notifications = n; $scope.notifications = notifications;
$scope.notificationsN = total;
$timeout(function() { $timeout(function() {
$ionicScrollDelegate.resize(); $ionicScrollDelegate.resize();
$scope.$apply(); $scope.$apply();

View file

@ -796,8 +796,8 @@ angular.module('copayApp.services')
root.getNotifications = function(opts, cb) { root.getNotifications = function(opts, cb) {
opts = opts || {}; opts = opts || {};
var TIME_STAMP = 60 * 60 * 6; var TIME_STAMP = 60 * 60 * 6;
var MAX = 100; var MAX = 30;
var typeFilter = { var typeFilter = {
'NewOutgoingTx': 1, 'NewOutgoingTx': 1,
@ -925,7 +925,8 @@ angular.module('copayApp.services')
if (j == l) { if (j == l) {
notifications = lodash.sortBy(notifications, 'createdOn'); notifications = lodash.sortBy(notifications, 'createdOn');
notifications = lodash.compact(lodash.flatten(notifications)).slice(0, MAX); notifications = lodash.compact(lodash.flatten(notifications)).slice(0, MAX);
return cb(null, process(notifications)); var total = notifications.length;
return cb(null, process(notifications), total);
}; };
}); });
}); });

View file

@ -347,14 +347,16 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
return ret; return ret;
}; };
var updateLocalTxHistory = function(wallet, progressFn, cb) { var updateLocalTxHistory = function(wallet, opts, cb) {
var FIRST_LIMIT = 5; var FIRST_LIMIT = 5;
var LIMIT = 50; var LIMIT = 50;
var requestLimit = FIRST_LIMIT; var requestLimit = FIRST_LIMIT;
var walletId = wallet.credentials.walletId; var walletId = wallet.credentials.walletId;
var config = configService.getSync().wallet.settings; var config = configService.getSync().wallet.settings;
progressFn = progressFn || function() {}; var opts = opts || {};
var progressFn = opts.progressFn || function() {};
var foundLimitTx = false;
var fixTxsUnit = function(txs) { var fixTxsUnit = function(txs) {
if (!txs || !txs[0] || !txs[0].amountStr) return; if (!txs || !txs[0] || !txs[0].amountStr) return;
@ -387,17 +389,17 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
progressFn(txsFromLocal, 0); progressFn(txsFromLocal, 0);
wallet.completeHistory = txsFromLocal; wallet.completeHistory = txsFromLocal;
function getNewTxs(newTxs, skip, cb) { function getNewTxs(newTxs, skip, next) {
getTxsFromServer(wallet, skip, endingTxid, requestLimit, function(err, res, shouldContinue) { getTxsFromServer(wallet, skip, endingTxid, requestLimit, function(err, res, shouldContinue) {
if (err) { if (err) {
$log.warn(bwcError.msg(err, 'Server Error')); //TODO $log.warn(bwcError.msg(err, 'Server Error')); //TODO
if (err instanceof errors.CONNECTION_ERROR || (err.message && err.message.match(/5../))) { if (err instanceof errors.CONNECTION_ERROR || (err.message && err.message.match(/5../))) {
$log.info('Retrying history download in 5 secs...'); $log.info('Retrying history download in 5 secs...');
return $timeout(function() { return $timeout(function() {
return getNewTxs(newTxs, skip, cb); return getNewTxs(newTxs, skip, next);
}, 5000); }, 5000);
}; };
return cb(err); return next(err);
} }
newTxs = newTxs.concat(processNewTxs(wallet, lodash.compact(res))); 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); $log.debug('Syncing TXs. Got:' + newTxs.length + ' Skip:' + skip, ' EndingTxid:', endingTxid, ' Continue:', shouldContinue);
// TODO Dirty <HACK>
// 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);
}
}
// </HACK>
if (!shouldContinue) { if (!shouldContinue) {
$log.debug('Finished Sync: New / soft confirmed Txs: ' + newTxs.length); $log.debug('Finished Sync: New / soft confirmed Txs: ' + newTxs.length);
return cb(null, newTxs); return next(null, newTxs);
} }
requestLimit = LIMIT; 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() { updateNotes(function() {
// <HACK>
if (foundLimitTx) {
$log.debug('Tx history read until limitTx: ' + opts.limitTx);
return cb(null, newHistory);
}
// </HACK>
var historyToSave = JSON.stringify(newHistory); var historyToSave = JSON.stringify(newHistory);
lodash.each(txs, function(tx) { lodash.each(txs, function(tx) {
@ -506,7 +532,9 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
finish(); finish();
} else { } else {
root.getTxHistory(wallet, {}, function(err, txHistory) { root.getTxHistory(wallet, {
limitTx: txid
}, function(err, txHistory) {
if (err) return cb(err); if (err) return cb(err);
tx = lodash.find(txHistory, { tx = lodash.find(txHistory, {
@ -538,9 +566,13 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
$log.debug('Updating Transaction History'); $log.debug('Updating Transaction History');
updateLocalTxHistory(wallet, opts.progressFn, function(err) { updateLocalTxHistory(wallet, opts, function(err, txs) {
if (err) return cb(err); if (err) return cb(err);
if (opts.limitTx) {
return cb(err, txs);
}
wallet.completeHistory.isValid = true; wallet.completeHistory.isValid = true;
return cb(err, wallet.completeHistory); return cb(err, wallet.completeHistory);
}); });

View file

@ -135,4 +135,8 @@
position: absolute; position: absolute;
} }
} }
.badge {
top:11px;
}
} }

View file

@ -10,7 +10,7 @@
<div ng-if="fetchingNotifications" class="updatingHistory"> <div ng-if="fetchingNotifications" class="updatingHistory">
<div class="text-center"> <div class="text-center">
<ion-spinner class="spinner-dark" icon="lines"></ion-spinner> <ion-spinner class="spinner-dark" icon="crescent"></ion-spinner>
<div translate>Updating... Please stand by</div> <div translate>Updating... Please stand by</div>
</div> </div>
</div> </div>

View file

@ -47,6 +47,7 @@
<a class="item item-icon-right item-heading" ui-sref="tabs.activity"> <a class="item item-icon-right item-heading" ui-sref="tabs.activity">
<span translate>Recent Transactions</span> <span translate>Recent Transactions</span>
<i class="icon bp-arrow-right"></i> <i class="icon bp-arrow-right"></i>
<span class="badge badge-assertive m5t m10r" ng-show="notificationsN>3"> {{notificationsN}}</span>
</a> </a>
<a class="item item-sub activity" ng-repeat="notification in notifications" ng-click="openNotificationModal(notification)"> <a class="item item-sub activity" ng-repeat="notification in notifications" ng-click="openNotificationModal(notification)">
<span ng-include="'views/includes/walletActivity.html'"></span> <span ng-include="'views/includes/walletActivity.html'"></span>