1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-02 22:24:27 +01:00
metamask-extension/ui/components/app/qr-hardware-popover/qr-hardware-sign-request/qr-hardware-sign-request.component.js

48 lines
1.2 KiB
JavaScript
Raw Normal View History

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}
/>
);
};
if (status === 'play') {
return renderPlayer();
}
return renderReader();
};
QRHardwareSignRequest.propTypes = {
request: PropTypes.object.isRequired,
handleCancel: PropTypes.func.isRequired,
setErrorTitle: PropTypes.func.isRequired,
};
export default QRHardwareSignRequest;