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