2022-03-29 19:56:56 +00:00
|
|
|
import { useState } from 'react'
|
2022-03-15 22:27:51 +00:00
|
|
|
|
2022-03-29 19:56:56 +00:00
|
|
|
import { BetPanelSwitcher } from './bet-panel'
|
2022-01-26 20:08:03 +00:00
|
|
|
import { Row } from './layout/row'
|
|
|
|
import { YesNoSelector } from './yes-no-selector'
|
2022-03-15 22:27:51 +00:00
|
|
|
import { Binary, CPMM, DPM, FullContract } from '../../common/contract'
|
2022-03-29 19:56:56 +00:00
|
|
|
import { Modal } from './layout/modal'
|
2022-04-20 14:13:39 +00:00
|
|
|
import { SellButton } from './sell-button'
|
|
|
|
import { useUser } from '../hooks/use-user'
|
|
|
|
import { useUserContractBets } from '../hooks/use-user-bets'
|
|
|
|
import { useSaveShares } from './use-save-shares'
|
2022-01-26 20:08:03 +00:00
|
|
|
|
|
|
|
// Inline version of a bet panel. Opens BetPanel in a new modal.
|
2022-01-26 22:28:57 +00:00
|
|
|
export default function BetRow(props: {
|
2022-03-15 22:27:51 +00:00
|
|
|
contract: FullContract<DPM | CPMM, Binary>
|
2022-01-26 22:28:57 +00:00
|
|
|
className?: string
|
2022-01-27 21:02:47 +00:00
|
|
|
labelClassName?: string
|
2022-01-26 22:28:57 +00:00
|
|
|
}) {
|
2022-04-20 14:13:39 +00:00
|
|
|
const { className, labelClassName, contract } = props
|
2022-01-26 20:08:03 +00:00
|
|
|
const [open, setOpen] = useState(false)
|
|
|
|
const [betChoice, setBetChoice] = useState<'YES' | 'NO' | undefined>(
|
|
|
|
undefined
|
|
|
|
)
|
2022-04-20 14:13:39 +00:00
|
|
|
const user = useUser()
|
|
|
|
const userBets = useUserContractBets(user?.id, contract.id)
|
2022-04-22 10:43:34 +00:00
|
|
|
const { yesFloorShares, noFloorShares, yesShares, noShares } = useSaveShares(
|
|
|
|
contract,
|
|
|
|
userBets
|
|
|
|
)
|
2022-01-26 20:08:03 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-01-27 21:02:47 +00:00
|
|
|
<div className={className}>
|
2022-04-20 14:13:39 +00:00
|
|
|
<Row className="mt-2 justify-end space-x-3">
|
2022-04-09 21:13:36 +00:00
|
|
|
{/* <div className={clsx('mr-2 text-gray-400', labelClassName)}>
|
2022-01-27 21:02:47 +00:00
|
|
|
Place a trade
|
2022-04-09 21:13:36 +00:00
|
|
|
</div> */}
|
2022-01-27 21:02:47 +00:00
|
|
|
<YesNoSelector
|
2022-03-29 19:56:56 +00:00
|
|
|
btnClassName="btn-sm w-24"
|
2022-01-27 21:02:47 +00:00
|
|
|
onSelect={(choice) => {
|
|
|
|
setOpen(true)
|
|
|
|
setBetChoice(choice)
|
|
|
|
}}
|
2022-04-20 14:13:39 +00:00
|
|
|
replaceNoButton={
|
2022-04-22 10:30:13 +00:00
|
|
|
yesFloorShares > 0 ? (
|
2022-04-22 10:43:34 +00:00
|
|
|
<SellButton
|
|
|
|
contract={contract}
|
|
|
|
user={user}
|
|
|
|
sharesOutcome={'YES'}
|
|
|
|
shares={yesShares}
|
|
|
|
/>
|
2022-04-20 14:13:39 +00:00
|
|
|
) : undefined
|
|
|
|
}
|
|
|
|
replaceYesButton={
|
2022-04-22 10:30:13 +00:00
|
|
|
noFloorShares > 0 ? (
|
2022-04-22 10:43:34 +00:00
|
|
|
<SellButton
|
|
|
|
contract={contract}
|
|
|
|
user={user}
|
|
|
|
sharesOutcome={'NO'}
|
|
|
|
shares={noShares}
|
|
|
|
/>
|
2022-04-20 14:13:39 +00:00
|
|
|
) : undefined
|
|
|
|
}
|
2022-01-27 21:02:47 +00:00
|
|
|
/>
|
|
|
|
</Row>
|
|
|
|
<Modal open={open} setOpen={setOpen}>
|
2022-03-29 19:56:56 +00:00
|
|
|
<BetPanelSwitcher
|
2022-04-20 14:13:39 +00:00
|
|
|
contract={contract}
|
|
|
|
title={contract.question}
|
2022-01-27 21:02:47 +00:00
|
|
|
selected={betChoice}
|
2022-02-05 18:26:11 +00:00
|
|
|
onBetSuccess={() => setOpen(false)}
|
2022-01-27 21:02:47 +00:00
|
|
|
/>
|
|
|
|
</Modal>
|
|
|
|
</div>
|
2022-01-26 20:08:03 +00:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|