111 lines
2.6 KiB
TypeScript
111 lines
2.6 KiB
TypeScript
|
import React from "react";
|
||
|
import { NavLink } from "react-router-dom";
|
||
|
import TokenLogo from "./TokenLogo";
|
||
|
import { ResolvedAddressRenderer } from "../api/address-resolver/address-resolver";
|
||
|
import {
|
||
|
UniswapV2PairMeta,
|
||
|
UniswapV2TokenMeta,
|
||
|
} from "../api/address-resolver/UniswapV2Resolver";
|
||
|
import { ChecksummedAddress } from "../types";
|
||
|
|
||
|
type UniswapV2PairNameProps = {
|
||
|
address: string;
|
||
|
token0: UniswapV2TokenMeta;
|
||
|
token1: UniswapV2TokenMeta;
|
||
|
linkable: boolean;
|
||
|
dontOverrideColors?: boolean;
|
||
|
};
|
||
|
|
||
|
const UniswapV2PairName: React.FC<UniswapV2PairNameProps> = ({
|
||
|
address,
|
||
|
token0,
|
||
|
token1,
|
||
|
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`}
|
||
|
to={`/address/${address}`}
|
||
|
title={`Uniswap V2 LP (${token0.symbol}/${token1.symbol}): ${address}`}
|
||
|
>
|
||
|
<span>Uniswap V2 LP:</span>
|
||
|
<Content
|
||
|
linkable={true}
|
||
|
address={token0.address}
|
||
|
name={token0.name}
|
||
|
symbol={token0.symbol}
|
||
|
/>
|
||
|
<span>/</span>
|
||
|
<Content
|
||
|
linkable={true}
|
||
|
address={token1.address}
|
||
|
name={token1.name}
|
||
|
symbol={token1.symbol}
|
||
|
/>
|
||
|
</NavLink>
|
||
|
);
|
||
|
}
|
||
|
|
||
|
return (
|
||
|
<div
|
||
|
className="flex items-baseline space-x-1 font-sans text-gray-700 truncate"
|
||
|
title={`Uniswap V2 LP (${token0.symbol}/${token1.symbol}): ${address}`}
|
||
|
>
|
||
|
<span>Uniswap V2 LP:</span>
|
||
|
<Content
|
||
|
linkable={false}
|
||
|
address={token0.address}
|
||
|
name={token0.name}
|
||
|
symbol={token0.symbol}
|
||
|
/>
|
||
|
<span>/</span>
|
||
|
<Content
|
||
|
linkable={false}
|
||
|
address={token1.address}
|
||
|
name={token1.name}
|
||
|
symbol={token1.symbol}
|
||
|
/>
|
||
|
</div>
|
||
|
);
|
||
|
};
|
||
|
|
||
|
type ContentProps = {
|
||
|
linkable: boolean;
|
||
|
address: ChecksummedAddress;
|
||
|
name: string;
|
||
|
symbol: string;
|
||
|
};
|
||
|
|
||
|
const Content: React.FC<ContentProps> = ({
|
||
|
address,
|
||
|
name,
|
||
|
symbol,
|
||
|
linkable,
|
||
|
}) => (
|
||
|
<>
|
||
|
<div
|
||
|
className={`self-center w-5 h-5 ${linkable ? "" : "filter grayscale"}`}
|
||
|
>
|
||
|
<TokenLogo address={address} name={name} />
|
||
|
</div>
|
||
|
<span>{symbol}</span>
|
||
|
</>
|
||
|
);
|
||
|
|
||
|
export const uniswapV2PairRenderer: ResolvedAddressRenderer<UniswapV2PairMeta> =
|
||
|
(address, tokenMeta, linkable, dontOverrideColors) => (
|
||
|
<UniswapV2PairName
|
||
|
address={address}
|
||
|
token0={tokenMeta.token0}
|
||
|
token1={tokenMeta.token1}
|
||
|
linkable={linkable}
|
||
|
dontOverrideColors={dontOverrideColors}
|
||
|
/>
|
||
|
);
|
||
|
|
||
|
export default UniswapV2PairName;
|