From 5d4853042166e4c89ead65d7f75b081b130fe174 Mon Sep 17 00:00:00 2001 From: Ian Philips Date: Tue, 26 Jul 2022 18:03:51 -0700 Subject: [PATCH] Remove s from property, replace prob with outcome --- common/challenge.ts | 4 +-- functions/src/accept-challenge.ts | 18 +++++------ .../challenges/accept-challenge-button.tsx | 4 +-- web/lib/firebase/challenges.ts | 4 +-- .../[contractSlug]/[challengeSlug].tsx | 30 +++++++++---------- 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/common/challenge.ts b/common/challenge.ts index 561a0a85..a221a724 100644 --- a/common/challenge.ts +++ b/common/challenge.ts @@ -16,13 +16,13 @@ export type Challenge = { creatorAmount: number // YES or NO for now - creatorsOutcome: string + creatorOutcome: string // Different than the creator yourOutcome: string // The probability the challenger thinks - creatorsOutcomeProb: number + creatorOutcomeProb: number contractId: string contractSlug: string diff --git a/functions/src/accept-challenge.ts b/functions/src/accept-challenge.ts index ed78648b..704c5b5c 100644 --- a/functions/src/accept-challenge.ts +++ b/functions/src/accept-challenge.ts @@ -50,17 +50,17 @@ export const acceptchallenge = newEndpoint({}, async (req, auth) => { if (!creatorSnap.exists) throw new APIError(400, 'User not found.') const creator = creatorSnap.data() as User - const { creatorAmount, yourOutcome, creatorsOutcome, creatorsOutcomeProb } = + const { creatorAmount, yourOutcome, creatorOutcome, creatorOutcomeProb } = challenge const yourCost = - ((1 - creatorsOutcomeProb) / creatorsOutcomeProb) * creatorAmount + ((1 - creatorOutcomeProb) / creatorOutcomeProb) * creatorAmount if (user.balance < yourCost) throw new APIError(400, 'Insufficient balance.') const contract = anyContract as CPMMBinaryContract - const shares = (1 / creatorsOutcomeProb) * creatorAmount + const shares = (1 / creatorOutcomeProb) * creatorAmount const createdTime = Date.now() log( @@ -70,7 +70,7 @@ export const acceptchallenge = newEndpoint({}, async (req, auth) => { yourOutcome, 'shares', 'at', - formatPercent(creatorsOutcomeProb), + formatPercent(creatorOutcomeProb), 'for', formatMoney(yourCost) ) @@ -82,8 +82,8 @@ export const acceptchallenge = newEndpoint({}, async (req, auth) => { isCancelled: false, contractId: contract.id, outcome: yourOutcome, - probBefore: creatorsOutcomeProb, - probAfter: creatorsOutcomeProb, + probBefore: creatorOutcomeProb, + probAfter: creatorOutcomeProb, loanAmount: 0, createdTime, fees: noFees, @@ -104,9 +104,9 @@ export const acceptchallenge = newEndpoint({}, async (req, auth) => { shares: shares, isCancelled: false, contractId: contract.id, - outcome: creatorsOutcome, - probBefore: creatorsOutcomeProb, - probAfter: creatorsOutcomeProb, + outcome: creatorOutcome, + probBefore: creatorOutcomeProb, + probAfter: creatorOutcomeProb, loanAmount: 0, createdTime, fees: noFees, diff --git a/web/components/challenges/accept-challenge-button.tsx b/web/components/challenges/accept-challenge-button.tsx index a8490079..276e8002 100644 --- a/web/components/challenges/accept-challenge-button.tsx +++ b/web/components/challenges/accept-challenge-button.tsx @@ -21,9 +21,9 @@ export function AcceptChallengeButton(props: { const [open, setOpen] = useState(false) const [errorText, setErrorText] = useState('') const [loading, setLoading] = useState(false) - const { creatorsOutcomeProb, creatorAmount } = challenge + const { creatorOutcomeProb, creatorAmount } = challenge const yourCost = - ((1 - creatorsOutcomeProb) / creatorsOutcomeProb) * creatorAmount + ((1 - creatorOutcomeProb) / creatorOutcomeProb) * creatorAmount useEffect(() => { setErrorText('') }, [open]) diff --git a/web/lib/firebase/challenges.ts b/web/lib/firebase/challenges.ts index 37cf1079..63b06409 100644 --- a/web/lib/firebase/challenges.ts +++ b/web/lib/firebase/challenges.ts @@ -53,9 +53,9 @@ export async function createChallenge(data: { creatorAmount: amount, contractSlug: contract.slug, contractId: contract.id, - creatorsOutcome: outcome.toString(), + creatorOutcome: outcome.toString(), yourOutcome: outcome === 'YES' ? 'NO' : 'YES', - creatorsOutcomeProb: prob, + creatorOutcomeProb: prob, createdTime: Date.now(), expiresTime, maxUses: 1, diff --git a/web/pages/challenges/[username]/[contractSlug]/[challengeSlug].tsx b/web/pages/challenges/[username]/[contractSlug]/[challengeSlug].tsx index 9e6f66c3..b48252b4 100644 --- a/web/pages/challenges/[username]/[contractSlug]/[challengeSlug].tsx +++ b/web/pages/challenges/[username]/[contractSlug]/[challengeSlug].tsx @@ -100,7 +100,7 @@ export default function ChallengePage(props: { ogCardProps.creatorAvatarUrl = challenge.creatorAvatarUrl ogCardProps.question = 'I challenge you to a bet: ' + contract.question ogCardProps.probability = - Math.round(challenge.creatorsOutcomeProb * 100) + '%' + formatMoney(challenge.creatorAmount) + ' on ' + challenge.creatorOutcome return ( @@ -156,8 +156,8 @@ function ClosedChallengeContent(props: { const { acceptances, creatorAmount, - creatorsOutcome, - creatorsOutcomeProb, + creatorOutcome, + creatorOutcomeProb, yourOutcome, } = challenge @@ -169,10 +169,10 @@ function ClosedChallengeContent(props: { if (acceptances[0].createdTime > Date.now() - 1000 * 60) setShowConfetti(true) }, [acceptances]) - const creatorWon = resolution === creatorsOutcome + const creatorWon = resolution === creatorOutcome const amountWon = creatorWon ? acceptances[0].amount : creatorAmount const yourCost = - ((1 - creatorsOutcomeProb) / creatorsOutcomeProb) * creatorAmount + ((1 - creatorOutcomeProb) / creatorOutcomeProb) * creatorAmount if (!user) return @@ -275,12 +275,12 @@ function ClosedChallengeContent(props: { > {userCol( creator, - creatorsOutcome, - creatorsOutcomeProb, + creatorOutcome, + creatorOutcomeProb, creatorAmount )} VS - {userCol(user, yourOutcome, 1 - creatorsOutcomeProb, yourCost)} + {userCol(user, yourOutcome, 1 - creatorOutcomeProb, yourCost)} )} @@ -328,8 +328,8 @@ function OpenChallengeContent(props: { const { creatorAmount, creatorId, - creatorsOutcome, - creatorsOutcomeProb, + creatorOutcome, + creatorOutcomeProb, yourOutcome, } = challenge @@ -354,7 +354,7 @@ function OpenChallengeContent(props: { const isBinary = contract.outcomeType === 'BINARY' const isPseudoNumeric = contract.outcomeType === 'PSEUDO_NUMERIC' const yourCost = - ((1 - creatorsOutcomeProb) / creatorsOutcomeProb) * creatorAmount + ((1 - creatorOutcomeProb) / creatorOutcomeProb) * creatorAmount const userColumn = ( challenger: User | null | undefined, @@ -364,9 +364,9 @@ function OpenChallengeContent(props: { ) => { const lastPortfolioMetrics = last(portfolioHistory) const prob = - (outcome === creatorsOutcome - ? creatorsOutcomeProb - : 1 - creatorsOutcomeProb) * 100 + (outcome === creatorOutcome + ? creatorOutcomeProb + : 1 - creatorOutcomeProb) * 100 return ( @@ -436,7 +436,7 @@ function OpenChallengeContent(props: { {userColumn( creator, creatorPortfolioHistory, - creatorsOutcome, + creatorOutcome, creatorAmount )} VS