mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-24 07:09:14 +01:00
FIX: better transaction list refresh
This commit is contained in:
parent
74f0226c15
commit
d3761a4849
3 changed files with 27 additions and 5 deletions
|
@ -28,7 +28,7 @@ async function startAndDecrypt(retry) {
|
|||
let noErr = true;
|
||||
try {
|
||||
let wallets = BlueApp.getWallets();
|
||||
if (wallets && wallets[0] && wallets[0].timeToRefresh()) {
|
||||
if (wallets && wallets[0] && wallets[0].timeToRefreshBalance()) {
|
||||
console.log('time to refresh wallet #0');
|
||||
let oldBalance = wallets[0].getBalance();
|
||||
await wallets[0].fetchBalance();
|
||||
|
|
|
@ -19,16 +19,32 @@ export class LegacyWallet extends AbstractWallet {
|
|||
this._lastBalanceFetch = 0;
|
||||
}
|
||||
|
||||
timeToRefresh() {
|
||||
/**
|
||||
* Simple function which says that we havent tried to fetch balance
|
||||
* for a long time
|
||||
*
|
||||
* @return {boolean}
|
||||
*/
|
||||
timeToRefreshBalance() {
|
||||
if (+new Date() - this._lastBalanceFetch >= 5 * 60 * 1000) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple function which says if we hve some low-confirmed transactions
|
||||
* and we better fetch them
|
||||
*
|
||||
* @return {boolean}
|
||||
*/
|
||||
timeToRefreshTransaction() {
|
||||
for (let tx of this.transactions) {
|
||||
if (tx.confirmations < 7) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
generate() {
|
||||
|
|
|
@ -172,9 +172,10 @@ export default class WalletsList extends Component {
|
|||
}
|
||||
let oldBalance = wallets[index].getBalance();
|
||||
let noErr = true;
|
||||
let didRefresh = false;
|
||||
|
||||
try {
|
||||
if (wallets && wallets[index] && wallets[index].timeToRefresh()) {
|
||||
if (wallets && wallets[index] && wallets[index].timeToRefreshBalance()) {
|
||||
console.log('snapped to, and now its time to refresh wallet #', index);
|
||||
await wallets[index].fetchBalance();
|
||||
if (oldBalance !== wallets[index].getBalance() || wallets[index].getUnconfirmedBalance() !== 0) {
|
||||
|
@ -182,6 +183,12 @@ export default class WalletsList extends Component {
|
|||
// balance changed, thus txs too
|
||||
await wallets[index].fetchTransactions();
|
||||
this.refreshFunction();
|
||||
didRefresh = true;
|
||||
} else if (wallets[index].timeToRefreshTransaction()) {
|
||||
console.log('got TXs with low confirmations, refreshing');
|
||||
await wallets[index].fetchTransactions();
|
||||
this.refreshFunction();
|
||||
didRefresh = true;
|
||||
} else {
|
||||
console.log('balance not changed');
|
||||
}
|
||||
|
@ -191,8 +198,7 @@ export default class WalletsList extends Component {
|
|||
console.warn(Err);
|
||||
}
|
||||
|
||||
if (noErr && oldBalance !== wallets[index].getBalance()) {
|
||||
// so we DID refresh
|
||||
if (noErr && didRefresh) {
|
||||
await BlueApp.saveToDisk(); // caching
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue