Put sale value above quick bet button

This commit is contained in:
Ian Philips 2022-09-10 17:48:35 -06:00
parent b39e0f304f
commit 9ee7173305
3 changed files with 39 additions and 28 deletions

View File

@ -23,26 +23,11 @@ export default function BetButton(props: {
const user = useUser() const user = useUser()
const userBets = useUserContractBets(user?.id, contract.id) const userBets = useUserContractBets(user?.id, contract.id)
const { yesShares, noShares, hasYesShares, hasNoShares } = const { hasYesShares, hasNoShares } = useSaveBinaryShares(contract, userBets)
useSaveBinaryShares(contract, userBets)
const { outcomeType } = contract
const isPseudoNumeric = outcomeType === 'PSEUDO_NUMERIC'
return ( return (
<> <>
<Col className={clsx('items-center', className)}> <Col className={clsx('items-center', className)}>
{user && (
<div className={'mb-1 w-24 text-center text-sm text-gray-500'}>
{hasYesShares
? `(${Math.floor(yesShares)} ${
isPseudoNumeric ? 'HIGHER' : 'YES'
})`
: hasNoShares
? `(${Math.floor(noShares)} ${isPseudoNumeric ? 'LOWER' : 'NO'})`
: ''}
</div>
)}
{user ? ( {user ? (
<Button <Button
size="lg" size="lg"

View File

@ -38,7 +38,7 @@ const BetWidget = (props: { contract: CPMMContract }) => {
const user = useUser() const user = useUser()
return ( return (
<Col className={'justify-center'}> <Col className={'justify-center'}>
<Row className={'gap-4'}> <Row className={'items-end gap-4'}>
{contract.outcomeType === 'BINARY' && {contract.outcomeType === 'BINARY' &&
user && user &&
QuickBetButtons({ QuickBetButtons({

View File

@ -18,6 +18,7 @@ import { useUnfilledBets } from 'web/hooks/use-bets'
import { getBinaryProb } from 'common/contract-details' import { getBinaryProb } from 'common/contract-details'
import { quickOutcome } from 'web/components/contract/quick-bet-arrows' import { quickOutcome } from 'web/components/contract/quick-bet-arrows'
import { Button } from 'web/components/button' import { Button } from 'web/components/button'
import { Col } from 'web/components/layout/col'
const BET_SIZE = 10 const BET_SIZE = 10
@ -34,15 +35,16 @@ export function QuickBetButtons(props: {
const userBets = useUserContractBets(user.id, contract.id) const userBets = useUserContractBets(user.id, contract.id)
const unfilledBets = useUnfilledBets(contract.id) ?? [] const unfilledBets = useUnfilledBets(contract.id) ?? []
const { hasYesShares, hasNoShares, yesShares, noShares } =
const { yesShares, noShares } = useSaveBinaryShares(contract, userBets) useSaveBinaryShares(contract, userBets)
const oppositeShares = side === 'YES' ? noShares : yesShares const oppositeShares = side === 'YES' ? noShares : yesShares
if (oppositeShares > 0.01) { if (oppositeShares > 0.01) {
sellOutcome = side === 'YES' ? 'NO' : 'YES' sellOutcome = side === 'YES' ? 'NO' : 'YES'
const prob = getProb(contract) const prob = getProb(contract)
const maxSharesSold = const maxSharesSold =
(BET_SIZE + 0.05) / (sellOutcome === 'YES' ? prob : 1 - prob) (BET_SIZE + 1) / (sellOutcome === 'YES' ? prob : 1 - prob)
sharesSold = Math.min(oppositeShares, maxSharesSold) sharesSold = Math.min(oppositeShares, maxSharesSold)
const { saleValue } = calculateCpmmSale( const { saleValue } = calculateCpmmSale(
@ -53,6 +55,16 @@ export function QuickBetButtons(props: {
) )
saleAmount = saleValue saleAmount = saleValue
} }
const getValueOfShares = () => {
const { saleValue } = calculateCpmmSale(
contract,
side === 'YES' ? yesShares : noShares,
side,
unfilledBets
)
return saleValue
}
const saleValueOfShares = getValueOfShares()
async function placeQuickBet() { async function placeQuickBet() {
const betPromise = async () => { const betPromise = async () => {
@ -91,6 +103,19 @@ export function QuickBetButtons(props: {
} }
return ( return (
<Col>
{user && (
<div className={'min-w-sm mb-1 text-center text-sm text-gray-500'}>
{saleValueOfShares > 0.1 &&
hasYesShares &&
side === 'YES' &&
`${formatMoney(saleValueOfShares)}`}
{saleValueOfShares > 0.1 &&
hasNoShares &&
side === 'NO' &&
`${formatMoney(saleValueOfShares)}`}
</div>
)}
<Button <Button
size={'lg'} size={'lg'}
onClick={() => placeQuickBet()} onClick={() => placeQuickBet()}
@ -99,6 +124,7 @@ export function QuickBetButtons(props: {
> >
{side === 'YES' ? 'Yes' : 'No'} {side === 'YES' ? 'Yes' : 'No'}
</Button> </Button>
</Col>
) )
} }