mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-07 07:15:45 +00:00
29 lines
733 B
TypeScript
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;
|
|
}
|