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;
|
var refreshInterval;
|
||||||
|
|
||||||
$scope.$on("$ionicView.afterEnter", function(event, data) {
|
$scope.$on("$ionicView.afterEnter", function onAfterEnter(event, data) {
|
||||||
$scope.updateAll();
|
$scope.updateAll(true, true);
|
||||||
// refreshAmountSection();
|
// refreshAmountSection();
|
||||||
refreshInterval = $interval($scope.onRefresh, 10 * 1000);
|
refreshInterval = $interval($scope.onRefresh, 10 * 1000);
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
|
|
|
||||||
|
|
@ -27,20 +27,23 @@
|
||||||
|
|
||||||
function addEarlyTransactions(walletId, cachedTxs, newTxs) {
|
function addEarlyTransactions(walletId, cachedTxs, newTxs) {
|
||||||
|
|
||||||
var cachedTxIds = {};
|
var cachedTxIndexFromId = {};
|
||||||
cachedTxs.forEach(function forCachedTx(tx){
|
cachedTxs.forEach(function forCachedTx(tx){
|
||||||
cachedTxIds[tx.txid] = true;
|
cachedTxIndexFromId[tx.txid] = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var confirmationsUpdated = false;
|
||||||
var someTransactionsWereNew = false;
|
var someTransactionsWereNew = false;
|
||||||
var overlappingTxsCount = 0;
|
var overlappingTxsCount = 0;
|
||||||
|
|
||||||
newTxs.forEach(function forNewTx(tx){
|
newTxs.forEach(function forNewTx(tx){
|
||||||
if (cachedTxIds[tx.txid]) {
|
if (typeof cachedTxIndexFromId[tx.txid] === "undefined") {
|
||||||
overlappingTxsCount++;
|
|
||||||
} else {
|
|
||||||
someTransactionsWereNew = true;
|
someTransactionsWereNew = true;
|
||||||
cachedTxs.push(tx);
|
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 (overlappingTxFraction >= MIN_KNOWN_TX_OVERLAP_FRACTION) { // We are good
|
||||||
if (someTransactionsWereNew) {
|
if (someTransactionsWereNew) {
|
||||||
saveTxHistory(walletId, cachedTxs);
|
saveTxHistory(walletId, cachedTxs);
|
||||||
|
} else if (confirmationsUpdated) {
|
||||||
|
saveTxHistory(walletId, cachedTxs);
|
||||||
} else if (overlappingTxsCount === newTxs.length) {
|
} else if (overlappingTxsCount === newTxs.length) {
|
||||||
allTransactionsFetched = true;
|
allTransactionsFetched = true;
|
||||||
}
|
}
|
||||||
|
|
@ -65,9 +70,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function addLatestTransactions(walletId, cachedTxs, newTxs) {
|
function addLatestTransactions(walletId, cachedTxs, newTxs) {
|
||||||
var cachedTxIds = {};
|
var cachedTxIndexFromId = {};
|
||||||
cachedTxs.forEach(function forCachedTx(tx, txIndex){
|
cachedTxs.forEach(function forCachedTx(tx, txIndex){
|
||||||
cachedTxIds[tx.txid] = txIndex;
|
cachedTxIndexFromId[tx.txid] = txIndex;
|
||||||
});
|
});
|
||||||
|
|
||||||
var someTransactionsWereNew = false;
|
var someTransactionsWereNew = false;
|
||||||
|
|
@ -76,15 +81,13 @@
|
||||||
var uniqueNewTxs = [];
|
var uniqueNewTxs = [];
|
||||||
|
|
||||||
newTxs.forEach(function forNewTx(tx){
|
newTxs.forEach(function forNewTx(tx){
|
||||||
if (typeof cachedTxIds[tx.txid] !== "undefined") {
|
if (typeof cachedTxIndexFromId[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 {
|
|
||||||
someTransactionsWereNew = true;
|
someTransactionsWereNew = true;
|
||||||
uniqueNewTxs.push(tx);
|
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) {
|
if (flushCacheOnNew) {
|
||||||
fetchTxHistoryByPage(wallet, 0, function onFetchTxHistory(err, txs){
|
fetchTxHistoryByPage(wallet, 0, function onFetchTxHistory(err, txs){
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue