-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
115 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 token transfers and bytecode |
This file contains 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 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,93 @@ | ||
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' | ||
|
||
export const ContractCodeCard: FC = () => { | ||
const { t } = useTranslation() | ||
const scope = useRequiredScopeParam() | ||
const address = useLoaderData() as string | ||
const { isMobile } = useScreenSize() | ||
|
||
const { isFetched, account } = useAccount(scope, address) | ||
const contract = account?.evm_contract | ||
const hasCreation = !!contract?.creation_bytecode | ||
const hasRuntime = !!contract?.runtime_bytecode | ||
const noCode = isFetched && !hasCreation && !hasRuntime | ||
return ( | ||
<Card> | ||
<ScrollingDiv id={contractCodeContainerId}> | ||
{noCode && <CardEmptyState label={t('contract.noCode')} />} | ||
{(hasCreation || hasRuntime) && ( | ||
<CardContent> | ||
{hasCreation && ( | ||
<> | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
justifyContent: 'space-between', | ||
alignItems: 'center', | ||
mb: '10px', | ||
}} | ||
> | ||
<Typography variant="h4" component="h4"> | ||
{t('contract.creationByteCode')} | ||
</Typography> | ||
<CopyToClipboard | ||
value={contract?.creation_bytecode!} | ||
label={ | ||
isMobile | ||
? t('common.copy') | ||
: t('contract.copyButton', { subject: t('contract.creationByteCode') }) | ||
} | ||
/> | ||
</Box> | ||
|
||
<ScrollingDataDisplay data={contract.creation_bytecode!} /> | ||
</> | ||
)} | ||
{hasRuntime && ( | ||
<> | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
justifyContent: 'space-between', | ||
alignItems: 'center', | ||
mt: '10px', | ||
pt: '20px', | ||
mb: '10px', | ||
}} | ||
> | ||
<Typography variant="h4" component="h4"> | ||
{t('contract.runtimeByteCode')} | ||
</Typography> | ||
<CopyToClipboard | ||
value={contract?.runtime_bytecode!} | ||
label={ | ||
isMobile | ||
? t('common.copy') | ||
: t('contract.copyButton', { subject: t('contract.runtimeByteCode') }) | ||
} | ||
/> | ||
</Box> | ||
<ScrollingDataDisplay data={contract.runtime_bytecode!} /> | ||
</> | ||
)} | ||
</CardContent> | ||
)} | ||
</ScrollingDiv> | ||
</Card> | ||
) | ||
} |
This file contains 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 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 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 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