Show amount moved in probability
This commit is contained in:
parent
6551aa7ea4
commit
2373f8e009
|
@ -6,7 +6,6 @@ import {
|
||||||
Contract,
|
Contract,
|
||||||
contractPath,
|
contractPath,
|
||||||
getBinaryProbPercent,
|
getBinaryProbPercent,
|
||||||
listenForContract,
|
|
||||||
} from 'web/lib/firebase/contracts'
|
} from 'web/lib/firebase/contracts'
|
||||||
import { Col } from '../layout/col'
|
import { Col } from '../layout/col'
|
||||||
import {
|
import {
|
||||||
|
@ -26,7 +25,6 @@ import {
|
||||||
import { getOutcomeProbability, getTopAnswer } from 'common/calculate'
|
import { getOutcomeProbability, getTopAnswer } from 'common/calculate'
|
||||||
import { AvatarDetails, MiscDetails } from './contract-details'
|
import { AvatarDetails, MiscDetails } from './contract-details'
|
||||||
import { getExpectedValue, getValueFromBucket } from 'common/calculate-dpm'
|
import { getExpectedValue, getValueFromBucket } from 'common/calculate-dpm'
|
||||||
import { useEffect, useState } from 'react'
|
|
||||||
import { QuickBet, QuickOutcomeView, ProbBar, getColor } from './quick-bet'
|
import { QuickBet, QuickOutcomeView, ProbBar, getColor } from './quick-bet'
|
||||||
import { useContractWithPreload } from 'web/hooks/use-contract'
|
import { useContractWithPreload } from 'web/hooks/use-contract'
|
||||||
|
|
||||||
|
@ -107,8 +105,9 @@ export function BinaryResolutionOrChance(props: {
|
||||||
large?: boolean
|
large?: boolean
|
||||||
className?: string
|
className?: string
|
||||||
hideText?: boolean
|
hideText?: boolean
|
||||||
|
override?: string
|
||||||
}) {
|
}) {
|
||||||
const { contract, large, className, hideText } = props
|
const { contract, large, className, hideText, override } = props
|
||||||
const { resolution } = contract
|
const { resolution } = contract
|
||||||
const textColor = `text-${getColor(contract)}`
|
const textColor = `text-${getColor(contract)}`
|
||||||
|
|
||||||
|
@ -128,7 +127,9 @@ export function BinaryResolutionOrChance(props: {
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<div className={textColor}>{getBinaryProbPercent(contract)}</div>
|
<div className={clsx(textColor, 'transition-all')}>
|
||||||
|
{override ?? getBinaryProbPercent(contract)}
|
||||||
|
</div>
|
||||||
{!hideText && (
|
{!hideText && (
|
||||||
<div className={clsx(textColor, large ? 'text-xl' : 'text-base')}>
|
<div className={clsx(textColor, large ? 'text-xl' : 'text-base')}>
|
||||||
chance
|
chance
|
||||||
|
@ -163,8 +164,9 @@ export function FreeResponseResolutionOrChance(props: {
|
||||||
truncate: 'short' | 'long' | 'none'
|
truncate: 'short' | 'long' | 'none'
|
||||||
className?: string
|
className?: string
|
||||||
hideText?: boolean
|
hideText?: boolean
|
||||||
|
override?: string
|
||||||
}) {
|
}) {
|
||||||
const { contract, truncate, className, hideText } = props
|
const { contract, truncate, className, hideText, override } = props
|
||||||
const { resolution } = contract
|
const { resolution } = contract
|
||||||
|
|
||||||
const topAnswer = getTopAnswer(contract)
|
const topAnswer = getTopAnswer(contract)
|
||||||
|
@ -187,7 +189,8 @@ export function FreeResponseResolutionOrChance(props: {
|
||||||
<Row className="items-center gap-6">
|
<Row className="items-center gap-6">
|
||||||
<Col className={clsx('text-3xl', textColor)}>
|
<Col className={clsx('text-3xl', textColor)}>
|
||||||
<div>
|
<div>
|
||||||
{formatPercent(getOutcomeProbability(contract, topAnswer.id))}
|
{override ??
|
||||||
|
formatPercent(getOutcomeProbability(contract, topAnswer.id))}
|
||||||
</div>
|
</div>
|
||||||
{!hideText && <div className="text-base">chance</div>}
|
{!hideText && <div className="text-base">chance</div>}
|
||||||
</Col>
|
</Col>
|
||||||
|
@ -202,8 +205,9 @@ export function NumericResolutionOrExpectation(props: {
|
||||||
contract: NumericContract
|
contract: NumericContract
|
||||||
className?: string
|
className?: string
|
||||||
hideText?: boolean
|
hideText?: boolean
|
||||||
|
override?: string
|
||||||
}) {
|
}) {
|
||||||
const { contract, className, hideText } = props
|
const { contract, className, hideText, override } = props
|
||||||
const { resolution } = contract
|
const { resolution } = contract
|
||||||
const textColor = `text-${getColor(contract)}`
|
const textColor = `text-${getColor(contract)}`
|
||||||
|
|
||||||
|
@ -220,7 +224,7 @@ export function NumericResolutionOrExpectation(props: {
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<div className={clsx('text-3xl', textColor)}>
|
<div className={clsx('text-3xl', textColor)}>
|
||||||
{formatLargeNumber(getExpectedValue(contract))}
|
{override ?? formatLargeNumber(getExpectedValue(contract))}
|
||||||
</div>
|
</div>
|
||||||
{!hideText && (
|
{!hideText && (
|
||||||
<div className={clsx('text-base', textColor)}>expected</div>
|
<div className={clsx('text-base', textColor)}>expected</div>
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
import clsx from 'clsx'
|
import clsx from 'clsx'
|
||||||
import { getOutcomeProbability, getTopAnswer } from 'common/calculate'
|
import {
|
||||||
|
getOutcomeProbability,
|
||||||
|
getOutcomeProbabilityAfterBet,
|
||||||
|
getTopAnswer,
|
||||||
|
} from 'common/calculate'
|
||||||
import { getExpectedValue } from 'common/calculate-dpm'
|
import { getExpectedValue } from 'common/calculate-dpm'
|
||||||
import {
|
import {
|
||||||
Contract,
|
Contract,
|
||||||
|
@ -10,7 +14,8 @@ import {
|
||||||
NumericContract,
|
NumericContract,
|
||||||
FreeResponse,
|
FreeResponse,
|
||||||
} from 'common/contract'
|
} from 'common/contract'
|
||||||
import { formatMoney } from 'common/util/format'
|
import { formatMoney, formatPercent } from 'common/util/format'
|
||||||
|
import { useState } from 'react'
|
||||||
import toast from 'react-hot-toast'
|
import toast from 'react-hot-toast'
|
||||||
import { useUser } from 'web/hooks/use-user'
|
import { useUser } from 'web/hooks/use-user'
|
||||||
import { useUserContractBets } from 'web/hooks/use-user-bets'
|
import { useUserContractBets } from 'web/hooks/use-user-bets'
|
||||||
|
@ -42,6 +47,34 @@ export function QuickBet(props: { contract: Contract }) {
|
||||||
const hasDownShares =
|
const hasDownShares =
|
||||||
contract.outcomeType === 'BINARY' ? noFloorShares : yesFloorShares
|
contract.outcomeType === 'BINARY' ? noFloorShares : yesFloorShares
|
||||||
|
|
||||||
|
// TODO: Consider making up/down two different components, for code reuse?
|
||||||
|
const [upHover, setUpHover] = useState(false)
|
||||||
|
const [downHover, setDownHover] = useState(false)
|
||||||
|
|
||||||
|
let override
|
||||||
|
try {
|
||||||
|
override = upHover
|
||||||
|
? formatPercent(
|
||||||
|
getOutcomeProbabilityAfterBet(
|
||||||
|
contract,
|
||||||
|
quickOutcome(contract, 'UP') || '',
|
||||||
|
10
|
||||||
|
)
|
||||||
|
)
|
||||||
|
: downHover
|
||||||
|
? formatPercent(
|
||||||
|
1 -
|
||||||
|
getOutcomeProbabilityAfterBet(
|
||||||
|
contract,
|
||||||
|
quickOutcome(contract, 'DOWN') || '',
|
||||||
|
10
|
||||||
|
)
|
||||||
|
)
|
||||||
|
: undefined
|
||||||
|
} catch (e) {
|
||||||
|
// Catch any errors from hovering on an invalid option
|
||||||
|
}
|
||||||
|
|
||||||
const color = getColor(contract)
|
const color = getColor(contract)
|
||||||
|
|
||||||
async function placeQuickBet(direction: 'UP' | 'DOWN') {
|
async function placeQuickBet(direction: 'UP' | 'DOWN') {
|
||||||
|
@ -91,6 +124,8 @@ export function QuickBet(props: { contract: Contract }) {
|
||||||
<div>
|
<div>
|
||||||
<div
|
<div
|
||||||
className="peer absolute top-0 left-0 right-0 h-[50%]"
|
className="peer absolute top-0 left-0 right-0 h-[50%]"
|
||||||
|
onMouseEnter={() => setUpHover(true)}
|
||||||
|
onMouseLeave={() => setUpHover(false)}
|
||||||
onClick={() => placeQuickBet('UP')}
|
onClick={() => placeQuickBet('UP')}
|
||||||
></div>
|
></div>
|
||||||
<div className="mt-2 text-center text-xs text-transparent peer-hover:text-gray-400">
|
<div className="mt-2 text-center text-xs text-transparent peer-hover:text-gray-400">
|
||||||
|
@ -109,12 +144,14 @@ export function QuickBet(props: { contract: Contract }) {
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<QuickOutcomeView contract={contract} />
|
<QuickOutcomeView contract={contract} override={override} />
|
||||||
|
|
||||||
{/* Down bet triangle */}
|
{/* Down bet triangle */}
|
||||||
<div>
|
<div>
|
||||||
<div
|
<div
|
||||||
className="peer absolute bottom-0 left-0 right-0 h-[50%]"
|
className="peer absolute bottom-0 left-0 right-0 h-[50%]"
|
||||||
|
onMouseEnter={() => setDownHover(true)}
|
||||||
|
onMouseLeave={() => setDownHover(false)}
|
||||||
onClick={() => placeQuickBet('DOWN')}
|
onClick={() => placeQuickBet('DOWN')}
|
||||||
></div>
|
></div>
|
||||||
{hasDownShares > 0 ? (
|
{hasDownShares > 0 ? (
|
||||||
|
@ -161,8 +198,13 @@ export function ProbBar(props: { contract: Contract }) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function QuickOutcomeView(props: { contract: Contract }) {
|
// TODO: just directly code in the outcomes for quick bet, rather than relying on
|
||||||
const { contract } = props
|
// code resuse. Too many differences anyways
|
||||||
|
export function QuickOutcomeView(props: {
|
||||||
|
contract: Contract
|
||||||
|
override?: string
|
||||||
|
}) {
|
||||||
|
const { contract, override } = props
|
||||||
const { outcomeType } = contract
|
const { outcomeType } = contract
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -171,6 +213,7 @@ export function QuickOutcomeView(props: { contract: Contract }) {
|
||||||
className="items-center"
|
className="items-center"
|
||||||
contract={contract}
|
contract={contract}
|
||||||
hideText
|
hideText
|
||||||
|
override={override}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
@ -179,6 +222,7 @@ export function QuickOutcomeView(props: { contract: Contract }) {
|
||||||
className="items-center"
|
className="items-center"
|
||||||
contract={contract as NumericContract}
|
contract={contract as NumericContract}
|
||||||
hideText
|
hideText
|
||||||
|
override={override}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
@ -188,6 +232,7 @@ export function QuickOutcomeView(props: { contract: Contract }) {
|
||||||
contract={contract as FullContract<DPM, FreeResponse>}
|
contract={contract as FullContract<DPM, FreeResponse>}
|
||||||
truncate="long"
|
truncate="long"
|
||||||
hideText
|
hideText
|
||||||
|
override={override}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user