"use client";
import { useMemo, useState } from "react";
import type { AssetType } from "@/lib/assets";
import { FIAT_FLAG_CODES } from "@/lib/fiat-flag-codes";
import { cn } from "@/lib/utils";
const sizeClassMap = {
sm: "h-5 w-5",
md: "h-6 w-6",
lg: "h-8 w-8"
} as const;
type IconSize = keyof typeof sizeClassMap;
interface CurrencyIconProps {
code: string;
type: AssetType;
size?: IconSize;
className?: string;
}
export function CurrencyIcon({
code,
type,
size = "md",
className
}: CurrencyIconProps) {
const [cryptoMissing, setCryptoMissing] = useState(false);
const lowerCode = useMemo(() => code.toLowerCase(), [code]);
const wrapperSize = sizeClassMap[size];
if (type === "fiat" && FIAT_FLAG_CODES.has(lowerCode)) {
return (
);
}
if (type === "crypto" && !cryptoMissing) {
return (
setCryptoMissing(true)}
/>
);
}
return (
{code.slice(0, 2)}
);
}