Skip to content

Commit

Permalink
fix: respect Currency.logoURI (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
zzmp authored Oct 13, 2022
1 parent f00cd08 commit 278e264
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/components/TokenImg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@ const MissingTokenSymbol = styled.span<{ size?: number }>`
`

interface BaseProps {
token: Currency
// TODO(1533): Include logoURI as an optional property of Currency.
token: Currency & { logoURI?: string }
size?: number
}

type TokenImgProps = BaseProps & Omit<React.ImgHTMLAttributes<HTMLImageElement>, keyof BaseProps>

function TokenImg({ token, size, ...rest }: TokenImgProps) {
// Use the wrapped token info so that it includes the logoURI.
// Use the wrapped token info so that it includes the logoURI...
const currency = useToken(token.isToken ? token.wrapped.address : undefined) ?? token
const srcs = useCurrencyLogoURIs(currency)
// ..but use the token directly if logoURI was included in its specification.
const srcs = useCurrencyLogoURIs(token?.logoURI ? token : currency)
const alt = currency.name || currency.symbol

const [attempt, setAttempt] = useState(0)
Expand Down
6 changes: 2 additions & 4 deletions src/hooks/useCurrencyLogoURIs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ function getTokenLogoURI(address: string, chainId: SupportedChainId = SupportedC
}
}

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

1 comment on commit 278e264

@vercel
Copy link

@vercel vercel bot commented on 278e264 Oct 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

widgets – ./

widgets-git-main-uniswap.vercel.app
widgets-uniswap.vercel.app
widgets-seven-tau.vercel.app

Please sign in to comment.