Skip to content

Commit

Permalink
First steps towards displaying contract info
Browse files Browse the repository at this point in the history
- When displaying a contract, say so in the title
- Show link to TX that created the contract
  • Loading branch information
csillag committed Jun 19, 2023
1 parent 483bfb3 commit 2062505
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions .changelog/544.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
At address page, recognize contracts, and use appropriate title
1 change: 1 addition & 0 deletions .changelog/544.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Rename many Account-related pieces of code to use Address instead
11 changes: 11 additions & 0 deletions src/app/components/AddressDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Link from '@mui/material/Link'
import { DashboardLink } from '../../pages/DashboardPage/DashboardLink'
import { getNameForTicker, Ticker } from '../../../types/ticker'
import { TokenPriceInfo } from '../../../coin-gecko/api'
import { TransactionLink } from '../Transactions/TransactionLink'

export const StyledAvatarContainer = styled('dt')(({ theme }) => ({
'&&': {
Expand Down Expand Up @@ -61,6 +62,7 @@ export const AddressDetails: FC<AddressDetailsProps> = ({
}) => {
const { t } = useTranslation()
const { isMobile } = useScreenSize()
const creationTxHash = addressDetails?.evm_contract?.creation_tx // TODO: use evm_hash if available
const balance = addressDetails?.balances[0]?.balance ?? '0'
const address = addressDetails ? addressDetails.address_eth ?? addressDetails.address : undefined

Expand Down Expand Up @@ -102,6 +104,15 @@ export const AddressDetails: FC<AddressDetailsProps> = ({
<CopyToClipboard value={address!} />
</dd>

{creationTxHash && (
<>
<dt>{t('common.createdAt')}</dt>
<dd>
<TransactionLink scope={addressDetails} hash={creationTxHash} />
</dd>
</>
)}

<dt>{t('common.balance')}</dt>
<dd>{t('common.valueInToken', { value: balance, ticker: tickerName })}</dd>

Expand Down
4 changes: 2 additions & 2 deletions src/app/components/Transactions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export const Transactions: FC<TransactionsProps> = ({
{trimLongString(transaction.sender_0_eth || transaction.sender_0)}
</Typography>
) : (
<AddressLink
<AddressLink
scope={transaction}
address={transaction.sender_0_eth || transaction.sender_0}
alwaysTrim={true}
Expand Down Expand Up @@ -178,7 +178,7 @@ export const Transactions: FC<TransactionsProps> = ({
{trimLongString(transaction.to_eth || transaction.to!)}
</Typography>
) : (
<AddressLink
<AddressLink
scope={transaction}
address={transaction.to_eth || transaction.to!}
alwaysTrim={true}
Expand Down
8 changes: 7 additions & 1 deletion src/app/pages/AddressDetailsPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export const AddressDetailsPage: FC = () => {
const address = useLoaderData() as string
const { addressDetails, isLoading, isError } = useAddressDetails(scope, address)

const isContract = !!addressDetails?.evm_contract

const tokenPriceInfo = useTokenPrice(addressDetails?.ticker || Ticker.ROSE)

const showErc20 = showEmptyAccountDetails || !!addressDetails?.tokenBalances[EvmTokenType.ERC20].length
Expand All @@ -33,7 +35,11 @@ export const AddressDetailsPage: FC = () => {

return (
<PageLayout>
<SubPageCard featured title={t('account.title')}>
<SubPageCard
featured
isLoadingTitle={isLoading}
title={isContract ? t('contract.title') : t('account.title')}
>
<AddressDetailsView
isLoading={isLoading}
isError={isError}
Expand Down
6 changes: 5 additions & 1 deletion src/locales/en/translation.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"account": {
"emptyTokenList": "This account holds no {{token}} tokens.",
"emptyTokenList": "This account holds no {{token}} tokens.",
"emptyTransactionList": "There are no transactions on record for this account.",
"ERC20": "ERC-20",
"noTokens": "This account holds no tokens",
Expand Down Expand Up @@ -40,6 +40,7 @@
"block": "Block",
"bytes": "{{value, number}}",
"cancel": "Cancel",
"createdAt": "Created at",
"data": "Data",
"emerald": "Emerald",
"cipher": "Cipher",
Expand Down Expand Up @@ -91,6 +92,9 @@
"testnet": "Testnet",
"valuePair": "{{value, number}}"
},
"contract": {
"title": "Contract"
},
"nodes": {
"title": "Active nodes",
"unknown": "Consensus layer indexer is not caught up with the latest blocks. The number of active nodes is unknown.",
Expand Down

0 comments on commit 2062505

Please sign in to comment.