Files
ui/packages/react-qr/src/DisplayPayload.tsx
T
Jaco GreeffandHanwen Cheng 9252de79d4 Add genesisHash to signer payload (#323)
* Add genesisHash to signer payload

* fix order and add tests (#324)

* fix order and add tests

* Update packages/react-qr/src/util.spec.ts

* Update packages/react-qr/src/util.spec.ts

Co-authored-by: Jaco Greeff <jacogr@gmail.com>

* Apply suggestions from code review

Co-authored-by: Hanwen Cheng <heawen.cheng@gmail.com>
2020-05-27 17:48:32 +02:00

41 lines
1.0 KiB
TypeScript

// Copyright 2017-2020 @polkadot/react-qr authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { BaseProps } from './types';
import React, { useEffect, useState } from 'react';
import { createSignPayload } from './util';
import QrDisplay from './Display';
interface Props extends BaseProps {
address: string;
cmd: number;
genesisHash: Uint8Array | string;
payload: Uint8Array;
}
function DisplayPayload ({ address, className, cmd, genesisHash, payload, size, style }: Props): React.ReactElement<Props> | null {
const [data, setData] = useState<Uint8Array | null>(null);
useEffect((): void => {
setData(createSignPayload(address, cmd, payload, genesisHash));
}, [address, cmd, payload, genesisHash]);
if (!data) {
return null;
}
return (
<QrDisplay
className={className}
size={size}
style={style}
value={data}
/>
);
}
export default React.memo(DisplayPayload);