aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/identicon/identicon.component.js
diff options
context:
space:
mode:
authorAlexander Tseung <alextsg@users.noreply.github.com>2018-10-25 17:21:41 +0800
committerGitHub <noreply@github.com>2018-10-25 17:21:41 +0800
commit554f79c0e2ec8f3ddce81ab7aae9dc67ba057ac9 (patch)
treed3ccc31bf854644250036e3c0c5c01eb605f82d3 /ui/app/components/identicon/identicon.component.js
parent315028ec53654c4ad7817741330627eae742e59d (diff)
downloadtangerine-wallet-browser-554f79c0e2ec8f3ddce81ab7aae9dc67ba057ac9.tar.gz
tangerine-wallet-browser-554f79c0e2ec8f3ddce81ab7aae9dc67ba057ac9.tar.zst
tangerine-wallet-browser-554f79c0e2ec8f3ddce81ab7aae9dc67ba057ac9.zip
Fix blockies icons overriding contract map icons. Refactor Identicon component (#5599)
Diffstat (limited to 'ui/app/components/identicon/identicon.component.js')
-rw-r--r--ui/app/components/identicon/identicon.component.js99
1 files changed, 99 insertions, 0 deletions
diff --git a/ui/app/components/identicon/identicon.component.js b/ui/app/components/identicon/identicon.component.js
new file mode 100644
index 000000000..b892e5ae5
--- /dev/null
+++ b/ui/app/components/identicon/identicon.component.js
@@ -0,0 +1,99 @@
+import React, { PureComponent } from 'react'
+import PropTypes from 'prop-types'
+import classnames from 'classnames'
+import { toDataUrl } from '../../../lib/blockies'
+import contractMap from 'eth-contract-metadata'
+import { checksumAddress } from '../../../app/util'
+import Jazzicon from '../jazzicon'
+
+const getStyles = diameter => (
+ {
+ height: diameter,
+ width: diameter,
+ borderRadius: diameter / 2,
+ }
+)
+
+export default class Identicon extends PureComponent {
+ static propTypes = {
+ address: PropTypes.string,
+ className: PropTypes.string,
+ diameter: PropTypes.number,
+ image: PropTypes.string,
+ useBlockie: PropTypes.bool,
+ }
+
+ static defaultProps = {
+ diameter: 46,
+ }
+
+ renderImage () {
+ const { className, diameter, image } = this.props
+
+ return (
+ <img
+ className={classnames('identicon', className)}
+ src={image}
+ style={getStyles(diameter)}
+ />
+ )
+ }
+
+ renderJazzicon () {
+ const { address, className, diameter } = this.props
+
+ return (
+ <Jazzicon
+ address={address}
+ diameter={diameter}
+ className={classnames('identicon', className)}
+ style={getStyles(diameter)}
+ />
+ )
+ }
+
+ renderBlockie () {
+ const { address, className, diameter } = this.props
+
+ return (
+ <div
+ className={classnames('identicon', className)}
+ style={getStyles(diameter)}
+ >
+ <img
+ src={toDataUrl(address)}
+ height={diameter}
+ width={diameter}
+ />
+ </div>
+ )
+ }
+
+ render () {
+ const { className, address, image, diameter, useBlockie } = this.props
+
+ if (image) {
+ return this.renderImage()
+ }
+
+ if (address) {
+ const checksummedAddress = checksumAddress(address)
+
+ if (contractMap[checksummedAddress] && contractMap[checksummedAddress].logo) {
+ return this.renderJazzicon()
+ }
+
+ return useBlockie
+ ? this.renderBlockie()
+ : this.renderJazzicon()
+ }
+
+ return (
+ <img
+ className={classnames('balance-icon', className)}
+ src="./images/eth_logo.svg"
+ style={getStyles(diameter)}
+ />
+ )
+ }
+}