Style improvements

This commit is contained in:
Ian Philips 2022-04-29 14:45:53 -06:00
parent 5f5e7a63f5
commit c13c02f8c0
2 changed files with 14 additions and 16 deletions

View File

@ -316,17 +316,7 @@ function getCommentsWithPositions(
comments: Comment[], comments: Comment[],
contract: Contract contract: Contract
) { ) {
function mapBetsByUserId(bets: Bet[]) { const betsByUserId = _.groupBy(bets, (bet) => bet.userId)
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 items = comments.map((comment) => ({ const items = comments.map((comment) => ({
type: 'comment' as const, type: 'comment' as const,

View File

@ -156,7 +156,7 @@ export function FeedComment(props: {
} }
// Only calculated if they don't have a matching bet // Only calculated if they don't have a matching bet
const [userPosition, userPositionMoney, yesFloorShares, noFloorShares] = const { userPosition, userPositionMoney, yesFloorShares, noFloorShares } =
getBettorsPosition( getBettorsPosition(
contract, contract,
comment.createdTime, 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) getBettorsPosition(contract, Date.now(), bets)
return ( return (
@ -331,12 +331,20 @@ function getBettorsPosition(
yesShares = 0, yesShares = 0,
noShares = 0, noShares = 0,
noFloorShares = 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? // TODO: show which of the answers was their majority stake at time of comment for FR?
if (contract.outcomeType != 'BINARY') { if (contract.outcomeType != 'BINARY') {
return [0, 0, 0, 0] return emptyReturn
} }
if (bets.length === 0) { if (bets.length === 0) {
return [0, 0, 0, 0] return emptyReturn
} }
// Calculate the majority shares they had when they made the comment // Calculate the majority shares they had when they made the comment
@ -357,7 +365,7 @@ function getBettorsPosition(
yesFloorShares > noFloorShares ? 'YES' : 'NO' yesFloorShares > noFloorShares ? 'YES' : 'NO'
) )
const userPositionMoney = formatMoney(Math.abs(saleValue)) const userPositionMoney = formatMoney(Math.abs(saleValue))
return [userPosition, userPositionMoney, yesFloorShares, noFloorShares] return { userPosition, userPositionMoney, yesFloorShares, noFloorShares }
} }
export function FeedBet(props: { export function FeedBet(props: {