2022-07-02 19:37:59 +00:00
|
|
|
import { BinaryContract, PseudoNumericContract } from 'common/contract'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { User } from 'common/user'
|
2022-04-20 14:13:39 +00:00
|
|
|
import { useState } from 'react'
|
|
|
|
import { Col } from './layout/col'
|
|
|
|
import { Row } from './layout/row'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { formatWithCommas } from 'common/util/format'
|
2022-04-20 14:13:39 +00:00
|
|
|
import { OutcomeLabel } from './outcome-label'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { useUserContractBets } from 'web/hooks/use-user-bets'
|
2022-07-10 18:05:44 +00:00
|
|
|
import { useSaveBinaryShares } from './use-save-binary-shares'
|
2022-04-20 14:13:39 +00:00
|
|
|
import { SellSharesModal } from './sell-modal'
|
2022-10-12 06:31:32 +00:00
|
|
|
import { Button } from './button'
|
2022-04-20 14:13:39 +00:00
|
|
|
|
|
|
|
export function SellRow(props: {
|
2022-07-02 19:37:59 +00:00
|
|
|
contract: BinaryContract | PseudoNumericContract
|
2022-04-20 14:13:39 +00:00
|
|
|
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
|
2022-07-10 18:05:44 +00:00
|
|
|
const { sharesOutcome, shares } = useSaveBinaryShares(contract, userBets)
|
2022-04-20 14:13:39 +00:00
|
|
|
|
|
|
|
if (sharesOutcome && user && mechanism === 'cpmm-1') {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Col className={className}>
|
|
|
|
<Row className="items-center justify-between gap-2 ">
|
|
|
|
<div>
|
2022-07-10 18:05:44 +00:00
|
|
|
You have {formatWithCommas(shares)}{' '}
|
2022-04-20 14:13:39 +00:00
|
|
|
<OutcomeLabel
|
|
|
|
outcome={sharesOutcome}
|
|
|
|
contract={contract}
|
|
|
|
truncate={'short'}
|
|
|
|
/>{' '}
|
|
|
|
shares
|
|
|
|
</div>
|
|
|
|
|
2022-10-12 06:31:32 +00:00
|
|
|
<Button
|
|
|
|
className="my-auto"
|
|
|
|
size="xs"
|
|
|
|
color="gray-outline"
|
2022-04-20 14:13:39 +00:00
|
|
|
onClick={() => setShowSellModal(true)}
|
|
|
|
>
|
|
|
|
Sell
|
2022-10-12 06:31:32 +00:00
|
|
|
</Button>
|
2022-04-20 14:13:39 +00:00
|
|
|
</Row>
|
|
|
|
</Col>
|
|
|
|
{showSellModal && (
|
|
|
|
<SellSharesModal
|
2022-06-01 02:42:35 +00:00
|
|
|
contract={contract}
|
2022-04-20 14:13:39 +00:00
|
|
|
user={user}
|
|
|
|
userBets={userBets ?? []}
|
2022-07-10 18:05:44 +00:00
|
|
|
shares={shares}
|
2022-04-20 14:13:39 +00:00
|
|
|
sharesOutcome={sharesOutcome}
|
|
|
|
setOpen={setShowSellModal}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return <div />
|
|
|
|
}
|