txHistory cache
This commit is contained in:
parent
3bac497049
commit
240e26a783
3 changed files with 86 additions and 24 deletions
|
|
@ -6,12 +6,14 @@ angular.module('copayApp.controllers').controller('tabHomeController',
|
||||||
|
|
||||||
self.glideraEnabled = configService.getSync().glidera.enabled;
|
self.glideraEnabled = configService.getSync().glidera.enabled;
|
||||||
|
|
||||||
self.setWallets = function() {
|
|
||||||
$scope.wallets = profileService.getWallets();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
var setPendingTxps = function(txps) {
|
var setPendingTxps = function(txps) {
|
||||||
|
$scope.txps = lodash.sort(txps, function(x) {
|
||||||
|
return walletId;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
var formatPendingTxps = function(txps) {
|
||||||
$scope.pendingTxProposalsCountForUs = 0;
|
$scope.pendingTxProposalsCountForUs = 0;
|
||||||
var now = Math.floor(Date.now() / 1000);
|
var now = Math.floor(Date.now() / 1000);
|
||||||
|
|
||||||
|
|
@ -65,18 +67,17 @@ angular.module('copayApp.controllers').controller('tabHomeController',
|
||||||
|
|
||||||
if (!tx.deleteLockTime)
|
if (!tx.deleteLockTime)
|
||||||
tx.canBeRemoved = true;
|
tx.canBeRemoved = true;
|
||||||
|
|
||||||
if (tx.creatorId != tx.wallet.copayerId) {
|
|
||||||
$scope.pendingTxProposalsCountForUs = $scope.pendingTxProposalsCountForUs + 1;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
$scope.txps = txps;
|
|
||||||
|
return txps;
|
||||||
};
|
};
|
||||||
|
|
||||||
self.updateAllClients = function() {
|
self.updateAllWallets = function() {
|
||||||
|
|
||||||
|
$scope.wallets = profileService.getWallets();
|
||||||
|
|
||||||
var txps = [];
|
var txps = [];
|
||||||
var i = $scope.wallets.length;
|
var i = $scope.wallets.length;
|
||||||
|
|
||||||
lodash.each($scope.wallets, function(wallet) {
|
lodash.each($scope.wallets, function(wallet) {
|
||||||
walletService.getStatus(wallet, {}, function(err, status) {
|
walletService.getStatus(wallet, {}, function(err, status) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
@ -87,6 +88,7 @@ angular.module('copayApp.controllers').controller('tabHomeController',
|
||||||
txps = txps.concat(status.pendingTxps);
|
txps = txps.concat(status.pendingTxps);
|
||||||
}
|
}
|
||||||
if (--i == 0) {
|
if (--i == 0) {
|
||||||
|
txps = formatPendingTxps(txps);
|
||||||
setPendingTxps(txps);
|
setPendingTxps(txps);
|
||||||
}
|
}
|
||||||
wallet.status = status;
|
wallet.status = status;
|
||||||
|
|
@ -94,11 +96,33 @@ angular.module('copayApp.controllers').controller('tabHomeController',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
self.setWallets();
|
self.updateWallet = function(wallet) {
|
||||||
self.updateAllClients();
|
var txps = lodash.filter($scope.txps, function(x) {
|
||||||
|
return x.walletId != wallet.id;
|
||||||
|
});
|
||||||
|
|
||||||
|
walletService.getStatus(wallet, {}, function(err, status) {
|
||||||
|
if (err) {
|
||||||
|
console.log('[tab-home.js.35:err:]', $log.error(err)); //TODO
|
||||||
|
return;
|
||||||
|
} // TODO
|
||||||
|
if (status.pendingTxps && status.pendingTxps[0]) {
|
||||||
|
txps = txps.concat(status.pendingTxps);
|
||||||
|
txps = formatPendingTxps(txps);
|
||||||
|
setPendingTxps(txps);
|
||||||
|
}
|
||||||
|
wallet.status = status;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
self.updateAllWallets();
|
||||||
$scope.bitpayCardEnabled = true; // TODO
|
$scope.bitpayCardEnabled = true; // TODO
|
||||||
|
|
||||||
|
|
||||||
|
$scope.$on('$destroy', function() {});
|
||||||
|
|
||||||
var config = configService.getSync().wallet;
|
var config = configService.getSync().wallet;
|
||||||
|
|
||||||
var GLIDERA_LOCK_TIME = 6 * 60 * 60;
|
var GLIDERA_LOCK_TIME = 6 * 60 * 60;
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,36 @@ angular.module('copayApp.services')
|
||||||
walletId, wallet.credentials.walletName);
|
walletId, wallet.credentials.walletName);
|
||||||
|
|
||||||
$rootScope.$emit(n.type, n, wallet);
|
$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() {
|
wallet.on('walletCompleted', function() {
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,17 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
|
||||||
};
|
};
|
||||||
root.handleError = lodash.debounce(_handleError, 1000);
|
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) {
|
root.getStatus = function(wallet, opts, cb) {
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
|
|
||||||
|
|
@ -446,17 +457,22 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
|
||||||
|
|
||||||
if (!wallet.isComplete()) return cb();
|
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');
|
$log.debug('Updating Transaction History');
|
||||||
|
|
||||||
updateLocalTxHistory(wallet, opts.progressFn, function(err) {
|
updateLocalTxHistory(wallet, opts.progressFn, function(err) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
|
|
||||||
|
wallet.completeHistory.isValid = true;
|
||||||
return cb(err, wallet.completeHistory);
|
return cb(err, wallet.completeHistory);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
root.isEncrypted = function(wallet) {
|
root.isEncrypted = function(wallet) {
|
||||||
if (lodash.isEmpty(wallet)) return;
|
if (lodash.isEmpty(wallet)) return;
|
||||||
var isEncrypted = wallet.isPrivKeyEncrypted();
|
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) {
|
root.showErrorPopup = function(msg, cb) {
|
||||||
$log.warn('Showing err popup:' + msg);
|
$log.warn('Showing err popup:' + msg);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue