import clsx from 'clsx' import React, { useState } from 'react' import { Col } from './layout/col' import { User } from 'web/lib/firebase/users' import { YesNoCancelSelector } from './yes-no-selector' import { Spacer } from './layout/spacer' import { ResolveConfirmationButton } from './confirmation-button' import { APIError, resolveMarket } from 'web/lib/firebase/api' import { ProbabilitySelector } from './probability-selector' import { getProbability } from 'common/calculate' import { BinaryContract, resolution } from 'common/contract' export function ResolutionPanel(props: { isAdmin: boolean isCreator: boolean creator: User contract: BinaryContract className?: string }) { const { contract, className, isAdmin, isCreator } = props // const earnedFees = // contract.mechanism === 'dpm-2' // ? `${DPM_CREATOR_FEE * 100}% of trader profits` // : `${formatMoney(contract.collectedFees.creatorFee)} in fees` const [outcome, setOutcome] = useState() const [prob, setProb] = useState(getProbability(contract) * 100) const [isSubmitting, setIsSubmitting] = useState(false) const [error, setError] = useState(undefined) const resolve = async () => { if (!outcome) return setIsSubmitting(true) try { const result = await resolveMarket({ outcome, contractId: contract.id, probabilityInt: prob, }) 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 = outcome === 'YES' ? 'btn-primary' : outcome === 'NO' ? 'bg-red-400 hover:bg-red-500' : outcome === 'CANCEL' ? 'bg-yellow-400 hover:bg-yellow-500' : outcome === 'MKT' ? 'bg-blue-400 hover:bg-blue-500' : 'btn-disabled' return ( {isAdmin && !isCreator && ( ADMIN )}
Resolve market
Outcome
{outcome === 'YES' ? ( <> Winnings will be paid out to traders who bought YES. {/*

You will earn {earnedFees}. */} ) : outcome === 'NO' ? ( <> Winnings will be paid out to traders who bought NO. {/*

You will earn {earnedFees}. */} ) : outcome === 'CANCEL' ? ( <>All trades will be returned with no fees. ) : outcome === 'MKT' ? (
Traders will be paid out at the probability you specify:
{/* You will earn {earnedFees}. */} ) : ( <>Resolving this market will immediately pay out traders. )}
{!!error &&
{error}
} ) }