Commit ac044ac7 authored by tom's avatar tom

decoded values for logs

parent caa38ffd
...@@ -22,6 +22,7 @@ const TxLogItem = ({ address, index, topics, data, decoded }: Props) => { ...@@ -22,6 +22,7 @@ const TxLogItem = ({ address, index, topics, data, decoded }: Props) => {
const borderColor = useColorModeValue('blackAlpha.200', 'whiteAlpha.200'); const borderColor = useColorModeValue('blackAlpha.200', 'whiteAlpha.200');
const dataBgColor = useColorModeValue('blackAlpha.50', 'whiteAlpha.50'); const dataBgColor = useColorModeValue('blackAlpha.50', 'whiteAlpha.50');
const decodedTopics = decoded?.parameters.filter(({ indexed }) => indexed);
return ( return (
<Grid <Grid
...@@ -63,7 +64,15 @@ const TxLogItem = ({ address, index, topics, data, decoded }: Props) => { ...@@ -63,7 +64,15 @@ const TxLogItem = ({ address, index, topics, data, decoded }: Props) => {
) } ) }
<RowHeader>Topics</RowHeader> <RowHeader>Topics</RowHeader>
<GridItem> <GridItem>
{ topics.filter(Boolean).map((item, index) => <TxLogTopic key={ index } hex={ item } index={ index }/>) } { topics.filter(Boolean).map((item, index) => (
<TxLogTopic
key={ index }
hex={ item }
decoded={ decodedTopics?.[index - 1]?.value }
type={ decodedTopics?.[index - 1]?.type }
index={ index }
/>
)) }
</GridItem> </GridItem>
<RowHeader>Data</RowHeader> <RowHeader>Data</RowHeader>
<GridItem p={ 4 } fontSize="sm" borderRadius="md" bgColor={ dataBgColor }> <GridItem p={ 4 } fontSize="sm" borderRadius="md" bgColor={ dataBgColor }>
......
import { Flex, Button, Select, Box } from '@chakra-ui/react'; import { Flex, Button, Select, Box } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
import AddressLink from 'ui/shared/address/AddressLink';
import HashStringShortenDynamic from 'ui/shared/HashStringShortenDynamic'; import HashStringShortenDynamic from 'ui/shared/HashStringShortenDynamic';
interface Props { interface Props {
hex: string; hex: string;
decoded?: string;
type?: string;
index: number; index: number;
} }
type DataType = 'Hex' | 'Dec' type DataType = 'Hex' | 'Dec';
const OPTIONS: Array<DataType> = [ 'Hex', 'Dec' ]; const OPTIONS: Array<DataType> = [ 'Hex', 'Dec' ];
const TxLogTopic = ({ hex, index }: Props) => { const TxLogTopic = ({ hex, index, decoded, type }: Props) => {
const [ selectedDataType, setSelectedDataType ] = React.useState<DataType>('Hex'); const [ selectedDataType, setSelectedDataType ] = React.useState<DataType>('Hex');
const handleSelectChange = React.useCallback((event: React.ChangeEvent<HTMLSelectElement>) => { const handleSelectChange = React.useCallback((event: React.ChangeEvent<HTMLSelectElement>) => {
setSelectedDataType(event.target.value as DataType); setSelectedDataType(event.target.value as DataType);
}, []); }, []);
const content = (() => {
if (selectedDataType === 'Dec' && type === 'address' && decoded) {
return (
<AddressLink hash={ decoded }/>
);
}
const value = selectedDataType === 'Dec' && decoded ? decoded : hex;
return (
<Box overflow="hidden" whiteSpace="nowrap">
<HashStringShortenDynamic hash={ value }/>
</Box>
);
})();
return ( return (
<Flex alignItems="center" px={{ base: 0, lg: 3 }} _notFirst={{ mt: 3 }} overflow="hidden" maxW="100%"> <Flex alignItems="center" px={{ base: 0, lg: 3 }} _notFirst={{ mt: 3 }} overflow="hidden" maxW="100%">
<Button variant="outline" colorScheme="gray" isActive size="xs" fontWeight={ 400 } mr={ 3 } w={ 6 }> <Button variant="outline" colorScheme="gray" isActive size="xs" fontWeight={ 400 } mr={ 3 } w={ 6 }>
{ index } { index }
</Button> </Button>
<Select { decoded && (
size="sm" <Select
borderRadius="base" size="sm"
value={ selectedDataType } borderRadius="base"
onChange={ handleSelectChange } value={ selectedDataType }
focusBorderColor="none" onChange={ handleSelectChange }
w="75px" focusBorderColor="none"
mr={ 3 } w="75px"
flexShrink={ 0 } mr={ 3 }
> flexShrink={ 0 }
{ OPTIONS.map((option) => <option key={ option } value={ option }>{ option }</option>) } >
</Select> { OPTIONS.map((option) => <option key={ option } value={ option }>{ option }</option>) }
<Box overflow="hidden" whiteSpace="nowrap"> </Select>
<HashStringShortenDynamic hash={ hex }/> ) }
</Box> { content }
</Flex> </Flex>
); );
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment