Proposal.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2017-2020 @polkadot/app-extrinsics 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 { Props, RawParam } from '@polkadot/react-params/types';
  5. import React, { useCallback } from 'react';
  6. import { registry } from '@polkadot/react-api';
  7. import { useApi } from '@polkadot/react-hooks';
  8. import ExtrinsicDisplay from './Extrinsic';
  9. function ProposalDisplay ({ className = '', isDisabled, isError, label, onChange, onEnter, onEscape, withLabel }: Props): React.ReactElement<Props> {
  10. const { apiDefaultTxSudo } = useApi();
  11. const _onChange = useCallback(
  12. ({ isValid, value }: RawParam): void => {
  13. let proposal = null;
  14. if (isValid && value) {
  15. proposal = registry.createType('Proposal', value);
  16. }
  17. onChange && onChange({
  18. isValid,
  19. value: proposal
  20. });
  21. },
  22. [onChange]
  23. );
  24. return (
  25. <ExtrinsicDisplay
  26. className={className}
  27. defaultValue={apiDefaultTxSudo}
  28. isDisabled={isDisabled}
  29. isError={isError}
  30. isPrivate
  31. label={label}
  32. onChange={_onChange}
  33. onEnter={onEnter}
  34. onEscape={onEscape}
  35. withLabel={withLabel}
  36. />
  37. );
  38. }
  39. export default React.memo(ProposalDisplay);