Remove s from property, replace prob with outcome
This commit is contained in:
parent
dfd6831717
commit
5d48530421
|
@ -16,13 +16,13 @@ export type Challenge = {
|
||||||
creatorAmount: number
|
creatorAmount: number
|
||||||
|
|
||||||
// YES or NO for now
|
// YES or NO for now
|
||||||
creatorsOutcome: string
|
creatorOutcome: string
|
||||||
|
|
||||||
// Different than the creator
|
// Different than the creator
|
||||||
yourOutcome: string
|
yourOutcome: string
|
||||||
|
|
||||||
// The probability the challenger thinks
|
// The probability the challenger thinks
|
||||||
creatorsOutcomeProb: number
|
creatorOutcomeProb: number
|
||||||
|
|
||||||
contractId: string
|
contractId: string
|
||||||
contractSlug: string
|
contractSlug: string
|
||||||
|
|
|
@ -50,17 +50,17 @@ export const acceptchallenge = newEndpoint({}, async (req, auth) => {
|
||||||
if (!creatorSnap.exists) throw new APIError(400, 'User not found.')
|
if (!creatorSnap.exists) throw new APIError(400, 'User not found.')
|
||||||
const creator = creatorSnap.data() as User
|
const creator = creatorSnap.data() as User
|
||||||
|
|
||||||
const { creatorAmount, yourOutcome, creatorsOutcome, creatorsOutcomeProb } =
|
const { creatorAmount, yourOutcome, creatorOutcome, creatorOutcomeProb } =
|
||||||
challenge
|
challenge
|
||||||
|
|
||||||
const yourCost =
|
const yourCost =
|
||||||
((1 - creatorsOutcomeProb) / creatorsOutcomeProb) * creatorAmount
|
((1 - creatorOutcomeProb) / creatorOutcomeProb) * creatorAmount
|
||||||
|
|
||||||
if (user.balance < yourCost)
|
if (user.balance < yourCost)
|
||||||
throw new APIError(400, 'Insufficient balance.')
|
throw new APIError(400, 'Insufficient balance.')
|
||||||
|
|
||||||
const contract = anyContract as CPMMBinaryContract
|
const contract = anyContract as CPMMBinaryContract
|
||||||
const shares = (1 / creatorsOutcomeProb) * creatorAmount
|
const shares = (1 / creatorOutcomeProb) * creatorAmount
|
||||||
const createdTime = Date.now()
|
const createdTime = Date.now()
|
||||||
|
|
||||||
log(
|
log(
|
||||||
|
@ -70,7 +70,7 @@ export const acceptchallenge = newEndpoint({}, async (req, auth) => {
|
||||||
yourOutcome,
|
yourOutcome,
|
||||||
'shares',
|
'shares',
|
||||||
'at',
|
'at',
|
||||||
formatPercent(creatorsOutcomeProb),
|
formatPercent(creatorOutcomeProb),
|
||||||
'for',
|
'for',
|
||||||
formatMoney(yourCost)
|
formatMoney(yourCost)
|
||||||
)
|
)
|
||||||
|
@ -82,8 +82,8 @@ export const acceptchallenge = newEndpoint({}, async (req, auth) => {
|
||||||
isCancelled: false,
|
isCancelled: false,
|
||||||
contractId: contract.id,
|
contractId: contract.id,
|
||||||
outcome: yourOutcome,
|
outcome: yourOutcome,
|
||||||
probBefore: creatorsOutcomeProb,
|
probBefore: creatorOutcomeProb,
|
||||||
probAfter: creatorsOutcomeProb,
|
probAfter: creatorOutcomeProb,
|
||||||
loanAmount: 0,
|
loanAmount: 0,
|
||||||
createdTime,
|
createdTime,
|
||||||
fees: noFees,
|
fees: noFees,
|
||||||
|
@ -104,9 +104,9 @@ export const acceptchallenge = newEndpoint({}, async (req, auth) => {
|
||||||
shares: shares,
|
shares: shares,
|
||||||
isCancelled: false,
|
isCancelled: false,
|
||||||
contractId: contract.id,
|
contractId: contract.id,
|
||||||
outcome: creatorsOutcome,
|
outcome: creatorOutcome,
|
||||||
probBefore: creatorsOutcomeProb,
|
probBefore: creatorOutcomeProb,
|
||||||
probAfter: creatorsOutcomeProb,
|
probAfter: creatorOutcomeProb,
|
||||||
loanAmount: 0,
|
loanAmount: 0,
|
||||||
createdTime,
|
createdTime,
|
||||||
fees: noFees,
|
fees: noFees,
|
||||||
|
|
|
@ -21,9 +21,9 @@ export function AcceptChallengeButton(props: {
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
const [errorText, setErrorText] = useState('')
|
const [errorText, setErrorText] = useState('')
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const { creatorsOutcomeProb, creatorAmount } = challenge
|
const { creatorOutcomeProb, creatorAmount } = challenge
|
||||||
const yourCost =
|
const yourCost =
|
||||||
((1 - creatorsOutcomeProb) / creatorsOutcomeProb) * creatorAmount
|
((1 - creatorOutcomeProb) / creatorOutcomeProb) * creatorAmount
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setErrorText('')
|
setErrorText('')
|
||||||
}, [open])
|
}, [open])
|
||||||
|
|
|
@ -53,9 +53,9 @@ export async function createChallenge(data: {
|
||||||
creatorAmount: amount,
|
creatorAmount: amount,
|
||||||
contractSlug: contract.slug,
|
contractSlug: contract.slug,
|
||||||
contractId: contract.id,
|
contractId: contract.id,
|
||||||
creatorsOutcome: outcome.toString(),
|
creatorOutcome: outcome.toString(),
|
||||||
yourOutcome: outcome === 'YES' ? 'NO' : 'YES',
|
yourOutcome: outcome === 'YES' ? 'NO' : 'YES',
|
||||||
creatorsOutcomeProb: prob,
|
creatorOutcomeProb: prob,
|
||||||
createdTime: Date.now(),
|
createdTime: Date.now(),
|
||||||
expiresTime,
|
expiresTime,
|
||||||
maxUses: 1,
|
maxUses: 1,
|
||||||
|
|
|
@ -100,7 +100,7 @@ export default function ChallengePage(props: {
|
||||||
ogCardProps.creatorAvatarUrl = challenge.creatorAvatarUrl
|
ogCardProps.creatorAvatarUrl = challenge.creatorAvatarUrl
|
||||||
ogCardProps.question = 'I challenge you to a bet: ' + contract.question
|
ogCardProps.question = 'I challenge you to a bet: ' + contract.question
|
||||||
ogCardProps.probability =
|
ogCardProps.probability =
|
||||||
Math.round(challenge.creatorsOutcomeProb * 100) + '%'
|
formatMoney(challenge.creatorAmount) + ' on ' + challenge.creatorOutcome
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Page>
|
<Page>
|
||||||
|
@ -156,8 +156,8 @@ function ClosedChallengeContent(props: {
|
||||||
const {
|
const {
|
||||||
acceptances,
|
acceptances,
|
||||||
creatorAmount,
|
creatorAmount,
|
||||||
creatorsOutcome,
|
creatorOutcome,
|
||||||
creatorsOutcomeProb,
|
creatorOutcomeProb,
|
||||||
yourOutcome,
|
yourOutcome,
|
||||||
} = challenge
|
} = challenge
|
||||||
|
|
||||||
|
@ -169,10 +169,10 @@ function ClosedChallengeContent(props: {
|
||||||
if (acceptances[0].createdTime > Date.now() - 1000 * 60)
|
if (acceptances[0].createdTime > Date.now() - 1000 * 60)
|
||||||
setShowConfetti(true)
|
setShowConfetti(true)
|
||||||
}, [acceptances])
|
}, [acceptances])
|
||||||
const creatorWon = resolution === creatorsOutcome
|
const creatorWon = resolution === creatorOutcome
|
||||||
const amountWon = creatorWon ? acceptances[0].amount : creatorAmount
|
const amountWon = creatorWon ? acceptances[0].amount : creatorAmount
|
||||||
const yourCost =
|
const yourCost =
|
||||||
((1 - creatorsOutcomeProb) / creatorsOutcomeProb) * creatorAmount
|
((1 - creatorOutcomeProb) / creatorOutcomeProb) * creatorAmount
|
||||||
|
|
||||||
if (!user) return <LoadingIndicator />
|
if (!user) return <LoadingIndicator />
|
||||||
|
|
||||||
|
@ -275,12 +275,12 @@ function ClosedChallengeContent(props: {
|
||||||
>
|
>
|
||||||
{userCol(
|
{userCol(
|
||||||
creator,
|
creator,
|
||||||
creatorsOutcome,
|
creatorOutcome,
|
||||||
creatorsOutcomeProb,
|
creatorOutcomeProb,
|
||||||
creatorAmount
|
creatorAmount
|
||||||
)}
|
)}
|
||||||
<Col className="items-center justify-center py-4 text-xl">VS</Col>
|
<Col className="items-center justify-center py-4 text-xl">VS</Col>
|
||||||
{userCol(user, yourOutcome, 1 - creatorsOutcomeProb, yourCost)}
|
{userCol(user, yourOutcome, 1 - creatorOutcomeProb, yourCost)}
|
||||||
</Col>
|
</Col>
|
||||||
)}
|
)}
|
||||||
<Spacer h={3} />
|
<Spacer h={3} />
|
||||||
|
@ -328,8 +328,8 @@ function OpenChallengeContent(props: {
|
||||||
const {
|
const {
|
||||||
creatorAmount,
|
creatorAmount,
|
||||||
creatorId,
|
creatorId,
|
||||||
creatorsOutcome,
|
creatorOutcome,
|
||||||
creatorsOutcomeProb,
|
creatorOutcomeProb,
|
||||||
yourOutcome,
|
yourOutcome,
|
||||||
} = challenge
|
} = challenge
|
||||||
|
|
||||||
|
@ -354,7 +354,7 @@ function OpenChallengeContent(props: {
|
||||||
const isBinary = contract.outcomeType === 'BINARY'
|
const isBinary = contract.outcomeType === 'BINARY'
|
||||||
const isPseudoNumeric = contract.outcomeType === 'PSEUDO_NUMERIC'
|
const isPseudoNumeric = contract.outcomeType === 'PSEUDO_NUMERIC'
|
||||||
const yourCost =
|
const yourCost =
|
||||||
((1 - creatorsOutcomeProb) / creatorsOutcomeProb) * creatorAmount
|
((1 - creatorOutcomeProb) / creatorOutcomeProb) * creatorAmount
|
||||||
|
|
||||||
const userColumn = (
|
const userColumn = (
|
||||||
challenger: User | null | undefined,
|
challenger: User | null | undefined,
|
||||||
|
@ -364,9 +364,9 @@ function OpenChallengeContent(props: {
|
||||||
) => {
|
) => {
|
||||||
const lastPortfolioMetrics = last(portfolioHistory)
|
const lastPortfolioMetrics = last(portfolioHistory)
|
||||||
const prob =
|
const prob =
|
||||||
(outcome === creatorsOutcome
|
(outcome === creatorOutcome
|
||||||
? creatorsOutcomeProb
|
? creatorOutcomeProb
|
||||||
: 1 - creatorsOutcomeProb) * 100
|
: 1 - creatorOutcomeProb) * 100
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Col className="w-full items-start justify-center gap-1">
|
<Col className="w-full items-start justify-center gap-1">
|
||||||
|
@ -436,7 +436,7 @@ function OpenChallengeContent(props: {
|
||||||
{userColumn(
|
{userColumn(
|
||||||
creator,
|
creator,
|
||||||
creatorPortfolioHistory,
|
creatorPortfolioHistory,
|
||||||
creatorsOutcome,
|
creatorOutcome,
|
||||||
creatorAmount
|
creatorAmount
|
||||||
)}
|
)}
|
||||||
<Col className="items-center justify-center py-4 text-4xl">VS</Col>
|
<Col className="items-center justify-center py-4 text-4xl">VS</Col>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user