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 d5dfc7d commit ba3cb31
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
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
13 changes: 12 additions & 1 deletion src/app/pages/AddressDetailsPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useAddressDetails } from './hook'
import { useRequiredScopeParam } from '../../hooks/useScopeParam'
import { showEmptyAccountDetails } from '../../../config'
import { CardEmptyState } from './CardEmptyState'
import Skeleton from '@mui/material/Skeleton'

export const AddressDetailsPage: FC = () => {
const { t } = useTranslation()
Expand All @@ -22,6 +23,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 @@ -31,9 +34,17 @@ export const AddressDetailsPage: FC = () => {

const showDetails = showTxs || showErc20

const title = isLoading ? (
<Skeleton variant="text" />
) : isContract ? (
t('contract.title')
) : (
t('account.title')
)

return (
<PageLayout>
<SubPageCard featured title={t('account.title')}>
<SubPageCard featured title={title as string}>
<AddressDetailsView
isLoading={isLoading}
isError={isError}
Expand Down
4 changes: 4 additions & 0 deletions src/locales/en/translation.json
Original file line number Diff line number Diff line change
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 ba3cb31

Please sign in to comment.