diff --git a/common/sell-bet.ts b/common/sell-bet.ts index 2e75e4e7..6d487ff2 100644 --- a/common/sell-bet.ts +++ b/common/sell-bet.ts @@ -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 diff --git a/web/components/feed/feed-answer-comment-group.tsx b/web/components/feed/feed-answer-comment-group.tsx index 92d28153..c3c4289d 100644 --- a/web/components/feed/feed-answer-comment-group.tsx +++ b/web/components/feed/feed-answer-comment-group.tsx @@ -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 ( - +