2021-12-14 00:00:02 +00:00
|
|
|
import clsx from 'clsx'
|
2022-05-26 22:22:44 +00:00
|
|
|
import React, { ReactNode } from 'react'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { formatMoney } from 'common/util/format'
|
2022-01-02 06:27:58 +00:00
|
|
|
import { Col } from './layout/col'
|
2021-12-10 14:56:17 +00:00
|
|
|
import { Row } from './layout/row'
|
2022-06-03 00:30:34 +00:00
|
|
|
import { resolution } from 'common/contract'
|
2021-12-10 14:56:17 +00:00
|
|
|
|
2022-07-15 16:03:42 +00:00
|
|
|
export function YesNoSelector(props: {
|
|
|
|
selected?: 'YES' | 'NO'
|
|
|
|
onSelect: (selected: 'YES' | 'NO') => void
|
|
|
|
className?: string
|
|
|
|
btnClassName?: string
|
|
|
|
replaceYesButton?: React.ReactNode
|
|
|
|
replaceNoButton?: React.ReactNode
|
|
|
|
isPseudoNumeric?: boolean
|
|
|
|
}) {
|
|
|
|
const {
|
|
|
|
selected,
|
|
|
|
onSelect,
|
|
|
|
className,
|
|
|
|
btnClassName,
|
|
|
|
replaceNoButton,
|
|
|
|
replaceYesButton,
|
|
|
|
isPseudoNumeric,
|
|
|
|
} = props
|
|
|
|
|
|
|
|
const commonClassNames =
|
|
|
|
'inline-flex items-center justify-center rounded-3xl border-2 p-2'
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Row className={clsx('space-x-3', className)}>
|
|
|
|
{replaceYesButton ? (
|
|
|
|
replaceYesButton
|
|
|
|
) : (
|
|
|
|
<button
|
|
|
|
className={clsx(
|
|
|
|
commonClassNames,
|
|
|
|
'hover:bg-primary-focus border-primary hover:border-primary-focus hover:text-white',
|
|
|
|
selected == 'YES'
|
|
|
|
? 'bg-primary text-white'
|
|
|
|
: 'text-primary bg-transparent',
|
|
|
|
btnClassName
|
|
|
|
)}
|
|
|
|
onClick={() => onSelect('YES')}
|
|
|
|
>
|
|
|
|
{isPseudoNumeric ? 'HIGHER' : 'YES'}
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
{replaceNoButton ? (
|
|
|
|
replaceNoButton
|
|
|
|
) : (
|
|
|
|
<button
|
|
|
|
className={clsx(
|
|
|
|
commonClassNames,
|
|
|
|
'border-red-400 hover:border-red-500 hover:bg-red-500 hover:text-white',
|
|
|
|
selected == 'NO'
|
|
|
|
? 'bg-red-400 text-white'
|
|
|
|
: 'bg-transparent text-red-400',
|
|
|
|
btnClassName
|
|
|
|
)}
|
|
|
|
onClick={() => onSelect('NO')}
|
|
|
|
>
|
|
|
|
{isPseudoNumeric ? 'LOWER' : 'NO'}
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
</Row>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-12-14 00:00:02 +00:00
|
|
|
export function YesNoCancelSelector(props: {
|
2022-06-03 00:30:34 +00:00
|
|
|
selected: resolution | undefined
|
|
|
|
onSelect: (selected: resolution) => void
|
2021-12-14 00:00:02 +00:00
|
|
|
className?: string
|
2021-12-15 18:44:34 +00:00
|
|
|
btnClassName?: string
|
2021-12-14 00:00:02 +00:00
|
|
|
}) {
|
2022-02-13 23:41:08 +00:00
|
|
|
const { selected, onSelect } = props
|
2021-12-14 00:00:02 +00:00
|
|
|
|
2022-03-29 19:56:56 +00:00
|
|
|
const btnClassName = clsx('px-6 flex-1 rounded-3xl', props.btnClassName)
|
2021-12-15 18:44:34 +00:00
|
|
|
|
2021-12-14 00:00:02 +00:00
|
|
|
return (
|
2022-02-13 23:41:08 +00:00
|
|
|
<Col className="gap-2">
|
|
|
|
{/* Should ideally use a radio group instead of buttons */}
|
|
|
|
<Button
|
|
|
|
color={selected === 'YES' ? 'green' : 'gray'}
|
|
|
|
onClick={() => onSelect('YES')}
|
|
|
|
className={btnClassName}
|
|
|
|
>
|
|
|
|
YES
|
|
|
|
</Button>
|
2021-12-14 00:00:02 +00:00
|
|
|
|
2022-02-13 23:41:08 +00:00
|
|
|
<Button
|
|
|
|
color={selected === 'NO' ? 'red' : 'gray'}
|
|
|
|
onClick={() => onSelect('NO')}
|
|
|
|
className={btnClassName}
|
|
|
|
>
|
|
|
|
NO
|
|
|
|
</Button>
|
2021-12-14 00:00:02 +00:00
|
|
|
|
2022-02-13 23:41:08 +00:00
|
|
|
<Button
|
|
|
|
color={selected === 'MKT' ? 'blue' : 'gray'}
|
|
|
|
onClick={() => onSelect('MKT')}
|
|
|
|
className={clsx(btnClassName, 'btn-sm')}
|
|
|
|
>
|
|
|
|
PROB
|
|
|
|
</Button>
|
2022-01-02 06:27:58 +00:00
|
|
|
|
2022-02-13 23:41:08 +00:00
|
|
|
<Button
|
|
|
|
color={selected === 'CANCEL' ? 'yellow' : 'gray'}
|
|
|
|
onClick={() => onSelect('CANCEL')}
|
|
|
|
className={clsx(btnClassName, 'btn-sm')}
|
|
|
|
>
|
|
|
|
N/A
|
|
|
|
</Button>
|
2022-01-02 06:27:58 +00:00
|
|
|
</Col>
|
2021-12-10 14:56:17 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-02-17 23:00:19 +00:00
|
|
|
export function ChooseCancelSelector(props: {
|
2022-02-20 07:26:26 +00:00
|
|
|
selected: 'CHOOSE' | 'CHOOSE_MULTIPLE' | 'CANCEL' | undefined
|
|
|
|
onSelect: (selected: 'CHOOSE' | 'CHOOSE_MULTIPLE' | 'CANCEL') => void
|
2022-02-17 23:00:19 +00:00
|
|
|
className?: string
|
|
|
|
btnClassName?: string
|
|
|
|
}) {
|
|
|
|
const { selected, onSelect, className } = props
|
|
|
|
|
|
|
|
const btnClassName = clsx('px-6 flex-1', props.btnClassName)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Col className={clsx('gap-2', className)}>
|
|
|
|
<Button
|
|
|
|
color={selected === 'CHOOSE' ? 'green' : 'gray'}
|
|
|
|
onClick={() => onSelect('CHOOSE')}
|
|
|
|
className={clsx('whitespace-nowrap', btnClassName)}
|
|
|
|
>
|
|
|
|
Choose an answer
|
|
|
|
</Button>
|
|
|
|
|
2022-02-20 07:26:26 +00:00
|
|
|
<Button
|
|
|
|
color={selected === 'CHOOSE_MULTIPLE' ? 'blue' : 'gray'}
|
|
|
|
onClick={() => onSelect('CHOOSE_MULTIPLE')}
|
|
|
|
className={clsx('whitespace-nowrap', btnClassName)}
|
|
|
|
>
|
|
|
|
Choose multiple
|
|
|
|
</Button>
|
|
|
|
|
2022-02-17 23:00:19 +00:00
|
|
|
<Button
|
|
|
|
color={selected === 'CANCEL' ? 'yellow' : 'gray'}
|
|
|
|
onClick={() => onSelect('CANCEL')}
|
|
|
|
className={clsx(btnClassName, '')}
|
|
|
|
>
|
|
|
|
N/A
|
|
|
|
</Button>
|
|
|
|
</Col>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-04-09 23:56:05 +00:00
|
|
|
const fundAmounts = [1000, 2500, 10000]
|
2022-01-07 22:56:14 +00:00
|
|
|
|
|
|
|
export function FundsSelector(props: {
|
2022-04-09 23:56:05 +00:00
|
|
|
selected: 1000 | 2500 | 10000
|
|
|
|
onSelect: (selected: 1000 | 2500 | 10000) => void
|
2022-01-07 22:56:14 +00:00
|
|
|
className?: string
|
|
|
|
btnClassName?: string
|
|
|
|
}) {
|
|
|
|
const { selected, onSelect, className } = props
|
2022-01-14 03:15:44 +00:00
|
|
|
const btnClassName = clsx('!px-2 whitespace-nowrap', props.btnClassName)
|
2022-01-07 22:56:14 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Row className={clsx('space-x-3', className)}>
|
|
|
|
{fundAmounts.map((amount) => (
|
|
|
|
<Button
|
|
|
|
key={amount}
|
2022-06-13 04:25:57 +00:00
|
|
|
color={selected === amount ? 'indigo' : 'gray'}
|
2022-01-07 22:56:14 +00:00
|
|
|
onClick={() => onSelect(amount as any)}
|
|
|
|
className={btnClassName}
|
|
|
|
>
|
|
|
|
{formatMoney(amount)}
|
|
|
|
</Button>
|
|
|
|
))}
|
|
|
|
</Row>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-02-17 23:00:19 +00:00
|
|
|
export function BuyButton(props: { className?: string; onClick?: () => void }) {
|
|
|
|
const { className, onClick } = props
|
2022-03-17 04:42:24 +00:00
|
|
|
// Note: styles coppied from YesNoSelector
|
2022-02-17 23:00:19 +00:00
|
|
|
return (
|
2022-03-17 04:42:24 +00:00
|
|
|
<button
|
|
|
|
className={clsx(
|
|
|
|
'hover:bg-primary-focus border-primary hover:border-primary-focus inline-flex flex-1 items-center justify-center rounded-lg border-2 p-2 hover:text-white',
|
|
|
|
'text-primary bg-transparent text-lg',
|
|
|
|
className
|
|
|
|
)}
|
|
|
|
onClick={onClick}
|
|
|
|
>
|
2022-04-09 21:13:36 +00:00
|
|
|
Bet
|
2022-03-17 04:42:24 +00:00
|
|
|
</button>
|
2022-02-17 23:00:19 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-05-19 17:42:03 +00:00
|
|
|
export function NumberCancelSelector(props: {
|
|
|
|
selected: 'NUMBER' | 'CANCEL' | undefined
|
|
|
|
onSelect: (selected: 'NUMBER' | 'CANCEL') => void
|
|
|
|
className?: string
|
|
|
|
btnClassName?: string
|
|
|
|
}) {
|
|
|
|
const { selected, onSelect, className } = props
|
|
|
|
|
|
|
|
const btnClassName = clsx('px-6 flex-1', props.btnClassName)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Col className={clsx('gap-2', className)}>
|
|
|
|
<Button
|
|
|
|
color={selected === 'NUMBER' ? 'green' : 'gray'}
|
|
|
|
onClick={() => onSelect('NUMBER')}
|
|
|
|
className={clsx('whitespace-nowrap', btnClassName)}
|
|
|
|
>
|
|
|
|
Choose value
|
|
|
|
</Button>
|
|
|
|
|
|
|
|
<Button
|
|
|
|
color={selected === 'CANCEL' ? 'yellow' : 'gray'}
|
|
|
|
onClick={() => onSelect('CANCEL')}
|
|
|
|
className={clsx(btnClassName, '')}
|
|
|
|
>
|
|
|
|
N/A
|
|
|
|
</Button>
|
|
|
|
</Col>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-12-10 14:56:17 +00:00
|
|
|
function Button(props: {
|
|
|
|
className?: string
|
|
|
|
onClick?: () => void
|
2022-06-13 04:25:57 +00:00
|
|
|
color: 'green' | 'red' | 'blue' | 'indigo' | 'yellow' | 'gray'
|
2022-05-26 22:22:44 +00:00
|
|
|
children?: ReactNode
|
2021-12-10 14:56:17 +00:00
|
|
|
}) {
|
2021-12-14 00:00:02 +00:00
|
|
|
const { className, onClick, children, color } = props
|
2021-12-10 14:56:17 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<button
|
|
|
|
type="button"
|
2021-12-14 00:00:02 +00:00
|
|
|
className={clsx(
|
2022-02-17 23:00:19 +00:00
|
|
|
'inline-flex flex-1 items-center justify-center rounded-md border border-transparent px-8 py-3 font-medium shadow-sm',
|
2022-02-08 05:52:03 +00:00
|
|
|
color === 'green' && 'btn-primary text-white',
|
2022-02-11 18:40:22 +00:00
|
|
|
color === 'red' && 'bg-red-400 text-white hover:bg-red-500',
|
|
|
|
color === 'yellow' && 'bg-yellow-400 text-white hover:bg-yellow-500',
|
|
|
|
color === 'blue' && 'bg-blue-400 text-white hover:bg-blue-500',
|
2022-06-13 04:25:57 +00:00
|
|
|
color === 'indigo' && 'bg-indigo-500 text-white hover:bg-indigo-600',
|
2022-04-18 23:02:40 +00:00
|
|
|
color === 'gray' && 'bg-gray-200 text-gray-700 hover:bg-gray-300',
|
2021-12-10 14:56:17 +00:00
|
|
|
className
|
|
|
|
)}
|
|
|
|
onClick={onClick}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</button>
|
|
|
|
)
|
|
|
|
}
|