From d03bf1ec299e185c9a9fa584a2c896dc3da8fb6a Mon Sep 17 00:00:00 2001 From: lukaw3d Date: Fri, 12 May 2023 03:32:23 +0200 Subject: [PATCH] Prevent freezing UI rendering while pre-deriving accounts from mnemonic --- src/app/state/importaccounts/saga.test.ts | 2 ++ src/app/state/importaccounts/saga.ts | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/app/state/importaccounts/saga.test.ts b/src/app/state/importaccounts/saga.test.ts index 7282df6e47..af2e5fef36 100644 --- a/src/app/state/importaccounts/saga.test.ts +++ b/src/app/state/importaccounts/saga.test.ts @@ -11,6 +11,7 @@ import { ImportAccountsListAccount, ImportAccountsStep } from './types' import { WalletErrors } from 'types/errors' import { OasisTransaction } from 'app/lib/transaction' import { WalletType } from 'app/state/wallet/types' +import delayP from '@redux-saga/delay-p' describe('importAccounts Sagas', () => { describe('enumerateAccountsFromLedger', () => { @@ -123,6 +124,7 @@ describe('importAccounts Sagas', () => { ], [matchers.call.fn(publicKeyToAddress), mockAddress], [matchers.call.fn(getBalance), {}], + [matchers.call.fn(delayP), null], // https://github.com/jfairbank/redux-saga-test-plan/issues/257 ]) .dispatch(importAccountsActions.enumerateAccountsFromMnemonic('mnemonic')) .put(importAccountsActions.setStep(ImportAccountsStep.LoadingAccounts)) diff --git a/src/app/state/importaccounts/saga.ts b/src/app/state/importaccounts/saga.ts index acf8853467..2243d8a665 100644 --- a/src/app/state/importaccounts/saga.ts +++ b/src/app/state/importaccounts/saga.ts @@ -4,7 +4,7 @@ import * as oasis from '@oasisprotocol/client' import { hex2uint, publicKeyToAddress, uint2hex } from 'app/lib/helpers' import { Ledger, LedgerSigner } from 'app/lib/ledger' import { OasisTransaction } from 'app/lib/transaction' -import { all, call, fork, put, select, takeEvery } from 'typed-redux-saga' +import { all, call, delay, fork, put, select, takeEvery } from 'typed-redux-saga' import { ErrorPayload, WalletError, WalletErrors } from 'types/errors' import { WalletType } from 'app/state/wallet/types' import { importAccountsActions } from '.' @@ -66,6 +66,7 @@ function* enumerateAccountsFromMnemonic(action: PayloadAction) { try { yield* setStep(ImportAccountsStep.LoadingAccounts) + // Pre-derive all pages of accounts so we don't need to store mnemonic in redux. for (let i = 0; i < accountsPerPage * numberOfAccountPages; i++) { const signer = yield* call(oasis.hdkey.HDKey.getAccountSigner, mnemonic, i) const address = yield* call(publicKeyToAddress, signer.publicKey) @@ -79,6 +80,8 @@ function* enumerateAccountsFromMnemonic(action: PayloadAction) { selected: i === 0, type: WalletType.Mnemonic, }) + // Prevent freezing UI rendering. Especially noticeable on a phone. + yield* delay(0) } yield* put(importAccountsActions.accountsListed(wallets)) yield* setStep(ImportAccountsStep.Idle)