Skip to content
Snippets Groups Projects
Commit 657681eb authored by Dima Rifai's avatar Dima Rifai
Browse files

Issue #479 - Add useAggregatedHistory hook

parent 051a59d2
No related branches found
No related tags found
1 merge request!587Delrifai/#479 use aggregated balance api
import { useQuery } from "@tanstack/react-query";
import moment from "moment";
import fetchingService from "@/services/FetchingService";
const useAggregatedBalanceHistory = (
accountName: string,
coinType: string,
granularity: "daily"|"monthly"|"yearly",
direction: "asc" | "desc",
fromDate?: Date | number | undefined,
toDate?: Date | number | undefined
) => {
const fetchBalanceHist = async () => {
if (fromDate && toDate && moment(fromDate).isAfter(moment(toDate))) {
return [];
}
return await fetchingService.geAccountAggregatedtBalanceHistory(
accountName,
coinType,
granularity,
direction,
fromDate ? fromDate : undefined,
toDate ? toDate : undefined
);
};
const {
data: aggregatedAccountBalanceHistory,
isLoading: isAggregatedAccountBalanceHistoryLoading,
isError: isAggregatedAccountBalanceHistoryError,
}: any = useQuery({
queryKey: [
"get_balance_aggregation",
accountName,
coinType,
direction,
fromDate,
toDate,
],
queryFn: fetchBalanceHist,
enabled: !!accountName,
refetchOnWindowFocus: false,
});
return {
aggregatedAccountBalanceHistory,
isAggregatedAccountBalanceHistoryLoading,
isAggregatedAccountBalanceHistoryError,
};
};
export default useAggregatedBalanceHistory;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment