diff --git a/app/components/DisplayAsQR.tsx b/app/components/DisplayAsQR.tsx new file mode 100644 index 000000000..8a1b3455d --- /dev/null +++ b/app/components/DisplayAsQR.tsx @@ -0,0 +1,42 @@ +import React, { useLayoutEffect, useState, useRef } from 'react'; +import { QRCodeCanvas } from 'qrcode.react'; + +interface Props { + value: string; + className: string; +} + +/** + * Displays the given value as a QR code. The size of the QR is controlled by className. + */ +export default function QR({ value, className }: Props) { + const [size, setSize] = useState(0); + const ref = useRef(null); + const [obs] = useState( + new ResizeObserver((entries) => { + setSize( + ref.current !== null + ? Math.min( + entries[0].contentRect.height, + entries[0].contentRect.width + ) + : 0 + ); + }) + ); + + useLayoutEffect(() => { + if (ref.current) { + obs.observe(ref.current); + return () => obs.disconnect(); + } + return () => {}; + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [ref.current]); + + return ( +
+ +
+ ); +} diff --git a/app/pages/Accounts/Accounts.module.scss b/app/pages/Accounts/Accounts.module.scss index e601144d2..6c98c769f 100644 --- a/app/pages/Accounts/Accounts.module.scss +++ b/app/pages/Accounts/Accounts.module.scss @@ -90,3 +90,15 @@ top: calc(50% - 17px); height: 34px; } + +.displayAddressQRBig { + height: calc(min(512px, 70%)); + width: calc(min(512px, 70%)); + margin-bottom: 50px; +} + +.displayAddressQRSmall { + height: 200px; + width: 200px; + margin: 20px; +} diff --git a/app/pages/Accounts/ShowAccountAddress.tsx b/app/pages/Accounts/ShowAccountAddress.tsx index d6ab98abc..14ac80a31 100644 --- a/app/pages/Accounts/ShowAccountAddress.tsx +++ b/app/pages/Accounts/ShowAccountAddress.tsx @@ -1,6 +1,5 @@ import React from 'react'; import { useDispatch } from 'react-redux'; -import QRCode from 'qrcode.react'; import { push } from 'connected-react-router'; import clsx from 'clsx'; import ExpandIcon from '@resources/svg/expand.svg'; @@ -11,9 +10,10 @@ import DisplayAddress, { AddressDisplayFormat, } from '~/components/DisplayAddress'; -import { Account, ClassName } from '../../utils/types'; -import CopyButton from '../../components/CopyButton'; +import { Account, ClassName } from '~/utils/types'; +import CopyButton from '~/components/CopyButton'; import VerifyAddress from './VerifyAddress'; +import DisplayAsQR from '~/components/DisplayAsQR'; import styles from './Accounts.module.scss'; import CloseButton from '~/cross-app-components/CloseButton'; @@ -35,7 +35,10 @@ export default function ShowAccountAddress({ const display = ( <> - +
- +