2018-11-30 18:36:09 +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';
|
|
|
|
import Snackbar from '@material-ui/core/Snackbar';
|
|
|
|
import MenuItem from '@material-ui/core/MenuItem';
|
|
|
|
import web3 from 'Embark/web3';
|
|
|
|
import { MySnackbarContentWrapper } from './base/SnackBars';
|
2018-11-30 21:19:46 +00:00
|
|
|
import { currencies, TOKEN_ICON_API, getTokenLabel } from '../utils/currencies'
|
2018-11-30 18:36:09 +00:00
|
|
|
|
2018-11-30 21:19:46 +00:00
|
|
|
const { donate } = LiquidPledgingMock.methods
|
2018-11-30 18:36:09 +00:00
|
|
|
const hoursToSeconds = hours => hours * 60 * 60
|
|
|
|
const addFunderSucessMsg = response => {
|
|
|
|
const { events: { GiverAdded: { returnValues: { idGiver } } } } = response
|
|
|
|
return `Funder created with ID of ${idGiver}`
|
|
|
|
}
|
|
|
|
|
|
|
|
const CreateFunding = () => (
|
|
|
|
<Formik
|
2018-11-30 21:19:46 +00:00
|
|
|
initialValues={{ funderId: '', receiverId: '', tokenAddress : '', amount: '' }}
|
2018-11-30 18:36:09 +00:00
|
|
|
onSubmit={async (values, { setSubmitting, resetForm, setStatus }) => {
|
2018-11-30 21:19:46 +00:00
|
|
|
const { funderId, receiverId, tokenAddress, amount } = values
|
2018-11-30 18:36:09 +00:00
|
|
|
const account = await web3.eth.getCoinbase()
|
2018-11-30 21:19:46 +00:00
|
|
|
const args = [funderId, receiverId, tokenAddress, web3.utils.toWei(amount, 'ether')]
|
|
|
|
donate(...args)
|
2018-12-01 14:31:04 +00:00
|
|
|
.send({ from: account })
|
|
|
|
.then(res => {
|
|
|
|
console.log({res})
|
|
|
|
setStatus({
|
|
|
|
snackbar: { variant: 'success', message: 'funding provided!' }
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
console.log({e})
|
|
|
|
setStatus({
|
|
|
|
snackbar: { variant: 'error', message: 'There was an error' }
|
|
|
|
})
|
2018-11-30 18:36:09 +00:00
|
|
|
})
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{({
|
|
|
|
values,
|
|
|
|
errors,
|
|
|
|
touched,
|
|
|
|
handleChange,
|
|
|
|
handleBlur,
|
|
|
|
handleSubmit,
|
|
|
|
setFieldValue,
|
|
|
|
setStatus,
|
|
|
|
status
|
|
|
|
}) => (
|
|
|
|
<form onSubmit={handleSubmit} style={{ display: 'flex', flexDirection: 'column' }}>
|
|
|
|
<TextField
|
|
|
|
id="funderId"
|
|
|
|
name="funderId"
|
|
|
|
label="Funder Id"
|
|
|
|
placeholder="Funder Id"
|
|
|
|
margin="normal"
|
|
|
|
variant="outlined"
|
|
|
|
onChange={handleChange}
|
|
|
|
onBlur={handleBlur}
|
|
|
|
value={values.funderId || ''}
|
|
|
|
/>
|
|
|
|
<TextField
|
|
|
|
id="receiverId"
|
|
|
|
name="receiverId"
|
|
|
|
label="Receiver Id"
|
|
|
|
placeholder="Receiver Id"
|
|
|
|
margin="normal"
|
|
|
|
variant="outlined"
|
|
|
|
helperText="The receiver of the funding can be any admin, giver, delegate or a project"
|
|
|
|
onChange={handleChange}
|
|
|
|
onBlur={handleBlur}
|
|
|
|
value={values.receiverId || ''}
|
|
|
|
/>
|
|
|
|
<TextField
|
|
|
|
id="tokenAddress"
|
|
|
|
name="tokenAddress"
|
|
|
|
select
|
|
|
|
label="Select token for funding"
|
|
|
|
placeholder="Select token for funding"
|
|
|
|
margin="normal"
|
|
|
|
variant="outlined"
|
|
|
|
onChange={handleChange}
|
|
|
|
onBlur={handleBlur}
|
|
|
|
value={values.tokenAddress || ''}
|
|
|
|
>
|
|
|
|
{currencies.map(option => (
|
|
|
|
<MenuItem style={{ display: 'flex', alignItems: 'center' }} key={option.value} value={option.value}>
|
2018-12-01 20:32:00 +00:00
|
|
|
{option.icon || <img
|
2018-11-30 18:36:09 +00:00
|
|
|
src={option.img || `${TOKEN_ICON_API}/${option.value}.png`}
|
|
|
|
style={{ width: '3%', marginRight: '3%' }}
|
2018-12-01 20:32:00 +00:00
|
|
|
/>}
|
|
|
|
{option.label}
|
2018-11-30 18:36:09 +00:00
|
|
|
</MenuItem>
|
|
|
|
))}
|
|
|
|
</TextField>
|
2018-11-30 21:19:46 +00:00
|
|
|
<TextField
|
|
|
|
id="amount"
|
|
|
|
name="amount"
|
|
|
|
label={`Amount of ${getTokenLabel(values.tokenAddress) || 'tokens'} to provide`}
|
|
|
|
placeholder="Amount of tokens to provide"
|
|
|
|
margin="normal"
|
|
|
|
variant="outlined"
|
|
|
|
onChange={handleChange}
|
|
|
|
onBlur={handleBlur}
|
|
|
|
value={values.amount || ''}
|
|
|
|
/>
|
2018-11-30 18:36:09 +00:00
|
|
|
<Button variant="contained" color="primary" type="submit">
|
|
|
|
PROVIDE FUNDING
|
|
|
|
</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>
|
|
|
|
)
|
|
|
|
|
|
|
|
export default CreateFunding
|