From cc55a10b197792a7b9082262964897fa92a794a0 Mon Sep 17 00:00:00 2001 From: Marshall Polaris Date: Tue, 20 Sep 2022 15:39:34 -0700 Subject: [PATCH] Make comment position calculation more robust --- common/calculate.ts | 19 ++++++------------- web/components/feed/feed-comments.tsx | 2 +- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/common/calculate.ts b/common/calculate.ts index 5edf1211..156f95ea 100644 --- a/common/calculate.ts +++ b/common/calculate.ts @@ -257,11 +257,6 @@ export function getTopAnswer( } export function getLargestPosition(contract: Contract, userBets: Bet[]) { - let yesFloorShares = 0, - yesShares = 0, - noShares = 0, - noFloorShares = 0 - if (userBets.length === 0) { return null } @@ -286,12 +281,10 @@ export function getLargestPosition(contract: Contract, userBets: Bet[]) { } const [yesBets, noBets] = partition(userBets, (bet) => bet.outcome === 'YES') - yesShares = sumBy(yesBets, (bet) => bet.shares) - noShares = sumBy(noBets, (bet) => bet.shares) - yesFloorShares = Math.floor(yesShares) - noFloorShares = Math.floor(noShares) - - const shares = yesFloorShares || noFloorShares - const outcome = yesFloorShares > noFloorShares ? 'YES' : 'NO' - return { shares, outcome } + const yesShares = sumBy(yesBets, (bet) => bet.shares) + const noShares = sumBy(noBets, (bet) => bet.shares) + return { + shares: Math.abs(yesShares - noShares), + outcome: yesShares > noShares ? 'YES' : 'NO', + } } diff --git a/web/components/feed/feed-comments.tsx b/web/components/feed/feed-comments.tsx index 027b377f..d499be70 100644 --- a/web/components/feed/feed-comments.tsx +++ b/web/components/feed/feed-comments.tsx @@ -134,7 +134,7 @@ export function FeedComment(props: { commenterPositionProb != null && commenterPositionOutcome != null && commenterPositionShares != null && - commenterPositionShares > 0 && + Math.floor(commenterPositionShares) > 0 && contract.outcomeType !== 'NUMERIC' && ( <> {'is '}