2021-12-14 00:00:02 +00:00
|
|
|
import clsx from 'clsx'
|
2022-07-12 19:36:10 +00:00
|
|
|
import React, { useState } from 'react'
|
2021-12-14 00:00:02 +00:00
|
|
|
|
|
|
|
import { Col } from './layout/col'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { User } from 'web/lib/firebase/users'
|
2021-12-14 00:00:02 +00:00
|
|
|
import { YesNoCancelSelector } from './yes-no-selector'
|
|
|
|
import { Spacer } from './layout/spacer'
|
2022-02-17 23:00:19 +00:00
|
|
|
import { ResolveConfirmationButton } from './confirmation-button'
|
2022-07-10 22:03:15 +00:00
|
|
|
import { APIError, resolveMarket } from 'web/lib/firebase/api'
|
2022-01-30 21:51:30 +00:00
|
|
|
import { ProbabilitySelector } from './probability-selector'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { getProbability } from 'common/calculate'
|
2022-06-03 00:30:34 +00:00
|
|
|
import { BinaryContract, resolution } from 'common/contract'
|
2022-09-15 15:12:56 +00:00
|
|
|
import { BETTOR, BETTORS, PAST_BETS } from 'common/user'
|
2021-12-14 07:02:50 +00:00
|
|
|
|
2021-12-14 00:00:02 +00:00
|
|
|
export function ResolutionPanel(props: {
|
2022-09-15 03:28:40 +00:00
|
|
|
isAdmin: boolean
|
|
|
|
isCreator: boolean
|
2021-12-14 00:00:02 +00:00
|
|
|
creator: User
|
2022-06-01 02:42:35 +00:00
|
|
|
contract: BinaryContract
|
2021-12-14 00:00:02 +00:00
|
|
|
className?: string
|
|
|
|
}) {
|
2022-09-15 03:28:40 +00:00
|
|
|
const { contract, className, isAdmin, isCreator } = props
|
2021-12-14 00:00:02 +00:00
|
|
|
|
2022-08-24 20:29:48 +00:00
|
|
|
// const earnedFees =
|
|
|
|
// contract.mechanism === 'dpm-2'
|
|
|
|
// ? `${DPM_CREATOR_FEE * 100}% of trader profits`
|
|
|
|
// : `${formatMoney(contract.collectedFees.creatorFee)} in fees`
|
2022-03-15 22:27:51 +00:00
|
|
|
|
2022-06-03 00:30:34 +00:00
|
|
|
const [outcome, setOutcome] = useState<resolution | undefined>()
|
2021-12-14 00:00:02 +00:00
|
|
|
|
2022-03-15 22:27:51 +00:00
|
|
|
const [prob, setProb] = useState(getProbability(contract) * 100)
|
2022-01-30 21:51:30 +00:00
|
|
|
|
2021-12-15 18:44:34 +00:00
|
|
|
const [isSubmitting, setIsSubmitting] = useState(false)
|
|
|
|
const [error, setError] = useState<string | undefined>(undefined)
|
|
|
|
|
2021-12-14 07:02:50 +00:00
|
|
|
const resolve = async () => {
|
2022-02-17 23:00:19 +00:00
|
|
|
if (!outcome) return
|
|
|
|
|
2021-12-15 18:44:34 +00:00
|
|
|
setIsSubmitting(true)
|
|
|
|
|
2022-06-29 23:47:06 +00:00
|
|
|
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')
|
|
|
|
}
|
2021-12-15 18:44:34 +00:00
|
|
|
}
|
2022-06-29 23:47:06 +00:00
|
|
|
|
2021-12-15 18:44:34 +00:00
|
|
|
setIsSubmitting(false)
|
2021-12-14 00:28:37 +00:00
|
|
|
}
|
|
|
|
|
2021-12-14 00:00:02 +00:00
|
|
|
return (
|
2022-09-15 03:28:40 +00:00
|
|
|
<Col className={clsx('relative rounded-md bg-white px-8 py-6', className)}>
|
|
|
|
{isAdmin && !isCreator && (
|
|
|
|
<span className="absolute right-4 top-4 rounded bg-red-200 p-1 text-xs text-red-600">
|
|
|
|
ADMIN
|
|
|
|
</span>
|
|
|
|
)}
|
2022-05-02 16:15:00 +00:00
|
|
|
<div className="mb-6 whitespace-nowrap text-2xl">Resolve market</div>
|
|
|
|
<div className="mb-3 text-sm text-gray-500">Outcome</div>
|
2021-12-14 00:00:02 +00:00
|
|
|
<YesNoCancelSelector
|
2021-12-15 09:11:27 +00:00
|
|
|
className="mx-auto my-2"
|
2021-12-14 00:00:02 +00:00
|
|
|
selected={outcome}
|
|
|
|
onSelect={setOutcome}
|
2021-12-15 18:44:34 +00:00
|
|
|
btnClassName={isSubmitting ? 'btn-disabled' : ''}
|
2021-12-14 00:00:02 +00:00
|
|
|
/>
|
2022-02-17 23:47:23 +00:00
|
|
|
<Spacer h={4} />
|
2021-12-15 09:11:27 +00:00
|
|
|
<div>
|
2021-12-14 00:00:02 +00:00
|
|
|
{outcome === 'YES' ? (
|
|
|
|
<>
|
2022-09-15 15:12:56 +00:00
|
|
|
Winnings will be paid out to {BETTORS} who bought YES.
|
2022-08-24 20:29:48 +00:00
|
|
|
{/* <br />
|
2022-02-13 23:41:08 +00:00
|
|
|
<br />
|
2022-08-24 20:29:48 +00:00
|
|
|
You will earn {earnedFees}. */}
|
2021-12-14 00:00:02 +00:00
|
|
|
</>
|
|
|
|
) : outcome === 'NO' ? (
|
2022-02-03 23:07:30 +00:00
|
|
|
<>
|
2022-09-15 15:12:56 +00:00
|
|
|
Winnings will be paid out to {BETTORS} who bought NO.
|
2022-08-24 20:29:48 +00:00
|
|
|
{/* <br />
|
2022-02-13 23:41:08 +00:00
|
|
|
<br />
|
2022-08-24 20:29:48 +00:00
|
|
|
You will earn {earnedFees}. */}
|
2022-02-03 23:07:30 +00:00
|
|
|
</>
|
2021-12-14 00:00:02 +00:00
|
|
|
) : outcome === 'CANCEL' ? (
|
2022-09-15 15:12:56 +00:00
|
|
|
<>
|
|
|
|
All {PAST_BETS} will be returned. Unique {BETTOR} bonuses will be
|
|
|
|
withdrawn from your account
|
|
|
|
</>
|
2022-01-02 06:27:58 +00:00
|
|
|
) : outcome === 'MKT' ? (
|
2022-02-17 23:47:23 +00:00
|
|
|
<Col className="gap-6">
|
2022-09-15 15:12:56 +00:00
|
|
|
<div>
|
|
|
|
{PAST_BETS} will be paid out at the probability you specify:
|
|
|
|
</div>
|
2022-02-13 23:41:08 +00:00
|
|
|
<ProbabilitySelector
|
|
|
|
probabilityInt={Math.round(prob)}
|
|
|
|
setProbabilityInt={setProb}
|
|
|
|
/>
|
2022-08-24 20:29:48 +00:00
|
|
|
{/* You will earn {earnedFees}. */}
|
2022-02-17 23:47:23 +00:00
|
|
|
</Col>
|
2021-12-14 00:00:02 +00:00
|
|
|
) : (
|
2022-09-15 15:12:56 +00:00
|
|
|
<>Resolving this market will immediately pay out {BETTORS}.</>
|
2021-12-14 00:00:02 +00:00
|
|
|
)}
|
|
|
|
</div>
|
2022-02-17 23:47:23 +00:00
|
|
|
<Spacer h={4} />
|
2021-12-18 23:40:39 +00:00
|
|
|
{!!error && <div className="text-red-500">{error}</div>}
|
2022-02-17 23:00:19 +00:00
|
|
|
<ResolveConfirmationButton
|
2022-09-30 05:41:22 +00:00
|
|
|
color={
|
|
|
|
outcome === 'YES'
|
|
|
|
? 'green'
|
|
|
|
: outcome === 'NO'
|
|
|
|
? 'red'
|
|
|
|
: outcome === 'CANCEL'
|
|
|
|
? 'yellow'
|
|
|
|
: outcome === 'MKT'
|
|
|
|
? 'blue'
|
|
|
|
: 'indigo'
|
|
|
|
}
|
|
|
|
disabled={!outcome}
|
2022-02-17 23:00:19 +00:00
|
|
|
onResolve={resolve}
|
|
|
|
isSubmitting={isSubmitting}
|
|
|
|
/>
|
2021-12-14 00:00:02 +00:00
|
|
|
</Col>
|
|
|
|
)
|
|
|
|
}
|