2022-03-29 19:56:56 +00:00
|
|
|
import { useState } from 'react'
|
2022-05-09 22:50:20 +00:00
|
|
|
import clsx from 'clsx'
|
2022-03-15 22:27:51 +00:00
|
|
|
|
2022-07-10 18:05:44 +00:00
|
|
|
import { SimpleBetPanel } from './bet-panel'
|
|
|
|
import { CPMMBinaryContract, PseudoNumericContract } from 'common/contract'
|
2022-03-29 19:56:56 +00:00
|
|
|
import { Modal } from './layout/modal'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { useUser } from 'web/hooks/use-user'
|
|
|
|
import { useUserContractBets } from 'web/hooks/use-user-bets'
|
2022-07-10 18:05:44 +00:00
|
|
|
import { useSaveBinaryShares } from './use-save-binary-shares'
|
2022-07-12 22:34:10 +00:00
|
|
|
import { Col } from './layout/col'
|
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-07-10 18:05:44 +00:00
|
|
|
contract: CPMMBinaryContract | PseudoNumericContract
|
2022-01-26 22:28:57 +00:00
|
|
|
className?: string
|
2022-05-11 21:35:50 +00:00
|
|
|
btnClassName?: string
|
2022-05-17 17:31:19 +00:00
|
|
|
betPanelClassName?: string
|
2022-01-26 22:28:57 +00:00
|
|
|
}) {
|
2022-05-17 17:31:19 +00:00
|
|
|
const { className, btnClassName, betPanelClassName, contract } = props
|
2022-01-26 20:08:03 +00:00
|
|
|
const [open, setOpen] = useState(false)
|
2022-07-12 22:34:10 +00:00
|
|
|
|
2022-04-20 14:13:39 +00:00
|
|
|
const user = useUser()
|
|
|
|
const userBets = useUserContractBets(user?.id, contract.id)
|
2022-07-10 18:05:44 +00:00
|
|
|
const { yesShares, noShares, hasYesShares, hasNoShares } =
|
|
|
|
useSaveBinaryShares(contract, userBets)
|
2022-01-26 20:08:03 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-07-12 22:34:10 +00:00
|
|
|
<Col className={clsx('items-center', className)}>
|
|
|
|
<button
|
|
|
|
className={clsx(
|
|
|
|
'btn btn-lg btn-outline my-auto inline-flex h-10 min-h-0 w-24',
|
|
|
|
btnClassName
|
|
|
|
)}
|
|
|
|
onClick={() => setOpen(true)}
|
|
|
|
>
|
|
|
|
Bet
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<div className={'mt-1 w-24 text-center text-sm text-gray-500'}>
|
|
|
|
{hasYesShares
|
|
|
|
? `(${Math.floor(yesShares)} YES)`
|
|
|
|
: hasNoShares
|
|
|
|
? `(${Math.floor(noShares)} NO)`
|
|
|
|
: ''}
|
|
|
|
</div>
|
|
|
|
</Col>
|
|
|
|
|
2022-05-09 22:50:20 +00:00
|
|
|
<Modal open={open} setOpen={setOpen}>
|
2022-07-10 18:05:44 +00:00
|
|
|
<SimpleBetPanel
|
2022-05-17 17:31:19 +00:00
|
|
|
className={betPanelClassName}
|
2022-05-09 22:50:20 +00:00
|
|
|
contract={contract}
|
2022-07-12 22:34:10 +00:00
|
|
|
selected={undefined}
|
2022-05-09 22:50:20 +00:00
|
|
|
onBetSuccess={() => setOpen(false)}
|
2022-07-12 22:34:10 +00:00
|
|
|
hasShares={hasYesShares || hasNoShares}
|
2022-05-09 22:50:20 +00:00
|
|
|
/>
|
|
|
|
</Modal>
|
2022-01-26 20:08:03 +00:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|