Skip to content

Commit

Permalink
Refactor how we load and display contract creator info
Browse files Browse the repository at this point in the history
Make it so that only the contract address is needed,
and everything else is nicely wrapped in a component.
  • Loading branch information
csillag committed Jul 1, 2023
1 parent 7cf0b52 commit 6fe0139
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
36 changes: 28 additions & 8 deletions src/app/components/Account/ContractCreatorInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ 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-nexus/api'
import {
Layer,
Runtime,
useGetRuntimeAccountsAddress,
useGetRuntimeTransactionsTxHash,
} from '../../../oasis-nexus/api'
import { AppErrors } from '../../../types/errors'
import { AccountLink } from './AccountLink'
import Box from '@mui/material/Box'
Expand All @@ -22,12 +27,13 @@ const TxSender: FC<{ scope: SearchScope; txHash: string }> = ({ scope, txHash })
)
}

export const ContractCreatorInfo: FC<{ scope: SearchScope; address: string | undefined }> = ({
scope,
address,
}) => {
export const ContractCreatorInfo: FC<{
scope: SearchScope
creationTxHash: string | undefined
}> = ({ scope, creationTxHash }) => {
const { t } = useTranslation()
return address === undefined ? (

return creationTxHash === undefined ? (
t('common.missing')
) : (
<Box
Expand All @@ -37,15 +43,29 @@ export const ContractCreatorInfo: FC<{ scope: SearchScope; address: string | und
gap: 3,
}}
>
<TxSender scope={scope} txHash={address} />
<TxSender scope={scope} txHash={creationTxHash} />
&nbsp;
<Trans
t={t}
i18nKey={'contract.createdAt'}
components={{
TransactionLink: <TransactionLink scope={scope} hash={address} alwaysTrim />,
TransactionLink: <TransactionLink scope={scope} hash={creationTxHash} alwaysTrim />,
}}
/>
</Box>
)
}

export const DelayedContractCreatorInfo: FC<{
scope: SearchScope
contractAddress: string | undefined
}> = ({ scope, contractAddress }) => {
const accountQuery = useGetRuntimeAccountsAddress(scope.network, scope.layer as Runtime, contractAddress!)

const account = accountQuery.data?.data
const contract = account?.evm_contract

const creationTxHash = contract?.eth_creation_tx || contract?.creation_tx

return <ContractCreatorInfo scope={scope} creationTxHash={creationTxHash} />
}
2 changes: 1 addition & 1 deletion src/app/components/Account/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export const Account: FC<AccountProps> = ({ account, token, isLoading, tokenPric
<dd>
<ContractCreatorInfo
scope={account}
address={contract.eth_creation_tx || contract.creation_tx}
creationTxHash={contract.eth_creation_tx || contract.creation_tx}
/>
</dd>
</>
Expand Down
8 changes: 4 additions & 4 deletions src/app/pages/TokenDashboardPage/TokenDetailsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +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'
import { DelayedContractCreatorInfo } from '../../components/Account/ContractCreatorInfo'
import CardContent from '@mui/material/CardContent'

export const TokenDetailsCard: FC = () => {
Expand Down Expand Up @@ -60,9 +60,9 @@ export const TokenDetailsCard: FC = () => {

<dt>{t('contract.creator')}</dt>
<dd>
<ContractCreatorInfo
scope={account}
address={contract.eth_creation_tx || contract.creation_tx}
<DelayedContractCreatorInfo
scope={token}
contractAddress={token.eth_contract_addr || token.contract_addr}
/>
</dd>

Expand Down

0 comments on commit 6fe0139

Please sign in to comment.