mirror of
https://github.com/status-im/liquid-funding.git
synced 2025-01-11 20:14:12 +00:00
add delegate functionality
This commit is contained in:
parent
8963677360
commit
95bef6267c
@ -1,35 +1,52 @@
|
|||||||
import React from 'react';
|
import React from 'react'
|
||||||
import { Formik } from 'formik';
|
import { Formik } from 'formik'
|
||||||
import LiquidPledgingMock from 'Embark/contracts/LiquidPledgingMock';
|
import LiquidPledgingMock from 'Embark/contracts/LiquidPledgingMock'
|
||||||
import Button from '@material-ui/core/Button';
|
import Button from '@material-ui/core/Button'
|
||||||
import TextField from '@material-ui/core/TextField';
|
import MenuItem from '@material-ui/core/MenuItem'
|
||||||
import Snackbar from '@material-ui/core/Snackbar';
|
import TextField from '@material-ui/core/TextField'
|
||||||
import web3 from "Embark/web3";
|
import Snackbar from '@material-ui/core/Snackbar'
|
||||||
|
import web3 from 'Embark/web3'
|
||||||
import { MySnackbarContentWrapper } from './base/SnackBars'
|
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 hoursToSeconds = hours => hours * 60 * 60
|
||||||
const addFunderSucessMsg = response => {
|
const addFunderSucessMsg = response => {
|
||||||
const { events: { GiverAdded: { returnValues: { idGiver } } } } = response
|
const { events: { GiverAdded: { returnValues: { idGiver } } } } = response
|
||||||
return `Funder created with ID of ${idGiver}`
|
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 AddFunder = ({ appendFundProfile }) => (
|
||||||
<Formik
|
<Formik
|
||||||
initialValues={{ funderName: '', funderDescription: '', commitTime : '' }}
|
initialValues={{ funderName: '', funderDescription: '', commitTime : '' }}
|
||||||
onSubmit={async (values, { setSubmitting, resetForm, setStatus }) => {
|
onSubmit={async (values, { setSubmitting, resetForm, setStatus }) => {
|
||||||
const { funderName, funderDescription, commitTime } = values
|
const { adminType, funderName, funderDescription, commitTime } = values
|
||||||
const account = await web3.eth.getCoinbase()
|
const account = await web3.eth.getCoinbase()
|
||||||
const args = [funderName, funderDescription, hoursToSeconds(commitTime), 0]
|
const args = [funderName, funderDescription, hoursToSeconds(commitTime), 0]
|
||||||
addGiver(...args)
|
const isFunder = adminType === FUNDER
|
||||||
|
const sendFn = isFunder ? addGiver : addDelegate
|
||||||
|
sendFn(...args)
|
||||||
.estimateGas({ from: account })
|
.estimateGas({ from: account })
|
||||||
.then(async gas => {
|
.then(async gas => {
|
||||||
addGiver(...args)
|
sendFn(...args)
|
||||||
.send({ from: account, gas: gas + 100 })
|
.send({ from: account, gas: gas + 100 })
|
||||||
.then(res => {
|
.then(res => {
|
||||||
appendFundProfile(res.events.GiverAdded)
|
if (isFunder) appendFundProfile(res.events.GiverAdded)
|
||||||
setStatus({
|
setStatus({
|
||||||
snackbar: { variant: 'success', message: addFunderSucessMsg(res) }
|
snackbar: {
|
||||||
|
variant: 'success',
|
||||||
|
message: isFunder ? addFunderSucessMsg(res) : addDelegateSucessMsg(res)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
@ -53,11 +70,29 @@ const AddFunder = ({ appendFundProfile }) => (
|
|||||||
status
|
status
|
||||||
}) => (
|
}) => (
|
||||||
<form onSubmit={handleSubmit} style={{ display: 'flex', flexDirection: 'column' }}>
|
<form onSubmit={handleSubmit} style={{ display: 'flex', flexDirection: 'column' }}>
|
||||||
|
<TextField
|
||||||
|
id="adminType"
|
||||||
|
name="adminType"
|
||||||
|
select
|
||||||
|
label="Select admin type"
|
||||||
|
placeholder="Select admin type"
|
||||||
|
margin="normal"
|
||||||
|
variant="outlined"
|
||||||
|
onChange={handleChange}
|
||||||
|
onBlur={handleBlur}
|
||||||
|
value={values.adminType || ''}
|
||||||
|
>
|
||||||
|
{adminProfiles.map(profile => (
|
||||||
|
<MenuItem style={{ display: 'flex', alignItems: 'center' }} key={profile} value={profile}>
|
||||||
|
{profile}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</TextField>
|
||||||
<TextField
|
<TextField
|
||||||
id="funderName"
|
id="funderName"
|
||||||
name="funderName"
|
name="funderName"
|
||||||
label="Funding Name"
|
label={`${values.adminType === FUNDER ? 'Funding' : 'Delegate'} Name`}
|
||||||
placeholder="Funding Name"
|
placeholder={`${values.adminType === FUNDER ? 'Funding' : 'Delegate'} Name`}
|
||||||
margin="normal"
|
margin="normal"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
@ -82,13 +117,13 @@ const AddFunder = ({ appendFundProfile }) => (
|
|||||||
placeholder="Commit time in hours"
|
placeholder="Commit time in hours"
|
||||||
margin="normal"
|
margin="normal"
|
||||||
variant="outlined"
|
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}
|
onChange={handleChange}
|
||||||
onBlur={handleBlur}
|
onBlur={handleBlur}
|
||||||
value={values.commitTime || ''}
|
value={values.commitTime || ''}
|
||||||
/>
|
/>
|
||||||
<Button variant="contained" color="primary" type="submit">
|
<Button variant="contained" color="primary" type="submit">
|
||||||
ADD FUNDING PROFILE
|
{`ADD ${values.adminType === FUNDER ? 'FUNDING' : 'DELEGATE'} PROFILE`}
|
||||||
</Button>
|
</Button>
|
||||||
{status && <Snackbar
|
{status && <Snackbar
|
||||||
anchorOrigin={{
|
anchorOrigin={{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user