Fix and clean up top comment stuff

This commit is contained in:
Marshall Polaris 2022-09-21 14:52:50 -07:00
parent 73fad2e34b
commit 91f92bd362

View File

@ -65,7 +65,6 @@ export function ContractTopTrades(props: { contract: Contract; bets: Bet[] }) {
const { contract, bets } = props const { contract, bets } = props
// todo: this stuff should be calced in DB at resolve time // todo: this stuff should be calced in DB at resolve time
const comments = useComments(contract.id) const comments = useComments(contract.id)
const commentsById = keyBy(comments, 'id')
const betsById = keyBy(bets, 'id') const betsById = keyBy(bets, 'id')
// 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
@ -86,29 +85,23 @@ export function ContractTopTrades(props: { contract: Contract; bets: Bet[] }) {
const topBetId = sortBy(bets, (b) => -profitById[b.id])[0]?.id const topBetId = sortBy(bets, (b) => -profitById[b.id])[0]?.id
const topBettor = betsById[topBetId]?.userName const topBettor = betsById[topBetId]?.userName
// And also the commentId of the comment with the highest profit // And also the comment with the highest profit
const topCommentId = sortBy( const topComment = sortBy(comments, (c) => c.betId && -profitById[c.betId])[0]
comments,
(c) => c.betId && -profitById[c.betId]
)[0]?.id
return ( return (
<div className="mt-12 max-w-sm"> <div className="mt-12 max-w-sm">
{topCommentId && profitById[topCommentId] > 0 && ( {topComment && profitById[topComment.id] > 0 && (
<> <>
<Title text="💬 Proven correct" className="!mt-0" /> <Title text="💬 Proven correct" className="!mt-0" />
<div className="relative flex items-start space-x-3 rounded-md bg-gray-50 px-2 py-4"> <div className="relative flex items-start space-x-3 rounded-md bg-gray-50 px-2 py-4">
<FeedComment <FeedComment contract={contract} comment={topComment} />
contract={contract}
comment={commentsById[topCommentId]}
/>
</div> </div>
<Spacer h={16} /> <Spacer h={16} />
</> </>
)} )}
{/* If they're the same, only show the comment; otherwise show both */} {/* If they're the same, only show the comment; otherwise show both */}
{topBettor && topBetId !== topCommentId && profitById[topBetId] > 0 && ( {topBettor && topBetId !== topComment?.betId && profitById[topBetId] > 0 && (
<> <>
<Title text="💸 Best bet" className="!mt-0" /> <Title text="💸 Best bet" className="!mt-0" />
<div className="relative flex items-start space-x-3 rounded-md bg-gray-50 px-2 py-4"> <div className="relative flex items-start space-x-3 rounded-md bg-gray-50 px-2 py-4">