diff --git a/BlueApp.js b/BlueApp.js index 73f27572f..4ebccd0f4 100644 --- a/BlueApp.js +++ b/BlueApp.js @@ -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(); diff --git a/class/legacy-wallet.js b/class/legacy-wallet.js index ebe47768a..f3bd259df 100644 --- a/class/legacy-wallet.js +++ b/class/legacy-wallet.js @@ -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() { diff --git a/screen/wallets/list.js b/screen/wallets/list.js index 78982d00c..77b321aec 100644 --- a/screen/wallets/list.js +++ b/screen/wallets/list.js @@ -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 } }