Skip to content

Commit

Permalink
Add binaryMC pseudonyms
Browse files Browse the repository at this point in the history
  • Loading branch information
IanPhilips committed Feb 5, 2025
1 parent a382662 commit e7214a2
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 55 deletions.
13 changes: 2 additions & 11 deletions web/components/answers/answer-components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { AnswerCpmmBetPanel } from './answer-bet-panel'
import { useSavedContractMetrics } from 'web/hooks/use-saved-contract-metrics'
import { ContractMetric } from 'common/contract-metric'
import { floatingEqual } from 'common/util/math'
import { getAnswerColor } from '../charts/contract/choice'
import { getAnswerColor, getPseudonym } from '../charts/contract/choice'

export const AnswerBar = (props: {
color: string // 6 digit hex
Expand Down Expand Up @@ -365,16 +365,7 @@ export const BinaryMultiSellRow = (props: {
sharesOutcome={sharesOutcome}
setOpen={setOpen}
answerId={getMainBinaryMCAnswer(contract)?.id}
binaryPseudonym={{
YES: {
pseudonymName: answer.text,
pseudonymColor: getAnswerColor(answer),
},
NO: {
pseudonymName: otherAnswer.text,
pseudonymColor: getAnswerColor(otherAnswer),
},
}}
binaryPseudonym={getPseudonym(contract)}
/>
)}
<Button
Expand Down
17 changes: 2 additions & 15 deletions web/components/bet/contract-bets-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { formatTimeShort } from 'client-common/lib/time'
import { Pagination } from '../widgets/pagination'
import { MoneyDisplay } from './money-display'
import { ContractMetric } from 'common/contract-metric'
import { getAnswerColor } from '../charts/contract/choice'
import { getPseudonym } from '../charts/contract/choice'

export function ContractBetsTable(props: {
contract: Contract
Expand Down Expand Up @@ -238,20 +238,7 @@ function BetRow(props: { bet: Bet; contract: Contract }) {
<BinaryOutcomeLabel outcome={outcome as any} />
) : (
<OutcomeLabel
pseudonym={
isBinaryMC
? {
YES: {
pseudonymName: mainBinaryMCAnswer?.text ?? '',
pseudonymColor: getAnswerColor(mainBinaryMCAnswer),
},
NO: {
pseudonymName: otherBinaryMCAnswer?.text ?? '',
pseudonymColor: getAnswerColor(otherBinaryMCAnswer),
},
}
: undefined
}
pseudonym={getPseudonym(contract)}
outcome={outcome}
contract={contract}
truncate="short"
Expand Down
19 changes: 2 additions & 17 deletions web/components/bet/order-book.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
CPMMMultiContract,
CPMMNumericContract,
getBinaryMCProb,
getMainBinaryMCAnswer,
isBinaryMulti,
MultiContract,
PseudoNumericContract,
Expand Down Expand Up @@ -45,7 +44,7 @@ import { MoneyDisplay } from './money-display'
import { MultipleOrSingleAvatars } from '../multiple-or-single-avatars'
import { DisplayUser } from 'common/api/user-types'
import { UserLink } from '../widgets/user-link'
import { getAnswerColor } from '../charts/contract/choice'
import { getPseudonym } from '../charts/contract/choice'

export function YourOrders(props: {
contract:
Expand Down Expand Up @@ -202,11 +201,6 @@ function OrderRow(props: {
await api('bet/cancel/:betId', { betId: bet.id })
setIsCancelling(false)
}
const mainBinaryMCAnswer = getMainBinaryMCAnswer(contract)
const otherBinaryMCAnswer =
'answers' in contract
? contract.answers.find((a) => a.id !== mainBinaryMCAnswer?.id)
: undefined
const isCashContract = contract.token === 'CASH'
const expired = bet.expiresAt && bet.expiresAt < Date.now()

Expand All @@ -232,16 +226,7 @@ function OrderRow(props: {
<PseudoNumericOutcomeLabel outcome={outcome as 'YES' | 'NO'} />
) : isBinaryMC ? (
<OutcomeLabel
pseudonym={{
YES: {
pseudonymName: mainBinaryMCAnswer?.text ?? '',
pseudonymColor: getAnswerColor(mainBinaryMCAnswer),
},
NO: {
pseudonymName: otherBinaryMCAnswer?.text ?? '',
pseudonymColor: getAnswerColor(otherBinaryMCAnswer),
},
}}
pseudonym={getPseudonym(contract)}
contract={contract}
outcome={outcome}
truncate={'short'}
Expand Down
22 changes: 22 additions & 0 deletions web/components/charts/contract/choice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import { getAnswerProbability, getContractBetMetrics } from 'common/calculate'
import { HistoryPoint, MultiPoints } from 'common/chart'
import { ChartPosition } from 'common/chart-position'
import {
Contract,
CPMMMultiContract,
CPMMNumericContract,
getMainBinaryMCAnswer,
isBinaryMulti,
MultiContract,
} from 'common/contract'
import { ChartAnnotation } from 'common/supabase/chart-annotations'
Expand Down Expand Up @@ -85,6 +88,25 @@ export function getAnswerColor(answer: Answer | undefined) {
return answer.isOther ? CHOICE_OTHER_COLOR : answer.color ?? nthColor(index)
}

export const getPseudonym = (contract: Contract) => {
if (!isBinaryMulti(contract) || !('answers' in contract)) return undefined
const mainBinaryMCAnswer = getMainBinaryMCAnswer(contract)
const otherBinaryMCAnswer = contract.answers.find(
(a) => a.id !== mainBinaryMCAnswer?.id
)

return {
YES: {
pseudonymName: mainBinaryMCAnswer?.text ?? '',
pseudonymColor: getAnswerColor(mainBinaryMCAnswer),
},
NO: {
pseudonymName: otherBinaryMCAnswer?.text ?? '',
pseudonymColor: getAnswerColor(otherBinaryMCAnswer),
},
}
}

const getAnswers = (contract: MultiContract) => {
const { answers, outcomeType } = contract
const validAnswers = (answers ?? []).filter(
Expand Down
3 changes: 3 additions & 0 deletions web/components/contract/user-positions-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { db } from 'web/lib/supabase/db'
import { MoneyDisplay } from '../bet/money-display'
import { UserHovercard } from '../user/user-hovercard'
import { Select } from '../widgets/select'
import { getPseudonym } from '../charts/contract/choice'

export const UserPositionsTable = memo(
function UserPositionsTableContent(props: {
Expand Down Expand Up @@ -352,6 +353,7 @@ const BinaryUserPositionsTable = memo(
contract={contract}
outcome={outcome}
truncate={'short'}
pseudonym={getPseudonym(contract)}
/>
) : isBinary ? (
<>
Expand All @@ -374,6 +376,7 @@ const BinaryUserPositionsTable = memo(
{totalNoPositions}{' '}
{mainBinaryMCAnswer ? (
<OutcomeLabel
pseudonym={getPseudonym(contract)}
contract={contract}
outcome={outcome}
truncate={'short'}
Expand Down
3 changes: 3 additions & 0 deletions web/components/feed/feed-bets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { track } from 'web/lib/service/analytics'
import { MoneyDisplay } from '../bet/money-display'
import { UserHovercard } from '../user/user-hovercard'
import { InfoTooltip } from '../widgets/info-tooltip'
import { getPseudonym } from '../charts/contract/choice'

export const FeedBet = memo(function FeedBet(props: {
contract: Contract
Expand Down Expand Up @@ -265,6 +266,7 @@ export function BetStatusText(props: {
<>created limit order for {orderAmount}</>
)}{' '}
<OutcomeLabel
pseudonym={getPseudonym(contract)}
outcome={outcome}
answer={answer}
contract={contract}
Expand All @@ -278,6 +280,7 @@ export function BetStatusText(props: {
{orderAmount ? '/' : ''}
{orderAmount}{' '}
<OutcomeLabel
pseudonym={getPseudonym(contract)}
outcome={outcome}
answer={answer}
contract={contract}
Expand Down
12 changes: 0 additions & 12 deletions web/components/outcome-label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,6 @@ export function OutcomeLabel(props: {
)
}

// TODO: fix
// if (mainBinaryMCAnswer && mechanism === 'cpmm-multi-1') {
// return (
// <MultiOutcomeLabel
// contract={contract}
// resolution={answer.id}
// }
// truncate={truncate}
// answerClassName={'font-bold text-base-400 !break-normal'}
// />
// )
// }
if (outcomeType === 'PSEUDO_NUMERIC')
return <PseudoNumericOutcomeLabel outcome={outcome as any} />

Expand Down

0 comments on commit e7214a2

Please sign in to comment.