Add isHex check for addresses supplied to icons (#11071)

feature/default_network_editable
Thomas Huang 4 years ago committed by GitHub
parent cacefc72fc
commit e920fe15c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      ui/components/ui/identicon/identicon.component.js
  2. 9
      ui/helpers/utils/icon-factory.js

@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import classnames from 'classnames'; import classnames from 'classnames';
import contractMap from '@metamask/contract-metadata'; import contractMap from '@metamask/contract-metadata';
import { checksumAddress } from '../../../helpers/utils/util'; import { checksumAddress, isHex } from '../../../helpers/utils/util';
import Jazzicon from '../jazzicon'; import Jazzicon from '../jazzicon';
import BlockieIdenticon from './blockieIdenticon'; import BlockieIdenticon from './blockieIdenticon';
@ -85,10 +85,12 @@ export default class Identicon extends PureComponent {
} }
if (address) { if (address) {
const checksummedAddress = checksumAddress(address); if (isHex(address)) {
const checksummedAddress = checksumAddress(address);
if (contractMap[checksummedAddress]?.logo) { if (contractMap[checksummedAddress]?.logo) {
return this.renderJazzicon(); return this.renderJazzicon();
}
} }
return ( return (

@ -1,5 +1,5 @@
import contractMap from '@metamask/contract-metadata'; import contractMap from '@metamask/contract-metadata';
import { isValidAddress, checksumAddress } from './util'; import { isValidAddress, checksumAddress, isHex } from './util';
let iconFactory; let iconFactory;
@ -16,7 +16,12 @@ function IconFactory(jazzicon) {
} }
IconFactory.prototype.iconForAddress = function (address, diameter) { IconFactory.prototype.iconForAddress = function (address, diameter) {
const addr = checksumAddress(address); let addr = address;
if (isHex(address)) {
addr = checksumAddress(address);
}
if (iconExistsFor(addr)) { if (iconExistsFor(addr)) {
return imageElFor(addr); return imageElFor(addr);
} }

Loading…
Cancel
Save