import { createListCollection, Flex } from '@chakra-ui/react'; import { capitalize } from 'es-toolkit'; import React from 'react'; import hexToAddress from 'lib/hexToAddress'; import hexToUtf8 from 'lib/hexToUtf8'; import { SelectContent, SelectControl, SelectItem, SelectRoot, SelectValueText } from 'toolkit/chakra/select'; import { Skeleton } from 'toolkit/chakra/skeleton'; import CopyToClipboard from 'ui/shared/CopyToClipboard'; import AddressEntity from 'ui/shared/entities/address/AddressEntity'; import HashStringShortenDynamic from 'ui/shared/HashStringShortenDynamic'; import LogIndex from './LogIndex'; interface Props { hex: string; index: number; isLoading?: boolean; } type DataType = 'hex' | 'text' | 'address' | 'number'; const VALUE_CONVERTERS: Record string> = { hex: (hex) => hex, text: hexToUtf8, address: hexToAddress, number: (hex) => BigInt(hex).toString(), }; const OPTIONS: Array = [ 'hex', 'address', 'text', 'number' ]; const collection = createListCollection({ items: OPTIONS.map((option) => ({ value: option, label: capitalize(option), })), }); const LogTopic = ({ hex, index, isLoading }: Props) => { const [ selectedDataType, setSelectedDataType ] = React.useState('hex'); const handleSelectChange = React.useCallback((details: { value: Array }) => { setSelectedDataType(details.value[0] as DataType); }, []); const value = VALUE_CONVERTERS[selectedDataType.toLowerCase() as Lowercase](hex); const content = (() => { switch (selectedDataType) { case 'hex': case 'number': case 'text': { return ( <> ); } case 'address': { return ( ); } } })(); return ( { index } { index !== 0 && ( { collection.items.map((item) => ( { item.label } )) } ) } { content } ); }; export default React.memo(LogTopic);