2021-12-14 00:00:02 +00:00
|
|
|
import clsx from 'clsx'
|
|
|
|
import React, { useState } from 'react'
|
2021-12-14 07:02:50 +00:00
|
|
|
import { getFunctions, httpsCallable } from 'firebase/functions'
|
2021-12-14 00:00:02 +00:00
|
|
|
|
|
|
|
import { Contract } from '../lib/firebase/contracts'
|
|
|
|
import { Col } from './layout/col'
|
|
|
|
import { Title } from './title'
|
|
|
|
import { User } from '../lib/firebase/users'
|
|
|
|
import { YesNoCancelSelector } from './yes-no-selector'
|
|
|
|
import { Spacer } from './layout/spacer'
|
2021-12-14 00:47:43 +00:00
|
|
|
import { ConfirmationModal } from './confirmation-modal'
|
2021-12-14 00:00:02 +00:00
|
|
|
|
2021-12-14 07:02:50 +00:00
|
|
|
const functions = getFunctions()
|
|
|
|
export const resolveMarket = httpsCallable(functions, 'resolveMarket')
|
|
|
|
|
2021-12-14 00:00:02 +00:00
|
|
|
export function ResolutionPanel(props: {
|
|
|
|
creator: User
|
|
|
|
contract: Contract
|
|
|
|
className?: string
|
|
|
|
}) {
|
|
|
|
const { creator, contract, className } = props
|
|
|
|
|
|
|
|
const [outcome, setOutcome] = useState<'YES' | 'NO' | 'CANCEL' | undefined>()
|
|
|
|
|
2021-12-14 07:02:50 +00:00
|
|
|
const resolve = async () => {
|
|
|
|
const result = await resolveMarket({ outcome, contractId: contract.id })
|
|
|
|
console.log('resolved', outcome, 'result:', result.data)
|
2021-12-14 00:28:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const submitButtonClass =
|
|
|
|
outcome === 'YES'
|
|
|
|
? 'btn-primary'
|
|
|
|
: outcome === 'NO'
|
2021-12-14 07:30:09 +00:00
|
|
|
? 'bg-red-400 hover:bg-red-500'
|
|
|
|
: outcome === 'CANCEL'
|
|
|
|
? 'bg-yellow-400 hover:bg-yellow-500'
|
|
|
|
: 'btn-disabled'
|
2021-12-14 00:00:02 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Col
|
|
|
|
className={clsx(
|
2021-12-14 04:54:51 +00:00
|
|
|
'bg-gray-100 shadow-xl px-8 py-6 rounded-md w-full md:w-auto',
|
2021-12-14 00:00:02 +00:00
|
|
|
className
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<Title className="mt-0" text="Your market" />
|
|
|
|
|
2021-12-15 09:11:27 +00:00
|
|
|
<div className="pt-2 pb-1 text-sm text-gray-400">Resolve 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}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Spacer h={3} />
|
|
|
|
|
2021-12-15 09:11:27 +00:00
|
|
|
<div>
|
2021-12-14 00:00:02 +00:00
|
|
|
{outcome === 'YES' ? (
|
|
|
|
<>
|
|
|
|
Winnings will be paid out to Yes bettors. You earn 1% of the No
|
|
|
|
bets.
|
|
|
|
</>
|
|
|
|
) : outcome === 'NO' ? (
|
|
|
|
<>
|
|
|
|
Winnings will be paid out to No bettors. You earn 1% of the Yes
|
|
|
|
bets.
|
|
|
|
</>
|
|
|
|
) : outcome === 'CANCEL' ? (
|
|
|
|
<>All bets will be returned with no fees.</>
|
|
|
|
) : (
|
|
|
|
<>Resolving this market will immediately pay out bettors.</>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<Spacer h={3} />
|
|
|
|
|
2021-12-14 00:47:43 +00:00
|
|
|
<ConfirmationModal
|
|
|
|
id="resolution-modal"
|
|
|
|
openModelBtn={{
|
2021-12-15 09:11:27 +00:00
|
|
|
className: clsx(
|
|
|
|
'border-none self-start mt-2 w-full',
|
|
|
|
submitButtonClass
|
|
|
|
),
|
2021-12-14 00:47:43 +00:00
|
|
|
label: 'Resolve',
|
|
|
|
}}
|
|
|
|
cancelBtn={{
|
|
|
|
label: 'Back',
|
|
|
|
}}
|
|
|
|
submitBtn={{
|
|
|
|
label: 'Resolve',
|
|
|
|
className: submitButtonClass,
|
|
|
|
}}
|
|
|
|
onSubmit={resolve}
|
2021-12-14 00:00:02 +00:00
|
|
|
>
|
2021-12-14 00:47:43 +00:00
|
|
|
<p>Are you sure you want to resolve this market?</p>
|
|
|
|
</ConfirmationModal>
|
2021-12-14 00:00:02 +00:00
|
|
|
</Col>
|
|
|
|
)
|
|
|
|
}
|