CryptoIcon: convert to tsx
This commit is contained in:
parent
7e2a74b05d
commit
d8bde70043
2 changed files with 29 additions and 0 deletions
Binary file not shown.
|
@ -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;
|
Loading…
Reference in a new issue