CryptoIcon: convert to tsx

This commit is contained in:
Alex Gleason 2022-03-25 16:22:09 -05:00
parent 7e2a74b05d
commit d8bde70043
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 29 additions and 0 deletions

View file

@ -0,0 +1,29 @@
import React from 'react';
/** Get crypto icon URL by ticker symbol, or fall back to generic icon */
const getIcon = (ticker: string): string => {
try {
return require(`cryptocurrency-icons/svg/color/${ticker.toLowerCase()}.svg`);
} catch {
return require('cryptocurrency-icons/svg/color/generic.svg');
}
};
interface ICryptoIcon {
ticker: string,
title?: string,
className?: string,
}
const CryptoIcon: React.FC<ICryptoIcon> = ({ ticker, title, className }): JSX.Element => {
return (
<div className={className}>
<img
src={getIcon(ticker)}
alt={title || ticker}
/>
</div>
);
};
export default CryptoIcon;