add append fund profile

This commit is contained in:
Barry Gitarts 2018-12-02 09:46:20 -05:00
parent 63df7614e3
commit 8963677360
4 changed files with 19 additions and 7 deletions

View File

@ -5,7 +5,7 @@ import Button from '@material-ui/core/Button';
import TextField from '@material-ui/core/TextField'; import TextField from '@material-ui/core/TextField';
import Snackbar from '@material-ui/core/Snackbar'; import Snackbar from '@material-ui/core/Snackbar';
import web3 from "Embark/web3"; import web3 from "Embark/web3";
import { MySnackbarContentWrapper } from './base/SnackBars'; import { MySnackbarContentWrapper } from './base/SnackBars'
const { addGiver } = LiquidPledgingMock.methods const { addGiver } = LiquidPledgingMock.methods
const hoursToSeconds = hours => hours * 60 * 60 const hoursToSeconds = hours => hours * 60 * 60
@ -14,7 +14,7 @@ const addFunderSucessMsg = response => {
return `Funder created with ID of ${idGiver}` return `Funder created with ID of ${idGiver}`
} }
const AddFunder = () => ( 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 }) => {
@ -27,7 +27,7 @@ const AddFunder = () => (
addGiver(...args) addGiver(...args)
.send({ from: account, gas: gas + 100 }) .send({ from: account, gas: gas + 100 })
.then(res => { .then(res => {
console.log({res}) appendFundProfile(res.events.GiverAdded)
setStatus({ setStatus({
snackbar: { variant: 'success', message: addFunderSucessMsg(res) } snackbar: { variant: 'success', message: addFunderSucessMsg(res) }
}) })

View File

@ -16,7 +16,7 @@ const FunderProfilesTable = ({ data }) => (
{ title: 'Name', field: 'name' }, { title: 'Name', field: 'name' },
{ title: 'Url', field: 'url' }, { title: 'Url', field: 'url' },
{ title: 'Commit Time', field: 'commitTime', type: 'numeric' }, { title: 'Commit Time', field: 'commitTime', type: 'numeric' },
{ title: 'cancel', field: 'canceled' } { title: 'Canceled', field: 'canceled' }
]} ]}
data={data.map(formatField)} data={data.map(formatField)}
title="Funding Profiles" title="Funding Profiles"

View File

@ -9,7 +9,7 @@ import AddFunder from './components/AddFunder';
import CreateFunding from './components/CreateFunding'; import CreateFunding from './components/CreateFunding';
import FunderProfilesTable from './components/FunderProfilesTable.jsx' import FunderProfilesTable from './components/FunderProfilesTable.jsx'
import { initVaultAndLP, vaultPledgingNeedsInit, standardTokenApproval, getLpAllowance } from './utils/initialize' import { initVaultAndLP, vaultPledgingNeedsInit, standardTokenApproval, getLpAllowance } from './utils/initialize'
import { getUserFundProfiles } from './utils/events'; import { getUserFundProfiles, formatFundProfileEvent } from './utils/events';
const { getNetworkType } = web3.eth.net; const { getNetworkType } = web3.eth.net;
@ -37,12 +37,24 @@ class App extends React.Component {
}); });
} }
appendFundProfile = async event => {
const formattedEvent = await formatFundProfileEvent(event)
this.setState((state) => {
const { fundProfiles } = state;
return {
...state,
fundProfiles: [ ...fundProfiles, formattedEvent ]
}
})
}
render() { render() {
const { needsInit, lpAllowance, fundProfiles } = this.state; const { needsInit, lpAllowance, fundProfiles } = this.state;
const { appendFundProfile } = this;
return ( return (
<div> <div>
{fundProfiles && <FunderProfilesTable data={fundProfiles} />} {fundProfiles && <FunderProfilesTable data={fundProfiles} />}
<AddFunder /> <AddFunder appendFundProfile={appendFundProfile} />
<Divider variant="middle" /> <Divider variant="middle" />
<CreateFunding /> <CreateFunding />
{needsInit && <Button variant="outlined" color="secondary" onClick={initVaultAndLP}> {needsInit && <Button variant="outlined" color="secondary" onClick={initVaultAndLP}>

View File

@ -2,7 +2,7 @@ import LiquidPledgingMock from 'Embark/contracts/LiquidPledgingMock'
import web3 from 'Embark/web3' import web3 from 'Embark/web3'
const { getPledgeAdmin } = LiquidPledgingMock.methods const { getPledgeAdmin } = LiquidPledgingMock.methods
const formatFundProfileEvent = async event => { export const formatFundProfileEvent = async event => {
const { returnValues: { idGiver, url } } = event const { returnValues: { idGiver, url } } = event
const { commitTime, name, canceled } = await getPledgeAdmin(idGiver).call() const { commitTime, name, canceled } = await getPledgeAdmin(idGiver).call()
return { return {