Files
explore/ui/shared/CodeViewSnippet.tsx
T
tom goriunovandGitHub ba0a9a05e6 Contract page improvements (#2419)
* display address selector for non-verified proxy contract

* add code view snippet for ABI and Compiler Settings

* syntax highlighting for Scilla contracts

* ENV preset for zilliqa

* fix tests

* add native coin value to simulate method call

* fix test
2024-11-25 16:04:09 +01:00

38 lines
1.2 KiB
TypeScript

import { Box, chakra, Flex, Skeleton } from '@chakra-ui/react';
import React from 'react';
import CopyToClipboard from 'ui/shared/CopyToClipboard';
import CodeEditor from 'ui/shared/monaco/CodeEditor';
interface Props {
data: string;
copyData?: string;
language: string;
title?: string;
className?: string;
rightSlot?: React.ReactNode;
isLoading?: boolean;
}
const CodeViewSnippet = ({ data, copyData, language, title, className, rightSlot, isLoading }: Props) => {
const editorData = React.useMemo(() => {
return [ { file_path: 'index', source_code: data } ];
}, [ data ]);
return (
<Box className={ className } as="section" title={ title }>
{ (title || rightSlot) && (
<Flex justifyContent={ title ? 'space-between' : 'flex-end' } alignItems="center" mb={ 3 }>
{ title && <Skeleton fontWeight={ 500 } isLoaded={ !isLoading }>{ title }</Skeleton> }
{ rightSlot }
<CopyToClipboard text={ copyData ?? data } isLoading={ isLoading }/>
</Flex>
) }
{ isLoading ? <Skeleton height="500px" w="100%"/> : <CodeEditor data={ editorData } language={ language }/> }
</Box>
);
};
export default React.memo(chakra(CodeViewSnippet));