1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-30 16:18:07 +01:00
metamask-extension/ui/app/components/identicon.js

48 lines
1.3 KiB
JavaScript
Raw Normal View History

const Component = require('react').Component
const h = require('react-hyperscript')
const inherits = require('util').inherits
const findDOMNode = require('react-dom').findDOMNode
const jazzicon = require('jazzicon')
const iconFactoryGen = require('../../lib/icon-factory')
const iconFactory = iconFactoryGen(jazzicon)
module.exports = IdenticonComponent
inherits(IdenticonComponent, Component)
2016-06-21 22:18:32 +02:00
function IdenticonComponent () {
Component.call(this)
2016-05-11 11:11:31 +02:00
this.defaultDiameter = 46
}
2016-06-21 22:18:32 +02:00
IdenticonComponent.prototype.render = function () {
2016-05-11 11:11:31 +02:00
var state = this.props
var diameter = state.diameter || this.defaultDiameter
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,
overflow: 'hidden',
},
})
)
}
2016-06-21 22:18:32 +02:00
IdenticonComponent.prototype.componentDidMount = function () {
var state = this.props
var address = state.address
if (!address) return
var container = findDOMNode(this)
2016-05-11 11:11:31 +02:00
var diameter = state.diameter || this.defaultDiameter
2016-06-24 21:07:08 +02:00
var imageify = state.imageify === undefined ? true : state.imageify
var img = iconFactory.iconForAddress(address, diameter, imageify)
2016-05-11 08:53:07 +02:00
container.appendChild(img)
}