Skip to content

Commit

Permalink
Properly display contract creator info
Browse files Browse the repository at this point in the history
  • Loading branch information
csillag committed Jun 30, 2023
1 parent e7dfbe1 commit b27ec14
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 8 deletions.
1 change: 1 addition & 0 deletions .changelog/623.2.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Properly display creator info for contracts.
51 changes: 51 additions & 0 deletions src/app/components/Account/ContractCreatorInfo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { FC } from 'react'
import { SearchScope } from '../../../types/searchScope'
import { Trans, useTranslation } from 'react-i18next'
import { TransactionLink } from '../Transactions/TransactionLink'
import { Layer, useGetRuntimeTransactionsTxHash } from '../../../oasis-indexer/api'
import { AppErrors } from '../../../types/errors'
import { AccountLink } from './AccountLink'
import Box from '@mui/material/Box'

const TxSender: FC<{ scope: SearchScope; txHash: string }> = ({ scope, txHash }) => {
const { t } = useTranslation()
if (scope.layer === Layer.consensus) {
throw AppErrors.UnsupportedLayer
}
const query = useGetRuntimeTransactionsTxHash(scope.network, scope.layer, txHash)
const tx = query.data?.data.transactions[0]
const senderAddress = tx?.sender_0_eth || tx?.sender_0
return senderAddress ? (
<AccountLink scope={scope} address={senderAddress} alwaysTrim />
) : (
t('common.missing')
)
}

export const ContractCreatorInfo: FC<{ scope: SearchScope; address: string | undefined }> = ({
scope,
address,
}) => {
const { t } = useTranslation()
return address === undefined ? (
t('common.missing')
) : (
<Box
sx={{
display: 'flex',
alignItems: 'center',
gap: 3,
}}
>
<TxSender scope={scope} txHash={address} />
&nbsp;
<Trans
t={t}
i18nKey={'contract.createdAt'}
components={{
TransactionLink: <TransactionLink scope={scope} hash={address} alwaysTrim />,
}}
/>
</Box>
)
}
16 changes: 10 additions & 6 deletions src/app/components/Account/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Link from '@mui/material/Link'
import { DashboardLink } from '../../pages/ParatimeDashboardPage/DashboardLink'
import { getNameForTicker, Ticker } from '../../../types/ticker'
import { TokenPriceInfo } from '../../../coin-gecko/api'
import { TransactionLink } from '../Transactions/TransactionLink'
import { ContractCreatorInfo } from './ContractCreatorInfo'
import { ContractVerificationIcon } from '../ContractVerificationIcon'
import { TokenLink } from '../Tokens/TokenLink'

Expand Down Expand Up @@ -62,7 +62,6 @@ export const Account: FC<AccountProps> = ({ account, token, isLoading, tokenPric
const { isMobile } = useScreenSize()
const balance = account?.balances[0]?.balance
const address = account ? account.address_eth ?? account.address : undefined
const creationTxHash = account?.evm_contract?.eth_creation_tx ?? account?.evm_contract?.creation_tx

const transactionsLabel = account ? account.stats.num_txns.toLocaleString() : ''
const transactionsAnchor = account
Expand All @@ -80,6 +79,7 @@ export const Account: FC<AccountProps> = ({ account, token, isLoading, tokenPric
isFree: isTokenFree,
hasUsedCoinGecko,
} = tokenPriceInfo
const contract = account?.evm_contract

return (
<>
Expand Down Expand Up @@ -115,7 +115,7 @@ export const Account: FC<AccountProps> = ({ account, token, isLoading, tokenPric
</>
)}

{account?.evm_contract && (
{contract && (
<>
<dt>{t('contract.verification.title')}</dt>
<dd>
Expand All @@ -126,11 +126,15 @@ export const Account: FC<AccountProps> = ({ account, token, isLoading, tokenPric
</dd>
</>
)}
{creationTxHash && (

{contract && (
<>
<dt>{t('common.createdAt')}</dt>
<dt>{t('contract.creator')}</dt>
<dd>
<TransactionLink scope={account} hash={creationTxHash} />
<ContractCreatorInfo
scope={account}
address={contract.eth_creation_tx || contract.creation_tx}
/>
</dd>
</>
)}
Expand Down
5 changes: 4 additions & 1 deletion src/app/pages/TokenDashboardPage/TokenDetailsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { CopyToClipboard } from '../../components/CopyToClipboard'
import { ContractVerificationIcon } from '../../components/ContractVerificationIcon'
import { getTokenTypeName } from './TokenTypeCard'
import { getNameForTicker, Ticker } from '../../../types/ticker'
import { ContractCreatorInfo } from '../../components/Account/ContractCreatorInfo'

export const TokenDetailsCard: FC = () => {
const { t } = useTranslation()
Expand Down Expand Up @@ -57,7 +58,9 @@ export const TokenDetailsCard: FC = () => {
<dd>{getTokenTypeName(t, token.type)} </dd>

<dt>{t('contract.creator')}</dt>
<dd> {contract.creation_tx ? contract.creation_tx : t('common.missing')}</dd>
<dd>
<ContractCreatorInfo scope={account} address={contract.eth_creation_tx || contract.creation_tx} />
</dd>

<dt>{t('common.balance')} </dt>
<dd>
Expand Down
2 changes: 1 addition & 1 deletion src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"bytes": "{{value, number}}",
"cancel": "Cancel",
"copy": "Copy",
"createdAt": "Created at",
"data": "Data",
"emerald": "Emerald",
"cipher": "Cipher",
Expand Down Expand Up @@ -98,6 +97,7 @@
"copyButton": "Copy {{subject}}",
"creationByteCode": "Creation ByteCode",
"creator": "Creator",
"createdAt": "at <TransactionLink>",
"noCode": "There is no bytecode on record for this account. (Are you sure this is a contract?)",
"title": "Contract",
"runtimeByteCode": "Runtime ByteCode",
Expand Down

0 comments on commit b27ec14

Please sign in to comment.