// @flow import React from 'react'; import Button from 'component/button'; import { FormField, Form } from 'component/common/form'; type Props = { uri: string, claimIsMine: boolean, title: string, claim: StreamClaim, isPending: boolean, sendSupport: (number, string, string) => void, onCancel: () => void, sendTipCallback?: () => void, balance: number, }; type State = { tipAmount: number, tipError: string, }; class WalletSendTip extends React.PureComponent { constructor(props: Props) { super(props); this.state = { tipAmount: 0, tipError: '', }; (this: any).handleSendButtonClicked = this.handleSendButtonClicked.bind(this); } handleSendButtonClicked() { const { claim, uri, sendSupport, sendTipCallback } = this.props; const { claim_id: claimId } = claim; const { tipAmount } = this.state; sendSupport(tipAmount, claimId, uri); // ex: close modal if (sendTipCallback) { sendTipCallback(); } } handleSupportPriceChange(event: SyntheticInputEvent<*>) { const { balance } = this.props; const regexp = RegExp(/^(\d*([.]\d{0,8})?)$/); const validTipInput = regexp.test(event.target.value); const tipAmount = parseFloat(event.target.value); let tipError; if (!tipAmount) { tipError = __('Tip must be a number'); } else if (tipAmount <= 0) { tipError = __('Tip must be a positive number'); } else if (!validTipInput) { tipError = __('Tip must have no more than 8 decimal places'); } else if (tipAmount === balance) { tipError = __('Please decrease your tip to account for transaction fees'); } else if (tipAmount > balance) { tipError = __('Not enough credits'); } this.setState({ tipAmount, tipError, }); } render() { const { title, isPending, uri, onCancel, claimIsMine } = this.props; const { tipAmount, tipError } = this.state; return (
this.handleSupportPriceChange(event)} inputButton={