From 5e9a0da95c61b7f4825513e6e881bb38f70beb01 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Wed, 27 Jun 2018 14:44:37 -0400 Subject: [PATCH 1/2] Added gas estimation --- app/components/simple-voting/AddPoll.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/components/simple-voting/AddPoll.js b/app/components/simple-voting/AddPoll.js index 25f398f..322d10c 100644 --- a/app/components/simple-voting/AddPoll.js +++ b/app/components/simple-voting/AddPoll.js @@ -102,17 +102,20 @@ const AddPoll = withFormik({ const { addPoll } = PollManager.methods; const currentBlock = await getBlockNumber(); const endTime = currentBlock + (oneDayinBlocks * 90); - addPoll( - endTime, - singleChoiceDef(description, ['YES', 'NO']) - ) - .send() + + const toSend = addPoll(endTime, singleChoiceDef(description, ['YES'])); + toSend.estimateGas() + .then(gasEstimated => { + console.log("addPoll gas estimated: "+gasEstimated); + return toSend.send({gas: gasEstimated + 1000}); + }) .then(res => { console.log('sucess:', res); }) .catch(res => { console.log('fail:', res); - }) + }); + } })(StyledForm) From 8abcd28835e1ada78a0a05349f32637450d8842a Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Wed, 27 Jun 2018 15:00:50 -0400 Subject: [PATCH 2/2] Added validation when adding polls --- app/components/simple-voting/AddPoll.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/components/simple-voting/AddPoll.js b/app/components/simple-voting/AddPoll.js index 322d10c..f5f9c74 100644 --- a/app/components/simple-voting/AddPoll.js +++ b/app/components/simple-voting/AddPoll.js @@ -92,8 +92,10 @@ const InnerForm = ({ const StyledForm = withStyles(styles)(InnerForm); const AddPoll = withFormik({ mapPropsToValues: props => ({ description: ''}), - validate(values){ + validate(values, props){ const errors = {}; + const { description } = values; + if(description.toString().trim() === "") errors.description = true; return errors; }, async handleSubmit(values, { setSubmitting }) {