Commit faf1e0e4 authored by tom's avatar tom

refactor

parent 38bee0d0
import { Box, Text, Flex, Skeleton, Textarea, Button } from '@chakra-ui/react'; import { Flex, Skeleton, Button } from '@chakra-ui/react';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import React from 'react'; import React from 'react';
import useApiQuery from 'lib/api/useApiQuery'; import useApiQuery from 'lib/api/useApiQuery';
import link from 'lib/link/link'; import link from 'lib/link/link';
import CopyToClipboard from 'ui/shared/CopyToClipboard';
import DataFetchAlert from 'ui/shared/DataFetchAlert'; import DataFetchAlert from 'ui/shared/DataFetchAlert';
import RawDataSnippet from 'ui/shared/RawDataSnippet';
const ContractCode = () => { const ContractCode = () => {
const router = useRouter(); const router = useRouter();
...@@ -38,50 +38,33 @@ const ContractCode = () => { ...@@ -38,50 +38,33 @@ const ContractCode = () => {
); );
} }
const verificationButton = (
<Button
size="sm"
ml="auto"
mr={ 3 }
as="a"
href={ link('address_contract_verification', { id: router.query.id?.toString() }) }
>
Verify & publish
</Button>
);
return ( return (
<> <>
{ data.creation_bytecode && ( { data.creation_bytecode && (
<Box> <RawDataSnippet
<Flex alignItems="center" mb={ 3 }> data={ data.creation_bytecode }
<Text fontWeight={ 500 }>Contract creation code</Text> title="Contract creation code"
<Button rightSlot={ verificationButton }
size="sm" />
ml="auto"
mr={ 3 }
as="a"
href={ link('address_contract_verification', { id: router.query.id?.toString() }) }
>
Verify & publish
</Button>
<CopyToClipboard text={ data.creation_bytecode }/>
</Flex>
<Textarea
variant="filledInactive"
p={ 4 }
minHeight="400px"
value={ data.creation_bytecode }
fontSize="sm"
borderRadius="md"
readOnly
/>
</Box>
) } ) }
{ data.deployed_bytecode && ( { data.deployed_bytecode && (
<Box mt={ 6 }> <RawDataSnippet
<Flex justifyContent="space-between" mb={ 3 }> mt={ 6 }
<Text fontWeight={ 500 }>Deployed ByteCode</Text> data={ data.deployed_bytecode }
<CopyToClipboard text={ data.deployed_bytecode }/> title="Deployed ByteCode"
</Flex> />
<Textarea
variant="filledInactive"
p={ 4 }
minHeight="400px"
value={ data.deployed_bytecode }
fontSize="sm"
borderRadius="md"
readOnly
/>
</Box>
) } ) }
</> </>
); );
......
import { Box, Flex, Text, Textarea, chakra } from '@chakra-ui/react';
import React from 'react';
import CopyToClipboard from './CopyToClipboard';
interface Props {
data: string;
title?: string;
className?: string;
rightSlot?: React.ReactNode;
}
const RawDataSnippet = ({ data, className, title, rightSlot }: Props) => {
return (
<Box className={ className }>
<Flex justifyContent={ title ? 'space-between' : 'flex-end' } alignItems="center" mb={ 3 }>
{ title && <Text fontWeight={ 500 }>{ title }</Text> }
{ rightSlot }
<CopyToClipboard text={ data }/>
</Flex>
<Textarea
variant="filledInactive"
p={ 4 }
minHeight="400px"
value={ data }
fontSize="sm"
borderRadius="md"
readOnly
/>
</Box>
);
};
export default React.memo(chakra(RawDataSnippet));
import { Flex, Textarea, Skeleton } from '@chakra-ui/react'; import { Flex, Skeleton } from '@chakra-ui/react';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import React from 'react'; import React from 'react';
import useApiQuery from 'lib/api/useApiQuery'; import useApiQuery from 'lib/api/useApiQuery';
import { SECOND } from 'lib/consts'; import { SECOND } from 'lib/consts';
import CopyToClipboard from 'ui/shared/CopyToClipboard';
import DataFetchAlert from 'ui/shared/DataFetchAlert'; import DataFetchAlert from 'ui/shared/DataFetchAlert';
import RawDataSnippet from 'ui/shared/RawDataSnippet';
import TxPendingAlert from 'ui/tx/TxPendingAlert'; import TxPendingAlert from 'ui/tx/TxPendingAlert';
import TxSocketAlert from 'ui/tx/TxSocketAlert'; import TxSocketAlert from 'ui/tx/TxSocketAlert';
import useFetchTxInfo from 'ui/tx/useFetchTxInfo'; import useFetchTxInfo from 'ui/tx/useFetchTxInfo';
...@@ -46,22 +46,7 @@ const TxRawTrace = () => { ...@@ -46,22 +46,7 @@ const TxRawTrace = () => {
const text = JSON.stringify(data, undefined, 4); const text = JSON.stringify(data, undefined, 4);
return ( return <RawDataSnippet data={ text }/>;
<>
<Flex justifyContent="end" mb={ 2 }>
<CopyToClipboard text={ text }/>
</Flex>
<Textarea
variant="filledInactive"
minHeight="500px"
p={ 4 }
value={ text }
fontSize="sm"
borderRadius="md"
readOnly
/>
</>
);
}; };
export default TxRawTrace; export default TxRawTrace;
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