Skip to content

Commit

Permalink
fix: check for logoURI on currency (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
zzmp authored Oct 13, 2022
1 parent 69cd486 commit 08931ec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/components/TokenImg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ type TokenImgProps = BaseProps & Omit<React.ImgHTMLAttributes<HTMLImageElement>,

function TokenImg({ token, size, ...rest }: TokenImgProps) {
// Use the wrapped token info so that it includes the logoURI.
const tokenInfo = useToken(token.isToken ? token.wrapped.address : undefined) ?? token
const srcs = useCurrencyLogoURIs(tokenInfo)
const alt = tokenInfo.name || tokenInfo.symbol
const currency = useToken(token.isToken ? token.wrapped.address : undefined) ?? token
const srcs = useCurrencyLogoURIs(currency)
const alt = currency.name || currency.symbol

const [attempt, setAttempt] = useState(0)
const src = useMemo(() => {
Expand All @@ -52,7 +52,7 @@ function TokenImg({ token, size, ...rest }: TokenImgProps) {
return (
<MissingTokenImg {...rest}>
<MissingTokenSymbol size={size}>
{tokenInfo.symbol?.toUpperCase().replace('$', '').replace(/\s+/g, '').slice(0, 3)}
{currency.symbol?.toUpperCase().replace('$', '').replace(/\s+/g, '').slice(0, 3)}
</MissingTokenSymbol>
</MissingTokenImg>
)
Expand Down
5 changes: 3 additions & 2 deletions src/hooks/useCurrencyLogoURIs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import MaticLogo from 'assets/svg/matic-token-icon.svg'
import { SupportedChainId } from 'constants/chains'
import useHttpLocations from 'hooks/useHttpLocations'
import { useMemo } from 'react'
import { WrappedTokenInfo } from 'state/lists/wrappedTokenInfo'

type Network = 'ethereum' | 'arbitrum' | 'optimism'

Expand Down Expand Up @@ -40,7 +39,9 @@ function getTokenLogoURI(address: string, chainId: SupportedChainId = SupportedC
}

export default function useCurrencyLogoURIs(currency?: Currency | null): string[] {
const locations = useHttpLocations(currency instanceof WrappedTokenInfo ? currency.logoURI : undefined)
const locations = useHttpLocations(
currency && 'logoURI' in currency ? (currency as { logoURI: string }).logoURI : undefined
)
return useMemo(() => {
const logoURIs = [...locations]
if (currency) {
Expand Down

0 comments on commit 08931ec

Please sign in to comment.