1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-02 14:15:06 +01:00
metamask-extension/ui/components/app/qr-hardware-popover/qr-hardware-sign-request/player.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

72 lines
2.1 KiB
JavaScript

import React, { useEffect, useMemo, useState } from 'react';
import QRCode from 'qrcode.react';
import { UR, UREncoder } from '@ngraveio/bc-ur';
import PropTypes from 'prop-types';
import Typography from '../../../ui/typography';
import Box from '../../../ui/box';
import { useI18nContext } from '../../../../hooks/useI18nContext';
import {
ALIGN_ITEMS,
DISPLAY,
FLEX_DIRECTION,
TEXT_ALIGN,
} from '../../../../helpers/constants/design-system';
import { PageContainerFooter } from '../../../ui/page-container';
const Player = ({ type, cbor, cancelQRHardwareSignRequest, toRead }) => {
const t = useI18nContext();
const urEncoder = useMemo(
() => new UREncoder(new UR(Buffer.from(cbor, 'hex'), type), 400),
[cbor, type],
);
const [currentQRCode, setCurrentQRCode] = useState(urEncoder.nextPart());
useEffect(() => {
const id = setInterval(() => {
setCurrentQRCode(urEncoder.nextPart());
}, 100);
return () => {
clearInterval(id);
};
}, [urEncoder]);
return (
<>
<Box>
<Typography align={TEXT_ALIGN.CENTER}>
{t('QRHardwareSignRequestSubtitle')}
</Typography>
</Box>
<Box
paddingTop={4}
paddingBottom={4}
display={DISPLAY.FLEX}
alignItems={ALIGN_ITEMS.CENTER}
flexDirection={FLEX_DIRECTION.COLUMN}
>
<QRCode value={currentQRCode.toUpperCase()} size={250} />
</Box>
<Box paddingBottom={4} paddingLeft={4} paddingRight={4}>
<Typography align={TEXT_ALIGN.CENTER}>
{t('QRHardwareSignRequestDescription')}
</Typography>
</Box>
<PageContainerFooter
onCancel={cancelQRHardwareSignRequest}
onSubmit={toRead}
cancelText={t('QRHardwareSignRequestCancel')}
submitText={t('QRHardwareSignRequestGetSignature')}
submitButtonType="confirm"
/>
</>
);
};
Player.propTypes = {
type: PropTypes.string.isRequired,
cbor: PropTypes.string.isRequired,
cancelQRHardwareSignRequest: PropTypes.func.isRequired,
toRead: PropTypes.func.isRequired,
};
export default Player;