otterscan/src/components/TokenName.tsx

92 lines
1.9 KiB
TypeScript
Raw Normal View History

2021-10-31 22:51:11 +00:00
import React from "react";
import { NavLink } from "react-router-dom";
import TokenLogo from "./TokenLogo";
import { ResolvedAddressRenderer } from "../api/address-resolver/address-resolver";
import { TokenMeta } from "../types";
type TokenNameProps = {
2021-11-01 04:32:35 +00:00
address: string;
2021-10-31 22:51:11 +00:00
name: string;
2021-10-31 22:59:14 +00:00
symbol: string;
2021-10-31 22:51:11 +00:00
linkable: boolean;
dontOverrideColors?: boolean;
};
const TokenName: React.FC<TokenNameProps> = ({
2021-11-01 04:32:35 +00:00
address,
2021-10-31 22:51:11 +00:00
name,
2021-10-31 22:59:14 +00:00
symbol,
2021-10-31 22:51:11 +00:00
linkable,
dontOverrideColors,
}) => {
if (linkable) {
return (
<NavLink
className={`flex items-baseline space-x-1 font-sans ${
dontOverrideColors ? "" : "text-link-blue hover:text-link-blue-hover"
} truncate`}
2021-10-31 22:55:09 +00:00
to={`/address/${address}`}
2021-10-31 22:59:14 +00:00
title={`${name} (${symbol}): ${address}`}
2021-10-31 22:51:11 +00:00
>
2021-10-31 22:59:14 +00:00
<Content
address={address}
linkable={true}
name={name}
symbol={symbol}
/>
2021-10-31 22:51:11 +00:00
</NavLink>
);
}
return (
<div
className="flex items-baseline space-x-1 font-sans text-gray-700 truncate"
2021-10-31 22:59:14 +00:00
title={`${name} (${symbol}): ${address}`}
2021-10-31 22:51:11 +00:00
>
2021-10-31 22:59:14 +00:00
<Content address={address} linkable={false} name={name} symbol={symbol} />
2021-10-31 22:51:11 +00:00
</div>
);
};
type ContentProps = {
address: string;
name: string;
2021-10-31 22:59:14 +00:00
symbol: string;
2021-11-01 04:32:35 +00:00
linkable: boolean;
2021-10-31 22:51:11 +00:00
};
2021-10-31 22:59:14 +00:00
const Content: React.FC<ContentProps> = ({
address,
name,
symbol,
2021-11-01 04:32:35 +00:00
linkable,
2021-10-31 22:59:14 +00:00
}) => (
2021-10-31 22:51:11 +00:00
<>
2021-11-01 04:32:35 +00:00
<div
className={`self-center w-5 h-5 ${linkable ? "" : "filter grayscale"}`}
>
2021-10-31 22:51:11 +00:00
<TokenLogo address={address} name={name} />
</div>
2021-10-31 22:59:14 +00:00
<span className="truncate">
{name} ({symbol})
</span>
2021-10-31 22:51:11 +00:00
</>
);
export const tokenRenderer: ResolvedAddressRenderer<TokenMeta> = (
address,
2021-11-01 04:32:35 +00:00
tokenMeta,
2021-10-31 22:51:11 +00:00
linkable,
dontOverrideColors
) => (
<TokenName
address={address}
2021-11-01 04:32:35 +00:00
name={tokenMeta.name}
symbol={tokenMeta.symbol}
2021-10-31 22:51:11 +00:00
linkable={linkable}
dontOverrideColors={dontOverrideColors}
/>
);
export default TokenName;