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

Improvements for fetching data in the dApp #914

Merged
merged 14 commits into from
Dec 12, 2024
Merged

Conversation

kkosiorowska
Copy link
Contributor

@kkosiorowska kkosiorowska commented Dec 4, 2024

Closes AENG-18

This PR improves code for fetching data in the dApp. What has been done

  • Made each query a separate hook. This approach will allow us to use queries whenever we want. Additionally, the code becomes more clear.
  • Fixed for checking the status of fetched data, improvement for useIsFetchedWalletData. The previous solution was wrong because useIsFetching 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.
  • Fixed a bug from AENG-18. The problem was solved by using the @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

  • Make sure that the issue described in AENG-18 is no longer exist.
  • The skeleton of data loading works correctly.

Check if the data is fetched at the start of the app:

  • TVL
  • Total Mezo points
  • Total Acre points

Check if the data is fetched when the wallet is connected:

  • Bitcoin balance
  • Bitcoin position
  • Activities
  • User Acre points

Check if the data is reset when the wallet is disconnected:

  • Bitcoin balance
  • Bitcoin position
  • Activities
  • User Acre points

Check if the data is fetched in the time interval. It is currently every 5 minutes:

  • TVL
  • Total Mezo points
  • Total Acre points
  • Bitcoin balance
  • Bitcoin position
  • Activities

Checks if the data is updated after the deposit is executed:

  • Activities
  • Bitcoin balance

Checks if the data is updated after the withdrawal is executed:

  • Activities
  • Bitcoin position

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.
@kkosiorowska kkosiorowska added the 🎨 dApp dApp label Dec 4, 2024
@kkosiorowska kkosiorowska self-assigned this Dec 4, 2024
Copy link

netlify bot commented Dec 4, 2024

Deploy Preview for acre-dapp ready!

Name Link
🔨 Latest commit b69b1c0
🔍 Latest deploy log https://app.netlify.com/sites/acre-dapp/deploys/675ac1f2202a5d00087ca9e5
😎 Deploy Preview https://deploy-preview-914--acre-dapp.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Dec 4, 2024

Deploy Preview for acre-dapp-testnet ready!

Name Link
🔨 Latest commit b69b1c0
🔍 Latest deploy log https://app.netlify.com/sites/acre-dapp-testnet/deploys/675ac1f2202a5d00087ca9e1
😎 Deploy Preview https://deploy-preview-914--acre-dapp-testnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

linear bot commented Dec 4, 2024

@kkosiorowska kkosiorowska marked this pull request as ready for review December 4, 2024 11:16
dapp/src/hooks/useTrackActivities.ts Outdated Show resolved Hide resolved
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@r-czajkowski r-czajkowski left a 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.
r-czajkowski
r-czajkowski previously approved these changes Dec 9, 2024
Copy link
Contributor

@kpyszkowski kpyszkowski left a 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.

dapp/src/hooks/useEnhancedStatistics.ts Outdated Show resolved Hide resolved
dapp/src/hooks/useAggregatedAcrePointsData.ts Show resolved Hide resolved
@kkosiorowska
Copy link
Contributor Author

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.

I had a similar opinion. But I share Rafał's opinion here that the name should be more abstract. #914 (comment)

@kpyszkowski kpyszkowski merged commit f0a59c4 into main Dec 12, 2024
26 of 28 checks passed
@kpyszkowski kpyszkowski deleted the reset-activities branch December 12, 2024 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants