MemoForm.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import React from 'react';
  2. import { Labelled } from '@polkadot/react-components/index';
  3. import MemoEdit from '@polkadot/joy-utils/memo/MemoEdit';
  4. import TxButton from '@polkadot/joy-utils/TxButton';
  5. import { withMyAccount, MyAccountProps } from '@polkadot/joy-utils/MyAccount';
  6. import { Text } from '@polkadot/types';
  7. type Props = MyAccountProps & {};
  8. type State = {
  9. memo: string;
  10. modified: boolean;
  11. };
  12. class Component extends React.PureComponent<Props, State> {
  13. state: State = {
  14. memo: '',
  15. modified: false
  16. };
  17. render () {
  18. const { myAddress } = this.props;
  19. const { memo, modified } = this.state;
  20. return (
  21. <>
  22. <MemoEdit accountId={myAddress || ''} onChange={this.onChangeMemo} onReset={this.onResetMemo} />
  23. <Labelled style={{ marginTop: '.5rem' }}>
  24. <TxButton
  25. size='large'
  26. isDisabled={!modified}
  27. label='Update memo'
  28. params={[new Text(memo)]}
  29. tx='memo.updateMemo'
  30. />
  31. </Labelled>
  32. </>
  33. );
  34. }
  35. onChangeMemo = (memo: string): void => {
  36. this.setState({ memo, modified: true });
  37. }
  38. onResetMemo = (memo: string): void => {
  39. this.setState({ memo, modified: false });
  40. }
  41. }
  42. export default withMyAccount(Component);