Show current payout in bet panel! Abolish estimated max payout. Show shares in tooltip

This commit is contained in:
jahooma 2022-01-15 15:28:19 -06:00
parent 0069846335
commit 3f42991741
2 changed files with 35 additions and 43 deletions

View File

@ -18,14 +18,13 @@ import {
calculateShares, calculateShares,
getProbabilityAfterBet, getProbabilityAfterBet,
calculatePayoutAfterCorrectBet, calculatePayoutAfterCorrectBet,
calculateEstimatedWinnings,
} from '../../common/calculate' } from '../../common/calculate'
import { firebaseLogin } from '../lib/firebase/users' import { firebaseLogin } from '../lib/firebase/users'
import { OutcomeLabel } from './outcome-label'
import { AdvancedPanel } from './advanced-panel'
import { Bet } from '../../common/bet' import { Bet } from '../../common/bet'
import { placeBet } from '../lib/firebase/api-call' import { placeBet } from '../lib/firebase/api-call'
import { AmountInput } from './amount-input' import { AmountInput } from './amount-input'
import { InfoTooltip } from './info-tooltip'
import { OutcomeLabel } from './outcome-label'
export function BetPanel(props: { contract: Contract; className?: string }) { export function BetPanel(props: { contract: Contract; className?: string }) {
useEffect(() => { useEffect(() => {
@ -99,17 +98,16 @@ export function BetPanel(props: { contract: Contract; className?: string }) {
betChoice betChoice
) )
const estimatedWinnings = calculateEstimatedWinnings( const currentPayout = betAmount
contract.totalShares, ? calculatePayoutAfterCorrectBet(contract, {
outcome: betChoice,
amount: betAmount,
shares, shares,
betChoice } as Bet)
)
const estimatedReturn = betAmount
? (estimatedWinnings - betAmount) / betAmount
: 0 : 0
const estimatedReturnPercent = (estimatedReturn * 100).toFixed() + '%' const currentReturn = betAmount ? (currentPayout - betAmount) / betAmount : 0
const currentReturnPercent = (currentReturn * 100).toFixed() + '%'
return ( return (
<Col <Col
@ -127,7 +125,7 @@ export function BetPanel(props: { contract: Contract; className?: string }) {
onSelect={(choice) => onBetChoice(choice)} onSelect={(choice) => onBetChoice(choice)}
/> />
<div className="my-3 text-sm text-gray-500">Amount </div> <div className="my-3 text-sm text-gray-500 text-left">Amount </div>
<AmountInput <AmountInput
inputClassName="w-full" inputClassName="w-full"
amount={betAmount} amount={betAmount}
@ -146,39 +144,23 @@ export function BetPanel(props: { contract: Contract; className?: string }) {
<div>{formatPercent(resultProb)}</div> <div>{formatPercent(resultProb)}</div>
</Row> </Row>
<div className="mt-2 mb-1 text-sm text-gray-500"> <Row className="mt-2 mb-1 items-center gap-2 text-sm text-gray-500">
Estimated max payout Payout if <OutcomeLabel outcome={betChoice} />
</div> <InfoTooltip
text={`Current payout for ${formatWithCommas(
shares
)} / ${formatWithCommas(
shares +
contract.totalShares[betChoice] -
contract.phantomShares[betChoice]
)} ${betChoice} shares`}
/>
</Row>
<div> <div>
{formatMoney(estimatedWinnings)} &nbsp;{' '} {formatMoney(currentPayout)}
{estimatedWinnings ? <span>(+{estimatedReturnPercent})</span> : null} &nbsp; <span>(+{currentReturnPercent})</span>
</div> </div>
<AdvancedPanel>
<div className="mt-2 mb-1 text-sm text-gray-500">
<OutcomeLabel outcome={betChoice} /> shares
</div>
<div>
{formatWithCommas(shares)} of{' '}
{formatWithCommas(shares + contract.totalShares[betChoice])}
</div>
<div className="mt-2 mb-1 text-sm text-gray-500">
Current payout if <OutcomeLabel outcome={betChoice} />
</div>
<div>
{formatMoney(
betAmount
? calculatePayoutAfterCorrectBet(contract, {
outcome: betChoice,
amount: betAmount,
shares,
} as Bet)
: 0
)}
</div>
</AdvancedPanel>
<Spacer h={6} /> <Spacer h={6} />
{user ? ( {user ? (

View File

@ -0,0 +1,10 @@
import { InformationCircleIcon } from '@heroicons/react/solid'
export function InfoTooltip(props: { text: string }) {
const { text } = props
return (
<div className="tooltip" data-tip={text}>
<InformationCircleIcon className="h-5 w-5 text-gray-500" />
</div>
)
}