-
Notifications
You must be signed in to change notification settings - Fork 14
Display Contract ByteCode #616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f6ed30d
Rename some components for clarity
csillag dc6958d
Rename some hooks for clarity
csillag c2bd5e7
Rename ERC-20 card to tokens
csillag 08655a9
Update title on tokens card
csillag 37efab7
Use simple strings instead of JSX expressions, if possible
csillag 1e63414
CopyToClipboard: support displaying a button with label
csillag dc16c6b
Add component to display long data with scrolling
csillag 9e2a217
Display contract bytecode
csillag File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| For contracts, display bytecode |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { FC } from 'react' | ||
| import Typography from '@mui/material/Typography' | ||
| import Box from '@mui/material/Box' | ||
| import { COLORS } from '../../../styles/theme/colors' | ||
|
|
||
| export const ScrollingDataDisplay: FC<{ data: string; fontWeight?: number }> = ({ | ||
| data, | ||
| fontWeight = 700, | ||
| }) => { | ||
| return ( | ||
| <Box | ||
| sx={{ | ||
| display: 'flex', | ||
| padding: '10px 0px 0px 0px', | ||
| flexDirection: 'column', | ||
| alignItems: 'flex-start', | ||
| gap: '10px', | ||
| }} | ||
| > | ||
| <Box | ||
| sx={{ | ||
| borderRadius: '5px', | ||
| background: COLORS.grayLight, | ||
| border: `1px solid ${COLORS.grayMedium}`, | ||
| height: '349px', | ||
| overflowY: 'scroll', | ||
| p: 3, | ||
| }} | ||
| > | ||
| <Typography | ||
|
csillag marked this conversation as resolved.
|
||
| variant="mono" | ||
| fontSize={16} | ||
| sx={{ | ||
|
csillag marked this conversation as resolved.
|
||
| fontWeight, | ||
| overflowWrap: 'anywhere', | ||
| }} | ||
| color={COLORS.grayMedium} | ||
| > | ||
| {data} | ||
|
csillag marked this conversation as resolved.
|
||
| </Typography> | ||
| </Box> | ||
| </Box> | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import { FC } from 'react' | ||
| import { useTranslation } from 'react-i18next' | ||
| import Card from '@mui/material/Card' | ||
| import CardContent from '@mui/material/CardContent' | ||
| import { ScrollingDiv } from '../../components/PageLayout/ScrollingDiv' | ||
| import { useAccount } from './hook' | ||
| import { useRequiredScopeParam } from '../../hooks/useScopeParam' | ||
| import { useLoaderData } from 'react-router-dom' | ||
| import { CardEmptyState } from './CardEmptyState' | ||
| import Typography from '@mui/material/Typography' | ||
| import { ScrollingDataDisplay } from '../../components/ScrollingDataDisplay' | ||
| import Box from '@mui/material/Box' | ||
| import { CopyToClipboard } from '../../components/CopyToClipboard' | ||
| import { useScreenSize } from '../../hooks/useScreensize' | ||
|
|
||
| export const contractCodeContainerId = 'code' | ||
|
|
||
| const CodeDisplay: FC<{ code: string | undefined; label: string; extraTopPadding?: boolean }> = ({ | ||
| code, | ||
| label, | ||
| extraTopPadding, | ||
| }) => { | ||
| const { t } = useTranslation() | ||
| const { isMobile } = useScreenSize() | ||
| return code === undefined ? null : ( | ||
| <> | ||
| <Box | ||
| sx={{ | ||
| display: 'flex', | ||
| justifyContent: 'space-between', | ||
| alignItems: 'center', | ||
| my: 3, | ||
| pt: extraTopPadding ? 4 : 0, | ||
| }} | ||
| > | ||
| <Typography variant="h4" component="h4"> | ||
| {label} | ||
| </Typography> | ||
| <CopyToClipboard | ||
| value={code} | ||
| label={isMobile ? t('common.copy') : t('contract.copyButton', { subject: label })} | ||
| /> | ||
| </Box> | ||
|
|
||
| <ScrollingDataDisplay data={code} /> | ||
| </> | ||
| ) | ||
| } | ||
|
|
||
| export const ContractCodeCard: FC = () => { | ||
| const { t } = useTranslation() | ||
| const scope = useRequiredScopeParam() | ||
| const address = useLoaderData() as string | ||
|
|
||
| const { isFetched, account } = useAccount(scope, address) | ||
| const contract = account?.evm_contract | ||
| const noCode = isFetched && !contract?.creation_bytecode && !contract?.runtime_bytecode | ||
| return ( | ||
| <Card> | ||
| <ScrollingDiv id={contractCodeContainerId}> | ||
|
csillag marked this conversation as resolved.
|
||
| {noCode && <CardEmptyState label={t('contract.noCode')} />} | ||
| {contract && (contract.creation_bytecode || contract.runtime_bytecode) && ( | ||
| <CardContent> | ||
| <CodeDisplay code={contract.creation_bytecode} label={t('contract.creationByteCode')} /> | ||
| <CodeDisplay | ||
| code={contract.runtime_bytecode} | ||
| label={t('contract.runtimeByteCode')} | ||
| extraTopPadding={!!contract.creation_bytecode} | ||
| /> | ||
| </CardContent> | ||
| )} | ||
| </ScrollingDiv> | ||
| </Card> | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.