import { Contract } from 'common/contract' import { useUser } from 'web/hooks/use-user' import { useState } from 'react' import { addCommentBounty } from 'web/lib/firebase/api' import { track } from 'web/lib/service/analytics' import { InfoTooltip } from 'web/components/info-tooltip' import { BETTORS, PRESENT_BET } from 'common/user' import { Row } from 'web/components/layout/row' import { AmountInput } from 'web/components/amount-input' import clsx from 'clsx' import { formatMoney } from 'common/util/format' export function AddCommentBountyPanel(props: { contract: Contract }) { const { contract } = props const { id: contractId, slug } = contract const user = useUser() const [amount, setAmount] = useState(undefined) const [error, setError] = useState(undefined) const [isSuccess, setIsSuccess] = useState(false) const [isLoading, setIsLoading] = useState(false) const onAmountChange = (amount: number | undefined) => { setIsSuccess(false) setAmount(amount) // Check for errors. if (amount !== undefined) { if (user && user.balance < amount) { setError('Insufficient balance') } else if (amount < 1) { setError('Minimum amount: ' + formatMoney(1)) } else { setError(undefined) } } } const submit = () => { if (!amount) return setIsLoading(true) setIsSuccess(false) addCommentBounty({ amount, contractId }) .then((_) => { setIsSuccess(true) setError(undefined) setIsLoading(false) }) .catch((_) => setError('Server error')) track('add comment bounty', { amount, contractId, slug }) } return ( <>
Contribute your M$ to make this market more accurate.{' '}
{isSuccess && amount && (
Success! Added {formatMoney(amount)} in bounties.
)} {isLoading &&
Processing...
} ) }