diff --git a/common/challenge.ts b/common/challenge.ts index a221a724..344c765f 100644 --- a/common/challenge.ts +++ b/common/challenge.ts @@ -19,7 +19,8 @@ export type Challenge = { creatorOutcome: string // Different than the creator - yourOutcome: string + acceptorOutcome: string + acceptorAmount: number // The probability the challenger thinks creatorOutcomeProb: number @@ -51,9 +52,6 @@ export type Acceptance = { userName: string userAvatarUrl: string - // The amount acceptor put up - amount: number - // The ID of the successful bet that tracks the money moved betId: string diff --git a/functions/src/accept-challenge.ts b/functions/src/accept-challenge.ts index 9b135fe2..8f319887 100644 --- a/functions/src/accept-challenge.ts +++ b/functions/src/accept-challenge.ts @@ -50,13 +50,15 @@ 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, creatorOutcome, creatorOutcomeProb } = - challenge + const { + creatorAmount, + acceptorOutcome, + creatorOutcome, + creatorOutcomeProb, + acceptorAmount, + } = challenge - const yourCost = - ((1 - creatorOutcomeProb) / creatorOutcomeProb) * creatorAmount - - if (user.balance < yourCost) + if (user.balance < acceptorAmount) throw new APIError(400, 'Insufficient balance.') const contract = anyContract as CPMMBinaryContract @@ -67,21 +69,21 @@ export const acceptchallenge = newEndpoint({}, async (req, auth) => { 'Creating challenge bet for', user.username, shares, - yourOutcome, + acceptorOutcome, 'shares', 'at', formatPercent(creatorOutcomeProb), 'for', - formatMoney(yourCost) + formatMoney(acceptorAmount) ) const yourNewBet: CandidateBet = removeUndefinedProps({ - orderAmount: yourCost, - amount: yourCost, + orderAmount: acceptorAmount, + amount: acceptorAmount, shares: shares, isCancelled: false, contractId: contract.id, - outcome: yourOutcome, + outcome: acceptorOutcome, probBefore: creatorOutcomeProb, probAfter: creatorOutcomeProb, loanAmount: 0, @@ -134,7 +136,7 @@ export const acceptchallenge = newEndpoint({}, async (req, auth) => { userId: user.id, betId: yourNewBetDoc.id, createdTime, - amount: yourCost, + amount: acceptorAmount, userUsername: user.username, userName: user.name, userAvatarUrl: user.avatarUrl, @@ -147,7 +149,7 @@ export const acceptchallenge = newEndpoint({}, async (req, auth) => { user, creator, challenge, - yourCost, + acceptorAmount, contract ) log('Done, sent notification.') diff --git a/web/components/SEO.tsx b/web/components/SEO.tsx index e5ff9360..0d43f9b0 100644 --- a/web/components/SEO.tsx +++ b/web/components/SEO.tsx @@ -17,7 +17,7 @@ function buildCardUrl(props: OgCardProps, challenge?: Challenge) { acceptances, creatorOutcomeProb, creatorOutcome, - yourOutcome, + acceptorOutcome, } = challenge || {} const { userName, userAvatarUrl } = acceptances?.[0] ?? {} const challengeAmount = @@ -35,7 +35,7 @@ function buildCardUrl(props: OgCardProps, challenge?: Challenge) { const challengeUrlParams = challenge ? `&creatorAmount=${creatorAmount}&creatorOutcome=${creatorOutcome}` + - `&challengerAmount=${challengeAmount}&challengerOutcome=${yourOutcome}` + + `&challengerAmount=${challengeAmount}&challengerOutcome=${acceptorOutcome}` + `&acceptedName=${userName ?? ''}&acceptedAvatarUrl=${userAvatarUrl ?? ''}` : '' diff --git a/web/components/challenges/accept-challenge-button.tsx b/web/components/challenges/accept-challenge-button.tsx index 46a769c2..86eb4079 100644 --- a/web/components/challenges/accept-challenge-button.tsx +++ b/web/components/challenges/accept-challenge-button.tsx @@ -21,9 +21,8 @@ export function AcceptChallengeButton(props: { const [open, setOpen] = useState(false) const [errorText, setErrorText] = useState('') const [loading, setLoading] = useState(false) - const { creatorOutcomeProb, creatorAmount } = challenge - const yourCost = - ((1 - creatorOutcomeProb) / creatorOutcomeProb) * creatorAmount + const { acceptorAmount } = challenge + useEffect(() => { setErrorText('') }, [open]) @@ -69,7 +68,9 @@ export function AcceptChallengeButton(props: {