Convert QrCodeView to use JSX (#7504)

feature/default_network_editable
Whymarrh Whitby 5 years ago committed by GitHub
parent 7d097dedaf
commit c775a842d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 92
      ui/app/components/ui/qr-code.js

@ -1,7 +1,6 @@
const Component = require('react').Component import PropTypes from 'prop-types'
const h = require('react-hyperscript') import React from 'react'
const qrCode = require('qrcode-generator') const qrCode = require('qrcode-generator')
const inherits = require('util').inherits
const connect = require('react-redux').connect const connect = require('react-redux').connect
const { isHexPrefixed } = require('ethereumjs-util') const { isHexPrefixed } = require('ethereumjs-util')
const ReadOnlyInput = require('./readonly-input') const ReadOnlyInput = require('./readonly-input')
@ -17,47 +16,60 @@ function mapStateToProps (state) {
} }
} }
inherits(QrCodeView, Component) function QrCodeView (props) {
const { message, data } = props.Qr
function QrCodeView () { const address = `${isHexPrefixed(data) ? 'ethereum:' : ''}${checksumAddress(data)}`
Component.call(this)
}
QrCodeView.prototype.render = function () {
const props = this.props
const { message, data, network } = props.Qr
const address = `${isHexPrefixed(data) ? 'ethereum:' : ''}${checksumAddress(data, network)}`
const qrImage = qrCode(4, 'M') const qrImage = qrCode(4, 'M')
qrImage.addData(address) qrImage.addData(address)
qrImage.make() qrImage.make()
return h('.div.flex-column.flex-center', [ return (
Array.isArray(message) <div className="div flex-column flex-center">
? h('.message-container', this.renderMultiMessage()) {
: message && h('.qr-header', message), Array.isArray(message)
? (
this.props.warning ? this.props.warning && h('span.error.flex-center', { <div className="message-container">
style: { {props.Qr.message.map((message, index) => (
}, <div className="qr-message" key={index}>
}, {message}
this.props.warning) : null, </div>
))}
h('.div.qr-wrapper', { </div>
style: {}, )
dangerouslySetInnerHTML: { : message && (
__html: qrImage.createTableTag(4), <div className="qr-header">
}, {message}
}), </div>
h(ReadOnlyInput, { )
wrapperClass: 'ellip-address-wrapper', }
inputClass: 'qr-ellip-address', {
value: checksumAddress(data, network), props.warning
}), ? (props.warning && (
]) <span className="error flex-center">
{props.warning}
</span>
))
: null
}
<div
className="div qr-wrapper"
dangerouslySetInnerHTML={{
__html: qrImage.createTableTag(4),
}}
/>
<ReadOnlyInput
wrapperClass="ellip-address-wrapper"
inputClass="qr-ellip-address"
value={checksumAddress(data)}
/>
</div>
)
} }
QrCodeView.prototype.renderMultiMessage = function () { QrCodeView.propTypes = {
var Qr = this.props.Qr warning: PropTypes.node,
var multiMessage = Qr.message.map((message) => h('.qr-message', message)) Qr: PropTypes.shape({
return multiMessage message: PropTypes.array,
data: PropTypes.string.isRequired,
}).isRequired,
} }

Loading…
Cancel
Save