-
Notifications
You must be signed in to change notification settings - Fork 3
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
Improvements for fetching data in the dApp #914
Conversation
Let's create a dedicated folder for tanstack queries make each query a separate hook. This approach will allow us to use queries whenever we want.Additionally, the code becomes more clear.
The previous solution was wrong because `useIsFetching` returns the number of the queries that your application is loading or fetching in the background. We should check the fetch status for all the data we are interested in.
✅ Deploy Preview for acre-dapp ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for acre-dapp-testnet ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with query
too but imo it's unnecessary. W/o query
we had a bit of abstraction I mean the name did not suggest which lib is used for fetching data. For example, if we decided to replace the @tanstack/react-query
library, the word query
would probably no longer fit. Just a thought.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested the code on testnet and it looks like it works as expected 👍. It would be great if Kamil could take a look at it.
`setQueriesData` is a synchronous function that can be used to immediately update cached data of multiple queries by using matching the query key. With the new approach, we can remove activities from redux.
The name should not suggest which lib is used for fetching data.The current solution is more abstract.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summarizing my review:
I wouldn't like to use terms like aggregation
or enhancement
because it doesn't say anything descriptive.
Respecting your approach of splitting data querying I suggest the following change:
- Keep previous hooks structure and names so
useStatistics
,useAcrePoints
etc. - Add new "subcategory" of hooks called
queries
. From that point we can have hooks such as@/hooks/queries/useStatisticsQuery
or@/hooks/queries/useAcrePointsQuery
.
The term query sounds quite familiar since we are used to querying paradigm introduced by Tanstack Query library.
Please let me know what do you think.
I had a similar opinion. But I share Rafał's opinion here that the name should be more abstract. #914 (comment) |
Closes AENG-18
This PR improves code for fetching data in the dApp. What has been done
useIsFetchedWalletData
. The previous solution was wrong becauseuseIsFetching
returns the number of queries that our application is loading or fetching in the background. We should check the fetch status for all the data we are interested in.@tanstack/react-query
package to fetch activities. The data will be reset together at the same time.UI
Before
Screen.Recording.2024-12-04.at.10.50.42.mov
After
Screen.Recording.2024-12-04.at.10.46.55.mov
Testing
Use React Query dev tools for testing. They help visualize all of the inner workings of React Query.
Screen.Recording.2024-12-04.at.11.11.18.mov
What should be tested before merge
Check if the data is fetched at the start of the app:
Check if the data is fetched when the wallet is connected:
Check if the data is reset when the wallet is disconnected:
Check if the data is fetched in the time interval. It is currently every 5 minutes:
Checks if the data is updated after the deposit is executed:
Checks if the data is updated after the withdrawal is executed: