# All files / src/hooks useResellerCredits.ts

0% Statements 0/10
0% Branches 0/4
0% Functions 0/2
0% Lines 0/10

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

     import { useQuery } from '@tanstack/react-query';
    import { useTranslation } from 'react-i18next';
    import { resellerService } from '@/services/reseller';

    export function useResellerCredits() {
      const { t } = useTranslation();
      return useQuery({
        queryKey: ['reseller-credits'],
        queryFn: async () => {
          const result = await resellerService.getCreditBalance();
          if (result.success) {
            return result.data;
          }
          throw new Error(result.error?.error || t('common.serverError'));
        },
        refetchInterval: 30000, // Refetch every 30 seconds
        staleTime: 10000, // Consider data stale after 10 seconds
      });
    }