2017-03-07 00:03:49 +01:00
|
|
|
const Component = require('react').Component
|
|
|
|
const h = require('react-hyperscript')
|
|
|
|
const inherits = require('util').inherits
|
|
|
|
const ethUtil = require('ethereumjs-util')
|
2017-03-16 20:22:09 +01:00
|
|
|
const extend = require('xtend')
|
2017-03-07 00:03:49 +01:00
|
|
|
|
|
|
|
module.exports = BinaryRenderer
|
|
|
|
|
|
|
|
inherits(BinaryRenderer, Component)
|
|
|
|
function BinaryRenderer () {
|
|
|
|
Component.call(this)
|
|
|
|
}
|
|
|
|
|
|
|
|
BinaryRenderer.prototype.render = function () {
|
|
|
|
const props = this.props
|
2017-03-16 20:22:09 +01:00
|
|
|
const { value, style } = props
|
2017-03-07 00:03:49 +01:00
|
|
|
const text = this.hexToText(value)
|
|
|
|
|
2017-03-16 20:22:09 +01:00
|
|
|
const defaultStyle = extend({
|
|
|
|
width: '315px',
|
|
|
|
maxHeight: '210px',
|
|
|
|
resize: 'none',
|
|
|
|
border: 'none',
|
|
|
|
background: 'white',
|
|
|
|
padding: '3px',
|
|
|
|
}, style)
|
|
|
|
|
2017-03-07 00:03:49 +01:00
|
|
|
return (
|
|
|
|
h('textarea.font-small', {
|
|
|
|
readOnly: true,
|
2017-03-16 20:22:09 +01:00
|
|
|
style: defaultStyle,
|
2017-03-07 00:03:49 +01:00
|
|
|
defaultValue: text,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
BinaryRenderer.prototype.hexToText = function (hex) {
|
|
|
|
try {
|
|
|
|
const stripped = ethUtil.stripHexPrefix(hex)
|
|
|
|
const buff = Buffer.from(stripped, 'hex')
|
|
|
|
return buff.toString('utf8')
|
|
|
|
} catch (e) {
|
|
|
|
return hex
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|