Merge branch 'main' into create-contract

This commit is contained in:
Austin Chen 2021-12-10 09:37:23 -08:00
commit bf2461c5bd
5 changed files with 75 additions and 31 deletions

View File

@ -1,15 +1,20 @@
import React, { useState } from 'react' import React, { useState } from 'react'
import { Contract } from '../lib/firebase/contracts' import { Contract } from '../lib/firebase/contracts'
import { Button } from './button'
import { Col } from './layout/col' import { Col } from './layout/col'
import { Row } from './layout/row'
import { Spacer } from './layout/spacer' import { Spacer } from './layout/spacer'
import { YesNoSelector } from './yes-no-selector' import { YesNoSelector } from './yes-no-selector'
export function BetPanel(props: { contract: Contract; className?: string }) { export function BetPanel(props: { contract: Contract; className?: string }) {
const { contract, className } = props const { contract, className } = props
const [betChoice, setBetChoice] = useState<'yes' | 'no'>('yes') const [betChoice, setBetChoice] = useState<'YES' | 'NO'>('YES')
const [shares, setShares] = useState(0) const [betAmount, setBetAmount] = useState<number | undefined>(undefined)
function onBetChange(str: string) {
const amount = parseInt(str)
setBetAmount(isNaN(amount) ? undefined : amount)
}
return ( return (
<Col className={'bg-gray-600 p-6 rounded ' + className}> <Col className={'bg-gray-600 p-6 rounded ' + className}>
@ -24,29 +29,37 @@ export function BetPanel(props: { contract: Contract; className?: string }) {
<Spacer h={4} /> <Spacer h={4} />
<div className="p-2 font-medium">Shares</div> <div className="p-2 font-medium">Bet amount</div>
<div className="p-2"> <Row className="p-2 items-center">
<input <input
className="input input-bordered input-md" className="input input-bordered input-md"
style={{ maxWidth: 80 }} style={{ maxWidth: 80 }}
type="text" type="text"
value={shares} placeholder="0"
onChange={(e) => setShares(parseInt(e.target.value) || 0)} value={betAmount ?? ''}
onFocus={(e) => e.target.select()} onChange={(e) => onBetChange(e.target.value)}
/> />
</div> <div className="ml-3">points</div>
</Row>
{!!betAmount && (
<>
<Spacer h={4} /> <Spacer h={4} />
<div className="p-2 font-medium">Price</div> <div className="p-2 font-medium">Average price</div>
<div className="px-2">{betChoice === 'YES' ? 0.57 : 0.43} points</div>
<Spacer h={2} />
<div className="p-2 font-medium">Estimated winnings</div>
<div className="px-2"> <div className="px-2">
{shares * (betChoice === 'yes' ? 57 : 43)} points {Math.floor(betAmount / (betChoice === 'YES' ? 0.57 : 0.43))} points
</div> </div>
<Spacer h={6} /> <Spacer h={6} />
{shares !== 0 && ( <button className="btn btn-primary">Place bet</button>
<Button color={shares ? 'green' : 'deemphasized'}>Place bet</Button> </>
)} )}
</Col> </Col>
) )

View File

@ -6,7 +6,7 @@ import { firebaseLogin } from '../lib/firebase/users'
const navigation = [ const navigation = [
{ {
name: 'About', name: 'About',
href: 'https://mantic.notion.site/About-Mantic-Markets-09bdde9044614e62a27477b4b1bf77ea', href: 'https://mantic.notion.site/About-Mantic-Markets-46a1a0fb6e294011a8b6b582e276359f',
}, },
{ name: 'Simulator', href: '/simulator' }, { name: 'Simulator', href: '/simulator' },
] ]

View File

@ -18,8 +18,7 @@ export const Hero = () => {
</span> </span>
</h1> </h1>
<p className="mt-3 text-base text-gray-300 sm:mt-5 sm:text-xl lg:text-lg xl:text-xl"> <p className="mt-3 text-base text-gray-300 sm:mt-5 sm:text-xl lg:text-lg xl:text-xl">
Create and resolve your own prediction markets to earn a Forecast the future with play-money prediction markets for you and your community
percent of the bet volume. Powered by Solana.
</p> </p>
<div className="mt-10 sm:mt-12"> <div className="mt-10 sm:mt-12">
<ConvertKitEmailForm /> <ConvertKitEmailForm />

View File

@ -1,10 +1,9 @@
import React from 'react' import React from 'react'
import { Button } from './button'
import { Row } from './layout/row' import { Row } from './layout/row'
export function YesNoSelector(props: { export function YesNoSelector(props: {
selected: 'yes' | 'no' selected: 'YES' | 'NO'
onSelect: (selected: 'yes' | 'no') => void onSelect: (selected: 'YES' | 'NO') => void
yesLabel?: string yesLabel?: string
noLabel?: string noLabel?: string
className?: string className?: string
@ -14,17 +13,17 @@ export function YesNoSelector(props: {
return ( return (
<Row className={className}> <Row className={className}>
<Button <Button
color={selected === 'yes' ? 'green' : 'deemphasized'} color={selected === 'YES' ? 'green' : 'deemphasized'}
hideFocusRing hideFocusRing
onClick={() => onSelect('yes')} onClick={() => onSelect('YES')}
> >
{yesLabel ?? 'Yes'} {yesLabel ?? 'Yes'}
</Button> </Button>
<Button <Button
color={selected === 'no' ? 'red' : 'deemphasized'} color={selected === 'NO' ? 'red' : 'deemphasized'}
hideFocusRing hideFocusRing
onClick={() => onSelect('no')} onClick={() => onSelect('NO')}
className="ml-3" className="ml-3"
> >
{noLabel ?? 'No'} {noLabel ?? 'No'}
@ -32,3 +31,36 @@ export function YesNoSelector(props: {
</Row> </Row>
) )
} }
function Button(props: {
className?: string
onClick?: () => void
color: 'green' | 'red' | 'deemphasized'
hideFocusRing?: boolean
children?: any
}) {
const { className, onClick, children, color, hideFocusRing } = props
return (
<button
type="button"
className={classNames(
'inline-flex items-center px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white',
!hideFocusRing && 'focus:outline-none focus:ring-2 focus:ring-offset-2',
color === 'green' &&
'bg-green-500 hover:bg-green-600 focus:ring-green-500',
color === 'red' && 'bg-red-500 hover:bg-red-600 focus:ring-red-500',
color === 'deemphasized' &&
'bg-transparent hover:bg-gray-500 focus:ring-gray-400',
className
)}
onClick={onClick}
>
{children}
</button>
)
}
function classNames(...classes: any[]) {
return classes.filter(Boolean).join(' ')
}

8
web/package-lock.json generated
View File

@ -8,12 +8,12 @@
"dependencies": { "dependencies": {
"@headlessui/react": "1.4.2", "@headlessui/react": "1.4.2",
"@heroicons/react": "1.0.5", "@heroicons/react": "1.0.5",
"chart.js": "^3.6.1", "chart.js": "3.6.1",
"daisyui": "^1.16.2", "daisyui": "1.16.2",
"firebase": "^9.6.0", "firebase": "9.6.0",
"next": "12.0.4", "next": "12.0.4",
"react": "17.0.2", "react": "17.0.2",
"react-chartjs-2": "^4.0.0", "react-chartjs-2": "4.0.0",
"react-dom": "17.0.2" "react-dom": "17.0.2"
}, },
"devDependencies": { "devDependencies": {