From e920fe15c3851092a3a5766c41d1561908c651d9 Mon Sep 17 00:00:00 2001 From: Thomas Huang Date: Wed, 12 May 2021 15:25:37 -0700 Subject: [PATCH] Add isHex check for addresses supplied to icons (#11071) --- ui/components/ui/identicon/identicon.component.js | 10 ++++++---- ui/helpers/utils/icon-factory.js | 9 +++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/ui/components/ui/identicon/identicon.component.js b/ui/components/ui/identicon/identicon.component.js index bad826dc9..d52717d05 100644 --- a/ui/components/ui/identicon/identicon.component.js +++ b/ui/components/ui/identicon/identicon.component.js @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'; import classnames from 'classnames'; import contractMap from '@metamask/contract-metadata'; -import { checksumAddress } from '../../../helpers/utils/util'; +import { checksumAddress, isHex } from '../../../helpers/utils/util'; import Jazzicon from '../jazzicon'; import BlockieIdenticon from './blockieIdenticon'; @@ -85,10 +85,12 @@ export default class Identicon extends PureComponent { } if (address) { - const checksummedAddress = checksumAddress(address); + if (isHex(address)) { + const checksummedAddress = checksumAddress(address); - if (contractMap[checksummedAddress]?.logo) { - return this.renderJazzicon(); + if (contractMap[checksummedAddress]?.logo) { + return this.renderJazzicon(); + } } return ( diff --git a/ui/helpers/utils/icon-factory.js b/ui/helpers/utils/icon-factory.js index f0d3dc4d4..4d69b842f 100644 --- a/ui/helpers/utils/icon-factory.js +++ b/ui/helpers/utils/icon-factory.js @@ -1,5 +1,5 @@ import contractMap from '@metamask/contract-metadata'; -import { isValidAddress, checksumAddress } from './util'; +import { isValidAddress, checksumAddress, isHex } from './util'; let iconFactory; @@ -16,7 +16,12 @@ function IconFactory(jazzicon) { } IconFactory.prototype.iconForAddress = function (address, diameter) { - const addr = checksumAddress(address); + let addr = address; + + if (isHex(address)) { + addr = checksumAddress(address); + } + if (iconExistsFor(addr)) { return imageElFor(addr); }