mirror of
https://github.com/pezkuwichain/pezkuwi-ui.git
synced 2026-04-22 19:38:03 +00:00
8865d2a2c5
* Some functional components * Pass param to useCallback * Bump berry * Scan -> functional
44 lines
972 B
TypeScript
44 lines
972 B
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, { useCallback } from 'react';
|
|
|
|
import QrScan from './Scan';
|
|
|
|
interface ScanType {
|
|
signature: string;
|
|
}
|
|
|
|
interface Props extends BaseProps {
|
|
onError?: (error: Error) => void;
|
|
onScan?: (scanned: ScanType) => void;
|
|
}
|
|
|
|
function ScanSignature ({ className, onError, onScan, size, style }: Props): React.ReactElement<Props> {
|
|
const _onScan = useCallback(
|
|
(signature: string | null): void => {
|
|
if (!signature || !onScan) {
|
|
return;
|
|
}
|
|
|
|
onScan({ signature: `0x${signature}` });
|
|
},
|
|
[onScan]
|
|
);
|
|
|
|
return (
|
|
<QrScan
|
|
className={className}
|
|
onError={onError}
|
|
onScan={_onScan}
|
|
size={size}
|
|
style={style}
|
|
/>
|
|
);
|
|
}
|
|
|
|
export default React.memo(ScanSignature);
|