Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(wallet): ERC721 Token Registry Icons #15847

Merged
merged 1 commit into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { BraveWallet } from '../../../constants/types'

// Utils
import { getTokensNetwork } from '../../../utils/network-utils'
import { isDataURL } from '../../../utils/string-utils'
import { getLocale } from '../../../../common/locale'
import Amount from '../../../utils/amount'

Expand Down Expand Up @@ -58,7 +59,7 @@ const AssetWatchlistItem = (props: Props) => {
}, [token, onRemoveAsset])

const AssetIconWithPlaceholder = React.useMemo(() => {
return withPlaceholderIcon(token.isErc721 ? NftIcon : AssetIcon, { size: 'big', marginLeft: 0, marginRight: 8 })
return withPlaceholderIcon(token.isErc721 && !isDataURL(token.logo) ? NftIcon : AssetIcon, { size: 'big', marginLeft: 0, marginRight: 8 })
}, [token])

const tokensNetwork = React.useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { getLocale } from '../../../../common/locale'
import { getTokensNetwork } from '../../../utils/network-utils'
import { computeFiatAmount } from '../../../utils/pricing-utils'
import { unbiasedRandom } from '../../../utils/random-utils'
import { isDataURL } from '../../../utils/string-utils'

// Components
import { withPlaceholderIcon, CreateNetworkIcon, LoadingSkeleton } from '../../shared'
Expand Down Expand Up @@ -62,7 +63,7 @@ export const PortfolioAssetItem = ({

// memos & computed
const AssetIconWithPlaceholder = React.useMemo(() => {
return withPlaceholderIcon(token.isErc721 ? NftIcon : AssetIcon, { size: 'big', marginLeft: 0, marginRight: 8 })
return withPlaceholderIcon(token.isErc721 && !isDataURL(token.logo) ? NftIcon : AssetIcon, { size: 'big', marginLeft: 0, marginRight: 8 })
}, [token.isErc721])

const formattedAssetBalance = token.isErc721
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
isRemoteImageURL,
isValidIconExtension,
httpifyIpfsUrl,
isIpfs
isIpfs,
isDataURL
} from '../../../utils/string-utils'

// Styled components
Expand Down Expand Up @@ -53,18 +54,17 @@ function withPlaceholderIcon (WrappedComponent: React.ComponentType<any>, config

const tokenImageURL = stripERC20TokenImageURL(asset.logo)
const isRemoteURL = isRemoteImageURL(tokenImageURL)
const isDataURL = asset.logo.startsWith('chrome://erc-token-images/')
const isStorybook = asset.logo.startsWith('static/media/components/brave_wallet_ui/')

const isValidIcon = React.useMemo(() => {
if (isRemoteURL || isDataURL) {
if (isRemoteURL || isDataURL(asset.logo)) {
return tokenImageURL?.includes('data:image/') || isIpfs(tokenImageURL) ? true : isValidIconExtension(new URL(asset.logo).pathname)
}
if (isStorybook) {
return true
}
return false
}, [isRemoteURL, isDataURL, tokenImageURL, asset.logo, isStorybook])
}, [isRemoteURL, tokenImageURL, asset.logo, isStorybook])

const needsPlaceholder = isNativeAsset
? (tokenImageURL === '' || !isValidIcon) && networkLogo === ''
Expand Down
2 changes: 2 additions & 0 deletions components/brave_wallet_ui/utils/string-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export const httpifyIpfsUrl = (url: string | undefined) => {

export const isIpfs = (url?: string) => url?.startsWith('ipfs://')

export const isDataURL = (url?: string) => url?.startsWith('chrome://erc-token-images/')

/**
* Wyre currently supports the following chains:
* bitcoin, ethereum, avalanche(X & C), stellar, algorand, matic, flow
Expand Down