Skip to content

Commit

Permalink
Fix: sandbox coingecko icons
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh committed Jan 3, 2025
1 parent bb44a5f commit f97faf3
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions apps/web/src/components/common/TokenIcon/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { type ReactElement } from 'react'
import { memo, type ReactElement } from 'react'
import ImageFallback from '../ImageFallback'
import css from './styles.module.css'

const FALLBACK_ICON = '/images/common/token-placeholder.svg'
const COINGECKO_URL = 'https://assets.coingecko.com/'
const COINGECKO_THUMB = '/thumb/'
const COINGECKO_SMALL = '/small/'

const TokenIcon = ({
logoUri,
Expand All @@ -15,15 +18,26 @@ const TokenIcon = ({
size?: number
fallbackSrc?: string
}): ReactElement => {
let crossOrigin = false
let src = logoUri

if (logoUri?.startsWith(COINGECKO_URL)) {
src = logoUri?.replace(COINGECKO_THUMB, COINGECKO_SMALL)
crossOrigin = true
}

return (
<ImageFallback
src={logoUri}
src={src}
alt={tokenSymbol}
fallbackSrc={fallbackSrc || FALLBACK_ICON}
height={size}
className={css.image}
loading="lazy"
referrerPolicy={crossOrigin ? 'no-referrer' : undefined}
crossOrigin={crossOrigin ? 'anonymous' : undefined}
/>
)
}

export default TokenIcon
export default memo(TokenIcon)

0 comments on commit f97faf3

Please sign in to comment.