otterscan/src/components/TransactionDirection.tsx

73 lines
1.7 KiB
TypeScript
Raw Normal View History

2021-07-01 18:21:40 +00:00
import React from "react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faCoins } from "@fortawesome/free-solid-svg-icons/faCoins";
import { faLongArrowAltRight } from "@fortawesome/free-solid-svg-icons/faLongArrowAltRight";
2021-07-01 18:21:40 +00:00
export enum Direction {
IN,
OUT,
SELF,
INTERNAL,
}
export enum Flags {
2022-08-23 19:11:02 +00:00
// Means the transaction internal sends ETH to the miner, e.g. flashbots
MINER,
}
2021-07-01 18:21:40 +00:00
type TransactionDirectionProps = {
direction?: Direction;
flags?: Flags;
2021-07-01 18:21:40 +00:00
};
const TransactionDirection: React.FC<TransactionDirectionProps> = ({
direction,
flags,
2021-07-01 18:21:40 +00:00
}) => {
2022-08-08 04:56:24 +00:00
let bgColor = "bg-emerald-50";
let fgColor = "text-emerald-500";
2021-07-01 18:21:40 +00:00
let msg: string | null = null;
if (direction === Direction.IN) {
msg = "IN";
} else if (direction === Direction.OUT) {
2022-08-08 04:56:24 +00:00
bgColor = "bg-amber-100";
fgColor = "text-amber-600";
2021-07-01 18:21:40 +00:00
msg = "OUT";
} else if (direction === Direction.SELF) {
bgColor = "bg-gray-200";
fgColor = "text-gray-500";
msg = "SELF";
} else if (direction === Direction.INTERNAL) {
msg = "INT";
2022-08-08 04:56:24 +00:00
bgColor = "bg-emerald-100";
2021-07-01 18:21:40 +00:00
}
if (flags === Flags.MINER) {
2022-08-08 04:56:24 +00:00
bgColor = "bg-amber-50";
fgColor = "text-amber-400";
}
2021-07-01 18:21:40 +00:00
return (
<span
className={`${bgColor} ${fgColor} ${
direction !== undefined
? "px-2 py-1 rounded-lg"
: "w-5 h-5 rounded-full flex justify-center items-center"
} text-xs font-bold`}
>
{flags === Flags.MINER ? (
<FontAwesomeIcon icon={faCoins} size="1x" />
) : (
msg ?? (
<span>
<FontAwesomeIcon icon={faLongArrowAltRight} />
</span>
)
2021-07-01 18:21:40 +00:00
)}
</span>
);
};
export default React.memo(TransactionDirection);