2021-11-23 18:28:39 +01:00
|
|
|
import React, { useCallback, useState } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { submitQRHardwareSignature } from '../../../../store/actions';
|
|
|
|
import Player from './player';
|
|
|
|
import Reader from './reader';
|
|
|
|
|
|
|
|
const QRHardwareSignRequest = ({ request, handleCancel, setErrorTitle }) => {
|
|
|
|
const [status, setStatus] = useState('play');
|
|
|
|
|
|
|
|
const toRead = useCallback(() => setStatus('read'), []);
|
|
|
|
|
|
|
|
const renderPlayer = () => {
|
|
|
|
const { payload } = request;
|
|
|
|
return (
|
|
|
|
<Player
|
|
|
|
type={payload.type}
|
|
|
|
cbor={payload.cbor}
|
|
|
|
cancelQRHardwareSignRequest={handleCancel}
|
|
|
|
toRead={toRead}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const renderReader = () => {
|
|
|
|
return (
|
|
|
|
<Reader
|
|
|
|
cancelQRHardwareSignRequest={handleCancel}
|
|
|
|
submitQRHardwareSignature={submitQRHardwareSignature}
|
|
|
|
requestId={request.requestId}
|
|
|
|
setErrorTitle={setErrorTitle}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-01-06 23:56:51 +01:00
|
|
|
if (status === 'play') {
|
|
|
|
return renderPlayer();
|
|
|
|
}
|
2021-11-23 18:28:39 +01:00
|
|
|
return renderReader();
|
|
|
|
};
|
|
|
|
|
|
|
|
QRHardwareSignRequest.propTypes = {
|
|
|
|
request: PropTypes.object.isRequired,
|
|
|
|
handleCancel: PropTypes.func.isRequired,
|
|
|
|
setErrorTitle: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default QRHardwareSignRequest;
|