Commit 29ae755f authored by Jordan Frankfurt's avatar Jordan Frankfurt Committed by GitHub

add new token image to widget (#3433)

parent 27b831b3
import { Currency } from '@uniswap/sdk-core' import { Currency } from '@uniswap/sdk-core'
import useCurrencyLogoURIs from 'lib/hooks/useCurrencyLogoURIs' import useCurrencyLogoURIs from 'lib/hooks/useCurrencyLogoURIs'
import { Slash } from 'lib/icons' import { MissingToken } from 'lib/icons'
import styled from 'lib/theme' import styled from 'lib/theme'
import { useCallback, useEffect, useState } from 'react' import { useCallback, useEffect, useState } from 'react'
const badSrcs = new Set<string>() const badSrcs = new Set<string>()
interface TokenImgProps { interface BaseProps {
className?: string
token: Currency token: Currency
} }
function TokenImg({ className, token }: TokenImgProps) { type TokenImgProps = BaseProps & Omit<React.ImgHTMLAttributes<HTMLImageElement>, keyof BaseProps>
function TokenImg({ token, ...rest }: TokenImgProps) {
const srcs = useCurrencyLogoURIs(token) const srcs = useCurrencyLogoURIs(token)
const [src, setSrc] = useState<string | undefined>() const [src, setSrc] = useState<string | undefined>()
useEffect(() => { useEffect(() => {
...@@ -23,9 +24,9 @@ function TokenImg({ className, token }: TokenImgProps) { ...@@ -23,9 +24,9 @@ function TokenImg({ className, token }: TokenImgProps) {
}, [src, srcs]) }, [src, srcs])
if (src) { if (src) {
return <img className={className} src={src} alt={token.name || token.symbol} onError={onError} /> return <img src={src} alt={token.name || token.symbol} onError={onError} {...rest} />
} }
return <Slash className={className} color="secondary" /> return <MissingToken color="secondary" {...rest} />
} }
export default styled(TokenImg)<{ size?: number }>` export default styled(TokenImg)<{ size?: number }>`
......
import MissingTokenIcon from 'lib/assets/missing-token-image.png'
import { ReactComponent as RouterIcon } from 'lib/assets/svg/auto_router.svg' import { ReactComponent as RouterIcon } from 'lib/assets/svg/auto_router.svg'
import { ReactComponent as CheckIcon } from 'lib/assets/svg/check.svg' import { ReactComponent as CheckIcon } from 'lib/assets/svg/check.svg'
import { ReactComponent as ExpandoIcon } from 'lib/assets/svg/expando.svg' import { ReactComponent as ExpandoIcon } from 'lib/assets/svg/expando.svg'
...@@ -31,6 +32,10 @@ import { ...@@ -31,6 +32,10 @@ import {
type SVGIcon = FunctionComponent<SVGProps<SVGSVGElement>> type SVGIcon = FunctionComponent<SVGProps<SVGSVGElement>>
const StyledImage = styled.img`
height: 1em;
width: 1em;
`
function icon(Icon: FeatherIcon | SVGIcon) { function icon(Icon: FeatherIcon | SVGIcon) {
return styled(Icon)<{ color?: Color }>` return styled(Icon)<{ color?: Color }>`
clip-path: stroke-box; clip-path: stroke-box;
...@@ -91,6 +96,9 @@ export const Trash2 = icon(Trash2Icon) ...@@ -91,6 +96,9 @@ export const Trash2 = icon(Trash2Icon)
export const Wallet = icon(WalletIcon) export const Wallet = icon(WalletIcon)
export const X = icon(XIcon) export const X = icon(XIcon)
export const XOctagon = icon(XOctagonIcon) export const XOctagon = icon(XOctagonIcon)
export const MissingToken = (props: React.ImgHTMLAttributes<HTMLImageElement>) => (
<StyledImage src={MissingTokenIcon} alt="Missing token" {...props} />
)
export const Check = styled(icon(CheckIcon))` export const Check = styled(icon(CheckIcon))`
circle { circle {
......
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