Commit caa38ffd authored by tom's avatar tom

tx data decode to utf-8

parent b5e35553
export default function hexToBytes(hex: string) {
const bytes = [];
for (let c = 0; c < hex.length; c += 2) {
bytes.push(parseInt(hex.substring(c, c + 2), 16));
}
return bytes;
}
import hexToBytes from 'lib/hexToBytes';
export default function hexToUtf8(hex: string) {
const utf8decoder = new TextDecoder();
const bytes = new Uint8Array(hexToBytes(hex));
return utf8decoder.decode(bytes);
}
import { Box, Flex, Select, Textarea } from '@chakra-ui/react'; import { Box, Flex, Select, Textarea } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
import hexToUtf8 from 'lib/hexToUtf8';
import CopyToClipboard from 'ui/shared/CopyToClipboard'; import CopyToClipboard from 'ui/shared/CopyToClipboard';
type DataType = 'Hex' | 'UTF-8' type DataType = 'Hex' | 'UTF-8'
...@@ -26,7 +27,7 @@ const RawInputData = ({ hex }: Props) => { ...@@ -26,7 +27,7 @@ const RawInputData = ({ hex }: Props) => {
<CopyToClipboard text={ hex }/> <CopyToClipboard text={ hex }/>
</Flex> </Flex>
<Textarea <Textarea
value={ selectedDataType === 'Hex' ? hex : 'UTF-8 equivalent' } value={ selectedDataType === 'Hex' ? hex : hexToUtf8(hex) }
w="100%" w="100%"
maxH="220px" maxH="220px"
mt={ 2 } mt={ 2 }
...@@ -38,4 +39,4 @@ const RawInputData = ({ hex }: Props) => { ...@@ -38,4 +39,4 @@ const RawInputData = ({ hex }: Props) => {
); );
}; };
export default RawInputData; export default React.memo(RawInputData);
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