Buy panel only non-limit orders
This commit is contained in:
parent
529165147c
commit
8fa9637a6b
|
@ -25,23 +25,15 @@ import { getProbability } from 'common/calculate'
|
||||||
import { useFocus } from 'web/hooks/use-focus'
|
import { useFocus } from 'web/hooks/use-focus'
|
||||||
import { useUserContractBets } from 'web/hooks/use-user-bets'
|
import { useUserContractBets } from 'web/hooks/use-user-bets'
|
||||||
import { calculateCpmmSale, getCpmmProbability } from 'common/calculate-cpmm'
|
import { calculateCpmmSale, getCpmmProbability } from 'common/calculate-cpmm'
|
||||||
import {
|
import { getFormattedMappedValue } from 'common/pseudo-numeric'
|
||||||
getFormattedMappedValue,
|
|
||||||
getPseudoProbability,
|
|
||||||
} from 'common/pseudo-numeric'
|
|
||||||
import { SellRow } from './sell-row'
|
import { SellRow } from './sell-row'
|
||||||
import { useSaveBinaryShares } from './use-save-binary-shares'
|
import { useSaveBinaryShares } from './use-save-binary-shares'
|
||||||
import { SignUpPrompt } from './sign-up-prompt'
|
import { SignUpPrompt } from './sign-up-prompt'
|
||||||
import { isIOS } from 'web/lib/util/device'
|
import { isIOS } from 'web/lib/util/device'
|
||||||
import {
|
import { ProbabilityOrNumericInput } from './probability-input'
|
||||||
ProbabilityInput,
|
|
||||||
ProbabilityOrNumericInput,
|
|
||||||
} from './probability-input'
|
|
||||||
import { track } from 'web/lib/service/analytics'
|
import { track } from 'web/lib/service/analytics'
|
||||||
import { removeUndefinedProps } from 'common/util/object'
|
|
||||||
import { useUnfilledBets } from 'web/hooks/use-bets'
|
import { useUnfilledBets } from 'web/hooks/use-bets'
|
||||||
import { LimitBets } from './limit-bets'
|
import { LimitBets } from './limit-bets'
|
||||||
import { BucketInput } from './bucket-input'
|
|
||||||
import { PillButton } from './buttons/pill-button'
|
import { PillButton } from './buttons/pill-button'
|
||||||
import { YesNoSelector } from './yes-no-selector'
|
import { YesNoSelector } from './yes-no-selector'
|
||||||
|
|
||||||
|
@ -75,21 +67,18 @@ export function BetPanel(props: {
|
||||||
isLimitOrder={isLimitOrder}
|
isLimitOrder={isLimitOrder}
|
||||||
setIsLimitOrder={setIsLimitOrder}
|
setIsLimitOrder={setIsLimitOrder}
|
||||||
/>
|
/>
|
||||||
{isLimitOrder ? (
|
|
||||||
<RangeOrderPanel
|
|
||||||
contract={contract}
|
|
||||||
user={user}
|
|
||||||
unfilledBets={unfilledBets}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<BuyPanel
|
<BuyPanel
|
||||||
|
hidden={isLimitOrder}
|
||||||
|
contract={contract}
|
||||||
|
user={user}
|
||||||
|
unfilledBets={unfilledBets}
|
||||||
|
/>
|
||||||
|
<LimitOrderPanel
|
||||||
|
hidden={!isLimitOrder}
|
||||||
contract={contract}
|
contract={contract}
|
||||||
user={user}
|
user={user}
|
||||||
isLimitOrder={isLimitOrder}
|
|
||||||
unfilledBets={unfilledBets}
|
unfilledBets={unfilledBets}
|
||||||
/>
|
/>
|
||||||
)}
|
|
||||||
|
|
||||||
<SignUpPrompt />
|
<SignUpPrompt />
|
||||||
</Col>
|
</Col>
|
||||||
{unfilledBets.length > 0 && (
|
{unfilledBets.length > 0 && (
|
||||||
|
@ -131,14 +120,20 @@ export function SimpleBetPanel(props: {
|
||||||
setIsLimitOrder={setIsLimitOrder}
|
setIsLimitOrder={setIsLimitOrder}
|
||||||
/>
|
/>
|
||||||
<BuyPanel
|
<BuyPanel
|
||||||
|
hidden={isLimitOrder}
|
||||||
contract={contract}
|
contract={contract}
|
||||||
user={user}
|
user={user}
|
||||||
unfilledBets={unfilledBets}
|
unfilledBets={unfilledBets}
|
||||||
selected={selected}
|
selected={selected}
|
||||||
onBuySuccess={onBetSuccess}
|
onBuySuccess={onBetSuccess}
|
||||||
isLimitOrder={isLimitOrder}
|
|
||||||
/>
|
/>
|
||||||
|
<LimitOrderPanel
|
||||||
|
hidden={!isLimitOrder}
|
||||||
|
contract={contract}
|
||||||
|
user={user}
|
||||||
|
unfilledBets={unfilledBets}
|
||||||
|
onBuySuccess={onBetSuccess}
|
||||||
|
/>
|
||||||
<SignUpPrompt />
|
<SignUpPrompt />
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
|
@ -153,21 +148,17 @@ function BuyPanel(props: {
|
||||||
contract: CPMMBinaryContract | PseudoNumericContract
|
contract: CPMMBinaryContract | PseudoNumericContract
|
||||||
user: User | null | undefined
|
user: User | null | undefined
|
||||||
unfilledBets: Bet[]
|
unfilledBets: Bet[]
|
||||||
isLimitOrder?: boolean
|
hidden: boolean
|
||||||
selected?: 'YES' | 'NO'
|
selected?: 'YES' | 'NO'
|
||||||
onBuySuccess?: () => void
|
onBuySuccess?: () => void
|
||||||
}) {
|
}) {
|
||||||
const { contract, user, unfilledBets, isLimitOrder, selected, onBuySuccess } =
|
const { contract, user, unfilledBets, hidden, selected, onBuySuccess } = props
|
||||||
props
|
|
||||||
|
|
||||||
const initialProb = getProbability(contract)
|
const initialProb = getProbability(contract)
|
||||||
const isPseudoNumeric = contract.outcomeType === 'PSEUDO_NUMERIC'
|
const isPseudoNumeric = contract.outcomeType === 'PSEUDO_NUMERIC'
|
||||||
|
|
||||||
const [betChoice, setBetChoice] = useState<'YES' | 'NO' | undefined>(selected)
|
const [betChoice, setBetChoice] = useState<'YES' | 'NO' | undefined>(selected)
|
||||||
const [betAmount, setBetAmount] = useState<number | undefined>(undefined)
|
const [betAmount, setBetAmount] = useState<number | undefined>(undefined)
|
||||||
const [limitProb, setLimitProb] = useState<number | undefined>(
|
|
||||||
Math.round(100 * initialProb)
|
|
||||||
)
|
|
||||||
const [error, setError] = useState<string | undefined>()
|
const [error, setError] = useState<string | undefined>()
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false)
|
const [isSubmitting, setIsSubmitting] = useState(false)
|
||||||
const [wasSubmitted, setWasSubmitted] = useState(false)
|
const [wasSubmitted, setWasSubmitted] = useState(false)
|
||||||
|
@ -197,22 +188,15 @@ function BuyPanel(props: {
|
||||||
|
|
||||||
async function submitBet() {
|
async function submitBet() {
|
||||||
if (!user || !betAmount) return
|
if (!user || !betAmount) return
|
||||||
if (isLimitOrder && limitProb === undefined) return
|
|
||||||
|
|
||||||
const limitProbScaled =
|
|
||||||
isLimitOrder && limitProb !== undefined ? limitProb / 100 : undefined
|
|
||||||
|
|
||||||
setError(undefined)
|
setError(undefined)
|
||||||
setIsSubmitting(true)
|
setIsSubmitting(true)
|
||||||
|
|
||||||
placeBet(
|
placeBet({
|
||||||
removeUndefinedProps({
|
|
||||||
amount: betAmount,
|
amount: betAmount,
|
||||||
outcome: betChoice,
|
outcome: betChoice,
|
||||||
contractId: contract.id,
|
contractId: contract.id,
|
||||||
limitProb: limitProbScaled,
|
|
||||||
})
|
})
|
||||||
)
|
|
||||||
.then((r) => {
|
.then((r) => {
|
||||||
console.log('placed bet. Result:', r)
|
console.log('placed bet. Result:', r)
|
||||||
setIsSubmitting(false)
|
setIsSubmitting(false)
|
||||||
|
@ -237,20 +221,17 @@ function BuyPanel(props: {
|
||||||
contractId: contract.id,
|
contractId: contract.id,
|
||||||
amount: betAmount,
|
amount: betAmount,
|
||||||
outcome: betChoice,
|
outcome: betChoice,
|
||||||
isLimitOrder,
|
isLimitOrder: false,
|
||||||
limitProb: limitProbScaled,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const betDisabled = isSubmitting || !betAmount || error
|
const betDisabled = isSubmitting || !betAmount || error
|
||||||
|
|
||||||
const limitProbFrac = (limitProb ?? 0) / 100
|
|
||||||
|
|
||||||
const { newPool, newP, newBet } = getBinaryCpmmBetInfo(
|
const { newPool, newP, newBet } = getBinaryCpmmBetInfo(
|
||||||
betChoice ?? 'YES',
|
betChoice ?? 'YES',
|
||||||
betAmount ?? 0,
|
betAmount ?? 0,
|
||||||
contract,
|
contract,
|
||||||
isLimitOrder ? limitProbFrac : undefined,
|
undefined,
|
||||||
unfilledBets as LimitBet[]
|
unfilledBets as LimitBet[]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -258,11 +239,7 @@ function BuyPanel(props: {
|
||||||
const probStayedSame =
|
const probStayedSame =
|
||||||
formatPercent(resultProb) === formatPercent(initialProb)
|
formatPercent(resultProb) === formatPercent(initialProb)
|
||||||
|
|
||||||
const remainingMatched = isLimitOrder
|
const currentPayout = newBet.shares
|
||||||
? ((newBet.orderAmount ?? 0) - newBet.amount) /
|
|
||||||
(betChoice === 'YES' ? limitProbFrac : 1 - limitProbFrac)
|
|
||||||
: 0
|
|
||||||
const currentPayout = newBet.shares + remainingMatched
|
|
||||||
|
|
||||||
const currentReturn = betAmount ? (currentPayout - betAmount) / betAmount : 0
|
const currentReturn = betAmount ? (currentPayout - betAmount) / betAmount : 0
|
||||||
const currentReturnPercent = formatPercent(currentReturn)
|
const currentReturnPercent = formatPercent(currentReturn)
|
||||||
|
@ -272,7 +249,7 @@ function BuyPanel(props: {
|
||||||
const format = getFormattedMappedValue(contract)
|
const format = getFormattedMappedValue(contract)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<Col className={hidden ? 'hidden' : ''}>
|
||||||
<div className="my-3 text-left text-sm text-gray-500">
|
<div className="my-3 text-left text-sm text-gray-500">
|
||||||
{isPseudoNumeric ? 'Direction' : 'Outcome'}
|
{isPseudoNumeric ? 'Direction' : 'Outcome'}
|
||||||
</div>
|
</div>
|
||||||
|
@ -294,46 +271,7 @@ function BuyPanel(props: {
|
||||||
disabled={isSubmitting}
|
disabled={isSubmitting}
|
||||||
inputRef={inputRef}
|
inputRef={inputRef}
|
||||||
/>
|
/>
|
||||||
{isLimitOrder && (
|
|
||||||
<>
|
|
||||||
<Row className="my-3 items-center gap-2 text-left text-sm text-gray-500">
|
|
||||||
Limit {isPseudoNumeric ? 'value' : 'probability'}
|
|
||||||
<InfoTooltip
|
|
||||||
text={`Bet ${betChoice === 'NO' ? 'down' : 'up'} to this ${
|
|
||||||
isPseudoNumeric ? 'value' : 'probability'
|
|
||||||
} and wait to match other bets.`}
|
|
||||||
/>
|
|
||||||
</Row>
|
|
||||||
{isPseudoNumeric ? (
|
|
||||||
<BucketInput
|
|
||||||
contract={contract}
|
|
||||||
onBucketChange={(value) =>
|
|
||||||
setLimitProb(
|
|
||||||
value === undefined
|
|
||||||
? undefined
|
|
||||||
: 100 *
|
|
||||||
getPseudoProbability(
|
|
||||||
value,
|
|
||||||
contract.min,
|
|
||||||
contract.max,
|
|
||||||
contract.isLogScale
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
isSubmitting={isSubmitting}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<ProbabilityInput
|
|
||||||
inputClassName="w-full max-w-none"
|
|
||||||
prob={limitProb}
|
|
||||||
onChange={setLimitProb}
|
|
||||||
disabled={isSubmitting}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
<Col className="mt-3 w-full gap-3">
|
<Col className="mt-3 w-full gap-3">
|
||||||
{!isLimitOrder && (
|
|
||||||
<Row className="items-center justify-between text-sm">
|
<Row className="items-center justify-between text-sm">
|
||||||
<div className="text-gray-500">
|
<div className="text-gray-500">
|
||||||
{isPseudoNumeric ? 'Estimated value' : 'Probability'}
|
{isPseudoNumeric ? 'Estimated value' : 'Probability'}
|
||||||
|
@ -348,7 +286,6 @@ function BuyPanel(props: {
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</Row>
|
</Row>
|
||||||
)}
|
|
||||||
|
|
||||||
<Row className="items-center justify-between gap-2 text-sm">
|
<Row className="items-center justify-between gap-2 text-sm">
|
||||||
<Row className="flex-nowrap items-center gap-2 whitespace-nowrap text-gray-500">
|
<Row className="flex-nowrap items-center gap-2 whitespace-nowrap text-gray-500">
|
||||||
|
@ -389,28 +326,23 @@ function BuyPanel(props: {
|
||||||
)}
|
)}
|
||||||
onClick={betDisabled ? undefined : submitBet}
|
onClick={betDisabled ? undefined : submitBet}
|
||||||
>
|
>
|
||||||
{isSubmitting
|
{isSubmitting ? 'Submitting...' : 'Submit bet'}
|
||||||
? 'Submitting...'
|
|
||||||
: isLimitOrder
|
|
||||||
? 'Submit order'
|
|
||||||
: 'Submit bet'}
|
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{wasSubmitted && (
|
{wasSubmitted && <div className="mt-4">Bet submitted!</div>}
|
||||||
<div className="mt-4">{isLimitOrder ? 'Order' : 'Bet'} submitted!</div>
|
</Col>
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function RangeOrderPanel(props: {
|
function LimitOrderPanel(props: {
|
||||||
contract: CPMMBinaryContract | PseudoNumericContract
|
contract: CPMMBinaryContract | PseudoNumericContract
|
||||||
user: User | null | undefined
|
user: User | null | undefined
|
||||||
unfilledBets: Bet[]
|
unfilledBets: Bet[]
|
||||||
|
hidden: boolean
|
||||||
onBuySuccess?: () => void
|
onBuySuccess?: () => void
|
||||||
}) {
|
}) {
|
||||||
const { contract, user, unfilledBets, onBuySuccess } = props
|
const { contract, user, unfilledBets, hidden, onBuySuccess } = props
|
||||||
|
|
||||||
const initialProb = getProbability(contract)
|
const initialProb = getProbability(contract)
|
||||||
const isPseudoNumeric = contract.outcomeType === 'PSEUDO_NUMERIC'
|
const isPseudoNumeric = contract.outcomeType === 'PSEUDO_NUMERIC'
|
||||||
|
@ -554,7 +486,7 @@ function RangeOrderPanel(props: {
|
||||||
const noReturnPercent = formatPercent(noReturn)
|
const noReturnPercent = formatPercent(noReturn)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<Col className={hidden ? 'hidden' : ''}>
|
||||||
<div className="my-3 text-sm text-gray-500">
|
<div className="my-3 text-sm text-gray-500">
|
||||||
Bet only when the {isPseudoNumeric ? 'value' : 'probability'} reaches
|
Bet only when the {isPseudoNumeric ? 'value' : 'probability'} reaches
|
||||||
Low or High limit.
|
Low or High limit.
|
||||||
|
@ -717,7 +649,7 @@ function RangeOrderPanel(props: {
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{wasSubmitted && <div className="mt-4">Order submitted!</div>}
|
{wasSubmitted && <div className="mt-4">Order submitted!</div>}
|
||||||
</>
|
</Col>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user