aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/jazzicon/jazzicon.component.js
diff options
context:
space:
mode:
authorhackyminer <hackyminer@gmail.com>2018-10-26 19:37:35 +0800
committerhackyminer <hackyminer@gmail.com>2018-10-26 19:37:35 +0800
commitbc7f8d0a5bf42b73ee1d1102362fc0a94dc80c0d (patch)
tree96fc1c969b49c66081ff1a042a6e2e3e787723c7 /ui/app/components/jazzicon/jazzicon.component.js
parentb62d07f3a5bdfde7e295f17b7f601c6f2d5314ef (diff)
parent54a8ade2669cb5f8f046509873bc2a9c25425847 (diff)
downloadtangerine-wallet-browser-bc7f8d0a5bf42b73ee1d1102362fc0a94dc80c0d.tar
tangerine-wallet-browser-bc7f8d0a5bf42b73ee1d1102362fc0a94dc80c0d.tar.gz
tangerine-wallet-browser-bc7f8d0a5bf42b73ee1d1102362fc0a94dc80c0d.tar.bz2
tangerine-wallet-browser-bc7f8d0a5bf42b73ee1d1102362fc0a94dc80c0d.tar.lz
tangerine-wallet-browser-bc7f8d0a5bf42b73ee1d1102362fc0a94dc80c0d.tar.xz
tangerine-wallet-browser-bc7f8d0a5bf42b73ee1d1102362fc0a94dc80c0d.tar.zst
tangerine-wallet-browser-bc7f8d0a5bf42b73ee1d1102362fc0a94dc80c0d.zip
Merge branch 'develop' into eth_chainid
Diffstat (limited to 'ui/app/components/jazzicon/jazzicon.component.js')
-rw-r--r--ui/app/components/jazzicon/jazzicon.component.js69
1 files changed, 69 insertions, 0 deletions
diff --git a/ui/app/components/jazzicon/jazzicon.component.js b/ui/app/components/jazzicon/jazzicon.component.js
new file mode 100644
index 000000000..fcb1c59b1
--- /dev/null
+++ b/ui/app/components/jazzicon/jazzicon.component.js
@@ -0,0 +1,69 @@
+import React, { PureComponent } from 'react'
+import PropTypes from 'prop-types'
+import isNode from 'detect-node'
+import { findDOMNode } from 'react-dom'
+import jazzicon from 'jazzicon'
+import iconFactoryGenerator from '../../../lib/icon-factory'
+const iconFactory = iconFactoryGenerator(jazzicon)
+
+/**
+ * Wrapper around the jazzicon library to return a React component, as the library returns an
+ * HTMLDivElement which needs to be appended.
+ */
+export default class Jazzicon extends PureComponent {
+ static propTypes = {
+ address: PropTypes.string.isRequired,
+ className: PropTypes.string,
+ diameter: PropTypes.number,
+ style: PropTypes.object,
+ }
+
+ static defaultProps = {
+ diameter: 46,
+ }
+
+ componentDidMount () {
+ if (!isNode) {
+ this.appendJazzicon()
+ }
+ }
+
+ componentDidUpdate (prevProps) {
+ const { address: prevAddress } = prevProps
+ const { address } = this.props
+
+ if (!isNode && address !== prevAddress) {
+ this.removeExistingChildren()
+ this.appendJazzicon()
+ }
+ }
+
+ removeExistingChildren () {
+ // eslint-disable-next-line react/no-find-dom-node
+ const container = findDOMNode(this)
+ const { children } = container
+
+ for (let i = 0; i < children.length; i++) {
+ container.removeChild(children[i])
+ }
+ }
+
+ appendJazzicon () {
+ // eslint-disable-next-line react/no-find-dom-node
+ const container = findDOMNode(this)
+ const { address, diameter } = this.props
+ const image = iconFactory.iconForAddress(address, diameter)
+ container.appendChild(image)
+ }
+
+ render () {
+ const { className, style } = this.props
+
+ return (
+ <div
+ className={className}
+ style={style}
+ />
+ )
+ }
+}