Put sale value above quick bet button
This commit is contained in:
		
							parent
							
								
									b39e0f304f
								
							
						
					
					
						commit
						9ee7173305
					
				| 
						 | 
					@ -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"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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({
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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,14 +103,28 @@ export function QuickBetButtons(props: {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
    <Button
 | 
					    <Col>
 | 
				
			||||||
      size={'lg'}
 | 
					      {user && (
 | 
				
			||||||
      onClick={() => placeQuickBet()}
 | 
					        <div className={'min-w-sm mb-1 text-center text-sm text-gray-500'}>
 | 
				
			||||||
      color={side === 'YES' ? 'green' : 'red'}
 | 
					          {saleValueOfShares > 0.1 &&
 | 
				
			||||||
      className={props.className}
 | 
					            hasYesShares &&
 | 
				
			||||||
    >
 | 
					            side === 'YES' &&
 | 
				
			||||||
      {side === 'YES' ? 'Yes' : 'No'}
 | 
					            `${formatMoney(saleValueOfShares)}`}
 | 
				
			||||||
    </Button>
 | 
					          {saleValueOfShares > 0.1 &&
 | 
				
			||||||
 | 
					            hasNoShares &&
 | 
				
			||||||
 | 
					            side === 'NO' &&
 | 
				
			||||||
 | 
					            `${formatMoney(saleValueOfShares)}`}
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					      )}
 | 
				
			||||||
 | 
					      <Button
 | 
				
			||||||
 | 
					        size={'lg'}
 | 
				
			||||||
 | 
					        onClick={() => placeQuickBet()}
 | 
				
			||||||
 | 
					        color={side === 'YES' ? 'green' : 'red'}
 | 
				
			||||||
 | 
					        className={props.className}
 | 
				
			||||||
 | 
					      >
 | 
				
			||||||
 | 
					        {side === 'YES' ? 'Yes' : 'No'}
 | 
				
			||||||
 | 
					      </Button>
 | 
				
			||||||
 | 
					    </Col>
 | 
				
			||||||
  )
 | 
					  )
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user