otterscan/src/TokenTransferItem.tsx

74 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/faCaretRight";
2021-11-07 11:56:12 +00:00
import TransactionAddress from "./components/TransactionAddress";
import ValueHighlighter from "./components/ValueHighlighter";
2021-07-06 00:08:58 +00:00
import FormattedBalance from "./components/FormattedBalance";
import {
AddressContext,
ChecksummedAddress,
2021-09-27 03:49:23 +00:00
TokenMeta,
TokenTransfer,
} from "./types";
import { ResolvedAddresses } from "./api/address-resolver";
2021-11-25 18:50:59 +00:00
import { Metadata } from "./sourcify/useSourcify";
2021-07-06 00:08:58 +00:00
type TokenTransferItemProps = {
t: TokenTransfer;
tokenMeta?: TokenMeta | null | undefined;
resolvedAddresses: ResolvedAddresses | undefined;
metadatas: Record<ChecksummedAddress, Metadata | null | undefined>;
2021-07-06 00:08:58 +00:00
};
// TODO: handle partial
2021-07-06 00:08:58 +00:00
const TokenTransferItem: React.FC<TokenTransferItemProps> = ({
t,
2021-09-27 03:49:23 +00:00
tokenMeta,
resolvedAddresses,
metadatas,
2021-07-06 00:08:58 +00:00
}) => (
<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>
2021-11-07 11:56:12 +00:00
<TransactionAddress
address={t.from}
addressCtx={AddressContext.FROM}
resolvedAddresses={resolvedAddresses}
metadata={metadatas[t.from]}
2021-11-07 11:56:12 +00:00
/>
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>
2021-11-07 11:56:12 +00:00
<TransactionAddress
address={t.to}
addressCtx={AddressContext.TO}
resolvedAddresses={resolvedAddresses}
metadata={metadatas[t.to]}
2021-11-07 11:56:12 +00:00
/>
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>
<ValueHighlighter value={t.value}>
<FormattedBalance
value={t.value}
2021-09-27 03:49:23 +00:00
decimals={tokenMeta?.decimals ?? 0}
/>
</ValueHighlighter>
2021-07-06 05:00:54 +00:00
</span>
2021-11-07 11:56:12 +00:00
<TransactionAddress
address={t.token}
resolvedAddresses={resolvedAddresses}
metadata={metadatas[t.token]}
2021-11-07 11:56:12 +00:00
/>
2021-07-06 05:00:54 +00:00
</div>
</div>
2021-07-06 00:08:58 +00:00
</div>
);
export default React.memo(TokenTransferItem);