From d4ca88e22cc92d74406beafa86d7f9746673df04 Mon Sep 17 00:00:00 2001 From: Barry Gitarts Date: Wed, 3 Apr 2019 15:46:09 -0400 Subject: [PATCH] add addProject --- app/components/projects/CreateProject.jsx | 61 ++++++++++++++++++++--- 1 file changed, 54 insertions(+), 7 deletions(-) diff --git a/app/components/projects/CreateProject.jsx b/app/components/projects/CreateProject.jsx index 44ced88..b905b5f 100644 --- a/app/components/projects/CreateProject.jsx +++ b/app/components/projects/CreateProject.jsx @@ -1,5 +1,6 @@ -import React, { createRef, useState } from 'react' +import React, { createRef, useState, useContext } from 'react' import { Formik } from 'formik' +import LiquidPledging from 'Embark/contracts/LiquidPledging' import TextField from '@material-ui/core/TextField' import Divider from '@material-ui/core/Divider' import FormControlLabel from '@material-ui/core/FormControlLabel' @@ -8,7 +9,14 @@ import Button from '@material-ui/core/Button' import InputAdornment from '@material-ui/core/InputAdornment' import CloudUpload from '@material-ui/icons/CloudUpload' import { withStyles } from '@material-ui/core/styles' -import { captureFile, formatForIpfs, uploadToIpfs } from '../../utils/ipfs' +import { formatForIpfs, uploadToIpfs } from '../../utils/ipfs' +import { FundingContext } from '../../context' + +const { addProject } = LiquidPledging.methods + + +const hoursToSeconds = hours => hours * 60 * 60 +const helperText = 'The length of time the Project has to veto when the project delegates to another delegate and they pledge those funds to a project' const styles = theme => ({ root: { @@ -58,6 +66,9 @@ const styles = theme => ({ }) const isWeb = str => str.includes('http') +const formatMedia = str => { + return isWeb(str) ? str : `/root/${str}` +} const createJSON = values => { const { title, @@ -75,13 +86,13 @@ const createJSON = values => { title, subtitle, creator, - avatar, + avatar: formatMedia(avatar), goal, goalToken, description, media: { isPlaying, - url: video, + url: formatMedia(video), type: 'video' } } @@ -96,8 +107,13 @@ const Title = ({ className }) => ( ) let uploadInput = createRef() +const addProjectSucessMsg = response => { + const { events: { ProjectAdded: { returnValues: { idProject } } } } = response + return `Project created with ID of ${idProject}` +} const SubmissionSection = ({ classes }) => { const [uploads, setUploads] = useState({}) + const { account, openSnackBar } = useContext(FundingContext) return ( { goalToken: '', video: '', isPlaying: false, - description: '' + description: '', + commitTime: 24 }} onSubmit={async (values, { resetForm }) => { + const { title, commitTime } = values const manifest = createJSON(values) let fileLists = [] Object.keys(uploads).forEach(k => { @@ -121,7 +139,19 @@ const SubmissionSection = ({ classes }) => { path: '/root/manifest.json', content: Buffer.from(manifest) }) const contentHash = await uploadToIpfs(fileLists) - //saveToIpfs(fileLists, console.log, console.log) + const args = [title, contentHash, account, 0, hoursToSeconds(commitTime), 0] + addProject(...args) + .estimateGas({ from: account }) + .then(async gas => { + addProject(...args) + .send({ from: account, gas: gas + 100 }) + .then(res => { + console.log({res}) + openSnackBar('success', addProjectSucessMsg(res)) + resetForm() + }) + .catch(e => openSnackBar('error', e)) + }) console.log({manifest, values, uploads, fileLists, contentHash}) }} @@ -153,7 +183,6 @@ const SubmissionSection = ({ classes }) => { ...status, activeField: null }) - console.log({file, activeField, status}, e.target) } } style={{ display: 'none' }} @@ -175,6 +204,24 @@ const SubmissionSection = ({ classes }) => { onBlur={handleBlur} value={values.title || ''} /> +