Fixed updating of confirmations of cached transactions. Cache now properly cleared on first fetch from Wallet Details screen.
This commit is contained in:
parent
3cad7d7ad8
commit
ea51e035ab
2 changed files with 37 additions and 17 deletions
|
|
@ -400,8 +400,8 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
|
|||
|
||||
var refreshInterval;
|
||||
|
||||
$scope.$on("$ionicView.afterEnter", function(event, data) {
|
||||
$scope.updateAll();
|
||||
$scope.$on("$ionicView.afterEnter", function onAfterEnter(event, data) {
|
||||
$scope.updateAll(true, true);
|
||||
// refreshAmountSection();
|
||||
refreshInterval = $interval($scope.onRefresh, 10 * 1000);
|
||||
$timeout(function() {
|
||||
|
|
|
|||
|
|
@ -27,20 +27,23 @@
|
|||
|
||||
function addEarlyTransactions(walletId, cachedTxs, newTxs) {
|
||||
|
||||
var cachedTxIds = {};
|
||||
var cachedTxIndexFromId = {};
|
||||
cachedTxs.forEach(function forCachedTx(tx){
|
||||
cachedTxIds[tx.txid] = true;
|
||||
cachedTxIndexFromId[tx.txid] = true;
|
||||
});
|
||||
|
||||
var confirmationsUpdated = false;
|
||||
var someTransactionsWereNew = false;
|
||||
var overlappingTxsCount = 0;
|
||||
|
||||
newTxs.forEach(function forNewTx(tx){
|
||||
if (cachedTxIds[tx.txid]) {
|
||||
overlappingTxsCount++;
|
||||
} else {
|
||||
if (typeof cachedTxIndexFromId[tx.txid] === "undefined") {
|
||||
someTransactionsWereNew = true;
|
||||
cachedTxs.push(tx);
|
||||
} else {
|
||||
var txUpdated = updateCachedTx(cachedTxs, cachedTxIndexFromId, tx);
|
||||
confirmationsUpdated = confirmationsUpdated || txUpdated;
|
||||
overlappingTxsCount++;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -50,6 +53,8 @@
|
|||
if (overlappingTxFraction >= MIN_KNOWN_TX_OVERLAP_FRACTION) { // We are good
|
||||
if (someTransactionsWereNew) {
|
||||
saveTxHistory(walletId, cachedTxs);
|
||||
} else if (confirmationsUpdated) {
|
||||
saveTxHistory(walletId, cachedTxs);
|
||||
} else if (overlappingTxsCount === newTxs.length) {
|
||||
allTransactionsFetched = true;
|
||||
}
|
||||
|
|
@ -65,9 +70,9 @@
|
|||
}
|
||||
|
||||
function addLatestTransactions(walletId, cachedTxs, newTxs) {
|
||||
var cachedTxIds = {};
|
||||
var cachedTxIndexFromId = {};
|
||||
cachedTxs.forEach(function forCachedTx(tx, txIndex){
|
||||
cachedTxIds[tx.txid] = txIndex;
|
||||
cachedTxIndexFromId[tx.txid] = txIndex;
|
||||
});
|
||||
|
||||
var someTransactionsWereNew = false;
|
||||
|
|
@ -76,15 +81,13 @@
|
|||
var uniqueNewTxs = [];
|
||||
|
||||
newTxs.forEach(function forNewTx(tx){
|
||||
if (typeof cachedTxIds[tx.txid] !== "undefined") {
|
||||
if (cachedTxs[cachedTxIds[tx.txid]].confirmations < SAFE_CONFIRMATIONS && tx.confirmations >= SAFE_CONFIRMATIONS) {
|
||||
cachedTxs[cachedTxIds[tx.txid]].confirmations = tx.confirmations;
|
||||
confirmationsUpdated = true;
|
||||
}
|
||||
overlappingTxsCount++;
|
||||
} else {
|
||||
if (typeof cachedTxIndexFromId[tx.txid] === "undefined") {
|
||||
someTransactionsWereNew = true;
|
||||
uniqueNewTxs.push(tx);
|
||||
} else {
|
||||
var txUpdated = updateCachedTx(cachedTxs, cachedTxIndexFromId, tx);
|
||||
confirmationsUpdated = confirmationsUpdated || txUpdated;
|
||||
overlappingTxsCount++;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -207,8 +210,25 @@
|
|||
});
|
||||
}
|
||||
|
||||
function updateLocalTxHistoryByPage(wallet, getLatest, flushCacheOnNew, cb) {
|
||||
/**
|
||||
* Returns true if the cached tx was updated
|
||||
* @param {*} cachedTxs
|
||||
* @param {*} cachedTxIndexFromId - Indices for cachedTxs, based on txid
|
||||
* @param {*} tx - The most recent tx info
|
||||
*/
|
||||
function updateCachedTx(cachedTxs, cachedTxIndexFromId, tx) {
|
||||
var updated = false;
|
||||
var txIndex = cachedTxIndexFromId[tx.txid];
|
||||
var cachedTx = cachedTxs[txIndex];
|
||||
|
||||
if (cachedTx.confirmations < SAFE_CONFIRMATIONS && tx.confirmations > cachedTx.confirmations) {
|
||||
cachedTxs[txIndex].confirmations = tx.confirmations;
|
||||
updated = true;
|
||||
}
|
||||
return updated;
|
||||
}
|
||||
|
||||
function updateLocalTxHistoryByPage(wallet, getLatest, flushCacheOnNew, cb) {
|
||||
if (flushCacheOnNew) {
|
||||
fetchTxHistoryByPage(wallet, 0, function onFetchTxHistory(err, txs){
|
||||
if (err) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue