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)