Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix importing multiple accounts from ledger #980

Merged
merged 3 commits into from
Sep 5, 2022

Conversation

buberdds
Copy link
Contributor

Select the first wallet from a selection after all wallets are loaded

Closes #934

@buberdds buberdds changed the title Fix importing accounts from ledger Fix importing multiple accounts from ledger Aug 31, 2022
@buberdds buberdds force-pushed the buberdds/934-ledger-accounts branch from cd84005 to 75b969d Compare August 31, 2022 16:23
@github-actions
Copy link

github-actions bot commented Aug 31, 2022

MegaLinter status: ✅ SUCCESS

Descriptor Linter Files Fixed Errors Elapsed time
✅ EDITORCONFIG editorconfig-checker 2 0 0.01s
✅ GIT git_diff yes no 0.01s
✅ TYPESCRIPT eslint 2 0 0 4.65s

See errors details in artifact MegaLinter reports on CI Job page
Set VALIDATE_ALL_CODEBASE: true in mega-linter.yml to validate all sources, not only the diff

@codecov
Copy link

codecov bot commented Aug 31, 2022

Codecov Report

Merging #980 (52dde69) into master (6b86f62) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #980      +/-   ##
==========================================
+ Coverage   88.19%   88.20%   +0.01%     
==========================================
  Files          99       99              
  Lines        1711     1713       +2     
  Branches      395      396       +1     
==========================================
+ Hits         1509     1511       +2     
  Misses        202      202              
Flag Coverage Δ
cypress 57.60% <0.00%> (-0.13%) ⬇️
jest 79.12% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/app/state/wallet/saga.ts 98.55% <100.00%> (+0.04%) ⬆️

@buberdds buberdds requested a review from lukaw3d August 31, 2022 16:36
Comment on lines +87 to +88
address: 'oasis1qq2vzcvxn0js5unsch5me2xz4kr43vcasv0d5eq4',
id: 1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be here to work around walletId global variable messing everything up?

Copy link
Contributor Author

@buberdds buberdds Sep 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not related to global variable. Test covers another bug/issue when user imports wallets and the first selected wallet exists in redux store. In this case we will use existing id not a new one stored in global walletId variable.

Steps to repro (selection modal):
A - selected
B - selected
C
D
E - selected

nav to import again
A
B - selected
C - selected
D - selected
E - selected

@lukaw3d
Copy link
Member

lukaw3d commented Aug 31, 2022

How come this fixed the bug?

@@ -70,6 +71,40 @@ describe('Wallet Sagas', () => {
.silentRun(50)
})

it('Should open from ledger and select the first imported wallet as active', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this test be extended to validate the bug was fixed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you have already answered this question :D

@lukaw3d
Copy link
Member

lukaw3d commented Aug 31, 2022

Update: I can't reproduce the bug with expectSaga on master. Looks like reducer + saga scheduling in app is different than in expectSaga.

const result = await expectSaga(rootWalletSaga)
.provide(providers)
.withReducer(walletReducer)
.dispatch(
  walletActions.openWalletsFromLedger([
    {
      address: 'oasis1qq2vzcvxn0js5unsch5me2xz4kr43vcasv0d5eq4',
    } as LedgerAccount,
    {
      address: 'oasis1qq5t7f2gecsjsdxmp5zxtwgck6pzpjmkvc657z6l',
    } as LedgerAccount,
    {
      address: 'oasis1qrusst9f8ey6kphgp5d02nuf4kx5qsa80vamtxj8',
    } as LedgerAccount,
    {
      address: 'oasis1qpqs54pdwxstpjefw5t6ucy425nt4yud3c4fgr8p',
    } as LedgerAccount,
    {
      address: 'oasis1qrf54xw003wkznm90w0q05ns8nryla0455tlex38',
    } as LedgerAccount,
  ]),
)
.fork(walletSaga)
.put({ type: walletActions.walletSelected.type, payload: 4 })
.silentRun(50)

expect(result.storeState).toMatchObject({
  selectedWallet: 4,
} as WalletState)

put(selectWallet) in step 8 schedules walletSelected at the end:

1. 'wallet/addWallet', payload: { id: 4, address: 'oasis1qq2vzcvxn0js5unsch5me2xz4kr43vcasv0d5eq4' }
2. 'wallet/addWallet', payload: { id: 5, address: 'oasis1qq5t7f2gecsjsdxmp5zxtwgck6pzpjmkvc657z6l' }
3. 'wallet/addWallet', payload: { id: 6, address: 'oasis1qrusst9f8ey6kphgp5d02nuf4kx5qsa80vamtxj8' }
4. 'wallet/addWallet', payload: { id: 7, address: 'oasis1qpqs54pdwxstpjefw5t6ucy425nt4yud3c4fgr8p' }
5. 'wallet/addWallet', payload: { id: 8, address: 'oasis1qrf54xw003wkznm90w0q05ns8nryla0455tlex38' }

6. 'wallet/walletSelected', payload: undefined
7. 'wallet/walletOpened', payload: { id: 4, address: 'oasis1qq2vzcvxn0js5unsch5me2xz4kr43vcasv0d5eq4' }
8. 'wallet/selectWallet', payload: 4

9. 'wallet/walletSelected', payload: undefined
10. 'wallet/walletOpened', payload: { id: 5, address: 'oasis1qq5t7f2gecsjsdxmp5zxtwgck6pzpjmkvc657z6l' }

11. 'wallet/walletSelected', payload: undefined
12. 'wallet/walletOpened', payload: { id: 6, address: 'oasis1qrusst9f8ey6kphgp5d02nuf4kx5qsa80vamtxj8' }

13. 'wallet/walletSelected', payload: undefined
14. 'wallet/walletOpened', payload: { id: 7, address: 'oasis1qpqs54pdwxstpjefw5t6ucy425nt4yud3c4fgr8p' }

15. 'wallet/walletSelected', payload: undefined
16. 'wallet/walletOpened', payload: { id: 8, address: 'oasis1qrf54xw003wkznm90w0q05ns8nryla0455tlex38' }

17. 'wallet/walletSelected', payload: 4

But it looks like can fix the bug by just removing yield* put(walletActions.walletSelected(initialState.selectedWallet)). There is no reason to select undefined when adding every wallet.

@buberdds
Copy link
Contributor Author

buberdds commented Sep 1, 2022

Yeah probably there are many ways to fix it. My preference is to select a wallet when prev actions are done.

@lukaw3d
Copy link
Member

lukaw3d commented Sep 1, 2022

I think we should do:

  • commit: test for re-importing existing accounts (this test is already passing before any changes)
  • commit: fix the issue by removing yield* put(walletActions.walletSelected(initialState.selectedWallet)) (selecting undefined when adding every wallet makes no sense)
  • optionally commit: replacing selectImmediately with a select after all wallets are added

@buberdds buberdds force-pushed the buberdds/934-ledger-accounts branch 2 times, most recently from 43806ee to e2664f6 Compare September 1, 2022 17:37
@buberdds buberdds closed this Sep 1, 2022
@buberdds buberdds force-pushed the buberdds/934-ledger-accounts branch from e2664f6 to b1f5e81 Compare September 1, 2022 17:38
@buberdds buberdds reopened this Sep 1, 2022
@buberdds buberdds force-pushed the buberdds/934-ledger-accounts branch from bba22f6 to 61bcfc5 Compare September 2, 2022 14:50
@buberdds buberdds requested a review from lukaw3d September 2, 2022 14:59
@buberdds buberdds force-pushed the buberdds/934-ledger-accounts branch from 61bcfc5 to 52dde69 Compare September 2, 2022 15:29
@buberdds buberdds merged commit 9bc9677 into master Sep 5, 2022
@buberdds buberdds deleted the buberdds/934-ledger-accounts branch September 5, 2022 05:48
@buberdds
Copy link
Contributor Author

buberdds commented Sep 6, 2022

  • (selecting undefined when adding every wallet makes no sense)

fyi @lukaw3d this was actually handling a case when you open an active wallet again

@lukaw3d
Copy link
Member

lukaw3d commented Sep 6, 2022

  • (selecting undefined when adding every wallet makes no sense)

fyi @lukaw3d this was actually handling a case when you open an active wallet again

Ah, I didn't notice when it was added in https://github.com/oasisprotocol/oasis-wallet-web/pull/787/files#diff-f5039a29f4edb72ce140205418b6a20f84c4e5ed87c38bd33c4724aaee5c66fbR130

when changing from

  yield* takeLatest(walletActions.selectWallet, selectWallet)
    
  export function* selectWallet({ payload: index }: PayloadAction<number>) {
    ...
    yield* put(push(`/account/${newWallet?.address}`))
  }

to

  useEffect(() => {
    if (typeof activeWalletIndex !== 'undefined' && address) {
      history.push(`/account/${address}`)
    }
  }, [activeWalletIndex, address, history])

:/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Importing more than three accounts from ledger doesn't work
2 participants