Add eoa/contract legend support to token transfers section

This commit is contained in:
Willian Mitsuda 2022-03-02 06:29:59 -03:00
parent 716ec73478
commit 52a2f01342
2 changed files with 58 additions and 36 deletions

View File

@ -1,4 +1,4 @@
import React from "react"; import React, { useContext } from "react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faCaretRight } from "@fortawesome/free-solid-svg-icons/faCaretRight"; import { faCaretRight } from "@fortawesome/free-solid-svg-icons/faCaretRight";
import TransactionAddress from "./components/TransactionAddress"; import TransactionAddress from "./components/TransactionAddress";
@ -9,13 +9,17 @@ import {
ChecksummedAddress, ChecksummedAddress,
TokenMeta, TokenMeta,
TokenTransfer, TokenTransfer,
TransactionData,
} from "./types"; } from "./types";
import { RuntimeContext } from "./useRuntime";
import { useHasCode } from "./useErigonHooks";
import { Metadata } from "./sourcify/useSourcify"; import { Metadata } from "./sourcify/useSourcify";
type TokenTransferItemProps = { type TokenTransferItemProps = {
t: TokenTransfer; t: TokenTransfer;
tokenMeta?: TokenMeta | null | undefined; tokenMeta?: TokenMeta | null | undefined;
metadatas: Record<ChecksummedAddress, Metadata | null | undefined>; metadatas: Record<ChecksummedAddress, Metadata | null | undefined>;
txData: TransactionData;
}; };
// TODO: handle partial // TODO: handle partial
@ -23,7 +27,21 @@ const TokenTransferItem: React.FC<TokenTransferItemProps> = ({
t, t,
tokenMeta, tokenMeta,
metadatas, metadatas,
}) => ( 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"> <div className="flex items-baseline space-x-2 px-2 py-1 truncate hover:bg-gray-100">
<span className="text-gray-500"> <span className="text-gray-500">
<FontAwesomeIcon icon={faCaretRight} size="1x" /> <FontAwesomeIcon icon={faCaretRight} size="1x" />
@ -35,6 +53,7 @@ const TokenTransferItem: React.FC<TokenTransferItemProps> = ({
address={t.from} address={t.from}
addressCtx={AddressContext.FROM} addressCtx={AddressContext.FROM}
metadata={metadatas[t.from]} metadata={metadatas[t.from]}
eoa={fromHasCode === undefined ? undefined : !fromHasCode}
/> />
</div> </div>
<div className="col-span-2 flex space-x-1"> <div className="col-span-2 flex space-x-1">
@ -43,6 +62,7 @@ const TokenTransferItem: React.FC<TokenTransferItemProps> = ({
address={t.to} address={t.to}
addressCtx={AddressContext.TO} addressCtx={AddressContext.TO}
metadata={metadatas[t.to]} metadata={metadatas[t.to]}
eoa={toHasCode === undefined ? undefined : !toHasCode}
/> />
</div> </div>
<div className="col-span-3 flex space-x-1"> <div className="col-span-3 flex space-x-1">
@ -59,6 +79,7 @@ const TokenTransferItem: React.FC<TokenTransferItemProps> = ({
</div> </div>
</div> </div>
</div> </div>
); );
};
export default React.memo(TokenTransferItem); export default React.memo(TokenTransferItem);

View File

@ -314,6 +314,7 @@ const Details: React.FC<DetailsProps> = ({
t={t} t={t}
tokenMeta={txData.tokenMetas[t.token]} tokenMeta={txData.tokenMetas[t.token]}
metadatas={metadatas} metadatas={metadatas}
txData={txData}
/> />
))} ))}
</InfoRow> </InfoRow>