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
|
2018-03-29 17:00:44 +02:00
|
|
|
const connect = require('react-redux').connect
|
2018-04-17 21:57:55 +02:00
|
|
|
const { isHexPrefixed } = require('ethereumjs-util')
|
2017-09-20 03:16:51 +02:00
|
|
|
const ReadOnlyInput = require('./readonly-input')
|
2018-04-17 21:57:55 +02:00
|
|
|
const { checksumAddress } = require('../util')
|
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
|
2018-04-17 21:57:55 +02:00
|
|
|
const { message, data } = props.Qr
|
|
|
|
const address = `${isHexPrefixed(data) ? 'ethereum:' : ''}${data}`
|
2017-06-12 23:37:32 +02:00
|
|
|
const qrImage = qrCode(4, 'M')
|
|
|
|
qrImage.addData(address)
|
2016-09-13 02:27:14 +02:00
|
|
|
qrImage.make()
|
2017-10-26 03:23:46 +02:00
|
|
|
|
|
|
|
return h('.div.flex-column.flex-center', [
|
2018-04-17 21:57:55 +02:00
|
|
|
Array.isArray(message)
|
2017-10-26 03:23:46 +02:00
|
|
|
? h('.message-container', this.renderMultiMessage())
|
2018-04-17 21:57:55 +02:00
|
|
|
: message && h('.qr-header', 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-09-20 03:16:51 +02:00
|
|
|
h(ReadOnlyInput, {
|
|
|
|
wrapperClass: 'ellip-address-wrapper',
|
|
|
|
inputClass: 'qr-ellip-address',
|
2018-04-17 21:57:55 +02:00
|
|
|
value: checksumAddress(data),
|
2017-09-20 03:16:51 +02:00
|
|
|
}),
|
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
|
|
|
|
}
|