Commit 92af2167 authored by cartcrom's avatar cartcrom Committed by GitHub

refactor: L2 icons in component (#5901)

* feat: feature complete

* fix: hide l2 icons on most currencylogos

* linted

* refactor: remove unecessary logo container skeleton

* fix: removed todo comment and linted
parent db6084d7
...@@ -17,10 +17,10 @@ interface DoubleCurrencyLogoProps { ...@@ -17,10 +17,10 @@ interface DoubleCurrencyLogoProps {
currency1?: Currency currency1?: Currency
} }
const HigherLogo = styled(CurrencyLogo)` const HigherLogoWrapper = styled.div`
z-index: 1; z-index: 1;
` `
const CoveredLogo = styled(CurrencyLogo)<{ sizeraw: number }>` const CoveredLogoWapper = styled.div<{ sizeraw: number }>`
position: absolute; position: absolute;
left: ${({ sizeraw }) => '-' + (sizeraw / 2).toString() + 'px'} !important; left: ${({ sizeraw }) => '-' + (sizeraw / 2).toString() + 'px'} !important;
` `
...@@ -33,8 +33,16 @@ export default function DoubleCurrencyLogo({ ...@@ -33,8 +33,16 @@ export default function DoubleCurrencyLogo({
}: DoubleCurrencyLogoProps) { }: DoubleCurrencyLogoProps) {
return ( return (
<Wrapper sizeraw={size} margin={margin}> <Wrapper sizeraw={size} margin={margin}>
{currency0 && <HigherLogo currency={currency0} size={size.toString() + 'px'} />} {currency0 && (
{currency1 && <CoveredLogo currency={currency1} size={size.toString() + 'px'} sizeraw={size} />} <HigherLogoWrapper>
<CurrencyLogo hideL2Icon currency={currency0} size={size.toString() + 'px'} />
</HigherLogoWrapper>
)}
{currency1 && (
<CoveredLogoWapper sizeraw={size}>
<CurrencyLogo hideL2Icon currency={currency1} size={size.toString() + 'px'} />
</CoveredLogoWapper>
)}
</Wrapper> </Wrapper>
) )
} }
import { getChainInfo } from 'constants/chainInfo'
import { SupportedChainId } from 'constants/chains' import { SupportedChainId } from 'constants/chains'
import useTokenLogoSource from 'hooks/useAssetLogoSource' import useTokenLogoSource from 'hooks/useAssetLogoSource'
import React from 'react' import React from 'react'
...@@ -29,10 +30,28 @@ export type AssetLogoBaseProps = { ...@@ -29,10 +30,28 @@ export type AssetLogoBaseProps = {
backupImg?: string | null backupImg?: string | null
size?: string size?: string
style?: React.CSSProperties style?: React.CSSProperties
hideL2Icon?: boolean
} }
type AssetLogoProps = AssetLogoBaseProps & { isNative?: boolean; address?: string | null; chainId?: number } type AssetLogoProps = AssetLogoBaseProps & { isNative?: boolean; address?: string | null; chainId?: number }
// TODO(cartcrom): add prop to optionally render an L2Icon w/ the logo const LogoContainer = styled.div`
position: relative;
display: flex;
`
const L2NetworkLogo = styled.div<{ networkUrl?: string; parentSize: string }>`
--size: ${({ parentSize }) => `calc(${parentSize} / 2)`};
width: var(--size);
height: var(--size);
position: absolute;
left: 50%;
bottom: 0;
background: url(${({ networkUrl }) => networkUrl});
background-repeat: no-repeat;
background-size: ${({ parentSize }) => `calc(${parentSize} / 2) calc(${parentSize} / 2)`};
display: ${({ networkUrl }) => !networkUrl && 'none'};
`
/** /**
* Renders an image by prioritizing a list of sources, and then eventually a fallback triangle alert * Renders an image by prioritizing a list of sources, and then eventually a fallback triangle alert
*/ */
...@@ -44,25 +63,27 @@ export default function AssetLogo({ ...@@ -44,25 +63,27 @@ export default function AssetLogo({
backupImg, backupImg,
size = '24px', size = '24px',
style, style,
...rest hideL2Icon = false,
}: AssetLogoProps) { }: AssetLogoProps) {
const imageProps = { const imageProps = {
alt: `${symbol ?? 'token'} logo`, alt: `${symbol ?? 'token'} logo`,
size, size,
style,
...rest,
} }
const [src, nextSrc] = useTokenLogoSource(address, chainId, isNative, backupImg) const [src, nextSrc] = useTokenLogoSource(address, chainId, isNative, backupImg)
const L2Icon = getChainInfo(chainId)?.circleLogoUrl
if (src) { return (
return <LogoImage {...imageProps} src={src} onError={nextSrc} /> <LogoContainer style={style}>
} else { {src ? (
return ( <LogoImage {...imageProps} src={src} onError={nextSrc} />
<MissingImageLogo size={size}> ) : (
{/* use only first 3 characters of Symbol for design reasons */} <MissingImageLogo size={size}>
{symbol?.toUpperCase().replace('$', '').replace(/\s+/g, '').slice(0, 3)} {/* use only first 3 characters of Symbol for design reasons */}
</MissingImageLogo> {symbol?.toUpperCase().replace('$', '').replace(/\s+/g, '').slice(0, 3)}
) </MissingImageLogo>
} )}
{!hideL2Icon && <L2NetworkLogo networkUrl={L2Icon} parentSize={size} />}
</LogoContainer>
)
} }
...@@ -15,6 +15,7 @@ export default function CurrencyLogo( ...@@ -15,6 +15,7 @@ export default function CurrencyLogo(
address={props.currency?.wrapped.address} address={props.currency?.wrapped.address}
symbol={props.symbol ?? props.currency?.symbol} symbol={props.symbol ?? props.currency?.symbol}
backupImg={(props.currency as TokenInfo)?.logoURI} backupImg={(props.currency as TokenInfo)?.logoURI}
hideL2Icon={props.hideL2Icon ?? true}
{...props} {...props}
/> />
) )
......
...@@ -4,7 +4,6 @@ import { formatUSDPrice } from '@uniswap/conedison/format' ...@@ -4,7 +4,6 @@ import { formatUSDPrice } from '@uniswap/conedison/format'
import { useWeb3React } from '@web3-react/core' import { useWeb3React } from '@web3-react/core'
import clsx from 'clsx' import clsx from 'clsx'
import AssetLogo from 'components/Logo/AssetLogo' import AssetLogo from 'components/Logo/AssetLogo'
import { L2NetworkLogo, LogoContainer } from 'components/Tokens/TokenTable/TokenRow'
import TokenSafetyIcon from 'components/TokenSafety/TokenSafetyIcon' import TokenSafetyIcon from 'components/TokenSafety/TokenSafetyIcon'
import { getChainInfo } from 'constants/chainInfo' import { getChainInfo } from 'constants/chainInfo'
import { NATIVE_CHAIN_ID } from 'constants/tokens' import { NATIVE_CHAIN_ID } from 'constants/tokens'
...@@ -25,9 +24,6 @@ import styled from 'styled-components/macro' ...@@ -25,9 +24,6 @@ import styled from 'styled-components/macro'
import { getDeltaArrow } from '../Tokens/TokenDetails/PriceChart' import { getDeltaArrow } from '../Tokens/TokenDetails/PriceChart'
import * as styles from './SearchBar.css' import * as styles from './SearchBar.css'
const StyledLogoContainer = styled(LogoContainer)`
margin-right: 8px;
`
const PriceChangeContainer = styled.div` const PriceChangeContainer = styled.div`
display: flex; display: flex;
align-items: center; align-items: center;
...@@ -160,7 +156,7 @@ export const TokenRow = ({ token, isHovered, setHoveredIndex, toggleOpen, index, ...@@ -160,7 +156,7 @@ export const TokenRow = ({ token, isHovered, setHoveredIndex, toggleOpen, index,
sendAnalyticsEvent(InterfaceEventName.NAVBAR_RESULT_SELECTED, { ...eventProperties }) sendAnalyticsEvent(InterfaceEventName.NAVBAR_RESULT_SELECTED, { ...eventProperties })
}, [addToSearchHistory, toggleOpen, token, eventProperties]) }, [addToSearchHistory, toggleOpen, token, eventProperties])
const [bridgedAddress, bridgedChain, L2Icon] = useBridgedAddress(token) const [bridgedAddress, bridgedChain] = useBridgedAddress(token)
const tokenDetailsPath = getTokenDetailsURL(bridgedAddress ?? token.address, undefined, bridgedChain ?? token.chainId) const tokenDetailsPath = getTokenDetailsURL(bridgedAddress ?? token.address, undefined, bridgedChain ?? token.chainId)
// Close the modal on escape // Close the modal on escape
useEffect(() => { useEffect(() => {
...@@ -190,17 +186,15 @@ export const TokenRow = ({ token, isHovered, setHoveredIndex, toggleOpen, index, ...@@ -190,17 +186,15 @@ export const TokenRow = ({ token, isHovered, setHoveredIndex, toggleOpen, index,
style={{ background: isHovered ? vars.color.lightGrayOverlay : 'none' }} style={{ background: isHovered ? vars.color.lightGrayOverlay : 'none' }}
> >
<Row style={{ width: '65%' }}> <Row style={{ width: '65%' }}>
<StyledLogoContainer> <AssetLogo
<AssetLogo isNative={token.address === NATIVE_CHAIN_ID}
isNative={token.address === NATIVE_CHAIN_ID} address={token.address}
address={token.address} chainId={token.chainId}
chainId={token.chainId} symbol={token.symbol}
symbol={token.symbol} size="36px"
size="36px" backupImg={token.logoURI}
backupImg={token.logoURI} style={{ margin: '8px 8px 8px 0' }}
/> />
<L2NetworkLogo networkUrl={L2Icon} size="16px" />
</StyledLogoContainer>
<Column className={styles.suggestionPrimaryContainer}> <Column className={styles.suggestionPrimaryContainer}>
<Row gap="4" width="full"> <Row gap="4" width="full">
<Box className={styles.primaryText}>{token.name}</Box> <Box className={styles.primaryText}>{token.name}</Box>
......
...@@ -81,7 +81,7 @@ export default function BalanceSummary({ token }: { token: Currency }) { ...@@ -81,7 +81,7 @@ export default function BalanceSummary({ token }: { token: Currency }) {
<Trans>Your balance on {label}</Trans> <Trans>Your balance on {label}</Trans>
</ThemedText.SubHeaderSmall> </ThemedText.SubHeaderSmall>
<BalanceRow> <BalanceRow>
<CurrencyLogo currency={token} size="2rem" /> <CurrencyLogo currency={token} size="2rem" hideL2Icon={false} />
<BalanceContainer> <BalanceContainer>
<BalanceAmountsContainer> <BalanceAmountsContainer>
<BalanceItem> <BalanceItem>
......
...@@ -6,7 +6,6 @@ import styled, { useTheme } from 'styled-components/macro' ...@@ -6,7 +6,6 @@ import styled, { useTheme } from 'styled-components/macro'
import { textFadeIn } from 'theme/styles' import { textFadeIn } from 'theme/styles'
import { LoadingBubble } from '../loading' import { LoadingBubble } from '../loading'
import { LogoContainer } from '../TokenTable/TokenRow'
import { AboutContainer, AboutHeader } from './About' import { AboutContainer, AboutHeader } from './About'
import { BreadcrumbNavLink } from './BreadcrumbNavLink' import { BreadcrumbNavLink } from './BreadcrumbNavLink'
import { TokenPrice } from './PriceChart' import { TokenPrice } from './PriceChart'
...@@ -227,9 +226,7 @@ export default function TokenDetailsSkeleton() { ...@@ -227,9 +226,7 @@ export default function TokenDetailsSkeleton() {
</BreadcrumbNavLink> </BreadcrumbNavLink>
<TokenInfoContainer> <TokenInfoContainer>
<TokenNameCell> <TokenNameCell>
<LogoContainer> <TokenLogoBubble />
<TokenLogoBubble />
</LogoContainer>
<TitleBubble /> <TitleBubble />
</TokenNameCell> </TokenNameCell>
</TokenInfoContainer> </TokenInfoContainer>
......
...@@ -21,7 +21,6 @@ import TokenDetailsSkeleton, { ...@@ -21,7 +21,6 @@ import TokenDetailsSkeleton, {
TokenNameCell, TokenNameCell,
} from 'components/Tokens/TokenDetails/Skeleton' } from 'components/Tokens/TokenDetails/Skeleton'
import StatsSection from 'components/Tokens/TokenDetails/StatsSection' import StatsSection from 'components/Tokens/TokenDetails/StatsSection'
import { L2NetworkLogo, LogoContainer } from 'components/Tokens/TokenTable/TokenRow'
import TokenSafetyMessage from 'components/TokenSafety/TokenSafetyMessage' import TokenSafetyMessage from 'components/TokenSafety/TokenSafetyMessage'
import TokenSafetyModal from 'components/TokenSafety/TokenSafetyModal' import TokenSafetyModal from 'components/TokenSafety/TokenSafetyModal'
import Widget from 'components/Widget' import Widget from 'components/Widget'
...@@ -169,8 +168,6 @@ export default function TokenDetails({ ...@@ -169,8 +168,6 @@ export default function TokenDetails({
[continueSwap, setContinueSwap] [continueSwap, setContinueSwap]
) )
const L2Icon = getChainInfo(pageChainId)?.circleLogoUrl
// address will never be undefined if token is defined; address is checked here to appease typechecker // address will never be undefined if token is defined; address is checked here to appease typechecker
if (token === undefined || !address) { if (token === undefined || !address) {
return <InvalidTokenDetails chainName={address && getChainInfo(pageChainId)?.label} /> return <InvalidTokenDetails chainName={address && getChainInfo(pageChainId)?.label} />
...@@ -189,10 +186,8 @@ export default function TokenDetails({ ...@@ -189,10 +186,8 @@ export default function TokenDetails({
</BreadcrumbNavLink> </BreadcrumbNavLink>
<TokenInfoContainer data-testid="token-info-container"> <TokenInfoContainer data-testid="token-info-container">
<TokenNameCell> <TokenNameCell>
<LogoContainer> <CurrencyLogo currency={token} size="32px" hideL2Icon={false} />
<CurrencyLogo currency={token} size="32px" />
<L2NetworkLogo networkUrl={L2Icon} size="16px" />
</LogoContainer>
{token.name ?? <Trans>Name not found</Trans>} {token.name ?? <Trans>Name not found</Trans>}
<TokenSymbol>{token.symbol ?? <Trans>Symbol not found</Trans>}</TokenSymbol> <TokenSymbol>{token.symbol ?? <Trans>Symbol not found</Trans>}</TokenSymbol>
</TokenNameCell> </TokenNameCell>
......
...@@ -6,7 +6,6 @@ import { ParentSize } from '@visx/responsive' ...@@ -6,7 +6,6 @@ import { ParentSize } from '@visx/responsive'
import SparklineChart from 'components/Charts/SparklineChart' import SparklineChart from 'components/Charts/SparklineChart'
import QueryTokenLogo from 'components/Logo/QueryTokenLogo' import QueryTokenLogo from 'components/Logo/QueryTokenLogo'
import { MouseoverTooltip } from 'components/Tooltip' import { MouseoverTooltip } from 'components/Tooltip'
import { getChainInfo } from 'constants/chainInfo'
import { SparklineMap, TopToken } from 'graphql/data/TopTokens' import { SparklineMap, TopToken } from 'graphql/data/TopTokens'
import { CHAIN_NAME_TO_CHAIN_ID, getTokenDetailsURL } from 'graphql/data/util' import { CHAIN_NAME_TO_CHAIN_ID, getTokenDetailsURL } from 'graphql/data/util'
import { useAtomValue } from 'jotai/utils' import { useAtomValue } from 'jotai/utils'
...@@ -279,23 +278,6 @@ export const SparkLineLoadingBubble = styled(LongLoadingBubble)` ...@@ -279,23 +278,6 @@ export const SparkLineLoadingBubble = styled(LongLoadingBubble)`
height: 4px; height: 4px;
` `
export const L2NetworkLogo = styled.div<{ networkUrl?: string; size?: string }>`
height: ${({ size }) => size ?? '12px'};
width: ${({ size }) => size ?? '12px'};
position: absolute;
left: 50%;
bottom: 0;
background: url(${({ networkUrl }) => networkUrl});
background-repeat: no-repeat;
background-size: ${({ size }) => (size ? `${size} ${size}` : '12px 12px')};
display: ${({ networkUrl }) => !networkUrl && 'none'};
`
export const LogoContainer = styled.div`
position: relative;
align-items: center;
display: flex;
`
const InfoIconContainer = styled.div` const InfoIconContainer = styled.div`
margin-left: 2px; margin-left: 2px;
display: flex; display: flex;
...@@ -453,7 +435,6 @@ export const LoadedRow = forwardRef((props: LoadedRowProps, ref: ForwardedRef<HT ...@@ -453,7 +435,6 @@ export const LoadedRow = forwardRef((props: LoadedRowProps, ref: ForwardedRef<HT
const lowercaseChainName = useParams<{ chainName?: string }>().chainName?.toUpperCase() ?? 'ethereum' const lowercaseChainName = useParams<{ chainName?: string }>().chainName?.toUpperCase() ?? 'ethereum'
const filterNetwork = lowercaseChainName.toUpperCase() const filterNetwork = lowercaseChainName.toUpperCase()
const chainId = CHAIN_NAME_TO_CHAIN_ID[filterNetwork] const chainId = CHAIN_NAME_TO_CHAIN_ID[filterNetwork]
const L2Icon = getChainInfo(chainId)?.circleLogoUrl
const timePeriod = useAtomValue(filterTimeAtom) const timePeriod = useAtomValue(filterTimeAtom)
const delta = token.market?.pricePercentChange?.value const delta = token.market?.pricePercentChange?.value
const arrow = getDeltaArrow(delta) const arrow = getDeltaArrow(delta)
...@@ -485,10 +466,7 @@ export const LoadedRow = forwardRef((props: LoadedRowProps, ref: ForwardedRef<HT ...@@ -485,10 +466,7 @@ export const LoadedRow = forwardRef((props: LoadedRowProps, ref: ForwardedRef<HT
listNumber={volumeRank} listNumber={volumeRank}
tokenInfo={ tokenInfo={
<ClickableName> <ClickableName>
<LogoContainer> <QueryTokenLogo token={token} />
<QueryTokenLogo token={token} />
<L2NetworkLogo networkUrl={L2Icon} />
</LogoContainer>
<TokenInfoCell> <TokenInfoCell>
<TokenName data-cy="token-name">{token.name}</TokenName> <TokenName data-cy="token-name">{token.name}</TokenName>
<TokenSymbol>{token.symbol}</TokenSymbol> <TokenSymbol>{token.symbol}</TokenSymbol>
......
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