1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-05 15:35:46 +01:00
metamask-extension/ui/components/app/qr-hardware-popover/qr-hardware-sign-request/reader.js
Aaron Chen a931316a53
Introduce QR based signer into MetaMask (#12065)
* support qr based signer

* add CSP for fire fox

* get QR Hardware wallet name from device

* fix qrHardware state missing in runtime

* support qr based signer sign transaction

* refine Request Signature modal ui

* remove feature toggle

* refine ui

* fix notification is closing even there is a pending qr hardware transaction

* add chinese translation, refine ui, fix qr process was breaking in some case

* support import accounts by pubkeys

* refine qr-based wallet ui and fix bugs

* update @keystonehq/metamask-airgapped-keyring to fix that the signing hd path was inconsistent in some edge case

* fix: avoid unnecessay navigation, fix ci

* refactor qr-hardware-popover with @zxing/browser

* update lavamoat policy, remove firefox CSP

* refine qr reader ui, ignore unnecessary warning display

* code refactor, use async functions insteads promise

Co-authored-by: Soralit <soralitria@gmail.com>
2021-11-23 13:58:39 -03:30

53 lines
1.5 KiB
JavaScript

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;