add addPoll method to handlesubmit
This commit is contained in:
parent
00957320b1
commit
a3807a8478
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue