import React, { useState } from "react"; import { hexlify } from "@ethersproject/bytes"; import { commify, formatEther } from "@ethersproject/units"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faSync } from "@fortawesome/free-solid-svg-icons/faSync"; type Uint256DecoderProps = { r: any; }; enum DisplayMode { RAW, HEX, EIGHTEEN_DECIMALS, } const Uint256Decoder: React.FC = ({ r }) => { const [displayMode, setDisplayMode] = useState( DisplayMode.EIGHTEEN_DECIMALS ); const toggleModes = () => { setDisplayMode( displayMode === DisplayMode.EIGHTEEN_DECIMALS ? 0 : displayMode + 1 ); }; return (
{displayMode === DisplayMode.RAW ? ( <>{commify(r.toString())} ) : displayMode === DisplayMode.HEX ? ( <>{hexlify(r)} ) : ( <>{commify(formatEther(r))} )}
); }; export default React.memo(Uint256Decoder);