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: fetch price immediately after currency changes #1276

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

aniskhalfallah
Copy link
Contributor

Description

as mentioned by @ekzyis here, when we change the currency in settings, we don't immediately query the price, we wait for 30 seconds before doing so, which leaves us with a new currency symbol but with the old value. this PR aims to fix that.

Screenshots

Screenshot 2024-07-24 150633

Additional Context

Checklist

Are your changes backwards compatible? Please answer below:

Yes
Did you QA this? Could we deploy this straight to production? Please answer below:
Yes

For frontend changes: Tested on mobile? Please answer below:

Did you introduce any new environment variables? If so, call them out explicitly here:
No

Copy link
Member

@ekzyis ekzyis left a comment

Choose a reason for hiding this comment

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

We want to only await the promise in the case where the currency was updated. As the comment mentioned, this is else on the SSR critical path so this would stall requests until the Coinbase API (over which we have no control) responds.

So I think you need a flag that you set in the useEffect query to await the price in this special case here.

@aniskhalfallah
Copy link
Contributor Author

OK thank you for the feedback, I have included a new flag changedCurrency so we only await the response when the currency changes. I think we are ready for a review now :)

* rename changedCurrency to fromCache
* remove duplicate logic in getPrice
* keep old cache code with comment about SSR critical path
Copy link
Member

@ekzyis ekzyis left a comment

Choose a reason for hiding this comment

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

You forgot to update the GraphQL type definition and query so changedCurrency never arrived at the server. I fixed that in 4fb250c.

I hope you don't mind but I also refactored the code in 5ef94ad since there was some duplicate if (changedCurrency) ... code. I also renamed changedCurrency to fromCache to reflect better what this variable is used for.

However, I noticed that refetch not only refetches the data with new variables, but also sets these new variables for following polls.

So this mean if we set fromCache: false in the refetch, the price polls will from now on also use fromCache: false which is not intended...

Not sure what's the best way to fix this unintended interaction between refetching and polling.

Tbh, I suggest you work on something else since this seems to indeed be more complicated than fixing this bug is relevant.

@huumn huumn marked this pull request as draft August 7, 2024 18:57
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