CryptoIcon: convert to tsx
This commit is contained in:
parent
7e2a74b05d
commit
d8bde70043
|
@ -1,34 +0,0 @@
|
|||
import classNames from 'classnames';
|
||||
import PropTypes from 'prop-types';
|
||||
import React from 'react';
|
||||
|
||||
const getIcon = ticker => {
|
||||
try {
|
||||
return require(`cryptocurrency-icons/svg/color/${ticker.toLowerCase()}.svg`);
|
||||
} catch {
|
||||
return require('cryptocurrency-icons/svg/color/generic.svg');
|
||||
}
|
||||
};
|
||||
|
||||
export default class CryptoIcon extends React.PureComponent {
|
||||
|
||||
static propTypes = {
|
||||
ticker: PropTypes.string.isRequired,
|
||||
title: PropTypes.string,
|
||||
className: PropTypes.string,
|
||||
}
|
||||
|
||||
render() {
|
||||
const { ticker, title, className } = this.props;
|
||||
|
||||
return (
|
||||
<div className={classNames('crypto-icon', className)}>
|
||||
<img
|
||||
src={getIcon(ticker)}
|
||||
alt={title || ticker}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -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 New Issue