Replace getQRCodeBytes with generateQRCode (#11241)

* Replace `getQRCodeBytes` with `generateQRCode`

* another test update

* remove obsolete snapshot
This commit is contained in:
Richard van der Hoff 2023-07-13 14:55:55 +01:00 committed by GitHub
parent 9077592bec
commit 2cfbd73cd3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 48 additions and 12 deletions

View file

@ -22,7 +22,8 @@ import { _t } from "../../../languageHandler";
import Spinner from "./Spinner";
interface IProps extends QRCodeRenderersOptions {
data: string | QRCodeSegment[];
/** The data for the QR code. If `null`, a spinner is shown. */
data: null | string | QRCodeSegment[];
className?: string;
}
@ -33,6 +34,10 @@ const defaultOptions: QRCodeToDataURLOptions = {
const QRCode: React.FC<IProps> = ({ data, className, ...options }) => {
const [dataUri, setUri] = React.useState<string | null>(null);
React.useEffect(() => {
if (data === null) {
setUri(null);
return;
}
let cancelled = false;
toDataURL(data, { ...defaultOptions, ...options }).then((uri) => {
if (cancelled) return;

View file

@ -19,14 +19,15 @@ import React from "react";
import QRCode from "../QRCode";
interface IProps {
qrCodeBytes: Buffer;
/** The data for the QR code. If `undefined`, a spinner is shown. */
qrCodeBytes: undefined | Buffer;
}
export default class VerificationQRCode extends React.PureComponent<IProps> {
public render(): React.ReactNode {
return (
<QRCode
data={[{ data: this.props.qrCodeBytes, mode: "byte" }]}
data={this.props.qrCodeBytes === undefined ? null : [{ data: this.props.qrCodeBytes, mode: "byte" }]}
className="mx_VerificationQRCode"
width={196}
/>