2016-08-13 00:41:59 +02:00
|
|
|
const Component = require('react').Component
|
|
|
|
const h = require('react-hyperscript')
|
2016-09-13 02:27:14 +02:00
|
|
|
const qrCode = require('qrcode-npm').qrcode
|
2016-08-13 00:41:59 +02:00
|
|
|
const inherits = require('util').inherits
|
|
|
|
const connect = require('react-redux').connect
|
2017-06-12 23:37:32 +02:00
|
|
|
const isHexPrefixed = require('ethereumjs-util').isHexPrefixed
|
2016-08-13 00:41:59 +02:00
|
|
|
|
|
|
|
module.exports = connect(mapStateToProps)(QrCodeView)
|
|
|
|
|
|
|
|
function mapStateToProps (state) {
|
|
|
|
return {
|
2017-08-21 19:06:29 +02:00
|
|
|
// Qr code is not fetched from state. 'message' and 'data' props are passed instead.
|
2016-08-13 00:41:59 +02:00
|
|
|
buyView: state.appState.buyView,
|
2016-08-18 19:40:35 +02:00
|
|
|
warning: state.appState.warning,
|
2016-08-13 00:41:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inherits(QrCodeView, Component)
|
|
|
|
|
|
|
|
function QrCodeView () {
|
|
|
|
Component.call(this)
|
|
|
|
}
|
|
|
|
|
|
|
|
QrCodeView.prototype.render = function () {
|
2017-06-12 23:37:32 +02:00
|
|
|
const props = this.props
|
|
|
|
const Qr = props.Qr
|
|
|
|
const address = `${isHexPrefixed(Qr.data) ? 'ethereum:' : ''}${Qr.data}`
|
|
|
|
const qrImage = qrCode(4, 'M')
|
|
|
|
qrImage.addData(address)
|
2016-09-13 02:27:14 +02:00
|
|
|
qrImage.make()
|
2017-08-21 19:27:56 +02:00
|
|
|
return h('.div.flex-column.flex-center', {
|
2016-08-13 00:41:59 +02:00
|
|
|
style: {
|
|
|
|
},
|
|
|
|
}, [
|
2016-09-13 02:27:14 +02:00
|
|
|
Array.isArray(Qr.message) ? h('.message-container', this.renderMultiMessage()) : h('.qr-header', Qr.message),
|
2016-08-18 19:40:35 +02:00
|
|
|
|
|
|
|
this.props.warning ? this.props.warning && h('span.error.flex-center', {
|
|
|
|
style: {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
this.props.warning) : null,
|
|
|
|
|
2017-08-25 02:25:27 +02:00
|
|
|
h('.div.qr-wrapper', {
|
|
|
|
style: {},
|
2016-08-13 00:41:59 +02:00
|
|
|
dangerouslySetInnerHTML: {
|
2016-09-13 02:27:14 +02:00
|
|
|
__html: qrImage.createTableTag(4),
|
2016-08-13 00:41:59 +02:00
|
|
|
},
|
|
|
|
}),
|
2017-08-25 02:25:27 +02:00
|
|
|
h('.div.ellip-address-wrapper', [
|
2017-09-06 15:24:27 +02:00
|
|
|
h('input.qr-ellip-address', {
|
2016-08-15 06:41:08 +02:00
|
|
|
style: {
|
|
|
|
width: '247px',
|
|
|
|
},
|
2017-09-06 15:24:27 +02:00
|
|
|
value: Qr.data,
|
2017-09-07 18:45:21 +02:00
|
|
|
readonly: true,
|
2017-09-06 15:24:27 +02:00
|
|
|
}),
|
2017-08-21 19:27:56 +02:00
|
|
|
// h(CopyButton, {
|
|
|
|
// value: Qr.data,
|
|
|
|
// }),
|
2016-08-13 00:41:59 +02:00
|
|
|
]),
|
|
|
|
])
|
|
|
|
}
|
2016-08-13 02:43:24 +02:00
|
|
|
|
|
|
|
QrCodeView.prototype.renderMultiMessage = function () {
|
|
|
|
var Qr = this.props.Qr
|
|
|
|
var multiMessage = Qr.message.map((message) => h('.qr-message', message))
|
|
|
|
return multiMessage
|
|
|
|
}
|