Prevent invalid contracts from being created
This commit is contained in:
parent
d1603de641
commit
bb5c74736d
|
@ -40,9 +40,16 @@ export default function NewContract() {
|
||||||
// We'd like this to look like "Apr 2, 2022, 23:59:59 PM PT" but timezones are hard with dayjs
|
// We'd like this to look like "Apr 2, 2022, 23:59:59 PM PT" but timezones are hard with dayjs
|
||||||
const formattedCloseTime = new Date(closeTime).toString()
|
const formattedCloseTime = new Date(closeTime).toString()
|
||||||
|
|
||||||
|
const isValid =
|
||||||
|
initialProb > 0 &&
|
||||||
|
initialProb < 100 &&
|
||||||
|
question.length > 0 &&
|
||||||
|
// If set, closeTime must be in the future
|
||||||
|
(!closeDate || closeTime > Date.now())
|
||||||
|
|
||||||
async function submit() {
|
async function submit() {
|
||||||
// TODO: add more rigorous error handling for question
|
// TODO: Tell users why their contract is invalid
|
||||||
if (!creator || !question) return
|
if (!creator || !isValid) return
|
||||||
|
|
||||||
setIsSubmitting(true)
|
setIsSubmitting(true)
|
||||||
|
|
||||||
|
@ -94,7 +101,6 @@ export default function NewContract() {
|
||||||
className="input input-bordered input-md"
|
className="input input-bordered input-md"
|
||||||
min={1}
|
min={1}
|
||||||
max={99}
|
max={99}
|
||||||
// TODO: validate that this is a number between 1 and 99
|
|
||||||
onChange={(e) => setInitialProb(parseInt(e.target.value))}
|
onChange={(e) => setInitialProb(parseInt(e.target.value))}
|
||||||
/>
|
/>
|
||||||
<span>%</span>
|
<span>%</span>
|
||||||
|
@ -145,6 +151,7 @@ export default function NewContract() {
|
||||||
className="input input-bordered"
|
className="input input-bordered"
|
||||||
onClick={(e) => e.stopPropagation()}
|
onClick={(e) => e.stopPropagation()}
|
||||||
onChange={(e) => setCloseDate(e.target.value || '')}
|
onChange={(e) => setCloseDate(e.target.value || '')}
|
||||||
|
min={new Date().toISOString().split('T')[0]}
|
||||||
value={closeDate}
|
value={closeDate}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -164,7 +171,7 @@ export default function NewContract() {
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
className="btn btn-primary"
|
className="btn btn-primary"
|
||||||
disabled={isSubmitting || !question}
|
disabled={isSubmitting || !isValid}
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
submit()
|
submit()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user