Qr.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2017-2020 @polkadot/react-signer authors & contributors
  2. // This software may be modified and distributed under the terms
  3. // of the Apache-2.0 license. See the LICENSE file for details.
  4. import React from 'react';
  5. import styled from 'styled-components';
  6. import { Columar, QrDisplayPayload, QrScanSignature, Spinner } from '@polkadot/react-components';
  7. import { useTranslation } from './translate';
  8. interface Props {
  9. address: string;
  10. className?: string;
  11. genesisHash: Uint8Array;
  12. isHashed: boolean;
  13. isScanning: boolean;
  14. onSignature: (signature: { signature: string }) => void;
  15. payload: Uint8Array;
  16. }
  17. const CMD_HASH = 1;
  18. const CMD_MORTAL = 2;
  19. function Qr ({ address, className, genesisHash, isHashed, onSignature, payload }: Props): React.ReactElement<Props> {
  20. const { t } = useTranslation();
  21. if (!address) {
  22. return (
  23. <Spinner label={t<string>('Preparing QR for signing')} />
  24. );
  25. }
  26. return (
  27. <Columar className={className}>
  28. <Columar.Column>
  29. <div className='qrDisplay'>
  30. <QrDisplayPayload
  31. address={address}
  32. cmd={
  33. isHashed
  34. ? CMD_HASH
  35. : CMD_MORTAL
  36. }
  37. genesisHash={genesisHash}
  38. payload={payload}
  39. />
  40. </div>
  41. </Columar.Column>
  42. <Columar.Column>
  43. <div className='qrDisplay'>
  44. <QrScanSignature onScan={onSignature} />
  45. </div>
  46. </Columar.Column>
  47. </Columar>
  48. );
  49. }
  50. export default React.memo(styled(Qr)`
  51. .qrDisplay {
  52. margin: 0 auto;
  53. max-width: 30rem;
  54. }
  55. `);