From 95bef6267c74222c117cde520b174335787a25f3 Mon Sep 17 00:00:00 2001 From: Barry Gitarts Date: Sun, 2 Dec 2018 12:25:49 -0500 Subject: [PATCH] add delegate functionality --- app/components/AddFunder.jsx | 69 +++++++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 17 deletions(-) diff --git a/app/components/AddFunder.jsx b/app/components/AddFunder.jsx index cfe3aa5..a488648 100644 --- a/app/components/AddFunder.jsx +++ b/app/components/AddFunder.jsx @@ -1,35 +1,52 @@ -import React from 'react'; -import { Formik } from 'formik'; -import LiquidPledgingMock from 'Embark/contracts/LiquidPledgingMock'; -import Button from '@material-ui/core/Button'; -import TextField from '@material-ui/core/TextField'; -import Snackbar from '@material-ui/core/Snackbar'; -import web3 from "Embark/web3"; +import React from 'react' +import { Formik } from 'formik' +import LiquidPledgingMock from 'Embark/contracts/LiquidPledgingMock' +import Button from '@material-ui/core/Button' +import MenuItem from '@material-ui/core/MenuItem' +import TextField from '@material-ui/core/TextField' +import Snackbar from '@material-ui/core/Snackbar' +import web3 from 'Embark/web3' import { MySnackbarContentWrapper } from './base/SnackBars' -const { addGiver } = LiquidPledgingMock.methods +const { addGiver, addDelegate } = LiquidPledgingMock.methods +const FUNDER = 'FUNDER' +const DELEGATE = 'DELEGATE' +const helperText = { + [FUNDER]: 'The length of time in hours the Funder has to veto when the delegates pledge funds to a project', + [DELEGATE]: 'The length of time in hours the Delegate can be vetoed. Whenever this delegate is in a delegate chain the time allowed to veto any event must be greater than or equal to this time' +} +const adminProfiles = [FUNDER, DELEGATE] const hoursToSeconds = hours => hours * 60 * 60 const addFunderSucessMsg = response => { const { events: { GiverAdded: { returnValues: { idGiver } } } } = response return `Funder created with ID of ${idGiver}` } +const addDelegateSucessMsg = response => { + const { events: { DelegateAdded: { returnValues: { idDelegate } } } } = response + return `Delegate created with ID of ${idDelegate}` +} const AddFunder = ({ appendFundProfile }) => ( { - const { funderName, funderDescription, commitTime } = values + const { adminType, funderName, funderDescription, commitTime } = values const account = await web3.eth.getCoinbase() const args = [funderName, funderDescription, hoursToSeconds(commitTime), 0] - addGiver(...args) + const isFunder = adminType === FUNDER + const sendFn = isFunder ? addGiver : addDelegate + sendFn(...args) .estimateGas({ from: account }) .then(async gas => { - addGiver(...args) + sendFn(...args) .send({ from: account, gas: gas + 100 }) .then(res => { - appendFundProfile(res.events.GiverAdded) + if (isFunder) appendFundProfile(res.events.GiverAdded) setStatus({ - snackbar: { variant: 'success', message: addFunderSucessMsg(res) } + snackbar: { + variant: 'success', + message: isFunder ? addFunderSucessMsg(res) : addDelegateSucessMsg(res) + } }) }) .catch(e => { @@ -53,11 +70,29 @@ const AddFunder = ({ appendFundProfile }) => ( status }) => (
+ + {adminProfiles.map(profile => ( + + {profile} + + ))} + ( placeholder="Commit time in hours" margin="normal" variant="outlined" - helperText="The length of time in hours the Funder has to veto when the delegates pledge funds to a project" + helperText={helperText[values.adminType]} onChange={handleChange} onBlur={handleBlur} value={values.commitTime || ''} /> {status &&