{predictions.map((prediction) =>
prediction.createdUrl ? (
) : (
)
)}
)
}
const TEST_VALUE = `1. Biden approval rating (as per 538) is greater than 50%: 80%
2. Court packing is clearly going to happen (new justices don't have to be appointed by end of year): 5%
3. Yang is New York mayor: 80%
4. Newsom recalled as CA governor: 5%
5. At least $250 million in damage from BLM protests this year: 30%
6. Significant capital gains tax hike (above 30% for highest bracket): 20%`
export default function MakePredictions() {
const user = useUser()
const [predictionsString, setPredictionsString] = useState('')
const [description, setDescription] = useState('')
const [isSubmitting, setIsSubmitting] = useState(false)
const [createdContracts, setCreatedContracts] = useState([])
const bulkPlaceholder = `e.g.
${TEST_VALUE}
...
`
const predictions: Prediction[] = []
// Parse bulkContracts, then run createContract for each
const lines = predictionsString ? predictionsString.split('\n') : []
for (const line of lines) {
// Parse line with regex
const matches = line.match(/^(.*):\s*(\d+)%\s*$/) || ['', '', '']
const [_, question, prob] = matches
if (!question || !prob) {
console.error('Invalid prediction: ', line)
continue
}
predictions.push({
question,
description,
initialProb: parseInt(prob),
})
}
async function createContracts() {
if (!user) {
// TODO: Convey error with snackbar/toast
console.error('You need to be signed in!')
return
}
setIsSubmitting(true)
for (const prediction of predictions) {
const contract = await createContract(
prediction.question,
prediction.description,
prediction.initialProb,
user
)
setCreatedContracts((prev) => [...prev, contract])
}
setPredictionsString('')
setIsSubmitting(false)
}
return (