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

[STK-247][FIX] - Network switching bug #194

Merged
merged 1 commit into from
Aug 6, 2024

Conversation

ElRodrigote
Copy link
Collaborator

@ElRodrigote ElRodrigote commented Aug 2, 2024

Fixes: STK-247

Context

Long story short: I couldn't find why some of our context chainId changes do not trigger the effect that fetches the balances for a connected wallet. The chainId value changes correctly, but this doesn't trigger the effect sometimes.

Some of the reasons for a value change in the effect dependency array not triggering the effect execution:

  • React makes a shallow comparison on values, meaning, if the value reference in memory does not change, then it won't trigger the effect (for example mutating an array or an object)
  • Values outside the React state sometimes do not trigger effects

So, all-in-all, values present in the dependency array do not guarantee the effect to trigger when these change. If there are other reasons for this to happen (most likely there are) I couldn't find them.

I propose this solution because it's simple and seems to fix the issue, but please check it and speak out your opinion because I'm not 100% convinced about it. As far as I could check, this happens just for token balances fetch. I also tried aborting ongoing fetch values (with the Abort Controller pattern) and a bunch of other stuff with no success.

Description

  • Uses different chain ID sources if a wallet is connected or not

Visual Evidence

https://www.loom.com/share/d49d6b37a5d2463ea1222dce3308780d?sid=e43f11f9-587e-4f86-b0da-0a92924afb6e

Copy link

vercel bot commented Aug 2, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
stackly-landing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 2, 2024 1:59pm

@Diogomartf
Copy link
Collaborator

looks to work much better there is only a small thing that's still off:

When switching networks seems like the input tokens lose context

9fae5ef6c4a4fb3aa797fa4903db4ab8.1.mp4

@ElRodrigote ElRodrigote merged commit 756db33 into develop Aug 6, 2024
4 checks passed
@ElRodrigote ElRodrigote deleted the fix/stk-247-network-switching-bug branch August 6, 2024 08:54
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.

3 participants