31 lines
886 B
TypeScript
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 };
|
|
}
|
|
|