add addPoll method to handlesubmit
This commit is contained in:
parent
00957320b1
commit
a3807a8478
|
@ -1,4 +1,5 @@
|
||||||
import React, { Fragment } from 'react';
|
import React, { Fragment } from 'react';
|
||||||
|
import web3 from 'web3';
|
||||||
import Card from '@material-ui/core/Card';
|
import Card from '@material-ui/core/Card';
|
||||||
import CardActions from '@material-ui/core/CardActions';
|
import CardActions from '@material-ui/core/CardActions';
|
||||||
import CardContent from '@material-ui/core/CardContent';
|
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 { withStyles } from '@material-ui/core/styles';
|
||||||
import { withFormik } from 'formik';
|
import { withFormik } from 'formik';
|
||||||
|
|
||||||
|
const Web3 = new web3;
|
||||||
|
|
||||||
|
const oneDayinBlocks = 5760;
|
||||||
|
|
||||||
const styles = theme => ({
|
const styles = theme => ({
|
||||||
button: {
|
button: {
|
||||||
margin: theme.spacing.unit,
|
margin: theme.spacing.unit,
|
||||||
|
@ -64,8 +69,23 @@ const AddPoll = withFormik({
|
||||||
const errors = {};
|
const errors = {};
|
||||||
return 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)
|
})(StyledForm)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue