From c13c02f8c08469e9f78cd50b9e154296dc5fd2fc Mon Sep 17 00:00:00 2001 From: Ian Philips Date: Fri, 29 Apr 2022 14:45:53 -0600 Subject: [PATCH] Style improvements --- web/components/feed/activity-items.ts | 12 +----------- web/components/feed/feed-items.tsx | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/web/components/feed/activity-items.ts b/web/components/feed/activity-items.ts index fa8b15b9..413259c0 100644 --- a/web/components/feed/activity-items.ts +++ b/web/components/feed/activity-items.ts @@ -316,17 +316,7 @@ function getCommentsWithPositions( comments: Comment[], contract: Contract ) { - function mapBetsByUserId(bets: Bet[]) { - return bets.reduce((acc, bet) => { - const userId = bet.userId - if (!acc[userId]) { - acc[userId] = [] - } - acc[userId].push(bet) - return acc - }, {} as { [userId: string]: Bet[] }) - } - const betsByUserId = mapBetsByUserId(bets) + const betsByUserId = _.groupBy(bets, (bet) => bet.userId) const items = comments.map((comment) => ({ type: 'comment' as const, diff --git a/web/components/feed/feed-items.tsx b/web/components/feed/feed-items.tsx index 5b224d9d..2b8e71dc 100644 --- a/web/components/feed/feed-items.tsx +++ b/web/components/feed/feed-items.tsx @@ -156,7 +156,7 @@ export function FeedComment(props: { } // Only calculated if they don't have a matching bet - const [userPosition, userPositionMoney, yesFloorShares, noFloorShares] = + const { userPosition, userPositionMoney, yesFloorShares, noFloorShares } = getBettorsPosition( contract, comment.createdTime, @@ -257,7 +257,7 @@ export function CommentInput(props: { /> ) } - const [userPosition, userPositionMoney, yesFloorShares, noFloorShares] = + const { userPosition, userPositionMoney, yesFloorShares, noFloorShares } = getBettorsPosition(contract, Date.now(), bets) return ( @@ -331,12 +331,20 @@ function getBettorsPosition( yesShares = 0, noShares = 0, noFloorShares = 0 + + const emptyReturn = { + userPosition: 0, + userPositionMoney: 0, + yesFloorShares, + noFloorShares, + } + // TODO: show which of the answers was their majority stake at time of comment for FR? if (contract.outcomeType != 'BINARY') { - return [0, 0, 0, 0] + return emptyReturn } if (bets.length === 0) { - return [0, 0, 0, 0] + return emptyReturn } // Calculate the majority shares they had when they made the comment @@ -357,7 +365,7 @@ function getBettorsPosition( yesFloorShares > noFloorShares ? 'YES' : 'NO' ) const userPositionMoney = formatMoney(Math.abs(saleValue)) - return [userPosition, userPositionMoney, yesFloorShares, noFloorShares] + return { userPosition, userPositionMoney, yesFloorShares, noFloorShares } } export function FeedBet(props: {