2016-05-11 08:07:01 +02:00
|
|
|
const Component = require('react').Component
|
|
|
|
const h = require('react-hyperscript')
|
|
|
|
const inherits = require('util').inherits
|
2017-05-15 23:35:24 +02:00
|
|
|
const isNode = require('detect-node')
|
2016-05-11 08:07:01 +02:00
|
|
|
const findDOMNode = require('react-dom').findDOMNode
|
2016-06-06 23:05:13 +02:00
|
|
|
const jazzicon = require('jazzicon')
|
|
|
|
const iconFactoryGen = require('../../lib/icon-factory')
|
|
|
|
const iconFactory = iconFactoryGen(jazzicon)
|
2016-05-11 08:07:01 +02:00
|
|
|
|
|
|
|
module.exports = IdenticonComponent
|
|
|
|
|
|
|
|
inherits(IdenticonComponent, Component)
|
2016-06-21 22:18:32 +02:00
|
|
|
function IdenticonComponent () {
|
2016-05-11 08:07:01 +02:00
|
|
|
Component.call(this)
|
|
|
|
|
2016-12-16 19:04:57 +01:00
|
|
|
this.defaultDiameter = 46
|
2016-05-11 08:07:01 +02:00
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
IdenticonComponent.prototype.render = function () {
|
2016-10-28 01:16:28 +02:00
|
|
|
var props = this.props
|
2017-09-07 08:03:23 +02:00
|
|
|
const { className = '', address } = props
|
2016-10-28 01:16:28 +02:00
|
|
|
var diameter = props.diameter || this.defaultDiameter
|
2017-09-07 08:03:23 +02:00
|
|
|
|
|
|
|
return address
|
|
|
|
? (
|
|
|
|
h('div', {
|
|
|
|
className: `${className} identicon`,
|
|
|
|
key: 'identicon-' + address,
|
|
|
|
style: {
|
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
|
|
|
height: diameter,
|
|
|
|
width: diameter,
|
|
|
|
borderRadius: diameter / 2,
|
|
|
|
overflow: 'hidden',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
: (
|
|
|
|
h('img.balance-icon', {
|
|
|
|
src: '../images/eth_logo.svg',
|
|
|
|
style: {
|
|
|
|
height: diameter,
|
|
|
|
width: diameter,
|
|
|
|
borderRadius: diameter / 2,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
2016-05-11 08:07:01 +02:00
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
IdenticonComponent.prototype.componentDidMount = function () {
|
2016-10-28 01:16:28 +02:00
|
|
|
var props = this.props
|
2017-06-13 02:06:39 +02:00
|
|
|
const { address } = props
|
2016-05-11 08:07:01 +02:00
|
|
|
|
|
|
|
if (!address) return
|
|
|
|
|
|
|
|
var container = findDOMNode(this)
|
2017-06-13 02:06:39 +02:00
|
|
|
|
2017-06-14 02:47:56 +02:00
|
|
|
var diameter = props.diameter || this.defaultDiameter
|
2017-05-15 23:35:24 +02:00
|
|
|
if (!isNode) {
|
2017-06-13 02:06:39 +02:00
|
|
|
var img = iconFactory.iconForAddress(address, diameter)
|
2017-05-15 23:35:24 +02:00
|
|
|
container.appendChild(img)
|
|
|
|
}
|
2016-05-11 08:07:01 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 01:04:36 +01:00
|
|
|
IdenticonComponent.prototype.componentDidUpdate = function () {
|
|
|
|
var props = this.props
|
2017-06-13 02:06:39 +02:00
|
|
|
const { address } = props
|
2016-11-02 01:04:36 +01:00
|
|
|
|
|
|
|
if (!address) return
|
|
|
|
|
|
|
|
var container = findDOMNode(this)
|
|
|
|
|
|
|
|
var children = container.children
|
|
|
|
for (var i = 0; i < children.length; i++) {
|
|
|
|
container.removeChild(children[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
var diameter = props.diameter || this.defaultDiameter
|
2017-05-15 23:35:24 +02:00
|
|
|
if (!isNode) {
|
2017-06-13 02:06:39 +02:00
|
|
|
var img = iconFactory.iconForAddress(address, diameter)
|
2017-05-15 23:35:24 +02:00
|
|
|
container.appendChild(img)
|
|
|
|
}
|
2016-11-02 01:04:36 +01:00
|
|
|
}
|
2017-06-13 02:06:39 +02:00
|
|
|
|