resolving things
This commit is contained in:
parent
266a21a509
commit
f34858465c
|
@ -76,14 +76,18 @@ export const resolvemarket = newEndpoint(opts, async (req, auth) => {
|
||||||
throw new APIError(404, 'No contract exists with the provided ID')
|
throw new APIError(404, 'No contract exists with the provided ID')
|
||||||
const contract = contractSnap.data() as Contract
|
const contract = contractSnap.data() as Contract
|
||||||
const { creatorId, closeTime } = contract
|
const { creatorId, closeTime } = contract
|
||||||
const user = await admin.auth().getUser(auth.uid)
|
const firebaseUser = await admin.auth().getUser(auth.uid)
|
||||||
|
|
||||||
const { value, resolutions, probabilityInt, outcome } = getResolutionParams(
|
const { value, resolutions, probabilityInt, outcome } = getResolutionParams(
|
||||||
contract,
|
contract,
|
||||||
req.body
|
req.body
|
||||||
)
|
)
|
||||||
|
|
||||||
if (creatorId !== auth.uid && !isManifoldId(auth.uid) && !isAdmin(user.email))
|
if (
|
||||||
|
creatorId !== auth.uid &&
|
||||||
|
!isManifoldId(auth.uid) &&
|
||||||
|
!isAdmin(firebaseUser.email)
|
||||||
|
)
|
||||||
throw new APIError(403, 'User is not creator of contract')
|
throw new APIError(403, 'User is not creator of contract')
|
||||||
|
|
||||||
if (contract.resolution) throw new APIError(400, 'Contract already resolved')
|
if (contract.resolution) throw new APIError(400, 'Contract already resolved')
|
||||||
|
|
|
@ -25,6 +25,7 @@ import { BuyButton } from 'web/components/yes-no-selector'
|
||||||
import { UserLink } from 'web/components/user-link'
|
import { UserLink } from 'web/components/user-link'
|
||||||
import { Button } from 'web/components/button'
|
import { Button } from 'web/components/button'
|
||||||
import { useAdmin } from 'web/hooks/use-admin'
|
import { useAdmin } from 'web/hooks/use-admin'
|
||||||
|
import { needsAdminToResolve } from 'web/pages/[username]/[contractSlug]'
|
||||||
|
|
||||||
export function AnswersPanel(props: {
|
export function AnswersPanel(props: {
|
||||||
contract: FreeResponseContract | MultipleChoiceContract
|
contract: FreeResponseContract | MultipleChoiceContract
|
||||||
|
@ -156,7 +157,8 @@ export function AnswersPanel(props: {
|
||||||
<CreateAnswerPanel contract={contract} />
|
<CreateAnswerPanel contract={contract} />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{(user?.id === creatorId || isAdmin) && !resolution && (
|
{(user?.id === creatorId || (isAdmin && needsAdminToResolve(contract))) &&
|
||||||
|
!resolution && (
|
||||||
<>
|
<>
|
||||||
<Spacer h={2} />
|
<Spacer h={2} />
|
||||||
<AnswerResolvePanel
|
<AnswerResolvePanel
|
||||||
|
|
|
@ -46,6 +46,7 @@ import { ContractsGrid } from 'web/components/contract/contracts-grid'
|
||||||
import { Title } from 'web/components/title'
|
import { Title } from 'web/components/title'
|
||||||
import { usePrefetch } from 'web/hooks/use-prefetch'
|
import { usePrefetch } from 'web/hooks/use-prefetch'
|
||||||
import { useAdmin } from 'web/hooks/use-admin'
|
import { useAdmin } from 'web/hooks/use-admin'
|
||||||
|
import dayjs from 'dayjs'
|
||||||
|
|
||||||
export const getStaticProps = fromPropz(getStaticPropz)
|
export const getStaticProps = fromPropz(getStaticPropz)
|
||||||
export async function getStaticPropz(props: {
|
export async function getStaticPropz(props: {
|
||||||
|
@ -111,6 +112,11 @@ export default function ContractPage(props: {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// requires an admin to resolve a week after market closes
|
||||||
|
export function needsAdminToResolve(contract: Contract) {
|
||||||
|
return !contract.isResolved && dayjs().diff(contract.closeTime, 'day') > 7
|
||||||
|
}
|
||||||
|
|
||||||
export function ContractPageSidebar(props: {
|
export function ContractPageSidebar(props: {
|
||||||
user: User | null | undefined
|
user: User | null | undefined
|
||||||
contract: Contract
|
contract: Contract
|
||||||
|
@ -123,7 +129,10 @@ export function ContractPageSidebar(props: {
|
||||||
const isNumeric = outcomeType === 'NUMERIC'
|
const isNumeric = outcomeType === 'NUMERIC'
|
||||||
const allowTrade = tradingAllowed(contract)
|
const allowTrade = tradingAllowed(contract)
|
||||||
const isAdmin = useAdmin()
|
const isAdmin = useAdmin()
|
||||||
const allowResolve = !isResolved && (isCreator || isAdmin) && !!user
|
const allowResolve =
|
||||||
|
!isResolved &&
|
||||||
|
(isCreator || (needsAdminToResolve(contract) && isAdmin)) &&
|
||||||
|
!!user
|
||||||
|
|
||||||
const hasSidePanel =
|
const hasSidePanel =
|
||||||
(isBinary || isNumeric || isPseudoNumeric) && (allowTrade || allowResolve)
|
(isBinary || isNumeric || isPseudoNumeric) && (allowTrade || allowResolve)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user