otterscan/src/components/TokenLogo.tsx

35 lines
931 B
TypeScript
Raw Normal View History

2021-07-09 17:22:25 +00:00
import React, { Suspense, useContext } from "react";
2021-07-01 18:21:40 +00:00
import { useImage } from "react-image";
2021-07-09 16:54:59 +00:00
import { tokenLogoURL } from "../url";
2021-07-09 17:22:25 +00:00
import { RuntimeContext } from "../useRuntime";
2021-07-01 18:21:40 +00:00
type TokenLogoProps = {
address: string;
name: string;
};
const TokenLogo: React.FC<TokenLogoProps> = (props) => (
<Suspense fallback={<></>}>
<InternalTokenLogo {...props} />
</Suspense>
);
const InternalTokenLogo: React.FC<TokenLogoProps> = ({ address, name }) => {
2021-07-09 17:22:25 +00:00
const { config } = useContext(RuntimeContext);
2021-07-09 16:54:59 +00:00
const srcList: string[] = [];
if (config) {
2021-07-09 17:13:31 +00:00
srcList.push(tokenLogoURL(config.assetsURLPrefix ?? "", address));
2021-07-09 16:54:59 +00:00
}
srcList.push("/eth-diamond-black.png");
const { src } = useImage({ srcList });
2021-07-01 18:21:40 +00:00
return (
<div className="flex items-center justify-center w-5 h-5">
<img className="max-w-full max-h-full" src={src} alt={`${name} logo`} />
</div>
);
};
export default React.memo(TokenLogo);