otterscan/src/components/MethodName.tsx

35 lines
914 B
TypeScript
Raw Normal View History

import React from "react";
import { extract4Bytes, use4Bytes } from "../use4Bytes";
2021-07-01 18:21:40 +00:00
type MethodNameProps = {
data: string;
};
const MethodName: React.FC<MethodNameProps> = ({ data }) => {
const rawFourBytes = extract4Bytes(data);
2021-09-27 04:09:56 +00:00
const fourBytesEntry = use4Bytes(rawFourBytes);
const isSimpleTransfer = data === "0x";
const methodName = isSimpleTransfer
? "transfer"
: fourBytesEntry?.name ?? rawFourBytes ?? "-";
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);