Only show both comment & bet if they differ

This commit is contained in:
Austin Chen 2022-03-20 11:39:32 -07:00
parent bafe6135bc
commit 9dd16c9851

View File

@ -261,16 +261,11 @@ function ContractTopTrades(props: {
comments: Comment[] comments: Comment[]
}) { }) {
const { contract, bets, comments } = props const { contract, bets, comments } = props
const commentsById = _.keyBy(comments, 'id')
// Also find the highest-profit comment (by profit? by percent?). const betsById = _.keyBy(bets, 'id')
// This could be a resolved buy,
// Harder: a sold bet (have to link sold )
// (not sure how to account for CFMM share redemptions...?)
// If 'id2' is the sale of 'id1', both are logged with (id2 - id1) of profit // If 'id2' is the sale of 'id1', both are logged with (id2 - id1) of profit
// Otherwise, we record the profit at resolution time // Otherwise, we record the profit at resolution time
const commentsById = _.keyBy(comments, 'id')
const betsById = _.keyBy(bets, 'id')
const profitById: Record<string, number> = {} const profitById: Record<string, number> = {}
for (const bet of bets) { for (const bet of bets) {
if (bet.sale) { if (bet.sale) {
@ -284,43 +279,53 @@ function ContractTopTrades(props: {
} }
// Now find the betId with the highest profit // Now find the betId with the highest profit
const topBetId = _.sortBy(bets, (b) => -profitById[b.id])[0].id const topBetId = _.sortBy(bets, (b) => -profitById[b.id])[0]?.id
const topBettor = useUserById(betsById[topBetId].userId) const topBettor = useUserById(betsById[topBetId].userId)
// And also the betId of the comment with the highest profit // And also the commentId of the comment with the highest profit
const topCommentId = _.sortBy(comments, (c) => -profitById[c.id])[0].id const topCommentId = _.sortBy(comments, (c) => -profitById[c.betId])[0]?.id
// TODO: If they're the same, only show the comment; otherwise show both
return ( return (
<div className="mt-12 max-w-sm"> <div className="mt-12 max-w-sm">
<Title text="💬 Top comment" className="!mt-0" /> {topCommentId && (
<div className="relative flex items-start space-x-3"> <>
<FeedComment <Title text="💬 Proven correct" className="!mt-0" />
contract={contract} <div className="relative flex items-start space-x-3 rounded-md bg-gray-50 px-2 py-4">
comment={commentsById[topCommentId]} <FeedComment
bet={betsById[topCommentId]} contract={contract}
hideOutcome={false} comment={commentsById[topCommentId]}
truncate={false} bet={betsById[topCommentId]}
smallAvatar={false} hideOutcome={false}
/> truncate={false}
</div> smallAvatar={false}
<div className="mt-4 text-sm text-gray-600"> />
(And made {formatMoney(profitById[topCommentId] || 0)}) </div>
</div> <div className="mt-2 text-sm text-gray-500">
<Spacer h={16} /> {commentsById[topCommentId].userName} made{' '}
<Title text="💸 Top trade" className="!mt-0" /> {formatMoney(profitById[topCommentId] || 0)}!
<div className="relative flex items-start space-x-3"> </div>
<FeedBet <Spacer h={16} />
contract={contract} </>
bet={betsById[topBetId]} )}
hideOutcome={false}
smallAvatar={false} {/* If they're the same, only show the comment; otherwise show both */}
bettor={topBettor} {topBettor && topBetId !== topCommentId && (
/> <>
</div> <Title text="💸 Smartest money" className="!mt-0" />
<div className="mt-4 text-sm text-gray-600"> <div className="relative flex items-start space-x-3 rounded-md bg-gray-50 px-2 py-4">
(And made {formatMoney(profitById[topBetId] || 0)}) <FeedBet
</div> contract={contract}
bet={betsById[topBetId]}
hideOutcome={false}
smallAvatar={false}
bettor={topBettor}
/>
</div>
<div className="mt-2 text-sm text-gray-500">
{topBettor?.name} made {formatMoney(profitById[topBetId] || 0)}!
</div>
</>
)}
</div> </div>
) )
} }