-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvements for fetching data in the dApp (#914)
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** https://github.com/user-attachments/assets/440ef97d-ecf7-46bd-9260-ad0025412dda **After** https://github.com/user-attachments/assets/07371345-3624-41ab-8b72-87cfbcb4cd00 ## Testing Use React Query dev tools for testing. They help visualize all of the inner workings of React Query. https://github.com/user-attachments/assets/a966c8f4-98ab-4c4c-91eb-b50f60eea798 ### 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
- Loading branch information
Showing
33 changed files
with
207 additions
and
417 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
export * from "./useInitializeAcreSdk" | ||
export * from "./useFetchMinDepositAmount" | ||
export * from "./useInitDataFromSdk" | ||
export * from "./useFetchActivities" | ||
export * from "./useMinWithdrawAmount" | ||
export { default as useBitcoinPosition } from "./useBitcoinPosition" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,5 @@ | ||
import { useEffect } from "react" | ||
import { useInterval } from "@chakra-ui/react" | ||
import { logPromiseFailure } from "#/utils" | ||
import { REFETCH_INTERVAL_IN_MILLISECONDS } from "#/constants" | ||
import { useFetchMinDepositAmount } from "./useFetchMinDepositAmount" | ||
import { useFetchActivities } from "./useFetchActivities" | ||
import { useWallet } from "../useWallet" | ||
|
||
export function useInitDataFromSdk() { | ||
const { address } = useWallet() | ||
const fetchActivities = useFetchActivities() | ||
|
||
useEffect(() => { | ||
if (address) { | ||
logPromiseFailure(fetchActivities()) | ||
} | ||
}, [address, fetchActivities]) | ||
|
||
useFetchMinDepositAmount() | ||
useInterval( | ||
() => logPromiseFailure(fetchActivities()), | ||
REFETCH_INTERVAL_IN_MILLISECONDS, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { selectWalletAddress } from "#/store/wallet" | ||
import { useAppSelector } from "./useAppSelector" | ||
|
||
export default function useWalletAddress() { | ||
return useAppSelector(selectWalletAddress) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { queryKeysFactory, REFETCH_INTERVAL_IN_MILLISECONDS } from "#/constants" | ||
import { useQuery } from "@tanstack/react-query" | ||
import { acreApi } from "#/utils" | ||
|
||
const { acreKeys } = queryKeysFactory | ||
|
||
export default function useAcrePointsData() { | ||
return useQuery({ | ||
queryKey: [...acreKeys.pointsData()], | ||
queryFn: async () => acreApi.getPointsData(), | ||
refetchInterval: REFETCH_INTERVAL_IN_MILLISECONDS, | ||
}) | ||
} |
Oops, something went wrong.