Browse Source

camera feature detection

all-modes
pbca26 8 years ago
parent
commit
5cfa7ca536
  1. 22
      react/src/components/dashboard/qrModal/qrModal.js
  2. 28
      react/src/components/dashboard/qrModal/qrModal.render.js
  3. 24
      react/src/components/dashboard/sendCoin/sendCoin.js
  4. 5
      react/src/components/dashboard/sendCoin/sendCoin.render.js

22
react/src/components/dashboard/qrModal/qrModal.js

@ -13,7 +13,7 @@ class QRModal extends React.Component {
super(props); super(props);
this.state = { this.state = {
modalIsOpen: false, modalIsOpen: false,
error: '' error: null,
}; };
this.openModal = this.openModal.bind(this); this.openModal = this.openModal.bind(this);
this.closeModal = this.closeModal.bind(this); this.closeModal = this.closeModal.bind(this);
@ -32,23 +32,35 @@ class QRModal extends React.Component {
} }
handleError(err) { handleError(err) {
this.setState({error: err}); this.setState({
error: err,
});
} }
openModal() { openModal() {
this.setState({modalIsOpen: true}); this.setState({
modalIsOpen: true
});
if (this.props.mode === 'scan') { if (this.props.mode === 'scan') {
ReactDOM.render( ReactDOM.render(
<QrReader <QrReader
delay={50} delay={50}
style={{ height: 281, width: 500, transform: 'scaleX(-1)' }} style={{
height: 281,
width: 500,
transform: 'scaleX(-1)'
}}
onError={ this.handleError } onError={ this.handleError }
onScan={ this.handleScan } />, document.getElementById('webcam')); onScan={ this.handleScan } />, document.getElementById('webcam'));
} }
} }
closeModal() { closeModal() {
this.setState({modalIsOpen: false}); this.setState({
modalIsOpen: false,
});
if (this.props.mode === 'scan') { if (this.props.mode === 'scan') {
ReactDOM.unmountComponentAtNode(document.getElementById('webcam')); ReactDOM.unmountComponentAtNode(document.getElementById('webcam'));
} }

28
react/src/components/dashboard/qrModal/qrModal.render.js

@ -8,24 +8,19 @@ export const QRModalRender = function () {
<span className="label label-default margin-left-10 action" <span className="label label-default margin-left-10 action"
title={ translate('INDEX.QRCODE') } title={ translate('INDEX.QRCODE') }
onClick={ this.openModal }> onClick={ this.openModal }>
<i className="icon fa-qrcode" aria-hidden="true"></i> <i className="icon fa-qrcode"></i>
</span> </span>
<div <div
className={ 'modal modal-3d-sign ' + (this.state.modalIsOpen ? 'show in' : 'fade hide') } className={ 'modal modal-3d-sign ' + (this.state.modalIsOpen ? 'show in' : 'fade hide') }
id="QRModal" id="QRModal">
aria-hidden="true"
aria-labelledby="QRModal"
role="dialog"
tabIndex="-1">
<div className="modal-dialog modal-center modal-sm"> <div className="modal-dialog modal-center modal-sm">
<div className="modal-content"> <div className="modal-content">
<div className="modal-header bg-orange-a400 wallet-send-header"> <div className="modal-header bg-orange-a400 wallet-send-header">
<button <button
type="button" type="button"
className="close white" className="close white"
aria-label="Close"
onClick={ this.closeModal }> onClick={ this.closeModal }>
<span aria-hidden="true">×</span> <span>×</span>
</button> </button>
<h4 className="modal-title white text-left">{ translate('INDEX.SCAN_QR_CODE') }</h4> <h4 className="modal-title white text-left">{ translate('INDEX.SCAN_QR_CODE') }</h4>
</div> </div>
@ -34,8 +29,7 @@ export const QRModalRender = function () {
<div className="page-content vertical-align-middle"> <div className="page-content vertical-align-middle">
<QRCode <QRCode
value={ this.props.content } value={ this.props.content }
size={198} size={ 198 } />
/>
</div> </div>
</div> </div>
</div> </div>
@ -53,24 +47,20 @@ export const QRModalReaderRender = function () {
<button type="button" <button type="button"
className="btn btn-default" className="btn btn-default"
onClick={ this.openModal }> onClick={ this.openModal }>
<i className="icon fa-qrcode" aria-hidden="true"></i> <i className="icon fa-qrcode"></i>
{ translate('INDEX.SCAN_QRCODE_WEBCAM') } { translate('INDEX.SCAN_QRCODE_WEBCAM') }
</button> </button>
<div className={ 'modal modal-3d-sign ' + (this.state.modalIsOpen ? 'show in' : 'fade hide') } <div
id="QRReadModal" className={ 'modal modal-3d-sign ' + (this.state.modalIsOpen ? 'show in' : 'fade hide') }
aria-hidden="true" id="QRReadModal">
aria-labelledby="QRReadModal"
role="dialog"
tabIndex="-1">
<div className="modal-dialog modal-center modal-md"> <div className="modal-dialog modal-center modal-md">
<div className="modal-content"> <div className="modal-content">
<div className="modal-header bg-orange-a400 wallet-send-header"> <div className="modal-header bg-orange-a400 wallet-send-header">
<button <button
type="button" type="button"
className="close white" className="close white"
aria-label="Close"
onClick={ this.closeModal }> onClick={ this.closeModal }>
<span aria-hidden="true">×</span> <span>×</span>
</button> </button>
<h4 className="modal-title white text-left">{ translate('INDEX.SCAN_QRCODE_WEBCAM') }</h4> <h4 className="modal-title white text-left">{ translate('INDEX.SCAN_QRCODE_WEBCAM') }</h4>
</div> </div>

24
react/src/components/dashboard/sendCoin/sendCoin.js

@ -55,6 +55,7 @@ class SendCoin extends React.Component {
currentStackLength: 0, currentStackLength: 0,
totalStackLength: 0, totalStackLength: 0,
utxoMethodInProgress: false, utxoMethodInProgress: false,
isCameraFeatureDetected: false,
}; };
this.updateInput = this.updateInput.bind(this); this.updateInput = this.updateInput.bind(this);
this.handleBasiliskSend = this.handleBasiliskSend.bind(this); this.handleBasiliskSend = this.handleBasiliskSend.bind(this);
@ -65,14 +66,33 @@ class SendCoin extends React.Component {
this._fetchNewUTXOData = this._fetchNewUTXOData.bind(this); this._fetchNewUTXOData = this._fetchNewUTXOData.bind(this);
this.handleClickOutside = this.handleClickOutside.bind(this); this.handleClickOutside = this.handleClickOutside.bind(this);
this.setRecieverFromScan = this.setRecieverFromScan.bind(this); this.setRecieverFromScan = this.setRecieverFromScan.bind(this);
this.detectCamera = this.detectCamera.bind(this);
socket.on('messages', msg => this.updateSocketsData(msg)); socket.on('messages', msg => this.updateSocketsData(msg));
} }
// test device camera capabilities
detectCamera() {
const _getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
_getUserMedia(
{ 'video': true },
function() {
this.setState({
isCameraFeatureDetected: true,
});
},
function() {
console.warn('this device doesn\'t have camera!');
}
);
}
setRecieverFromScan(receiver) { setRecieverFromScan(receiver) {
this.setState({ this.setState({
sendTo: receiver sendTo: receiver
}); });
document.getElementById('edexcoinSendTo').focus()
document.getElementById('edexcoinSendTo').focus();
} }
componentWillMount() { componentWillMount() {
@ -81,6 +101,8 @@ class SendCoin extends React.Component {
this.handleClickOutside, this.handleClickOutside,
false false
); );
this.detectCamera();
} }
componentWillUnmount() { componentWillUnmount() {

5
react/src/components/dashboard/sendCoin/sendCoin.render.js

@ -156,12 +156,13 @@ export const SendApiTypeSelectorRender = function () {
</div> </div>
</span> </span>
</div> </div>
{ this.stateisCameraFeatureDetected &&
<div className="col-lg-4 text-right"> <div className="col-lg-4 text-right">
<QRModal <QRModal
mode="scan" mode="scan"
setRecieverFromScan={this.setRecieverFromScan} setRecieverFromScan={this.setRecieverFromScan} />
/>
</div> </div>
}
</div> </div>
); );
}; };

Loading…
Cancel
Save