All files / src/features/MerchantPortal/ManageMoney/hooks useBalances.ts

100% Statements 8/8
80% Branches 4/5
100% Functions 3/3
100% Lines 8/8

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                      1x 4x           1x 111x 111x 111x       4x 4x          
import { ProcessorValue } from "@features/Merchants/MerchantSidePanel/types";
import { useGetCurrentMerchantId } from "@hooks/common";
import { customInstance } from "@services/api";
import { useQuery } from "react-query";
 
export type BalanceDataType = {
  processorName: ProcessorValue;
  availableBalance: number;
  processorID: number;
};
 
const getBalancesById = (id: string | number) => {
  return customInstance({
    url: `merchants/${id}/balances`,
    method: "GET",
  });
};
 
export const useGetBalancesById = (id?: string | number, enabled = true) => {
  const { merchantId } = useGetCurrentMerchantId();
  const usedID = id || merchantId;
  return useQuery(
    ["get-balances-by-id", usedID],
    async () => {
      const data: { data: BalanceDataType[]; total: number } =
        await getBalancesById(usedID);
      return data?.data;
    },
    { cacheTime: 0, enabled: Boolean(usedID && enabled), retry: false },
  );
};