improved create challenge modal; 2xs button
This commit is contained in:
parent
16f4fb9490
commit
5988dd1e48
|
@ -5,7 +5,7 @@ export function Button(props: {
|
||||||
className?: string
|
className?: string
|
||||||
onClick?: () => void
|
onClick?: () => void
|
||||||
children?: ReactNode
|
children?: ReactNode
|
||||||
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl'
|
size?: '2xs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl'
|
||||||
color?:
|
color?:
|
||||||
| 'green'
|
| 'green'
|
||||||
| 'red'
|
| 'red'
|
||||||
|
@ -29,6 +29,7 @@ export function Button(props: {
|
||||||
} = props
|
} = props
|
||||||
|
|
||||||
const sizeClasses = {
|
const sizeClasses = {
|
||||||
|
'2xs': 'px-2 py-1 text-xs',
|
||||||
xs: 'px-2.5 py-1.5 text-sm',
|
xs: 'px-2.5 py-1.5 text-sm',
|
||||||
sm: 'px-3 py-2 text-sm',
|
sm: 'px-3 py-2 text-sm',
|
||||||
md: 'px-4 py-2 text-sm',
|
md: 'px-4 py-2 text-sm',
|
||||||
|
|
|
@ -17,6 +17,8 @@ import { formatMoney } from 'common/util/format'
|
||||||
import { NoLabel, YesLabel } from '../outcome-label'
|
import { NoLabel, YesLabel } from '../outcome-label'
|
||||||
import { QRCode } from '../qr-code'
|
import { QRCode } from '../qr-code'
|
||||||
import { copyToClipboard } from 'web/lib/util/copy'
|
import { copyToClipboard } from 'web/lib/util/copy'
|
||||||
|
import { AmountInput } from '../amount-input'
|
||||||
|
import { getProbability } from 'common/calculate'
|
||||||
|
|
||||||
type challengeInfo = {
|
type challengeInfo = {
|
||||||
amount: number
|
amount: number
|
||||||
|
@ -36,7 +38,7 @@ export function CreateChallengeModal(props: {
|
||||||
const [challengeSlug, setChallengeSlug] = useState('')
|
const [challengeSlug, setChallengeSlug] = useState('')
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal open={isOpen} setOpen={setOpen} size={'sm'}>
|
<Modal open={isOpen} setOpen={setOpen}>
|
||||||
<Col className="gap-4 rounded-md bg-white px-8 py-6">
|
<Col className="gap-4 rounded-md bg-white px-8 py-6">
|
||||||
{/*// add a sign up to challenge button?*/}
|
{/*// add a sign up to challenge button?*/}
|
||||||
{user && (
|
{user && (
|
||||||
|
@ -104,7 +106,13 @@ function CreateChallengeForm(props: {
|
||||||
setFinishedCreating(true)
|
setFinishedCreating(true)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Title className="!mt-2" text="Challenge a friend to bet " />
|
<Title className="!mt-2" text="Challenge bet " />
|
||||||
|
|
||||||
|
<div className="mb-8">
|
||||||
|
Challenge a friend to bet on{' '}
|
||||||
|
<span className="underline">{contract.question}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="mt-2 flex flex-col flex-wrap justify-center gap-x-5 gap-y-2">
|
<div className="mt-2 flex flex-col flex-wrap justify-center gap-x-5 gap-y-2">
|
||||||
<div>You'll bet:</div>
|
<div>You'll bet:</div>
|
||||||
<Row
|
<Row
|
||||||
|
@ -112,37 +120,29 @@ function CreateChallengeForm(props: {
|
||||||
'form-control w-full max-w-xs items-center justify-between gap-4 pr-3'
|
'form-control w-full max-w-xs items-center justify-between gap-4 pr-3'
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Col>
|
<AmountInput
|
||||||
<div className="relative">
|
amount={challengeInfo.amount || undefined}
|
||||||
<span className="absolute mx-3 mt-3.5 text-sm text-gray-400">
|
onChange={(newAmount) =>
|
||||||
M$
|
setChallengeInfo((m: challengeInfo) => {
|
||||||
</span>
|
return {
|
||||||
<input
|
...m,
|
||||||
className="input input-bordered w-32 pl-10"
|
amount: newAmount ?? 0,
|
||||||
type="number"
|
acceptorAmount: editingAcceptorAmount
|
||||||
min={1}
|
? m.acceptorAmount
|
||||||
value={challengeInfo.amount}
|
: newAmount ?? 0,
|
||||||
onChange={(e) =>
|
|
||||||
setChallengeInfo((m: challengeInfo) => {
|
|
||||||
return {
|
|
||||||
...m,
|
|
||||||
amount: parseInt(e.target.value),
|
|
||||||
acceptorAmount: editingAcceptorAmount
|
|
||||||
? m.acceptorAmount
|
|
||||||
: parseInt(e.target.value),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
/>
|
})
|
||||||
</div>
|
}
|
||||||
</Col>
|
error={undefined}
|
||||||
|
label={'M$'}
|
||||||
|
inputClassName="w-24"
|
||||||
|
/>
|
||||||
<span className={''}>on</span>
|
<span className={''}>on</span>
|
||||||
{challengeInfo.outcome === 'YES' ? <YesLabel /> : <NoLabel />}
|
{challengeInfo.outcome === 'YES' ? <YesLabel /> : <NoLabel />}
|
||||||
</Row>
|
</Row>
|
||||||
<Row className={'mt-3 max-w-xs justify-end'}>
|
<Row className={'mt-3 max-w-xs justify-end'}>
|
||||||
<Button
|
<Button
|
||||||
color={'gradient'}
|
color={'gray-white'}
|
||||||
className={'opacity-80'}
|
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
setChallengeInfo((m: challengeInfo) => {
|
setChallengeInfo((m: challengeInfo) => {
|
||||||
return {
|
return {
|
||||||
|
@ -152,67 +152,70 @@ function CreateChallengeForm(props: {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<SwitchVerticalIcon className={'h-4 w-4'} />
|
<SwitchVerticalIcon className={'h-6 w-6'} />
|
||||||
</Button>
|
</Button>
|
||||||
</Row>
|
</Row>
|
||||||
<Row className={'items-center'}>If they bet:</Row>
|
<Row className={'items-center'}>If they bet:</Row>
|
||||||
<Row className={'max-w-xs items-center justify-between gap-4 pr-3'}>
|
<Row className={'max-w-xs items-center justify-between gap-4 pr-3'}>
|
||||||
<div className={'w-32 sm:mr-1'}>
|
<div className={'w-32 sm:mr-1'}>
|
||||||
{editingAcceptorAmount ? (
|
<AmountInput
|
||||||
<Col>
|
amount={challengeInfo.acceptorAmount || undefined}
|
||||||
<div className="relative">
|
onChange={(newAmount) => {
|
||||||
<span className="absolute mx-3 mt-3.5 text-sm text-gray-400">
|
setEditingAcceptorAmount(true)
|
||||||
M$
|
|
||||||
</span>
|
setChallengeInfo((m: challengeInfo) => {
|
||||||
<input
|
return {
|
||||||
className="input input-bordered w-32 pl-10"
|
...m,
|
||||||
type="number"
|
acceptorAmount: newAmount ?? 0,
|
||||||
min={1}
|
}
|
||||||
value={challengeInfo.acceptorAmount}
|
})
|
||||||
onChange={(e) =>
|
}}
|
||||||
setChallengeInfo((m: challengeInfo) => {
|
error={undefined}
|
||||||
return {
|
label={'M$'}
|
||||||
...m,
|
inputClassName="w-24"
|
||||||
acceptorAmount: parseInt(e.target.value),
|
/>
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</Col>
|
|
||||||
) : (
|
|
||||||
<span className="ml-1 font-bold">
|
|
||||||
{formatMoney(challengeInfo.acceptorAmount)}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
<span>on</span>
|
<span>on</span>
|
||||||
{challengeInfo.outcome === 'YES' ? <NoLabel /> : <YesLabel />}
|
{challengeInfo.outcome === 'YES' ? <NoLabel /> : <YesLabel />}
|
||||||
</Row>
|
</Row>
|
||||||
</div>
|
</div>
|
||||||
<Row
|
<Button
|
||||||
className={clsx(
|
size="2xs"
|
||||||
'mt-8',
|
color="gray"
|
||||||
!editingAcceptorAmount ? 'justify-between' : 'justify-end'
|
onClick={() => {
|
||||||
)}
|
setEditingAcceptorAmount(true)
|
||||||
|
|
||||||
|
const p = getProbability(contract)
|
||||||
|
const prob = challengeInfo.outcome === 'YES' ? p : 1 - p
|
||||||
|
const { amount } = challengeInfo
|
||||||
|
const acceptorAmount = Math.round(amount / prob - amount)
|
||||||
|
setChallengeInfo({ ...challengeInfo, acceptorAmount })
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{!editingAcceptorAmount && (
|
Use market odds
|
||||||
<Button
|
</Button>
|
||||||
color={'gray-white'}
|
|
||||||
onClick={() => setEditingAcceptorAmount(!editingAcceptorAmount)}
|
<div className="mt-8">
|
||||||
>
|
If the challenge is accepted, whoever is right will earn{' '}
|
||||||
Edit
|
<span className="font-semibold">
|
||||||
</Button>
|
{formatMoney(
|
||||||
)}
|
challengeInfo.acceptorAmount + challengeInfo.amount || 0
|
||||||
|
)}
|
||||||
|
</span>{' '}
|
||||||
|
in total.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Row className="mt-8 items-center">
|
||||||
<Button
|
<Button
|
||||||
type="submit"
|
type="submit"
|
||||||
color={'indigo'}
|
color={'gradient'}
|
||||||
|
size="xl"
|
||||||
className={clsx(
|
className={clsx(
|
||||||
'whitespace-nowrap drop-shadow-md',
|
'whitespace-nowrap drop-shadow-md',
|
||||||
isCreating ? 'disabled' : ''
|
isCreating ? 'disabled' : ''
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
Continue
|
Create challenge bet
|
||||||
</Button>
|
</Button>
|
||||||
</Row>
|
</Row>
|
||||||
<Row className={'text-error'}>{error} </Row>
|
<Row className={'text-error'}>{error} </Row>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user