Add challenge slug to bet and filter by it
This commit is contained in:
parent
ee3b0b32e6
commit
4dbabd2a77
|
@ -26,6 +26,7 @@ export type Bet = {
|
||||||
isAnte?: boolean
|
isAnte?: boolean
|
||||||
isLiquidityProvision?: boolean
|
isLiquidityProvision?: boolean
|
||||||
isRedemption?: boolean
|
isRedemption?: boolean
|
||||||
|
challengeSlug?: string
|
||||||
} & Partial<LimitProps>
|
} & Partial<LimitProps>
|
||||||
|
|
||||||
export type NumericBet = Bet & {
|
export type NumericBet = Bet & {
|
||||||
|
|
|
@ -91,6 +91,7 @@ export const acceptchallenge = newEndpoint({}, async (req, auth) => {
|
||||||
loanAmount: 0,
|
loanAmount: 0,
|
||||||
createdTime,
|
createdTime,
|
||||||
fees: noFees,
|
fees: noFees,
|
||||||
|
challengeSlug: challenge.slug,
|
||||||
})
|
})
|
||||||
|
|
||||||
const yourNewBetDoc = contractDoc.collection('bets').doc()
|
const yourNewBetDoc = contractDoc.collection('bets').doc()
|
||||||
|
@ -114,6 +115,7 @@ export const acceptchallenge = newEndpoint({}, async (req, auth) => {
|
||||||
loanAmount: 0,
|
loanAmount: 0,
|
||||||
createdTime,
|
createdTime,
|
||||||
fees: noFees,
|
fees: noFees,
|
||||||
|
challengeSlug: challenge.slug,
|
||||||
})
|
})
|
||||||
const creatorBetDoc = contractDoc.collection('bets').doc()
|
const creatorBetDoc = contractDoc.collection('bets').doc()
|
||||||
trans.create(creatorBetDoc, {
|
trans.create(creatorBetDoc, {
|
||||||
|
|
|
@ -21,7 +21,7 @@ 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 { acceptorAmount } = challenge
|
const { acceptorAmount, creatorAmount } = challenge
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setErrorText('')
|
setErrorText('')
|
||||||
|
@ -72,13 +72,6 @@ export function AcceptChallengeButton(props: {
|
||||||
{formatMoney(acceptorAmount)}
|
{formatMoney(acceptorAmount)}
|
||||||
</span>
|
</span>
|
||||||
</Row>
|
</Row>
|
||||||
{/*<Row className={'w-full justify-start gap-8'}>*/}
|
|
||||||
{/* <span className={'min-w-[4rem] font-bold'}>Probability:</span>{' '}*/}
|
|
||||||
{/* <span className={'ml-[3px]'}>*/}
|
|
||||||
{/* {' '}*/}
|
|
||||||
{/* {Math.round(yourProb * 100) + '%'}*/}
|
|
||||||
{/* </span>*/}
|
|
||||||
{/*</Row>*/}
|
|
||||||
<Col className={'w-full items-center justify-start'}>
|
<Col className={'w-full items-center justify-start'}>
|
||||||
<Row className={'w-full justify-start gap-10'}>
|
<Row className={'w-full justify-start gap-10'}>
|
||||||
<span className={'min-w-[4rem] font-bold'}>
|
<span className={'min-w-[4rem] font-bold'}>
|
||||||
|
@ -86,9 +79,8 @@ export function AcceptChallengeButton(props: {
|
||||||
</span>{' '}
|
</span>{' '}
|
||||||
<Row className={'items-center justify-center'}>
|
<Row className={'items-center justify-center'}>
|
||||||
<span className={'text-primary'}>
|
<span className={'text-primary'}>
|
||||||
{formatMoney(challenge.creatorAmount)}
|
{formatMoney(creatorAmount + acceptorAmount)}
|
||||||
</span>
|
</span>
|
||||||
{/*<InfoTooltip text={"If you're right"} />*/}
|
|
||||||
</Row>
|
</Row>
|
||||||
</Row>
|
</Row>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
|
@ -26,7 +26,10 @@ export function ContractActivity(props: {
|
||||||
|
|
||||||
const contract = useContractWithPreload(props.contract) ?? props.contract
|
const contract = useContractWithPreload(props.contract) ?? props.contract
|
||||||
const comments = props.comments
|
const comments = props.comments
|
||||||
const updatedBets = useBets(contract.id)
|
const updatedBets = useBets(contract.id, {
|
||||||
|
filterChallenges: false,
|
||||||
|
filterRedemptions: true,
|
||||||
|
})
|
||||||
const bets = (updatedBets ?? props.bets).filter(
|
const bets = (updatedBets ?? props.bets).filter(
|
||||||
(bet) => !bet.isRedemption && bet.amount !== 0
|
(bet) => !bet.isRedemption && bet.amount !== 0
|
||||||
)
|
)
|
||||||
|
|
|
@ -10,11 +10,14 @@ import { UsersIcon } from '@heroicons/react/solid'
|
||||||
import { formatMoney, formatPercent } from 'common/util/format'
|
import { formatMoney, formatPercent } from 'common/util/format'
|
||||||
import { OutcomeLabel } from 'web/components/outcome-label'
|
import { OutcomeLabel } from 'web/components/outcome-label'
|
||||||
import { RelativeTimestamp } from 'web/components/relative-timestamp'
|
import { RelativeTimestamp } from 'web/components/relative-timestamp'
|
||||||
import React, { Fragment } from 'react'
|
import React, { Fragment, useEffect } from 'react'
|
||||||
import { uniqBy, partition, sumBy, groupBy } from 'lodash'
|
import { uniqBy, partition, sumBy, groupBy } from 'lodash'
|
||||||
import { JoinSpans } from 'web/components/join-spans'
|
import { JoinSpans } from 'web/components/join-spans'
|
||||||
import { UserLink } from '../user-page'
|
import { UserLink } from '../user-page'
|
||||||
import { formatNumericProbability } from 'common/pseudo-numeric'
|
import { formatNumericProbability } from 'common/pseudo-numeric'
|
||||||
|
import { SiteLink } from 'web/components/site-link'
|
||||||
|
import { getChallenge, getChallengeUrl } from 'web/lib/firebase/challenges'
|
||||||
|
import { Challenge } from 'common/challenge'
|
||||||
|
|
||||||
export function FeedBet(props: {
|
export function FeedBet(props: {
|
||||||
contract: Contract
|
contract: Contract
|
||||||
|
@ -79,7 +82,15 @@ export function BetStatusText(props: {
|
||||||
const { outcomeType } = contract
|
const { outcomeType } = contract
|
||||||
const isPseudoNumeric = outcomeType === 'PSEUDO_NUMERIC'
|
const isPseudoNumeric = outcomeType === 'PSEUDO_NUMERIC'
|
||||||
const isFreeResponse = outcomeType === 'FREE_RESPONSE'
|
const isFreeResponse = outcomeType === 'FREE_RESPONSE'
|
||||||
const { amount, outcome, createdTime } = bet
|
const { amount, outcome, createdTime, challengeSlug } = bet
|
||||||
|
const [challenge, setChallenge] = React.useState<Challenge>()
|
||||||
|
useEffect(() => {
|
||||||
|
if (challengeSlug) {
|
||||||
|
getChallenge(challengeSlug, contract.id).then((c) => {
|
||||||
|
setChallenge(c)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [challengeSlug, contract.id])
|
||||||
|
|
||||||
const bought = amount >= 0 ? 'bought' : 'sold'
|
const bought = amount >= 0 ? 'bought' : 'sold'
|
||||||
const outOfTotalAmount =
|
const outOfTotalAmount =
|
||||||
|
@ -133,6 +144,14 @@ export function BetStatusText(props: {
|
||||||
{fromProb === toProb
|
{fromProb === toProb
|
||||||
? `at ${fromProb}`
|
? `at ${fromProb}`
|
||||||
: `from ${fromProb} to ${toProb}`}
|
: `from ${fromProb} to ${toProb}`}
|
||||||
|
{challengeSlug && (
|
||||||
|
<SiteLink
|
||||||
|
href={challenge ? getChallengeUrl(challenge) : ''}
|
||||||
|
className={'mx-1'}
|
||||||
|
>
|
||||||
|
[challenge]
|
||||||
|
</SiteLink>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
<RelativeTimestamp time={createdTime} />
|
<RelativeTimestamp time={createdTime} />
|
||||||
|
|
|
@ -9,12 +9,26 @@ import {
|
||||||
} from 'web/lib/firebase/bets'
|
} from 'web/lib/firebase/bets'
|
||||||
import { LimitBet } from 'common/bet'
|
import { LimitBet } from 'common/bet'
|
||||||
|
|
||||||
export const useBets = (contractId: string) => {
|
export const useBets = (
|
||||||
|
contractId: string,
|
||||||
|
options?: { filterChallenges: boolean; filterRedemptions: boolean }
|
||||||
|
) => {
|
||||||
const [bets, setBets] = useState<Bet[] | undefined>()
|
const [bets, setBets] = useState<Bet[] | undefined>()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (contractId) return listenForBets(contractId, setBets)
|
if (contractId)
|
||||||
}, [contractId])
|
return listenForBets(contractId, (bets) => {
|
||||||
|
if (options)
|
||||||
|
setBets(
|
||||||
|
bets.filter(
|
||||||
|
(bet) =>
|
||||||
|
(options.filterChallenges ? !bet.challengeSlug : true) &&
|
||||||
|
(options.filterRedemptions ? !bet.isRedemption : true)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else setBets(bets)
|
||||||
|
})
|
||||||
|
}, [contractId, options])
|
||||||
|
|
||||||
return bets
|
return bets
|
||||||
}
|
}
|
||||||
|
|
|
@ -211,7 +211,10 @@ export function ContractPageContent(
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<ContractOverview contract={contract} bets={bets} />
|
<ContractOverview
|
||||||
|
contract={contract}
|
||||||
|
bets={bets.filter((b) => !b.challengeSlug)}
|
||||||
|
/>
|
||||||
|
|
||||||
{isNumeric && (
|
{isNumeric && (
|
||||||
<AlertBox
|
<AlertBox
|
||||||
|
|
Loading…
Reference in New Issue
Block a user