2016-05-11 08:07:01 +02:00
|
|
|
const Component = require('react').Component
|
|
|
|
const h = require('react-hyperscript')
|
|
|
|
const inherits = require('util').inherits
|
|
|
|
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)
|
|
|
|
function IdenticonComponent() {
|
|
|
|
Component.call(this)
|
|
|
|
|
2016-05-11 11:11:31 +02:00
|
|
|
this.defaultDiameter = 46
|
2016-05-11 08:07:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
IdenticonComponent.prototype.render = function() {
|
2016-05-11 11:11:31 +02:00
|
|
|
var state = this.props
|
|
|
|
var diameter = state.diameter || this.defaultDiameter
|
2016-05-11 08:07:01 +02:00
|
|
|
return (
|
|
|
|
h('div', {
|
|
|
|
key: 'identicon-' + this.props.address,
|
|
|
|
style: {
|
|
|
|
display: 'inline-block',
|
2016-05-11 11:11:31 +02:00
|
|
|
height: diameter,
|
|
|
|
width: diameter,
|
|
|
|
borderRadius: diameter / 2,
|
2016-05-11 08:07:01 +02:00
|
|
|
overflow: 'hidden',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
IdenticonComponent.prototype.componentDidMount = function(){
|
|
|
|
var state = this.props
|
|
|
|
var address = state.address
|
|
|
|
|
|
|
|
if (!address) return
|
|
|
|
|
|
|
|
var container = findDOMNode(this)
|
2016-06-06 23:05:13 +02:00
|
|
|
|
2016-05-11 11:11:31 +02:00
|
|
|
var diameter = state.diameter || this.defaultDiameter
|
2016-06-06 23:05:13 +02:00
|
|
|
var dataUri = iconFactory.iconForAddress(address, diameter)
|
|
|
|
|
2016-05-11 08:53:07 +02:00
|
|
|
var img = document.createElement('img')
|
|
|
|
img.src = dataUri
|
|
|
|
container.appendChild(img)
|
2016-05-11 08:07:01 +02:00
|
|
|
}
|
|
|
|
|