pbca26
8 years ago
7 changed files with 216 additions and 5 deletions
@ -0,0 +1,78 @@ |
|||
import React from 'react'; |
|||
import ReactDOM from 'react-dom'; |
|||
import Store from '../../../store'; |
|||
import { translate } from '../../../translate/translate'; |
|||
import QrReader from 'react-qr-reader' |
|||
import { |
|||
QRModalRender, |
|||
QRModalReaderRender |
|||
} from './qrModal.render'; |
|||
|
|||
class QRModal extends React.Component { |
|||
constructor(props) { |
|||
super(props); |
|||
this.state = { |
|||
modalIsOpen: false, |
|||
error: null, |
|||
}; |
|||
this.openModal = this.openModal.bind(this); |
|||
this.closeModal = this.closeModal.bind(this); |
|||
this.handleScan = this.handleScan.bind(this); |
|||
this.handleError = this.handleError.bind(this); |
|||
document.body.addEventListener('click', this.closeModal); |
|||
} |
|||
|
|||
handleScan(data) { |
|||
if (data !== null) { |
|||
if (this.props.mode === 'scan') { |
|||
this.props.setRecieverFromScan(data) |
|||
} |
|||
this.closeModal(); |
|||
} |
|||
} |
|||
|
|||
handleError(err) { |
|||
this.setState({ |
|||
error: err, |
|||
}); |
|||
} |
|||
|
|||
openModal() { |
|||
this.setState({ |
|||
modalIsOpen: true |
|||
}); |
|||
|
|||
if (this.props.mode === 'scan') { |
|||
ReactDOM.render( |
|||
<QrReader |
|||
delay={50} |
|||
style={{ |
|||
height: 281, |
|||
width: 500, |
|||
transform: 'scaleX(-1)' |
|||
}} |
|||
onError={ this.handleError } |
|||
onScan={ this.handleScan } />, document.getElementById('webcam')); |
|||
} |
|||
} |
|||
|
|||
closeModal() { |
|||
this.setState({ |
|||
modalIsOpen: false, |
|||
}); |
|||
|
|||
if (this.props.mode === 'scan') { |
|||
ReactDOM.unmountComponentAtNode(document.getElementById('webcam')); |
|||
} |
|||
} |
|||
|
|||
render() { |
|||
if (this.props.mode === 'scan') { |
|||
return QRModalReaderRender.call(this); |
|||
} else { |
|||
return QRModalRender.call(this); |
|||
} |
|||
} |
|||
} |
|||
|
|||
export default QRModal; |
@ -0,0 +1,82 @@ |
|||
import React from 'react'; |
|||
import { translate } from '../../../translate/translate'; |
|||
import QRCode from 'qrcode.react'; |
|||
|
|||
export const QRModalRender = function () { |
|||
return ( |
|||
<span> |
|||
<span className="label label-default margin-left-10 action" |
|||
title={ translate('INDEX.QRCODE') } |
|||
onClick={ this.openModal }> |
|||
<i className="icon fa-qrcode"></i> |
|||
</span> |
|||
<div |
|||
className={ 'modal modal-3d-sign ' + (this.state.modalIsOpen ? 'show in' : 'fade hide') } |
|||
id="QRModal"> |
|||
<div className="modal-dialog modal-center modal-sm"> |
|||
<div className="modal-content"> |
|||
<div className="modal-header bg-orange-a400 wallet-send-header"> |
|||
<button |
|||
type="button" |
|||
className="close white" |
|||
onClick={ this.closeModal }> |
|||
<span>×</span> |
|||
</button> |
|||
<h4 className="modal-title white text-left">{ translate('INDEX.SCAN_QR_CODE') }</h4> |
|||
</div> |
|||
<div className="modal-body"> |
|||
<div className="animsition vertical-align fade-in"> |
|||
<div className="page-content vertical-align-middle"> |
|||
<QRCode |
|||
value={ this.props.content } |
|||
size={ 198 } /> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
<div className={ 'modal-backdrop ' + (this.state.modalIsOpen ? 'show in' : 'fade hide') }></div> |
|||
</span> |
|||
); |
|||
}; |
|||
|
|||
export const QRModalReaderRender = function () { |
|||
return ( |
|||
<span> |
|||
<button type="button" |
|||
className="btn btn-default" |
|||
onClick={ this.openModal }> |
|||
<i className="icon fa-qrcode"></i> |
|||
{ translate('INDEX.SCAN_QRCODE_WEBCAM') } |
|||
</button> |
|||
<div |
|||
className={ 'modal modal-3d-sign ' + (this.state.modalIsOpen ? 'show in' : 'fade hide') } |
|||
id="QRReadModal"> |
|||
<div className="modal-dialog modal-center modal-md"> |
|||
<div className="modal-content"> |
|||
<div className="modal-header bg-orange-a400 wallet-send-header"> |
|||
<button |
|||
type="button" |
|||
className="close white" |
|||
onClick={ this.closeModal }> |
|||
<span>×</span> |
|||
</button> |
|||
<h4 className="modal-title white text-left">{ translate('INDEX.SCAN_QRCODE_WEBCAM') }</h4> |
|||
</div> |
|||
<div className="modal-body"> |
|||
<div className="animsition vertical-align fade-in"> |
|||
<div className="page-content vertical-align-middle"> |
|||
<div id="webcam"> |
|||
{ this.state.error } |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
<div className={ 'modal-backdrop ' + (this.state.modalIsOpen ? 'show in' : 'fade hide') }></div> |
|||
</span> |
|||
); |
|||
}; |
Loading…
Reference in new issue