Restrict bet panel / bet row to only CPMMBinaryContracts (all binary DPM are resolved)
This commit is contained in:
parent
0c2ab5e9d7
commit
613c4d9374
|
@ -4,7 +4,7 @@ import { partition, sumBy } from 'lodash'
|
|||
import { SwitchHorizontalIcon } from '@heroicons/react/solid'
|
||||
|
||||
import { useUser } from 'web/hooks/use-user'
|
||||
import { BinaryContract, CPMMBinaryContract } from 'common/contract'
|
||||
import { CPMMBinaryContract } from 'common/contract'
|
||||
import { Col } from './layout/col'
|
||||
import { Row } from './layout/row'
|
||||
import { Spacer } from './layout/spacer'
|
||||
|
@ -42,7 +42,7 @@ import { isIOS } from 'web/lib/util/device'
|
|||
import { ProbabilityInput } from './probability-input'
|
||||
|
||||
export function BetPanel(props: {
|
||||
contract: BinaryContract
|
||||
contract: CPMMBinaryContract
|
||||
className?: string
|
||||
}) {
|
||||
const { contract, className } = props
|
||||
|
@ -91,7 +91,7 @@ export function BetPanel(props: {
|
|||
}
|
||||
|
||||
export function BetPanelSwitcher(props: {
|
||||
contract: BinaryContract
|
||||
contract: CPMMBinaryContract
|
||||
className?: string
|
||||
title?: string // Set if BetPanel is on a feed modal
|
||||
selected?: 'YES' | 'NO'
|
||||
|
@ -170,19 +170,16 @@ export function BetPanelSwitcher(props: {
|
|||
text={tradeType === 'BUY' ? title ?? 'Place a trade' : 'Sell shares'}
|
||||
/>
|
||||
|
||||
{tradeType === 'SELL' &&
|
||||
mechanism == 'cpmm-1' &&
|
||||
user &&
|
||||
sharesOutcome && (
|
||||
<SellPanel
|
||||
contract={contract}
|
||||
shares={yesShares || noShares}
|
||||
sharesOutcome={sharesOutcome}
|
||||
user={user}
|
||||
userBets={userBets ?? []}
|
||||
onSellSuccess={onBetSuccess}
|
||||
/>
|
||||
)}
|
||||
{tradeType === 'SELL' && user && sharesOutcome && (
|
||||
<SellPanel
|
||||
contract={contract}
|
||||
shares={yesShares || noShares}
|
||||
sharesOutcome={sharesOutcome}
|
||||
user={user}
|
||||
userBets={userBets ?? []}
|
||||
onSellSuccess={onBetSuccess}
|
||||
/>
|
||||
)}
|
||||
|
||||
{tradeType === 'BUY' && (
|
||||
<BuyPanel
|
||||
|
@ -200,7 +197,7 @@ export function BetPanelSwitcher(props: {
|
|||
}
|
||||
|
||||
function BuyPanel(props: {
|
||||
contract: BinaryContract
|
||||
contract: CPMMBinaryContract
|
||||
user: User | null | undefined
|
||||
isLimitOrder?: boolean
|
||||
selected?: 'YES' | 'NO'
|
||||
|
@ -293,20 +290,12 @@ function BuyPanel(props: {
|
|||
const currentReturn = betAmount ? (currentPayout - betAmount) / betAmount : 0
|
||||
const currentReturnPercent = formatPercent(currentReturn)
|
||||
|
||||
const cpmmFees =
|
||||
contract.mechanism === 'cpmm-1' &&
|
||||
getCpmmLiquidityFee(contract, betAmount ?? 0, betChoice ?? 'YES').totalFees
|
||||
const cpmmFees = getCpmmLiquidityFee(
|
||||
contract,
|
||||
betAmount ?? 0,
|
||||
betChoice ?? 'YES'
|
||||
).totalFees
|
||||
|
||||
const dpmTooltip =
|
||||
contract.mechanism === 'dpm-2'
|
||||
? `Current payout for ${formatWithCommas(shares)} / ${formatWithCommas(
|
||||
shares +
|
||||
contract.totalShares[betChoice ?? 'YES'] -
|
||||
(contract.phantomShares
|
||||
? contract.phantomShares[betChoice ?? 'YES']
|
||||
: 0)
|
||||
)} ${betChoice ?? 'YES'} shares`
|
||||
: undefined
|
||||
return (
|
||||
<>
|
||||
<YesNoSelector
|
||||
|
@ -355,24 +344,9 @@ function BuyPanel(props: {
|
|||
<Row className="items-center justify-between gap-2 text-sm">
|
||||
<Row className="flex-nowrap items-center gap-2 whitespace-nowrap text-gray-500">
|
||||
<div>
|
||||
{contract.mechanism === 'dpm-2' ? (
|
||||
<>
|
||||
Estimated
|
||||
<br /> payout if{' '}
|
||||
<BinaryOutcomeLabel outcome={betChoice ?? 'YES'} />
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
Payout if <BinaryOutcomeLabel outcome={betChoice ?? 'YES'} />
|
||||
</>
|
||||
)}
|
||||
Payout if <BinaryOutcomeLabel outcome={betChoice ?? 'YES'} />
|
||||
</div>
|
||||
|
||||
{cpmmFees !== false && (
|
||||
<InfoTooltip text={`Includes ${formatMoney(cpmmFees)} in fees`} />
|
||||
)}
|
||||
|
||||
{dpmTooltip && <InfoTooltip text={dpmTooltip} />}
|
||||
<InfoTooltip text={`Includes ${formatMoney(cpmmFees)} in fees`} />
|
||||
</Row>
|
||||
<div>
|
||||
<span className="mr-2 whitespace-nowrap">
|
||||
|
|
|
@ -3,7 +3,7 @@ import clsx from 'clsx'
|
|||
|
||||
import { BetPanelSwitcher } from './bet-panel'
|
||||
import { YesNoSelector } from './yes-no-selector'
|
||||
import { BinaryContract } from 'common/contract'
|
||||
import { CPMMBinaryContract } from 'common/contract'
|
||||
import { Modal } from './layout/modal'
|
||||
import { SellButton } from './sell-button'
|
||||
import { useUser } from 'web/hooks/use-user'
|
||||
|
@ -12,7 +12,7 @@ import { useSaveShares } from './use-save-shares'
|
|||
|
||||
// Inline version of a bet panel. Opens BetPanel in a new modal.
|
||||
export default function BetRow(props: {
|
||||
contract: BinaryContract
|
||||
contract: CPMMBinaryContract
|
||||
className?: string
|
||||
btnClassName?: string
|
||||
betPanelClassName?: string
|
||||
|
|
|
@ -16,7 +16,7 @@ import { Bet } from 'common/bet'
|
|||
import { Comment } from 'common/comment'
|
||||
import BetRow from '../bet-row'
|
||||
import { AnswersGraph } from '../answers/answers-graph'
|
||||
import { Contract } from 'common/contract'
|
||||
import { Contract, CPMMBinaryContract } from 'common/contract'
|
||||
import { ContractDescription } from './contract-description'
|
||||
import { ContractDetails } from './contract-details'
|
||||
import { ShareMarket } from '../share-market'
|
||||
|
@ -63,7 +63,9 @@ export const ContractOverview = (props: {
|
|||
<Row className="items-center justify-between gap-4 xl:hidden">
|
||||
<BinaryResolutionOrChance contract={contract} />
|
||||
|
||||
{tradingAllowed(contract) && <BetRow contract={contract} />}
|
||||
{tradingAllowed(contract) && (
|
||||
<BetRow contract={contract as CPMMBinaryContract} />
|
||||
)}
|
||||
</Row>
|
||||
) : (
|
||||
outcomeType === 'FREE_RESPONSE' &&
|
||||
|
|
|
@ -35,7 +35,7 @@ import {
|
|||
TruncatedComment,
|
||||
} from 'web/components/feed/feed-comments'
|
||||
import { FeedBet, FeedBetGroup } from 'web/components/feed/feed-bets'
|
||||
import { NumericContract } from 'common/contract'
|
||||
import { CPMMBinaryContract, NumericContract } from 'common/contract'
|
||||
|
||||
export function FeedItems(props: {
|
||||
contract: Contract
|
||||
|
@ -68,7 +68,10 @@ export function FeedItems(props: {
|
|||
))}
|
||||
</div>
|
||||
{outcomeType === 'BINARY' && tradingAllowed(contract) && (
|
||||
<BetRow contract={contract} className={clsx('mb-2', betRowClassName)} />
|
||||
<BetRow
|
||||
contract={contract as CPMMBinaryContract}
|
||||
className={clsx('mb-2', betRowClassName)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
|
|
|
@ -39,6 +39,7 @@ import { FeedBet } from 'web/components/feed/feed-bets'
|
|||
import { useIsIframe } from 'web/hooks/use-is-iframe'
|
||||
import ContractEmbedPage from '../embed/[username]/[contractSlug]'
|
||||
import { useBets } from 'web/hooks/use-bets'
|
||||
import { CPMMBinaryContract } from 'common/contract'
|
||||
|
||||
export const getStaticProps = fromPropz(getStaticPropz)
|
||||
export async function getStaticPropz(props: {
|
||||
|
@ -142,7 +143,10 @@ export function ContractPageContent(
|
|||
(isNumeric ? (
|
||||
<NumericBetPanel className="hidden xl:flex" contract={contract} />
|
||||
) : (
|
||||
<BetPanel className="hidden xl:flex" contract={contract} />
|
||||
<BetPanel
|
||||
className="hidden xl:flex"
|
||||
contract={contract as CPMMBinaryContract}
|
||||
/>
|
||||
))}
|
||||
{allowResolve &&
|
||||
(isNumeric ? (
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Bet } from 'common/bet'
|
||||
import { Contract } from 'common/contract'
|
||||
import { Contract, CPMMBinaryContract } from 'common/contract'
|
||||
import { DOMAIN } from 'common/envs/constants'
|
||||
import { AnswersGraph } from 'web/components/answers/answers-graph'
|
||||
import BetRow from 'web/components/bet-row'
|
||||
|
@ -110,9 +110,10 @@ function ContractEmbed(props: { contract: Contract; bets: Bet[] }) {
|
|||
|
||||
{isBinary && (
|
||||
<Row className="items-center gap-4">
|
||||
{/* this fails typechecking, but it doesn't explode because we will
|
||||
never */}
|
||||
<BetRow contract={contract as any} betPanelClassName="scale-75" />
|
||||
<BetRow
|
||||
contract={contract as CPMMBinaryContract}
|
||||
betPanelClassName="scale-75"
|
||||
/>
|
||||
<BinaryResolutionOrChance contract={contract} />
|
||||
</Row>
|
||||
)}
|
||||
|
|
Loading…
Reference in New Issue
Block a user