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 { useUser, useUserById } from 'web/hooks/use-user' import { cancelBet } from 'web/lib/firebase/api' import { Avatar } from './avatar' import { Col } from './layout/col' import { Tabs } from './layout/tabs' import { LoadingIndicator } from './loading-indicator' import { BinaryOutcomeLabel, PseudoNumericOutcomeLabel } from './outcome-label' export function LimitBets(props: { contract: CPMMBinaryContract | PseudoNumericContract bets: LimitBet[] className?: string }) { const { contract, bets, className } = props const sortedBets = sortBy( bets, (bet) => -1 * bet.limitProb, (bet) => -1 * bet.createdTime ) const user = useUser() const yourBets = sortedBets.filter((bet) => bet.userId === user?.id) return ( 0 ? [ { title: 'Your limit orders', content: ( ), }, ] : []), { title: 'All limit orders', content: ( ), }, ]} /> ) } export function LimitOrderTable(props: { limitBets: LimitBet[] contract: CPMMBinaryContract | PseudoNumericContract isYou: boolean }) { const { limitBets, contract, isYou } = props const isPseudoNumeric = contract.outcomeType === 'PSEUDO_NUMERIC' return ( {!isYou && } {isYou && } {limitBets.map((bet) => ( ))}
Outcome Amount {isPseudoNumeric ? 'Value' : 'Prob'}
) } function LimitBet(props: { contract: CPMMBinaryContract | PseudoNumericContract bet: LimitBet isYou: boolean }) { const { contract, bet, isYou } = 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) } const user = useUserById(bet.userId) return ( {!isYou && ( )}
{isPseudoNumeric ? ( ) : ( )}
{formatMoney(orderAmount - amount)} {isPseudoNumeric ? getFormattedMappedValue(contract)(limitProb) : formatPercent(limitProb)} {isYou && ( {isCancelling ? ( ) : ( )} )} ) }