From 801807ac46c4767aa5c24cb541fddaa3075f42e2 Mon Sep 17 00:00:00 2001 From: Overtorment Date: Sat, 16 Mar 2019 12:48:17 +0000 Subject: [PATCH] FIX: all wallets are refreshed when app launches --- screen/selftest.js | 9 +++++++++ screen/wallets/list.js | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/screen/selftest.js b/screen/selftest.js index 05c89b342..0bc0a7316 100644 --- a/screen/selftest.js +++ b/screen/selftest.js @@ -252,6 +252,15 @@ export default class Selftest extends Component { if (!hd2.validateMnemonic()) { throw new Error('mnemonic phrase validation not ok'); } + + // + + let hd3 = new HDSegwitP2SHWallet(); + hd3._xpub = 'ypub6XRSuTABFst6pd8BuTmjSwkDya7HrCRqmtsNmtrh1gyrEZwe24GcjJf6jk6nhhenZpLsm6sDHx2BXwnCQQtjF63FbpNyVEkmngKFQF11aph'; + await hd3.fetchBalance(); + if (hd3.getBalance() !== 0.00026) throw new Error('Could not fetch HD balance'); + await hd3.fetchTransactions(); + if (hd3.transactions.length !== 7) throw new Error('Could not fetch HD transactions'); } else { console.warn('skipping RN-specific test'); } diff --git a/screen/wallets/list.js b/screen/wallets/list.js index 046f9d221..fd0700999 100644 --- a/screen/wallets/list.js +++ b/screen/wallets/list.js @@ -11,6 +11,7 @@ let A = require('../../analytics'); /** @type {AppStorage} */ let BlueApp = require('../../BlueApp'); let loc = require('../../loc'); +let BlueElectrum = require('../../BlueElectrum'); export default class WalletsList extends Component { static navigationOptions = ({ navigation }) => ({ @@ -46,6 +47,26 @@ export default class WalletsList extends Component { componentDidMount() { this.redrawScreen(); + + // the idea is that upon wallet launch we will refresh + // all balances and all transactions here: + InteractionManager.runAfterInteractions(async () => { + let noErr = true; + try { + await BlueElectrum.waitTillConnected(); + let balanceStart = +new Date(); + await BlueApp.fetchWalletBalances(); + let balanceEnd = +new Date(); + console.log('fetch all wallet balances took', (balanceEnd - balanceStart) / 1000, 'sec'); + let start = +new Date(); + await BlueApp.fetchWalletTransactions(); + let end = +new Date(); + console.log('fetch all wallet txs took', (end - start) / 1000, 'sec'); + } catch (_) { + noErr = false; + } + if (noErr) this.redrawScreen(); + }); } /**