SetRewardDestination.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // Copyright 2017-2019 @polkadot/ui-staking 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 { I18nProps } from '@polkadot/react-components/types';
  5. import React from 'react';
  6. import { Button, Dropdown, InputAddress, Modal, TxButton, TxComponent } from '@polkadot/react-components';
  7. import { withMulti } from '@polkadot/react-api';
  8. import translate from '../../translate';
  9. import { rewardDestinationOptions } from '../constants';
  10. interface Props extends I18nProps {
  11. defaultDestination?: number;
  12. controllerId: string;
  13. onClose: () => void;
  14. }
  15. interface State {
  16. destination: number;
  17. }
  18. class SetRewardDestination extends TxComponent<Props, State> {
  19. public constructor (props: Props) {
  20. super(props);
  21. this.state = {
  22. destination: 0
  23. };
  24. }
  25. public render (): React.ReactNode {
  26. const { controllerId, onClose, t } = this.props;
  27. const { destination } = this.state;
  28. const canSubmit = !!controllerId;
  29. return (
  30. <Modal
  31. className='staking--Bonding'
  32. dimmer='inverted'
  33. open
  34. size='small'
  35. >
  36. {this.renderContent()}
  37. <Modal.Actions>
  38. <Button.Group>
  39. <Button
  40. isNegative
  41. onClick={onClose}
  42. label={t('Cancel')}
  43. icon='cancel'
  44. />
  45. <Button.Or />
  46. <TxButton
  47. accountId={controllerId}
  48. isDisabled={!canSubmit}
  49. isPrimary
  50. label={t('Set reward destination')}
  51. icon='sign-in'
  52. onClick={onClose}
  53. params={[destination]}
  54. tx={'staking.setPayee'}
  55. ref={this.button}
  56. />
  57. </Button.Group>
  58. </Modal.Actions>
  59. </Modal>
  60. );
  61. }
  62. private renderContent (): React.ReactNode {
  63. const { controllerId, defaultDestination, t } = this.props;
  64. const { destination } = this.state;
  65. return (
  66. <>
  67. <Modal.Header>
  68. {t('Bonding Preferences')}
  69. </Modal.Header>
  70. <Modal.Content className='ui--signer-Signer-Content'>
  71. <InputAddress
  72. className='medium'
  73. isDisabled
  74. defaultValue={controllerId}
  75. help={t('The controller is the account that is be used to control any nominating or validating actions. I will sign this transaction.')}
  76. label={t('controller account')}
  77. />
  78. <Dropdown
  79. className='medium'
  80. defaultValue={defaultDestination}
  81. help={t('The destination account for any payments as either a nominator or validator')}
  82. label={t('payment destination')}
  83. onChange={this.onChangeDestination}
  84. options={rewardDestinationOptions}
  85. value={destination}
  86. />
  87. </Modal.Content>
  88. </>
  89. );
  90. }
  91. private onChangeDestination = (destination: number): void => {
  92. this.setState({ destination });
  93. }
  94. }
  95. export default withMulti(
  96. SetRewardDestination,
  97. translate
  98. );