A Metamask fork with Infura removed and default networks editable
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ciphermask/ui/components/app/qr-hardware-popover/qr-hardware-sign-request/reader.js

53 lines
1.5 KiB

import React from 'react';
import { ETHSignature } from '@keystonehq/bc-ur-registry-eth';
import * as uuid from 'uuid';
import PropTypes from 'prop-types';
import BaseReader from '../base-reader';
import { useI18nContext } from '../../../../hooks/useI18nContext';
const Reader = ({
submitQRHardwareSignature,
cancelQRHardwareSignRequest,
requestId,
setErrorTitle,
}) => {
const t = useI18nContext();
const cancel = () => {
cancelQRHardwareSignRequest();
};
const handleSuccess = async (ur) => {
if (ur.type === 'eth-signature') {
const ethSignature = ETHSignature.fromCBOR(ur.cbor);
const buffer = ethSignature.getRequestId();
const signId = uuid.stringify(buffer);
if (signId === requestId) {
return await submitQRHardwareSignature(signId, ur.cbor.toString('hex'));
}
setErrorTitle(t('QRHardwareInvalidTransactionTitle'));
throw new Error(t('QRHardwareMismatchedSignId'));
} else {
setErrorTitle(t('QRHardwareInvalidTransactionTitle'));
throw new Error(t('unknownQrCode'));
}
};
return (
<BaseReader
isReadingWallet={false}
handleCancel={cancel}
handleSuccess={handleSuccess}
setErrorTitle={setErrorTitle}
/>
);
};
Reader.propTypes = {
submitQRHardwareSignature: PropTypes.func.isRequired,
cancelQRHardwareSignRequest: PropTypes.func.isRequired,
requestId: PropTypes.string.isRequired,
setErrorTitle: PropTypes.func.isRequired,
};
export default Reader;