From f0e0796b99e371ca1f862c7f6585b336e9c67b1b Mon Sep 17 00:00:00 2001 From: mantikoros Date: Wed, 15 Dec 2021 12:44:34 -0600 Subject: [PATCH] resolution panel: show errors, disable when submitting, rename confirm button --- ...tion-modal.tsx => confirmation-button.tsx} | 2 +- web/components/resolution-panel.tsx | 41 ++++++++++++++----- web/components/yes-no-selector.tsx | 9 ++-- 3 files changed, 38 insertions(+), 14 deletions(-) rename web/components/{confirmation-modal.tsx => confirmation-button.tsx} (96%) diff --git a/web/components/confirmation-modal.tsx b/web/components/confirmation-button.tsx similarity index 96% rename from web/components/confirmation-modal.tsx rename to web/components/confirmation-button.tsx index 2d6eefa2..3e36e325 100644 --- a/web/components/confirmation-modal.tsx +++ b/web/components/confirmation-button.tsx @@ -1,6 +1,6 @@ import clsx from 'clsx' -export function ConfirmationModal(props: { +export function ConfirmationButton(props: { id: string openModelBtn: { label: string diff --git a/web/components/resolution-panel.tsx b/web/components/resolution-panel.tsx index b50d50f2..2b913f41 100644 --- a/web/components/resolution-panel.tsx +++ b/web/components/resolution-panel.tsx @@ -8,7 +8,7 @@ import { Title } from './title' import { User } from '../lib/firebase/users' import { YesNoCancelSelector } from './yes-no-selector' import { Spacer } from './layout/spacer' -import { ConfirmationModal } from './confirmation-modal' +import { ConfirmationButton as ConfirmationButton } from './confirmation-button' const functions = getFunctions() export const resolveMarket = httpsCallable(functions, 'resolveMarket') @@ -18,23 +18,35 @@ export function ResolutionPanel(props: { contract: Contract className?: string }) { - const { creator, contract, className } = props + const { contract, className } = props const [outcome, setOutcome] = useState<'YES' | 'NO' | 'CANCEL' | undefined>() + const [isSubmitting, setIsSubmitting] = useState(false) + const [error, setError] = useState(undefined) + const resolve = async () => { + setIsSubmitting(true) + const result = await resolveMarket({ outcome, contractId: contract.id }) - console.log('resolved', outcome, 'result:', result.data) + .then(r => r.data as any) + + console.log('resolved', outcome, 'result:', result) + + if (result?.status !== 'success') { + setError(result?.error || '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' - : 'btn-disabled' + ? 'bg-red-400 hover:bg-red-500' + : outcome === 'CANCEL' + ? 'bg-yellow-400 hover:bg-yellow-500' + : 'btn-disabled' return (
Resolve outcome
+ +
{outcome === 'YES' ? ( <> @@ -72,14 +87,20 @@ export function ResolutionPanel(props: { )}
+ - {error} + } + +

Are you sure you want to resolve this market?

-
+ ) } diff --git a/web/components/yes-no-selector.tsx b/web/components/yes-no-selector.tsx index dde04834..07b64768 100644 --- a/web/components/yes-no-selector.tsx +++ b/web/components/yes-no-selector.tsx @@ -32,15 +32,18 @@ export function YesNoCancelSelector(props: { selected: 'YES' | 'NO' | 'CANCEL' | undefined onSelect: (selected: 'YES' | 'NO' | 'CANCEL') => void className?: string + btnClassName?: string }) { const { selected, onSelect, className } = props + const btnClassName = clsx('px-6', props.btnClassName) + return ( @@ -48,7 +51,7 @@ export function YesNoCancelSelector(props: { @@ -56,7 +59,7 @@ export function YesNoCancelSelector(props: {