import clsx from 'clsx' import React, { useState } from 'react' import { Col } from './layout/col' import { User } from 'web/lib/firebase/users' import { NumberCancelSelector } from './yes-no-selector' import { Spacer } from './layout/spacer' import { ResolveConfirmationButton } from './confirmation-button' import { NumericContract, PseudoNumericContract } from 'common/contract' import { APIError, resolveMarket } from 'web/lib/firebase/api' import { BucketInput } from './bucket-input' import { getPseudoProbability } from 'common/pseudo-numeric' export function NumericResolutionPanel(props: { creator: User contract: NumericContract | PseudoNumericContract className?: string }) { const { contract, className } = props const { min, max, outcomeType } = contract const [outcomeMode, setOutcomeMode] = useState< 'NUMBER' | 'CANCEL' | undefined >() const [outcome, setOutcome] = useState() const [value, setValue] = useState() const [isSubmitting, setIsSubmitting] = useState(false) const [error, setError] = useState(undefined) const resolve = async () => { const finalOutcome = outcomeMode === 'CANCEL' ? 'CANCEL' : outcomeType === 'PSEUDO_NUMERIC' ? 'MKT' : 'NUMBER' if (outcomeMode === undefined || finalOutcome === undefined) return setIsSubmitting(true) const boundedValue = Math.max(Math.min(max, value ?? 0), min) const probabilityInt = 100 * getPseudoProbability( boundedValue, min, max, outcomeType === 'PSEUDO_NUMERIC' && contract.isLogScale ) try { const result = await resolveMarket({ outcome: finalOutcome, value, probabilityInt, contractId: contract.id, }) console.log('resolved', outcome, 'result:', result) } catch (e) { if (e instanceof APIError) { setError(e.toString()) } else { console.error(e) setError('Error resolving market') } } setIsSubmitting(false) } const submitButtonClass = outcomeMode === 'CANCEL' ? 'bg-yellow-400 hover:bg-yellow-500' : outcome !== undefined ? 'btn-primary' : 'btn-disabled' return (
Resolve market
Outcome
{outcomeMode === 'NUMBER' && ( (setValue(v), setOutcome(o))} /> )}
{outcome === 'CANCEL' ? ( <>All trades will be returned with no fees. ) : ( <>Resolving this market will immediately pay out traders. )}
{!!error &&
{error}
} ) }