fix: missing token img (#3727)

This commit is contained in:
Zach Pomerantz 2022-04-15 14:19:38 -04:00 committed by GitHub
parent 71aebf33db
commit ef8432437d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -21,18 +21,21 @@ function TokenImg({ token, ...rest }: TokenImgProps) {
const srcs = useCurrencyLogoURIs(tokenInfo)
const [attempt, setAttempt] = useState(0)
const onError = useCallback((e) => {
if (e.target.src) badSrcs.add(e.target.src)
setAttempt((attempt) => ++attempt)
}, [])
const src = useMemo(() => {
// Trigger a re-render when an error occurs.
void attempt
return srcs.find((src) => !badSrcs.has(src))
}, [attempt, srcs])
const onError = useCallback(
(e) => {
if (src) badSrcs.add(src)
setAttempt((attempt) => ++attempt)
},
[src]
)
console.log('zzmp', tokenInfo.symbol, src)
if (!src) return <MissingToken color="secondary" {...rest} />
const alt = tokenInfo.name || tokenInfo.symbol