2018-11-29 20:52:24 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { Formik } from 'formik';
|
|
|
|
import EmbarkJS from 'Embark/EmbarkJS';
|
|
|
|
import LPVault from 'Embark/contracts/LPVault';
|
|
|
|
import LiquidPledgingMock from 'Embark/contracts/LiquidPledgingMock';
|
|
|
|
import Button from '@material-ui/core/Button';
|
|
|
|
import TextField from '@material-ui/core/TextField';
|
2018-11-30 15:33:48 +00:00
|
|
|
import Snackbar from '@material-ui/core/Snackbar';
|
2018-11-29 20:52:24 +00:00
|
|
|
import web3 from "Embark/web3";
|
2018-11-30 15:33:48 +00:00
|
|
|
import { MySnackbarContentWrapper } from './base/SnackBars';
|
2018-11-29 20:52:24 +00:00
|
|
|
|
|
|
|
const { addGiver, numberOfPledgeAdmins, getPledgeAdmin } = LiquidPledgingMock.methods;
|
|
|
|
const hoursToSeconds = hours => hours * 60 * 60;
|
2018-11-30 15:33:48 +00:00
|
|
|
const addFunderSucessMsg = response => {
|
|
|
|
const { events: { GiverAdded: { returnValues: { idGiver } } } } = response;
|
|
|
|
return `Funder created with ID of ${idGiver}`;
|
|
|
|
}
|
2018-11-29 20:52:24 +00:00
|
|
|
|
2018-11-30 11:02:57 +00:00
|
|
|
const AddFunder = () => (
|
2018-11-29 20:52:24 +00:00
|
|
|
<Formik
|
2018-11-30 16:38:58 +00:00
|
|
|
initialValues={{ funderName: '', funderDescription: '', commitTime : '' }}
|
2018-11-30 15:33:48 +00:00
|
|
|
onSubmit={async (values, { setSubmitting, resetForm, setStatus }) => {
|
2018-11-30 16:38:58 +00:00
|
|
|
const { funderName, funderDescription, commitTime } = values;
|
2018-11-30 15:33:48 +00:00
|
|
|
const account = await web3.eth.getCoinbase();
|
2018-11-30 16:38:58 +00:00
|
|
|
const args = [funderName, funderDescription, commitTime, 0];
|
2018-11-30 15:33:48 +00:00
|
|
|
addGiver(...args)
|
|
|
|
.estimateGas({ from: account })
|
|
|
|
.then(async gas => {
|
|
|
|
addGiver(...args)
|
|
|
|
.send({ from: account, gas: gas + 100 })
|
|
|
|
.then(res => {
|
|
|
|
console.log({res})
|
|
|
|
setStatus({
|
|
|
|
snackbar: { variant: 'success', message: addFunderSucessMsg(res) }
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
console.log({e})
|
|
|
|
setStatus({
|
|
|
|
snackbar: { variant: 'error', message: 'There was an error' }
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2018-11-29 20:52:24 +00:00
|
|
|
}}
|
|
|
|
>
|
2018-11-30 15:33:48 +00:00
|
|
|
{({
|
|
|
|
values,
|
|
|
|
errors,
|
|
|
|
touched,
|
|
|
|
handleChange,
|
|
|
|
handleBlur,
|
|
|
|
handleSubmit,
|
|
|
|
setFieldValue,
|
|
|
|
setStatus,
|
|
|
|
status
|
|
|
|
}) => (
|
|
|
|
<form onSubmit={handleSubmit} style={{ display: 'flex', flexDirection: 'column' }}>
|
|
|
|
<TextField
|
|
|
|
id="funderName"
|
|
|
|
name="funderName"
|
|
|
|
label="Funder Name"
|
|
|
|
placeholder="Funder Name"
|
|
|
|
margin="normal"
|
|
|
|
variant="outlined"
|
|
|
|
onChange={handleChange}
|
|
|
|
onBlur={handleBlur}
|
|
|
|
value={values.funderName || ''}
|
|
|
|
/>
|
|
|
|
<TextField
|
2018-11-30 16:38:58 +00:00
|
|
|
id="funderDescription"
|
|
|
|
name="funderDescription"
|
|
|
|
label="Funder Description (URL or IPFS Hash)"
|
|
|
|
placeholder="Funder Description (URL or IPFS Hash)"
|
2018-11-30 15:33:48 +00:00
|
|
|
margin="normal"
|
|
|
|
variant="outlined"
|
|
|
|
onChange={handleChange}
|
|
|
|
onBlur={handleBlur}
|
2018-11-30 16:38:58 +00:00
|
|
|
value={values.funderDescription || ''}
|
2018-11-30 15:33:48 +00:00
|
|
|
/>
|
|
|
|
<TextField
|
|
|
|
id="commitTime"
|
|
|
|
name="commitTime"
|
|
|
|
label="Commit time in hours"
|
|
|
|
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"
|
|
|
|
onChange={handleChange}
|
|
|
|
onBlur={handleBlur}
|
|
|
|
value={values.commitTime || ''}
|
|
|
|
/>
|
|
|
|
<Button variant="contained" color="primary" type="submit">
|
2018-11-30 16:38:58 +00:00
|
|
|
ADD FUNDER PROFILE
|
2018-11-30 15:33:48 +00:00
|
|
|
</Button>
|
|
|
|
{status && <Snackbar
|
|
|
|
anchorOrigin={{
|
|
|
|
vertical: 'bottom',
|
|
|
|
horizontal: 'left',
|
|
|
|
}}
|
|
|
|
open={!!status.snackbar}
|
|
|
|
autoHideDuration={6000}
|
|
|
|
onClose={() => setStatus(null)}
|
|
|
|
>
|
|
|
|
<MySnackbarContentWrapper
|
|
|
|
onClose={() => setStatus(null)}
|
|
|
|
variant={status.snackbar.variant}
|
|
|
|
message={status.snackbar.message}
|
|
|
|
/>
|
|
|
|
</Snackbar>}
|
|
|
|
</form>
|
|
|
|
)}
|
|
|
|
</Formik>
|
2018-11-29 20:52:24 +00:00
|
|
|
)
|
|
|
|
|
2018-11-30 11:02:57 +00:00
|
|
|
export default AddFunder;
|