Files
edr-platform/apps/edr-passenger-web/portal/src/lib/useCurrencies.ts
2026-07-10 10:33:36 +03:00

29 lines
733 B
TypeScript

import { useQuery } from '@tanstack/react-query';
import { apiClient } from './api-client';
interface Currency {
code: string;
symbol: string;
name: string;
}
const FALLBACK_SYMBOLS: Record<string, string> = {
ETB: 'Br',
DJF: 'Fdj',
USD: '$',
};
export function useCurrencies() {
return useQuery<Currency[]>({
queryKey: ['currencies'],
queryFn: () => apiClient.get<Currency[]>('/currencies'),
staleTime: 5 * 60 * 1000,
});
}
export function useCurrencySymbol(code: string): string {
const { data, isLoading, isError } = useCurrencies();
if (isLoading || isError || !data) return FALLBACK_SYMBOLS[code] ?? code;
return data.find(c => c.code === code)?.symbol ?? FALLBACK_SYMBOLS[code] ?? code;
}