diff options
author | brunobar79 <brunobar79@gmail.com> | 2018-11-07 09:21:19 +0800 |
---|---|---|
committer | brunobar79 <brunobar79@gmail.com> | 2018-11-07 09:21:19 +0800 |
commit | c651212025ab7cd0309d96be6687c1eba35ab9fa (patch) | |
tree | fa5a6020daae332c5df47bdee3492e8a079375e3 /ui/app/components/jazzicon | |
parent | 9c1b2108f69334884473eb95758e2d1c02c984d6 (diff) | |
parent | 7f944923d170d6e7e04f6e238d2fd5f80abe3161 (diff) | |
download | tangerine-wallet-browser-c651212025ab7cd0309d96be6687c1eba35ab9fa.tar tangerine-wallet-browser-c651212025ab7cd0309d96be6687c1eba35ab9fa.tar.gz tangerine-wallet-browser-c651212025ab7cd0309d96be6687c1eba35ab9fa.tar.bz2 tangerine-wallet-browser-c651212025ab7cd0309d96be6687c1eba35ab9fa.tar.lz tangerine-wallet-browser-c651212025ab7cd0309d96be6687c1eba35ab9fa.tar.xz tangerine-wallet-browser-c651212025ab7cd0309d96be6687c1eba35ab9fa.tar.zst tangerine-wallet-browser-c651212025ab7cd0309d96be6687c1eba35ab9fa.zip |
fix merge conflicts
Diffstat (limited to 'ui/app/components/jazzicon')
-rw-r--r-- | ui/app/components/jazzicon/index.js | 1 | ||||
-rw-r--r-- | ui/app/components/jazzicon/jazzicon.component.js | 69 |
2 files changed, 70 insertions, 0 deletions
diff --git a/ui/app/components/jazzicon/index.js b/ui/app/components/jazzicon/index.js new file mode 100644 index 000000000..bea900ab9 --- /dev/null +++ b/ui/app/components/jazzicon/index.js @@ -0,0 +1 @@ +export { default } from './jazzicon.component' 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} + /> + ) + } +} |