debounce new testnet blocks notifications

This commit is contained in:
Gabriel Bazán 2016-09-30 11:57:57 -03:00
parent 583e0a560c
commit 466fceac80
1 changed files with 25 additions and 18 deletions

View File

@ -129,26 +129,13 @@ angular.module('copayApp.services')
});
wallet.on('notification', function(n) {
$log.debug('BWC Notification:', n);
// notification?
// TODO (put this in wallet ViewModel)
if (wallet.cachedStatus)
wallet.cachedStatus.isValid = false;
if (wallet.completeHistory)
wallet.completeHistory.isValid = false;
if (wallet.cachedActivity)
wallet.cachedActivity.isValid = false;
if (wallet.cachedTxps)
wallet.cachedTxps.isValid = false;
$rootScope.$emit('bwsEvent', wallet.id, n.type, n);
if (n.type == "NewBlock" && n.data.network == "testnet") {
throttledBwsEvent(n, wallet);
}
else newBwsEvent(n, wallet);
});
wallet.on('walletCompleted', function() {
@ -183,6 +170,26 @@ angular.module('copayApp.services')
return true;
};
var throttledBwsEvent = lodash.throttle(function(n, wallet) {
newBwsEvent(n, wallet);
}, 10000);
var newBwsEvent = function(n, wallet) {
if (wallet.cachedStatus)
wallet.cachedStatus.isValid = false;
if (wallet.completeHistory)
wallet.completeHistory.isValid = false;
if (wallet.cachedActivity)
wallet.cachedActivity.isValid = false;
if (wallet.cachedTxps)
wallet.cachedTxps.isValid = false;
$rootScope.$emit('bwsEvent', wallet.id, n.type, n);
};
var validationLock = false;
root.runValidation = function(client, delay, retryDelay) {