otterscan/src/TokenTransferItem.tsx

70 lines
2.3 KiB
TypeScript
Raw Normal View History

2021-07-06 00:08:58 +00:00
import React from "react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faCaretRight } from "@fortawesome/free-solid-svg-icons";
import AddressHighlighter from "./components/AddressHighlighter";
import DecoratedAddressLink from "./components/DecoratedAddressLink";
2021-07-06 00:08:58 +00:00
import TokenLogo from "./components/TokenLogo";
import FormattedBalance from "./components/FormattedBalance";
import { AddressContext, TokenMetas, TokenTransfer } from "./types";
2021-07-06 00:08:58 +00:00
type TokenTransferItemProps = {
t: TokenTransfer;
tokenMetas: TokenMetas;
};
const TokenTransferItem: React.FC<TokenTransferItemProps> = ({
t,
tokenMetas,
}) => (
<div className="flex items-baseline space-x-2 px-2 py-1 truncate hover:bg-gray-100">
2021-07-06 00:08:58 +00:00
<span className="text-gray-500">
<FontAwesomeIcon icon={faCaretRight} size="1x" />
</span>
<div className="grid grid-cols-5 gap-x-1">
<div className="flex space-x-1">
2021-07-06 05:00:54 +00:00
<span className="font-bold">From</span>
<AddressHighlighter address={t.from}>
<DecoratedAddressLink
address={t.from}
addressCtx={AddressContext.FROM}
/>
</AddressHighlighter>
2021-07-06 05:00:54 +00:00
</div>
<div className="flex space-x-1">
2021-07-06 05:00:54 +00:00
<span className="font-bold">To</span>
<AddressHighlighter address={t.to}>
<DecoratedAddressLink address={t.to} addressCtx={AddressContext.TO} />
</AddressHighlighter>
2021-07-06 05:00:54 +00:00
</div>
<div className="col-span-3 flex space-x-1">
2021-07-06 05:00:54 +00:00
<span className="font-bold">For</span>
<span>
<FormattedBalance
value={t.value}
decimals={tokenMetas[t.token].decimals}
2021-07-06 00:08:58 +00:00
/>
2021-07-06 05:00:54 +00:00
</span>
<span className="flex space-x-1 items-baseline truncate">
{tokenMetas[t.token] ? (
<>
<div className="self-center">
<TokenLogo address={t.token} name={tokenMetas[t.token].name} />
</div>
<DecoratedAddressLink
2021-07-06 05:00:54 +00:00
address={t.token}
text={`${tokenMetas[t.token].name} (${
tokenMetas[t.token].symbol
})`}
/>
</>
) : (
<DecoratedAddressLink address={t.token} />
2021-07-06 05:00:54 +00:00
)}
</span>
</div>
</div>
2021-07-06 00:08:58 +00:00
</div>
);
export default React.memo(TokenTransferItem);