// @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, boolean) => void, onCancel: () => void, sendTipCallback?: () => void, balance: number, isSupport: boolean, }; 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, sendSupport, isSupport, sendTipCallback } = this.props; const { claim_id: claimId } = claim; const { tipAmount } = this.state; sendSupport(tipAmount, claimId, isSupport); // 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, onCancel, claimIsMine, isSupport } = this.props; const { tipAmount, tipError } = this.state; return (
this.handleSupportPriceChange(event)} inputButton={