import clsx from 'clsx' import { LimitBet } from 'common/bet' import { CPMMBinaryContract, PseudoNumericContract } from 'common/contract' import { getFormattedMappedValue } from 'common/pseudo-numeric' import { formatMoney, formatPercent } from 'common/util/format' import { sortBy } from 'lodash' import { useState } from 'react' import { cancelBet } from 'web/lib/firebase/api' import { Col } from './layout/col' import { LoadingIndicator } from './loading-indicator' import { BinaryOutcomeLabel, PseudoNumericOutcomeLabel } from './outcome-label' export function LimitBets(props: { contract: CPMMBinaryContract | PseudoNumericContract bets: LimitBet[] hideLabel?: boolean className?: string }) { const { contract, bets, hideLabel, className } = props const recentBets = sortBy( bets, (bet) => -1 * bet.limitProb, (bet) => -1 * bet.createdTime ) return ( {!hideLabel &&
Your limit orders
} {recentBets.map((bet) => ( ))}
) } function LimitBet(props: { contract: CPMMBinaryContract | PseudoNumericContract bet: LimitBet }) { const { contract, bet } = props const { orderAmount, amount, limitProb, outcome } = bet const isPseudoNumeric = contract.outcomeType === 'PSEUDO_NUMERIC' const [isCancelling, setIsCancelling] = useState(false) const onCancel = () => { cancelBet({ betId: bet.id }) setIsCancelling(true) } return (
{isPseudoNumeric ? ( ) : ( )}
{formatMoney(orderAmount - amount)} {isPseudoNumeric ? getFormattedMappedValue(contract)(limitProb) : formatPercent(limitProb)} {isCancelling ? ( ) : ( )} ) }