Commit fd4430fe authored by eddie's avatar eddie Committed by GitHub

fix: include descriptions and links for native tokens (#5756)

parent 167cc695
...@@ -17,4 +17,18 @@ describe('Testing tokens on uniswap page', () => { ...@@ -17,4 +17,18 @@ describe('Testing tokens on uniswap page', () => {
cy.get(getTestSelector('token-details-return-button')).click() cy.get(getTestSelector('token-details-return-button')).click()
cy.get(getTestSelectorStartsWith('token-table')).its('length').should('be.gte', 25) cy.get(getTestSelectorStartsWith('token-table')).its('length').should('be.gte', 25)
}) })
it('should go to native token on ethereum and render description', () => {
cy.visit('/tokens/ethereum/NATIVE')
cy.get(getTestSelector('token-details-about-section')).should('exist')
cy.contains('Ethereum is a smart contract platform that enables developers').should('exist')
cy.contains('Etherscan').should('exist')
})
it('should go to native token on polygon and render description and links', () => {
cy.visit('/tokens/polygon/NATIVE')
cy.get(getTestSelector('token-details-about-section')).should('exist')
cy.contains('Wrapped Matic on Polygon').should('exist')
cy.contains('Block Explorer').should('exist')
})
}) })
import { Trans } from '@lingui/macro' import { Trans } from '@lingui/macro'
import { SupportedChainId } from '@uniswap/sdk-core'
import { getChainInfo } from 'constants/chainInfo'
import { darken } from 'polished' import { darken } from 'polished'
import { useState } from 'react' import { useState } from 'react'
import styled from 'styled-components/macro' import styled from 'styled-components/macro'
...@@ -65,19 +67,22 @@ const ResourcesContainer = styled.div` ...@@ -65,19 +67,22 @@ const ResourcesContainer = styled.div`
type AboutSectionProps = { type AboutSectionProps = {
address: string address: string
chainId: SupportedChainId
description?: string | null | undefined description?: string | null | undefined
homepageUrl?: string | null | undefined homepageUrl?: string | null | undefined
twitterName?: string | null | undefined twitterName?: string | null | undefined
} }
export function AboutSection({ address, description, homepageUrl, twitterName }: AboutSectionProps) { export function AboutSection({ address, chainId, description, homepageUrl, twitterName }: AboutSectionProps) {
const [isDescriptionTruncated, setIsDescriptionTruncated] = useState(true) const [isDescriptionTruncated, setIsDescriptionTruncated] = useState(true)
const shouldTruncate = !!description && description.length > TRUNCATE_CHARACTER_COUNT const shouldTruncate = !!description && description.length > TRUNCATE_CHARACTER_COUNT
const tokenDescription = shouldTruncate && isDescriptionTruncated ? truncateDescription(description) : description const tokenDescription = shouldTruncate && isDescriptionTruncated ? truncateDescription(description) : description
const baseExplorerUrl = getChainInfo(chainId).explorer
return ( return (
<AboutContainer> <AboutContainer data-testid="token-details-about-section">
<AboutHeader> <AboutHeader>
<Trans>About</Trans> <Trans>About</Trans>
</AboutHeader> </AboutHeader>
...@@ -99,7 +104,11 @@ export function AboutSection({ address, description, homepageUrl, twitterName }: ...@@ -99,7 +104,11 @@ export function AboutSection({ address, description, homepageUrl, twitterName }:
<Trans>Links</Trans> <Trans>Links</Trans>
</ThemedText.SubHeaderSmall> </ThemedText.SubHeaderSmall>
<ResourcesContainer> <ResourcesContainer>
<Resource name="Etherscan" link={`https://etherscan.io/address/${address}`} /> <Resource
data-testid="token-details-about-section-explorer-link"
name={chainId === SupportedChainId.MAINNET ? 'Etherscan' : 'Block Explorer'}
link={`${baseExplorerUrl}${address === 'NATIVE' ? '' : 'address/' + address}`}
/>
<Resource name="More analytics" link={`https://info.uniswap.org/#/tokens/${address}`} /> <Resource name="More analytics" link={`https://info.uniswap.org/#/tokens/${address}`} />
{homepageUrl && <Resource name="Website" link={homepageUrl} />} {homepageUrl && <Resource name="Website" link={homepageUrl} />}
{twitterName && <Resource name="Twitter" link={`https://twitter.com/${twitterName}`} />} {twitterName && <Resource name="Twitter" link={`https://twitter.com/${twitterName}`} />}
......
...@@ -25,7 +25,7 @@ export const TokenDetailsLayout = styled.div` ...@@ -25,7 +25,7 @@ export const TokenDetailsLayout = styled.div`
@media screen and (min-width: ${({ theme }) => theme.breakpoint.sm}px) { @media screen and (min-width: ${({ theme }) => theme.breakpoint.sm}px) {
gap: 16px; gap: 16px;
padding: 0 16px; padding: 0 16px 52px;
} }
@media screen and (min-width: ${({ theme }) => theme.breakpoint.md}px) { @media screen and (min-width: ${({ theme }) => theme.breakpoint.md}px) {
gap: 40px; gap: 40px;
......
...@@ -206,18 +206,15 @@ export default function TokenDetails({ ...@@ -206,18 +206,15 @@ export default function TokenDetails({
priceHigh52W={tokenQueryData?.market?.priceHigh52W?.value} priceHigh52W={tokenQueryData?.market?.priceHigh52W?.value}
priceLow52W={tokenQueryData?.market?.priceLow52W?.value} priceLow52W={tokenQueryData?.market?.priceLow52W?.value}
/> />
{!token.isNative && ( <Hr />
<> <AboutSection
<Hr /> address={address}
<AboutSection chainId={pageChainId}
address={address} description={tokenQueryData?.project?.description}
description={tokenQueryData?.project?.description} homepageUrl={tokenQueryData?.project?.homepageUrl}
homepageUrl={tokenQueryData?.project?.homepageUrl} twitterName={tokenQueryData?.project?.twitterName}
twitterName={tokenQueryData?.project?.twitterName} />
/> {!token.isNative && <AddressSection address={address} />}
<AddressSection address={address} />
</>
)}
</LeftPanel> </LeftPanel>
) : ( ) : (
<TokenDetailsSkeleton /> <TokenDetailsSkeleton />
......
...@@ -7,6 +7,7 @@ import { useAtom } from 'jotai' ...@@ -7,6 +7,7 @@ import { useAtom } from 'jotai'
import { atomWithStorage } from 'jotai/utils' import { atomWithStorage } from 'jotai/utils'
import { useMemo } from 'react' import { useMemo } from 'react'
import { useParams } from 'react-router-dom' import { useParams } from 'react-router-dom'
import { getNativeTokenDBAddress } from 'utils/nativeTokens'
export const pageTimePeriodAtom = atomWithStorage<TimePeriod>('tokenDetailsTimePeriod', TimePeriod.DAY) export const pageTimePeriodAtom = atomWithStorage<TimePeriod>('tokenDetailsTimePeriod', TimePeriod.DAY)
...@@ -26,7 +27,7 @@ export default function TokenDetailsPage() { ...@@ -26,7 +27,7 @@ export default function TokenDetailsPage() {
const { data: tokenQuery, loading: tokenQueryLoading } = useTokenQuery({ const { data: tokenQuery, loading: tokenQueryLoading } = useTokenQuery({
variables: { variables: {
contract, contract: isNative ? { address: getNativeTokenDBAddress(chain), chain } : contract,
}, },
}) })
......
import { nativeOnChain } from 'constants/tokens'
import { Chain } from 'graphql/data/__generated__/types-and-hooks'
import { CHAIN_NAME_TO_CHAIN_ID } from 'graphql/data/util'
export function getNativeTokenDBAddress(chain: Chain): string {
const pageChainId = CHAIN_NAME_TO_CHAIN_ID[chain]
switch (chain) {
case Chain.Celo:
case Chain.Polygon:
return nativeOnChain(pageChainId).wrapped.address
case Chain.Ethereum:
case Chain.Arbitrum:
case Chain.EthereumGoerli:
case Chain.Optimism:
return 'ETH'
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment