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: make <AccountDropdown /> less infuriating #7571

Merged
merged 5 commits into from
Aug 23, 2024

Conversation

gomesalexandre
Copy link
Contributor

@gomesalexandre gomesalexandre commented Aug 20, 2024

Description

This PR fixes this guy #7509 (comment):

Account selector is not displayed if you change your wallet from metamask to native (should be able to reproduce with any wallet that does not support multi account to one supporting it I guess

This issue, as was found out after losing a bit of sanity and brain cells, was caused by <AccountDropdown /> reactivity, and ultimately selectPortfolioAccountIdsByAssetIdFilter lack therof.

quoting big @woodenfurniture on that one:

if (!selectedAccountId || previousSelectedAccountId === selectedAccountId) return // no-op, this would fire onChange an infuriating amount of times

Indeed, the amount of rerenders is infuriating, although a bit less currently as a result of the current createCachedSelector use, which was hiding the actual underlying issue.

  • selectPortfolioAccountIdsByAssetIdFilter being a createCachedSelector, it doesn't trigger reactivity when going back and forth between wallets. This is supposedly a feature, not a bug...
  • as a result, <RFOXHeader /> was never reactive on accountIds as it should, yielding unreliable results
  • While making selectPortfolioAccountIdsByAssetIdFilter a good ol' isEqual selector should fix this, this isn't enough. Doing so will make <AccountDropdown /> infinitely rerender, as proper checks are not in place, but this component was accidentally happy previously as a result of the lack of reactivity of the selector mentioned above.

Pull Request Type

  • 🐛 Bug fix (Non-breaking Change: Fixes an issue)
  • 🛠️ Chore (Non-breaking Change: Doc updates, pkg upgrades, typos, etc..)
  • 💅 New Feature (Breaking/Non-breaking Change)

Issue (if applicable)

N/A

Risk

High Risk PRs Require 2 approvals

What protocols, transaction types, wallets or contract interactions might be affected by this PR?

Medium - this doesn't only affect RFOX, but all components leveraging <AccountDropdown /> multi-account selection

Testing

  • RFOX multi-account selection is consistently happy when switching between MM and native, including a refresh of native then switch to native, and vice-versa
  • Multi-account selection is still happy across the app with native
  • Multi-account "selection" (i.e disabled selection, but happy selected account 0) is still happy with MM across the app

Engineering

  • ^

Operations

  • 🏁 My feature is behind a flag and doesn't require operations testing (yet)
  • ^

Screenshots (if applicable)

  • RFOX multi-account selection is consistently happy when switching between MM and native, including a refresh of native then switch to native, and vice-versa

https://jam.dev/c/a4af9fca-51d0-4710-b17d-09fbb82d586c

  • Multi-account selection is still happy across the app with native

https://jam.dev/c/c027dd53-62ac-43d6-bca2-e1dda20516e4

  • Multi-account "selection" (i.e disabled selection, but happy selected account 0) is still happy with MM across the app

https://jam.dev/c/d0467a43-9290-4b81-b6c7-6fd23af20d48

@gomesalexandre gomesalexandre marked this pull request as ready for review August 20, 2024 03:44
@gomesalexandre gomesalexandre requested a review from a team as a code owner August 20, 2024 03:44
@kaladinlight
Copy link
Contributor

Few cleanup suggestions: #7607

@gomesalexandre gomesalexandre force-pushed the fix_accountdropdown_infuriating_behavior branch from 7c6b184 to c44db7a Compare August 22, 2024 23:21
@gomesalexandre gomesalexandre enabled auto-merge (squash) August 23, 2024 16:15
@gomesalexandre gomesalexandre merged commit 62d8e68 into develop Aug 23, 2024
3 checks passed
@gomesalexandre gomesalexandre deleted the fix_accountdropdown_infuriating_behavior branch August 23, 2024 16:16
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.

2 participants