)
}
// Allow user to create a new contract
// TODO: Extract to a reusable UI, for listing contracts too?
export default function NewContract() {
const creator = useUser()
const [contract, setContract] = useState({
id: '',
creatorId: '',
question: '',
description: '',
seedAmounts: { YES: 100, NO: 100 },
// TODO: Set create time to Firestore timestamp
createdTime: Date.now(),
lastUpdatedTime: Date.now(),
} as Contract)
const [contracts, setContracts] = useState([])
useEffect(() => {
if (creator?.id) {
setContract({ ...contract, creatorId: creator.id })
listContracts(creator?.id).then(setContracts)
}
}, [creator?.id])
async function saveContract() {
await pushContract(contract)
// Update local contract list
setContracts([...contracts, { ...contract }])
}
function saveField(field: keyof Contract) {
return (changeEvent: React.ChangeEvent) =>
setContract({ ...contract, [field]: changeEvent.target.value })
}
const descriptionPlaceholder = `e.g. This market will resolve to “Yes” if, by June 2, 2021, 11:59:59 PM ET, Paxlovid (also known under PF-07321332)...`
return (
Create a new prediction market
{/* Create a Tailwind form that takes in all the fields needed for a new contract */}
{/* When the form is submitted, create a new contract in the database */}