diff --git a/src/app/state/wallet/saga.test.ts b/src/app/state/wallet/saga.test.ts index d809baf4a1..27051b02d5 100644 --- a/src/app/state/wallet/saga.test.ts +++ b/src/app/state/wallet/saga.test.ts @@ -2,6 +2,7 @@ import { expectSaga } from 'redux-saga-test-plan' import * as matchers from 'redux-saga-test-plan/matchers' import { EffectProviders, StaticProvider } from 'redux-saga-test-plan/providers' import { RootState } from 'types' +import { LedgerAccount } from '../ledger/types' import { walletActions } from '.' import { transactionActions } from '../transaction' @@ -70,6 +71,40 @@ describe('Wallet Sagas', () => { .silentRun(50) }) + it('Should open from ledger and select the first imported wallet as active', () => { + return expectSaga(rootWalletSaga) + .provide(providers) + .withState({ + wallet: { + isOpen: true, + selectedWallet: 0, + wallets: [ + { + address: 'oasis1qz0k5q8vjqvu4s4nwxyj406ylnflkc4vrcjghuwk', + id: 0, + }, + { + address: 'oasis1qq2vzcvxn0js5unsch5me2xz4kr43vcasv0d5eq4', + id: 1, + }, + ], + }, + }) + .dispatch( + walletActions.openWalletsFromLedger([ + { + address: 'oasis1qq2vzcvxn0js5unsch5me2xz4kr43vcasv0d5eq4', + } as LedgerAccount, + { + address: 'oasis1qq5t7f2gecsjsdxmp5zxtwgck6pzpjmkvc657z6l', + } as LedgerAccount, + ]), + ) + .fork(walletSaga) + .put({ type: walletActions.selectWallet.type, payload: 1 }) + .silentRun(50) + }) + it('Should close the wallet and wait for another open attempt', () => { return expectSaga(rootWalletSaga) .provide(providers) diff --git a/src/app/state/wallet/saga.ts b/src/app/state/wallet/saga.ts index 6d70125d2b..88423e1249 100644 --- a/src/app/state/wallet/saga.ts +++ b/src/app/state/wallet/saga.ts @@ -63,7 +63,8 @@ function* getWalletByAddress(address: string) { * Take multiple ledger accounts that we want to open */ export function* openWalletsFromLedger({ payload: accounts }: PayloadAction) { - for (const [index, account] of accounts.entries()) { + const newWalletId = walletId + for (const account of accounts) { yield* put( walletActions.addWallet({ id: walletId++, @@ -72,10 +73,12 @@ export function* openWalletsFromLedger({ payload: accounts }: PayloadAction) {