2022-03-02 09:29:59 +00:00
|
|
|
import React, { useContext } from "react";
|
2021-07-06 00:08:58 +00:00
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
2021-08-08 06:51:21 +00:00
|
|
|
import { faCaretRight } from "@fortawesome/free-solid-svg-icons/faCaretRight";
|
2021-11-07 11:56:12 +00:00
|
|
|
import TransactionAddress from "./components/TransactionAddress";
|
2021-07-20 02:33:19 +00:00
|
|
|
import ValueHighlighter from "./components/ValueHighlighter";
|
2021-07-06 00:08:58 +00:00
|
|
|
import FormattedBalance from "./components/FormattedBalance";
|
2021-07-19 16:29:49 +00:00
|
|
|
import {
|
|
|
|
AddressContext,
|
2021-11-11 18:51:03 +00:00
|
|
|
ChecksummedAddress,
|
2021-09-27 03:49:23 +00:00
|
|
|
TokenMeta,
|
2021-07-19 16:29:49 +00:00
|
|
|
TokenTransfer,
|
2022-03-02 09:29:59 +00:00
|
|
|
TransactionData,
|
2021-07-19 16:29:49 +00:00
|
|
|
} from "./types";
|
2022-03-02 09:29:59 +00:00
|
|
|
import { RuntimeContext } from "./useRuntime";
|
|
|
|
import { useHasCode } from "./useErigonHooks";
|
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;
|
2021-11-01 19:56:24 +00:00
|
|
|
tokenMeta?: TokenMeta | null | undefined;
|
2021-11-11 18:51:03 +00:00
|
|
|
metadatas: Record<ChecksummedAddress, Metadata | null | undefined>;
|
2022-03-02 09:29:59 +00:00
|
|
|
txData: TransactionData;
|
2021-07-06 00:08:58 +00:00
|
|
|
};
|
|
|
|
|
2021-09-22 18:30:54 +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,
|
2021-11-11 18:51:03 +00:00
|
|
|
metadatas,
|
2022-03-02 09:29:59 +00:00
|
|
|
txData,
|
|
|
|
}) => {
|
|
|
|
const { provider } = useContext(RuntimeContext);
|
|
|
|
const fromHasCode = useHasCode(
|
|
|
|
provider,
|
|
|
|
t.from,
|
|
|
|
txData.confirmedData ? txData.confirmedData.blockNumber - 1 : undefined
|
|
|
|
);
|
|
|
|
const toHasCode = useHasCode(
|
|
|
|
provider,
|
|
|
|
t.to,
|
|
|
|
txData.confirmedData ? txData.confirmedData.blockNumber - 1 : undefined
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="flex items-baseline space-x-2 px-2 py-1 truncate hover:bg-gray-100">
|
|
|
|
<span className="text-gray-500">
|
|
|
|
<FontAwesomeIcon icon={faCaretRight} size="1x" />
|
|
|
|
</span>
|
|
|
|
<div className="grid grid-cols-7 gap-x-1 w-full">
|
|
|
|
<div className="col-span-2 flex space-x-1">
|
|
|
|
<span className="font-bold">From</span>
|
|
|
|
<TransactionAddress
|
|
|
|
address={t.from}
|
|
|
|
addressCtx={AddressContext.FROM}
|
|
|
|
metadata={metadatas[t.from]}
|
|
|
|
eoa={fromHasCode === undefined ? undefined : !fromHasCode}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="col-span-2 flex space-x-1">
|
|
|
|
<span className="font-bold">To</span>
|
|
|
|
<TransactionAddress
|
|
|
|
address={t.to}
|
|
|
|
addressCtx={AddressContext.TO}
|
|
|
|
metadata={metadatas[t.to]}
|
|
|
|
eoa={toHasCode === undefined ? undefined : !toHasCode}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="col-span-3 flex space-x-1">
|
|
|
|
<span className="font-bold">For</span>
|
|
|
|
<span>
|
|
|
|
<ValueHighlighter value={t.value}>
|
|
|
|
<FormattedBalance
|
|
|
|
value={t.value}
|
|
|
|
decimals={tokenMeta?.decimals ?? 0}
|
|
|
|
/>
|
|
|
|
</ValueHighlighter>
|
|
|
|
</span>
|
|
|
|
<TransactionAddress address={t.token} metadata={metadatas[t.token]} />
|
|
|
|
</div>
|
2021-07-06 05:00:54 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-03-02 09:29:59 +00:00
|
|
|
);
|
|
|
|
};
|
2021-07-06 00:08:58 +00:00
|
|
|
|
|
|
|
export default React.memo(TokenTransferItem);
|