import { Binary, CPMM, DPM, FullContract } from '../../common/contract' import { User } from '../../common/user' import { Bet } from '../../common/bet' import { useState } from 'react' import { Col } from './layout/col' import { Row } from './layout/row' import { formatWithCommas } from '../../common/util/format' import { OutcomeLabel } from './outcome-label' import { Modal } from './layout/modal' import { Title } from './title' import { SellPanel } from './bet-panel' import { useUserContractBets } from '../hooks/use-user-bets' import clsx from 'clsx' import { useSaveShares } from './use-save-shares' export function SellRow(props: { contract: FullContract user: User | null | undefined className?: string }) { const { className, contract, user } = props const userBets = useUserContractBets(user?.id, contract.id) const [showSellModal, setShowSellModal] = useState(false) const { mechanism } = contract const { yesFloorShares, noFloorShares, yesShares, noShares } = useSaveShares( contract, userBets ) const floorShares = yesFloorShares || noFloorShares const sharesOutcome = yesFloorShares ? 'YES' : noFloorShares ? 'NO' : undefined if (sharesOutcome && user && mechanism === 'cpmm-1') { return (
You have {formatWithCommas(floorShares)}{' '} {' '} shares
{showSellModal && ( } user={user} userBets={userBets ?? []} shares={yesShares || noShares} sharesOutcome={sharesOutcome} setOpen={setShowSellModal} /> )}
) } return
} export function SellButton(props: { contract: FullContract user: User | null | undefined }) { const { contract, user } = props const userBets = useUserContractBets(user?.id, contract.id) const [showSellModal, setShowSellModal] = useState(false) const { mechanism } = contract const { yesFloorShares, noFloorShares, yesShares, noShares } = useSaveShares( contract, userBets ) const floorShares = yesFloorShares || noFloorShares const sharesOutcome = yesFloorShares ? 'YES' : noFloorShares ? 'NO' : undefined if (sharesOutcome && user && mechanism === 'cpmm-1') { return (
{'(' + floorShares + ' shares)'}
{showSellModal && ( } user={user} userBets={userBets ?? []} shares={yesShares || noShares} sharesOutcome={sharesOutcome} setOpen={setShowSellModal} /> )} ) } return
} function SellSharesModal(props: { contract: FullContract userBets: Bet[] shares: number sharesOutcome: 'YES' | 'NO' user: User setOpen: (open: boolean) => void }) { const { contract, shares, sharesOutcome, userBets, user, setOpen } = props return ( <div className="mb-6"> You have {formatWithCommas(Math.floor(shares))}{' '} <OutcomeLabel outcome={sharesOutcome} contract={contract} truncate={'short'} />{' '} shares </div> <SellPanel contract={contract} shares={shares} sharesOutcome={sharesOutcome} user={user} userBets={userBets ?? []} onSellSuccess={() => setOpen(false)} /> </Col> </Modal> ) }