From 497e38eda41b1925eaa2d20cce9e181656c41d87 Mon Sep 17 00:00:00 2001 From: Overtorment Date: Thu, 3 Sep 2020 21:01:03 +0100 Subject: [PATCH] FIX: speedup onchain wallet creation (dont pre-fill too much cache) --- class/wallets/abstract-hd-electrum-wallet.js | 4 ++-- screen/wallets/add.js | 2 +- screen/wallets/list.js | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/class/wallets/abstract-hd-electrum-wallet.js b/class/wallets/abstract-hd-electrum-wallet.js index 2b3591890..80dbd433b 100644 --- a/class/wallets/abstract-hd-electrum-wallet.js +++ b/class/wallets/abstract-hd-electrum-wallet.js @@ -404,10 +404,10 @@ export class AbstractHDElectrumWallet extends AbstractHDWallet { // its faster to pre-build hashmap of owned addresses than to query `this.weOwnAddress()`, which in turn // iterates over all addresses in hierarchy const ownedAddressesHashmap = {}; - for (let c = 0; c < this.next_free_address_index + this.gap_limit; c++) { + for (let c = 0; c < this.next_free_address_index + 1; c++) { ownedAddressesHashmap[this._getExternalAddressByIndex(c)] = true; } - for (let c = 0; c < this.next_free_change_address_index + this.gap_limit; c++) { + for (let c = 0; c < this.next_free_change_address_index + 1; c++) { ownedAddressesHashmap[this._getInternalAddressByIndex(c)] = true; } // hack: in case this code is called from LegacyWallet: diff --git a/screen/wallets/add.js b/screen/wallets/add.js index 57fd4c720..8405e9bf7 100644 --- a/screen/wallets/add.js +++ b/screen/wallets/add.js @@ -205,7 +205,7 @@ const WalletsAdd = () => { } BlueApp.wallets.push(w); await BlueApp.saveToDisk(); - EV(EV.enum.WALLETS_COUNT_CHANGED); + setTimeout(() => EV(EV.enum.WALLETS_COUNT_CHANGED), 500); // heavy task; hopefully will be executed while user is staring at backup screen A(A.ENUM.CREATED_WALLET); ReactNativeHapticFeedback.trigger('notificationSuccess', { ignoreAndroidSystemSettings: false }); if (w.type === HDSegwitP2SHWallet.type || w.type === HDSegwitBech32Wallet.type) { diff --git a/screen/wallets/list.js b/screen/wallets/list.js index 08e20600b..5b2624494 100644 --- a/screen/wallets/list.js +++ b/screen/wallets/list.js @@ -140,6 +140,7 @@ export default class WalletsList extends Component { } const wallets = BlueApp.getWallets().concat(false); + const dataSource = BlueApp.getTransactions(null, 10); if (scrollToEnd) { scrollToEnd = wallets.length > this.state.wallets.length; } @@ -148,8 +149,8 @@ export default class WalletsList extends Component { { isLoading: false, isFlatListRefreshControlHidden: true, - dataSource: BlueApp.getTransactions(null, 10), - wallets: BlueApp.getWallets().concat(false), + dataSource, + wallets, }, () => { if (scrollToEnd) {