bet.probAfter => getDpmOutcomeProb

This commit is contained in:
Ian Philips 2022-06-09 07:22:03 -06:00
parent f52b756163
commit 3d18b12ede

View File

@ -23,6 +23,7 @@ import { useRouter } from 'next/router'
import { groupBy } from 'lodash' import { groupBy } from 'lodash'
import { User } from 'common/user' import { User } from 'common/user'
import { useEvent } from 'web/hooks/use-event' import { useEvent } from 'web/hooks/use-event'
import { getDpmOutcomeProbability } from 'common/calculate-dpm'
export function FeedAnswerCommentGroup(props: { export function FeedAnswerCommentGroup(props: {
contract: any contract: any
@ -54,9 +55,10 @@ export function FeedAnswerCommentGroup(props: {
answerComments.map((c) => c.id).includes(comment.replyToCommentId) answerComments.map((c) => c.id).includes(comment.replyToCommentId)
) )
const commentsList = answerComments.concat(commentReplies) const commentsList = answerComments.concat(commentReplies)
const thisAnswerProb = bets const thisAnswerProb = getDpmOutcomeProbability(
.filter((bet) => bet.outcome === answer.number.toString()) contract.totalShares,
.sort((a, b) => b.createdTime - a.createdTime)[0].probAfter 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]) ?? []
@ -67,7 +69,7 @@ export function FeedAnswerCommentGroup(props: {
user, user,
answer.number.toString() answer.number.toString()
) )
const [mostRecentBetTimeAtLoad] = useState( const [usersMostRecentBetTimeAtLoad] = useState(
mostRecentCommentableBet?.createdTime ?? 0 mostRecentCommentableBet?.createdTime ?? 0
) )
@ -82,13 +84,13 @@ export function FeedAnswerCommentGroup(props: {
useEffect(() => { useEffect(() => {
if ( if (
mostRecentCommentableBet && mostRecentCommentableBet &&
mostRecentCommentableBet.createdTime > mostRecentBetTimeAtLoad && mostRecentCommentableBet.createdTime > usersMostRecentBetTimeAtLoad &&
!showReply !showReply
) )
scrollAndOpenReplyInput(undefined, answer) scrollAndOpenReplyInput(undefined, answer)
}, [ }, [
answer, answer,
mostRecentBetTimeAtLoad, usersMostRecentBetTimeAtLoad,
mostRecentCommentableBet, mostRecentCommentableBet,
scrollAndOpenReplyInput, scrollAndOpenReplyInput,
showReply, showReply,