txHistory cache

This commit is contained in:
Matias Alejo Garcia 2016-08-22 22:10:46 -03:00
commit 240e26a783
No known key found for this signature in database
GPG key ID: 02470DB551277AB3
3 changed files with 86 additions and 24 deletions

View file

@ -71,6 +71,36 @@ angular.module('copayApp.services')
walletId, wallet.credentials.walletName);
$rootScope.$emit(n.type, n, wallet);
// ))
// walletService allet.getStatus()
// wallet.getTxHistory()
//
// // update wallet?
// if (lodash.indexOf( [,'NewOutgoingTx','NewOutgoingTxByThirdParty','NewTxProposal', 'TxProposalFinallyRejected', 'TxProposalRemoved'], n.type)>=0) {
//
// wallet.update
//
// };
//
// 'NewBlock'
// });
//
// //untilItChange FALSE
// lodash.each(['NewTxProposal', , 'NewOutgoingTxByThirdParty',
// 'Local/GlideraTx'
// ], function(eventName) {
// $rootScope.$on(eventName, function(event) {
// self.updateAll({
// walletStatus: null,
// untilItChanges: null,
// triggerTxUpdate: true,
// });
// });
// });
//
//
// //
//
});
wallet.on('walletCompleted', function() {

View file

@ -112,6 +112,17 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
};
root.handleError = lodash.debounce(_handleError, 1000);
root.invalidateCache = function(wallet) {
if (wallet.cacheStatus) {
wallet.cacheStatus.isValid = false;
}
if (wallet.cacheHistory) {
wallet.cacheHistory.isValid = false;
}
};
root.getStatus = function(wallet, opts, cb) {
opts = opts || {};
@ -446,17 +457,22 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
if (!wallet.isComplete()) return cb();
function isHistoryCached() {
return wallet.completeHistory && wallet.completeHistory.isValid;
};
if (isHistoryCached() && !opts.force) return cb(null, wallet.completeHistory);
$log.debug('Updating Transaction History');
updateLocalTxHistory(wallet, opts.progressFn, function(err) {
if (err) return cb(err);
wallet.completeHistory.isValid = true;
return cb(err, wallet.completeHistory);
});
};
root.isEncrypted = function(wallet) {
if (lodash.isEmpty(wallet)) return;
var isEncrypted = wallet.isPrivKeyEncrypted();
@ -639,14 +655,6 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
});
};
root.debounceUpdateHistory = lodash.debounce(function() {
root.updateHistory();
}, 1000);
root.throttledUpdateHistory = lodash.throttle(function() {
root.updateHistory();
}, 5000);
root.showErrorPopup = function(msg, cb) {
$log.warn('Showing err popup:' + msg);