2022-05-09 13:04:36 +00:00
|
|
|
import { Binary, CPMM, DPM, FullContract } from 'common/contract'
|
|
|
|
import { User } from 'common/user'
|
|
|
|
import { useUserContractBets } from 'web/hooks/use-user-bets'
|
2022-04-20 14:13:39 +00:00
|
|
|
import { useState } from 'react'
|
|
|
|
import { Col } from './layout/col'
|
|
|
|
import clsx from 'clsx'
|
|
|
|
import { SellSharesModal } from './sell-modal'
|
|
|
|
|
|
|
|
export function SellButton(props: {
|
|
|
|
contract: FullContract<DPM | CPMM, Binary>
|
|
|
|
user: User | null | undefined
|
2022-04-22 10:43:34 +00:00
|
|
|
sharesOutcome: 'YES' | 'NO' | undefined
|
|
|
|
shares: number
|
2022-04-20 14:13:39 +00:00
|
|
|
}) {
|
2022-04-22 10:43:34 +00:00
|
|
|
const { contract, user, sharesOutcome, shares } = props
|
2022-04-20 14:13:39 +00:00
|
|
|
const userBets = useUserContractBets(user?.id, contract.id)
|
|
|
|
const [showSellModal, setShowSellModal] = useState(false)
|
|
|
|
const { mechanism } = contract
|
|
|
|
|
|
|
|
if (sharesOutcome && user && mechanism === 'cpmm-1') {
|
|
|
|
return (
|
|
|
|
<Col className={'items-center'}>
|
|
|
|
<button
|
|
|
|
className={clsx(
|
|
|
|
'btn-sm w-24 gap-1',
|
|
|
|
// from the yes-no-selector:
|
|
|
|
'flex inline-flex flex-row items-center justify-center rounded-3xl border-2 p-2',
|
|
|
|
sharesOutcome === 'NO'
|
|
|
|
? 'hover:bg-primary-focus border-primary hover:border-primary-focus text-primary hover:text-white'
|
|
|
|
: 'border-red-400 text-red-500 hover:border-red-500 hover:bg-red-500 hover:text-white'
|
|
|
|
)}
|
|
|
|
onClick={() => setShowSellModal(true)}
|
|
|
|
>
|
|
|
|
{'Sell ' + sharesOutcome}
|
|
|
|
</button>
|
|
|
|
<div className={'mt-1 w-24 text-center text-sm text-gray-500'}>
|
2022-04-22 10:43:34 +00:00
|
|
|
{'(' + Math.floor(shares) + ' shares)'}
|
2022-04-20 14:13:39 +00:00
|
|
|
</div>
|
|
|
|
{showSellModal && (
|
|
|
|
<SellSharesModal
|
|
|
|
contract={contract as FullContract<CPMM, Binary>}
|
|
|
|
user={user}
|
|
|
|
userBets={userBets ?? []}
|
2022-04-22 10:43:34 +00:00
|
|
|
shares={shares}
|
2022-04-20 14:13:39 +00:00
|
|
|
sharesOutcome={sharesOutcome}
|
|
|
|
setOpen={setShowSellModal}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Col>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
return <div />
|
|
|
|
}
|