Properly fill probs on DPMM bets (#480)
* Properly fill probs on DPMM bets * Remove unused import
This commit is contained in:
parent
15882904eb
commit
f1c3914807
|
@ -1,8 +1,8 @@
|
||||||
import { Bet } from './bet'
|
import { Bet } from './bet'
|
||||||
import {
|
import {
|
||||||
getDpmProbability,
|
|
||||||
calculateDpmShareValue,
|
calculateDpmShareValue,
|
||||||
deductDpmFees,
|
deductDpmFees,
|
||||||
|
getDpmOutcomeProbability,
|
||||||
} from './calculate-dpm'
|
} from './calculate-dpm'
|
||||||
import { calculateCpmmSale, getCpmmProbability } from './calculate-cpmm'
|
import { calculateCpmmSale, getCpmmProbability } from './calculate-cpmm'
|
||||||
import { CPMMContract, DPMContract } from './contract'
|
import { CPMMContract, DPMContract } from './contract'
|
||||||
|
@ -25,8 +25,8 @@ export const getSellBetInfo = (bet: Bet, contract: DPMContract) => {
|
||||||
|
|
||||||
const newTotalBets = { ...totalBets, [outcome]: totalBets[outcome] - amount }
|
const newTotalBets = { ...totalBets, [outcome]: totalBets[outcome] - amount }
|
||||||
|
|
||||||
const probBefore = getDpmProbability(totalShares)
|
const probBefore = getDpmOutcomeProbability(totalShares, outcome)
|
||||||
const probAfter = getDpmProbability(newTotalShares)
|
const probAfter = getDpmOutcomeProbability(newTotalShares, outcome)
|
||||||
|
|
||||||
const profit = adjShareValue - amount
|
const profit = adjShareValue - amount
|
||||||
|
|
||||||
|
|
|
@ -45,20 +45,14 @@ export function FeedAnswerCommentGroup(props: {
|
||||||
const answerElementId = `answer-${answer.id}`
|
const answerElementId = `answer-${answer.id}`
|
||||||
const betsByUserId = groupBy(bets, (bet) => bet.userId)
|
const betsByUserId = groupBy(bets, (bet) => bet.userId)
|
||||||
const commentsByUserId = groupBy(comments, (comment) => comment.userId)
|
const commentsByUserId = groupBy(comments, (comment) => comment.userId)
|
||||||
const answerComments = comments.filter(
|
const commentsList = comments.filter(
|
||||||
(comment) => comment.answerOutcome === answer.number.toString()
|
(comment) => comment.answerOutcome === answer.number.toString()
|
||||||
)
|
)
|
||||||
const commentReplies = comments.filter(
|
const thisAnswerProb =
|
||||||
(comment) =>
|
bets
|
||||||
comment.replyToCommentId &&
|
.filter((b) => b.outcome === answer.number.toString())
|
||||||
!comment.answerOutcome &&
|
.sort((a, b) => b.createdTime - a.createdTime)[0]?.probAfter ||
|
||||||
answerComments.map((c) => c.id).includes(comment.replyToCommentId)
|
getDpmOutcomeProbability(contract.totalShares, answer.id)
|
||||||
)
|
|
||||||
const commentsList = answerComments.concat(commentReplies)
|
|
||||||
const thisAnswerProb = getDpmOutcomeProbability(
|
|
||||||
contract.totalShares,
|
|
||||||
answer.id
|
|
||||||
)
|
|
||||||
const probPercent = formatPercent(thisAnswerProb)
|
const probPercent = formatPercent(thisAnswerProb)
|
||||||
const betsByCurrentUser = (user && betsByUserId[user.id]) ?? []
|
const betsByCurrentUser = (user && betsByUserId[user.id]) ?? []
|
||||||
const commentsByCurrentUser = (user && commentsByUserId[user.id]) ?? []
|
const commentsByCurrentUser = (user && commentsByUserId[user.id]) ?? []
|
||||||
|
@ -111,18 +105,15 @@ export function FeedAnswerCommentGroup(props: {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Only show one comment input for a bet at a time
|
// Only show one comment input for a bet at a time
|
||||||
const usersMostRecentBet = bets
|
|
||||||
.filter((b) => b.userId === user?.id)
|
|
||||||
.sort((a, b) => b.createdTime - a.createdTime)
|
|
||||||
if (
|
if (
|
||||||
usersMostRecentBet.length > 1 &&
|
betsByCurrentUser.length > 1 &&
|
||||||
usersMostRecentBet[0].outcome !== answer.number.toString()
|
betsByCurrentUser.sort((a, b) => b.createdTime - a.createdTime)[0]
|
||||||
) {
|
?.outcome !== answer.number.toString()
|
||||||
|
)
|
||||||
setShowReply(false)
|
setShowReply(false)
|
||||||
}
|
// Even if we pass memoized bets this still runs on every render, which we don't want
|
||||||
// if we pass memoized bets this still runs on every render, which we don't want
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [bets.length, user, answer.number])
|
}, [betsByCurrentUser.length, user, answer.number])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (showReply && inputRef) inputRef.focus()
|
if (showReply && inputRef) inputRef.focus()
|
||||||
|
@ -135,7 +126,7 @@ export function FeedAnswerCommentGroup(props: {
|
||||||
}, [answerElementId, router.asPath])
|
}, [answerElementId, router.asPath])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Col className={'relative flex-1 gap-2'}>
|
<Col className={'relative flex-1 gap-2'} key={answer.id + 'comment'}>
|
||||||
<Modal open={open} setOpen={setOpen}>
|
<Modal open={open} setOpen={setOpen}>
|
||||||
<AnswerBetPanel
|
<AnswerBetPanel
|
||||||
answer={answer}
|
answer={answer}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user