parent
9fbd521732
commit
d6c7230d6a
web/components
|
@ -11,6 +11,11 @@ import { AnswerItem } from './answer-item'
|
|||
import { CreateAnswerPanel } from './create-answer-panel'
|
||||
import { AnswerResolvePanel } from './answer-resolve-panel'
|
||||
import { Spacer } from '../layout/spacer'
|
||||
import { FeedItems } from '../feed/feed-items'
|
||||
import { ActivityItem } from '../feed/activity-items'
|
||||
import { User } from '../../../common/user'
|
||||
import { getOutcomeProbability } from '../../../common/calculate'
|
||||
import { Answer } from '../../../common/answer'
|
||||
|
||||
export function AnswersPanel(props: {
|
||||
contract: FullContract<DPM, FreeResponse>
|
||||
|
@ -47,6 +52,8 @@ export function AnswersPanel(props: {
|
|||
|
||||
const chosenTotal = _.sum(Object.values(chosenAnswers))
|
||||
|
||||
const answerItems = getAnswers(contract, user)
|
||||
|
||||
const onChoose = (answerId: string, prob: number) => {
|
||||
if (resolveOption === 'CHOOSE') {
|
||||
setChosenAnswers({ [answerId]: prob })
|
||||
|
@ -102,6 +109,15 @@ export function AnswersPanel(props: {
|
|||
<div className="pb-4 text-gray-500">No answers yet...</div>
|
||||
)}
|
||||
|
||||
{!resolveOption && sortedAnswers.length > 0 && (
|
||||
<FeedItems
|
||||
contract={contract}
|
||||
items={answerItems}
|
||||
className={''}
|
||||
betRowClassName={''}
|
||||
/>
|
||||
)}
|
||||
|
||||
{tradingAllowed(contract) &&
|
||||
(!resolveOption || resolveOption === 'CANCEL') && (
|
||||
<CreateAnswerPanel contract={contract} />
|
||||
|
@ -121,3 +137,32 @@ export function AnswersPanel(props: {
|
|||
</Col>
|
||||
)
|
||||
}
|
||||
|
||||
function getAnswers(
|
||||
contract: FullContract<DPM, FreeResponse>,
|
||||
user: User | undefined | null
|
||||
) {
|
||||
const { answers } = contract
|
||||
|
||||
let outcomes = _.uniq(
|
||||
answers.map((answer) => answer.number.toString())
|
||||
).filter((outcome) => getOutcomeProbability(contract, outcome) > 0.0001)
|
||||
outcomes = _.sortBy(outcomes, (outcome) =>
|
||||
getOutcomeProbability(contract, outcome)
|
||||
).reverse()
|
||||
|
||||
return outcomes
|
||||
.map((outcome) => {
|
||||
const answer = answers.find((answer) => answer.id === outcome) as Answer
|
||||
//unnecessary
|
||||
return {
|
||||
id: outcome,
|
||||
type: 'answer' as const,
|
||||
contract,
|
||||
answer,
|
||||
items: [] as ActivityItem[],
|
||||
user,
|
||||
}
|
||||
})
|
||||
.filter((group) => group.answer)
|
||||
}
|
||||
|
|
|
@ -256,38 +256,6 @@ function getAnswerGroups(
|
|||
return answerGroups
|
||||
}
|
||||
|
||||
function getAnswers(
|
||||
contract: FullContract<DPM, FreeResponse>,
|
||||
bets: Bet[],
|
||||
user: User | undefined | null
|
||||
) {
|
||||
let outcomes = _.uniq(bets.map((bet) => bet.outcome)).filter(
|
||||
(outcome) => getOutcomeProbability(contract, outcome) > 0.0001
|
||||
)
|
||||
outcomes = _.sortBy(outcomes, (outcome) =>
|
||||
getOutcomeProbability(contract, outcome)
|
||||
)
|
||||
|
||||
const answerGroups = outcomes
|
||||
.map((outcome) => {
|
||||
const answer = contract.answers?.find(
|
||||
(answer) => answer.id === outcome
|
||||
) as Answer
|
||||
|
||||
return {
|
||||
id: outcome,
|
||||
type: 'answer' as const,
|
||||
contract,
|
||||
answer,
|
||||
items: [] as ActivityItem[],
|
||||
user,
|
||||
}
|
||||
})
|
||||
.filter((group) => group.answer)
|
||||
|
||||
return answerGroups
|
||||
}
|
||||
|
||||
function groupBetsAndComments(
|
||||
bets: Bet[],
|
||||
comments: Comment[],
|
||||
|
@ -387,10 +355,6 @@ export function getAllContractActivityItems(
|
|||
commentsByBetId,
|
||||
contract,
|
||||
})
|
||||
|
||||
items.push(
|
||||
...getAnswers(contract as FullContract<DPM, FreeResponse>, bets, user)
|
||||
)
|
||||
} else {
|
||||
items.push(
|
||||
...groupBetsAndComments(bets, comments, contract, user?.id, {
|
||||
|
|
Loading…
Reference in New Issue
Block a user