mirror of
https://github.com/pezkuwichain/pezkuwi-ui.git
synced 2026-07-02 19:07:28 +00:00
f7bd11a293
* Basic QR tests (+ number encoding fix) * skipEncoding for Address display * Fixup comments
57 lines
1.3 KiB
TypeScript
57 lines
1.3 KiB
TypeScript
// Copyright 2017-2019 @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 from 'react';
|
|
import { xxhashAsHex } from '@polkadot/util-crypto';
|
|
|
|
import { createSignPayload } from './util';
|
|
import QrDisplay from './Display';
|
|
|
|
interface Props extends BaseProps {
|
|
address: string;
|
|
payload: Uint8Array;
|
|
}
|
|
|
|
interface State {
|
|
data: Uint8Array | null;
|
|
dataHash: string | null;
|
|
}
|
|
|
|
export default class DisplayPayload extends React.PureComponent<Props, State> {
|
|
public state: State = {
|
|
data: null,
|
|
dataHash: null
|
|
};
|
|
|
|
public static getDerivedStateFromProps ({ address, payload }: Props, prevState: State): State | null {
|
|
const data = createSignPayload(address, payload);
|
|
const dataHash = xxhashAsHex(data);
|
|
|
|
if (dataHash === prevState.dataHash) {
|
|
return null;
|
|
}
|
|
|
|
return { data, dataHash };
|
|
}
|
|
|
|
public render (): React.ReactNode {
|
|
const { className, style } = this.props;
|
|
const { data } = this.state;
|
|
|
|
if (!data) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<QrDisplay
|
|
className={className}
|
|
style={style}
|
|
value={data}
|
|
/>
|
|
);
|
|
}
|
|
}
|