otterscan/src/components/MethodName.tsx

33 lines
881 B
TypeScript
Raw Normal View History

import React from "react";
2021-09-25 17:29:09 +00:00
import { rawInputTo4Bytes, use4Bytes } from "../use4Bytes";
2021-07-01 18:21:40 +00:00
type MethodNameProps = {
data: string;
};
const MethodName: React.FC<MethodNameProps> = ({ data }) => {
2021-09-25 17:29:09 +00:00
const rawFourBytes = rawInputTo4Bytes(data);
2021-09-27 04:09:56 +00:00
const fourBytesEntry = use4Bytes(rawFourBytes);
const methodName = fourBytesEntry?.name ?? rawFourBytes;
const isSimpleTransfer = rawFourBytes === "0x";
const methodTitle = isSimpleTransfer
? "ETH Transfer"
: methodName === rawFourBytes
? methodName
: `${methodName} [${rawFourBytes}]`;
2021-07-01 18:21:40 +00:00
return (
<div
className={`${
isSimpleTransfer ? "bg-yellow-100" : "bg-blue-50"
} rounded-lg px-3 py-1 min-h-full flex items-baseline text-xs max-w-max`}
>
<p className="truncate" title={methodTitle}>
{methodName}
2021-07-01 18:21:40 +00:00
</p>
</div>
);
};
export default React.memo(MethodName);