Skip to content

Commit

Permalink
Merge pull request #1454 from oasisprotocol/lw/dont-freeze-mnemonic
Browse files Browse the repository at this point in the history
Prevent freezing UI rendering while pre-deriving accounts from mnemonic
  • Loading branch information
lukaw3d authored May 12, 2023
2 parents 85ec1b6 + d03bf1e commit 341daa9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/app/state/importaccounts/saga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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))
Expand Down
5 changes: 4 additions & 1 deletion src/app/state/importaccounts/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 '.'
Expand Down Expand Up @@ -66,6 +66,7 @@ function* enumerateAccountsFromMnemonic(action: PayloadAction<string>) {

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)
Expand All @@ -79,6 +80,8 @@ function* enumerateAccountsFromMnemonic(action: PayloadAction<string>) {
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)
Expand Down

0 comments on commit 341daa9

Please sign in to comment.