Skip to content

Commit

Permalink
Fix importing accounts from ledger
Browse files Browse the repository at this point in the history
  • Loading branch information
buberdds committed Aug 31, 2022
1 parent b1f5e81 commit cd84005
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
35 changes: 35 additions & 0 deletions src/app/state/wallet/saga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions src/app/state/wallet/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ function* getWalletByAddress(address: string) {
* Take multiple ledger accounts that we want to open
*/
export function* openWalletsFromLedger({ payload: accounts }: PayloadAction<LedgerAccount[]>) {
for (const [index, account] of accounts.entries()) {
const newWalletId = walletId
for (const account of accounts) {
yield* put(
walletActions.addWallet({
id: walletId++,
Expand All @@ -72,10 +73,12 @@ export function* openWalletsFromLedger({ payload: accounts }: PayloadAction<Ledg
type: WalletType.Ledger,
balance: account.balance,
path: account.path,
selectImmediately: index === 0,
selectImmediately: false,
}),
)
}
const existingWallet = yield* call(getWalletByAddress, accounts[0].address)
yield* put(walletActions.selectWallet(existingWallet ? existingWallet.id : newWalletId))
}

export function* openWalletFromPrivateKey({ payload: privateKey }: PayloadAction<string>) {
Expand Down

0 comments on commit cd84005

Please sign in to comment.