diff --git a/app/components/simple-voting/AddPoll.js b/app/components/simple-voting/AddPoll.js index d62c220..80ef1d4 100644 --- a/app/components/simple-voting/AddPoll.js +++ b/app/components/simple-voting/AddPoll.js @@ -1,4 +1,5 @@ import React, { Fragment } from 'react'; +import web3 from 'web3'; import Card from '@material-ui/core/Card'; import CardActions from '@material-ui/core/CardActions'; import CardContent from '@material-ui/core/CardContent'; @@ -8,6 +9,10 @@ import Button from '@material-ui/core/Button'; import { withStyles } from '@material-ui/core/styles'; import { withFormik } from 'formik'; +const Web3 = new web3; + +const oneDayinBlocks = 5760; + const styles = theme => ({ button: { margin: theme.spacing.unit, @@ -64,8 +69,23 @@ const AddPoll = withFormik({ const errors = {}; return errors; }, - handleSubmit(values) { - + async handleSubmit(values, { setSubmitting }) { + const { description } = values; + const { getBlockNumber } = Web3.eth; + const { addPoll } = PollManager.methods; + const currentBlock = await getBlockNumber(); + const endTime = currentBlock * oneDayinBlocks * 90; + addPoll( + endTime, + description + ) + .send() + .then(res => { + console.log('sucess:', res); + }) + .catch(res => { + console.log('fail:', res); + }) } })(StyledForm)