Skip to content

Commit

Permalink
When displaying the contract of a token, link to the token dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
csillag committed Jun 29, 2023
1 parent fb28059 commit db26f60
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions .changelog/623.3.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
When displaying a contract that describes a token, link to the token dashboard
19 changes: 17 additions & 2 deletions src/app/components/Account/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { CopyToClipboard } from '../../components/CopyToClipboard'
import { JazzIcon } from '../../components/JazzIcon'
import { CoinGeckoReferral } from '../../components/CoinGeckoReferral'
import { TextSkeleton } from '../../components/Skeleton'
import { type RuntimeAccount } from '../../../oasis-indexer/api'
import { EvmToken, type RuntimeAccount } from '../../../oasis-indexer/api'
import { TokenPills } from './TokenPills'
import { AccountLink } from './AccountLink'
import { RouteUtils } from '../../utils/route-utils'
Expand All @@ -21,6 +21,7 @@ import { getNameForTicker, Ticker } from '../../../types/ticker'
import { TokenPriceInfo } from '../../../coin-gecko/api'
import { TransactionLink } from '../Transactions/TransactionLink'
import { ContractVerificationIcon } from '../ContractVerificationIcon'
import { TokenLink } from '../Tokens/TokenLink'

export const StyledAvatarContainer = styled('dt')(({ theme }) => ({
'&&': {
Expand Down Expand Up @@ -50,12 +51,13 @@ export const FiatMoneyAmountBox = styled(Box)(() => ({

type AccountProps = {
account?: RuntimeAccount
token?: EvmToken
isLoading: boolean
tokenPriceInfo: TokenPriceInfo
showLayer?: boolean
}

export const Account: FC<AccountProps> = ({ account, isLoading, tokenPriceInfo, showLayer }) => {
export const Account: FC<AccountProps> = ({ account, token, isLoading, tokenPriceInfo, showLayer }) => {
const { t } = useTranslation()
const { isMobile } = useScreenSize()
const balance = account?.balances[0]?.balance ?? '0'
Expand Down Expand Up @@ -100,6 +102,19 @@ export const Account: FC<AccountProps> = ({ account, isLoading, tokenPriceInfo,
<CopyToClipboard value={address!} />
</dd>

{token && (
<>
<dt>{t('common.token')}</dt>
<dd>
<TokenLink
scope={account}
address={token.eth_contract_addr || token.contract_addr}
name={token.name}
/>
</dd>
</>
)}

{account?.evm_contract && (
<>
<dt>{t('contract.verification.title')}</dt>
Expand Down
16 changes: 13 additions & 3 deletions src/app/pages/AccountDetailsPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@ import { RouterTabs } from '../../components/RouterTabs'
import { TokenPriceInfo, useTokenPrice } from '../../../coin-gecko/api'
import { Ticker } from '../../../types/ticker'

import { EvmTokenType, RuntimeAccount } from '../../../oasis-indexer/api'
import { EvmToken, EvmTokenType, RuntimeAccount } from '../../../oasis-indexer/api'
import { accountTokenContainerId } from './AccountTokensCard'
import { useAccount } from './hook'
import { useRequiredScopeParam } from '../../hooks/useScopeParam'
import { showEmptyAccountDetails } from '../../../config'
import { CardEmptyState } from './CardEmptyState'
import { contractCodeContainerId } from './ContractCodeCard'
import { useTokenInfo } from '../TokenDashboardPage/hook'

export const AccountDetailsPage: FC = () => {
const { t } = useTranslation()

const scope = useRequiredScopeParam()
const address = useLoaderData() as string
const { account, isLoading, isError } = useAccount(scope, address)
const { token } = useTokenInfo(scope, address)

const tokenPriceInfo = useTokenPrice(account?.ticker || Ticker.ROSE)
const isContract = !!account?.evm_contract
Expand All @@ -46,6 +48,7 @@ export const AccountDetailsPage: FC = () => {
isLoading={isLoading}
isError={isError}
account={account}
token={token}
tokenPriceInfo={tokenPriceInfo}
/>
</SubPageCard>
Expand All @@ -66,13 +69,20 @@ export const AccountDetailsView: FC<{
isLoading: boolean
isError: boolean
account: RuntimeAccount | undefined
token?: EvmToken
tokenPriceInfo: TokenPriceInfo
showLayer?: boolean
}> = ({ isLoading, isError, account, tokenPriceInfo, showLayer }) => {
}> = ({ isLoading, isError, account, token, tokenPriceInfo, showLayer }) => {
const { t } = useTranslation()
return isError ? (
<CardEmptyState label={t('account.cantLoadDetails')} />
) : (
<Account account={account} isLoading={isLoading} tokenPriceInfo={tokenPriceInfo} showLayer={showLayer} />
<Account
account={account}
token={token}
isLoading={isLoading}
tokenPriceInfo={tokenPriceInfo}
showLayer={showLayer}
/>
)
}

0 comments on commit db26f60

Please sign in to comment.