All files / src/features/Settlements/hooks useSettlementStats.tsx

100% Statements 7/7
100% Branches 6/6
100% Functions 2/2
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45          1x 8x   8x     4x             8x                       8x               8x            
import { DEFAULT_QUERY_CONFIG } from "@components/VirtualList/hooks/queries";
import { useGetCurrentMerchantId } from "@hooks/common";
import { customInstance } from "@services/api";
import { useQuery } from "react-query";
 
export const useSettlementStats = () => {
  const { merchantId } = useGetCurrentMerchantId();
 
  const { data, isLoading } = useQuery(
    ["get-settlement-stats", merchantId],
    async () =>
      await customInstance({
        url: `/merchants/${merchantId}/transaction-settlements/stats`,
        method: "GET",
      }),
    { enabled: Boolean(merchantId), ...DEFAULT_QUERY_CONFIG },
  );
 
  const stats = [
    {
      title: "Total Fees Collected",
      value: data?.grossFeesAmount / 100 || 0,
      isAmount: true,
    },
    {
      title: "Total Transactions",
      value: data?.transactionCount || 0,
    },
  ];
 
  const mainStats = [
    {
      title: "Total Gross Sales",
      value: data?.purchaseAmount / 100 || 0,
      isAmount: true,
    },
  ];
 
  return {
    isLoading,
    mainStats,
    stats,
  };
};