2025-12-18 22:14:11 +01:00

31 lines
886 B
TypeScript

import { useState, useEffect } from 'react';
import { apiService } from '@/services/api';
import type { IApiCurrency } from '../types';
import type { TMerchant } from '@/config/api';
export function useCurrencies(merchant?: TMerchant) {
const [currencies, setCurrencies] = useState<IApiCurrency[]>([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<Error | null>(null);
useEffect(() => {
const fetchCurrencies = async () => {
try {
setLoading(true);
setError(null);
const data = await apiService.getCurrencies(merchant);
setCurrencies(data);
} catch (err) {
setError(err instanceof Error ? err : new Error('Failed to fetch currencies'));
} finally {
setLoading(false);
}
};
fetchCurrencies();
}, [merchant]);
return { currencies, loading, error };
}