diff --git a/src/components/MainCointainer.jsx b/src/components/MainCointainer.jsx index 720f8eb..299bf21 100644 --- a/src/components/MainCointainer.jsx +++ b/src/components/MainCointainer.jsx @@ -27,6 +27,7 @@ import Dashboard from './Dashboard' import Projects from './projects/Projects' import Project from './projects/Project' import BackProject from './projects/BackProject' +import ProjectPledges from './projects/ProjectPledges' import CreateProject from './projects/CreateProject' import CreateDelegate from './projects/CreateDelegate' @@ -192,6 +193,7 @@ class PersistentDrawerLeft extends React.Component { } /> } /> + {this.props.children} diff --git a/src/components/projects/ProjectPledges.jsx b/src/components/projects/ProjectPledges.jsx new file mode 100644 index 0000000..184cc7c --- /dev/null +++ b/src/components/projects/ProjectPledges.jsx @@ -0,0 +1,189 @@ +import React from 'react' +import PropTypes from 'prop-types' +import { Formik } from 'formik' +import LiquidPledging from '../../embarkArtifacts/contracts/LiquidPledging' +import withObservables from '@nozbe/with-observables' +import { Q } from '@nozbe/watermelondb' +import { withDatabase } from '@nozbe/watermelondb/DatabaseProvider' +import { withStyles } from '@material-ui/core/styles' +import { useProjectData, useProfileData } from './hooks' +import { Button, Divider, Typography, Card, CardActions, CardContent, FormControlLabel, Switch } from '@material-ui/core' +import { toEther, toWei } from '../../utils/conversions' +import { getTokenLabel } from '../../utils/currencies' + + +// create form with cards showing multiple pledges, allow each to be selected and use mWithdraw to submit a withdrawal for them all + +const { transfer } = LiquidPledging.methods + +const styles = theme => ({ + card: { + minWidth: 275, + }, + root: { + display: 'grid', + gridTemplateColumns: 'repeat(12, [col] 1fr)', + gridTemplateRows: 'repeat(5, [row] auto)', + gridColumnGap: '1em', + gridRowGap: '36px', + fontFamily: theme.typography.fontFamily, + [theme.breakpoints.up('sm')]: { + margin: '1.75rem 4.5rem' + } + }, + title: { + display: 'grid', + fontSize: '2.5rem', + gridColumnStart: '1', + gridColumnEnd: '13', + gridRowStart: '1', + gridRowEnd: '6', + textAlign: 'center' + }, + subText: { + textAlign: 'center' + }, + switchSelect: { + display: 'grid', + gridColumnStart: '3', + gridColumnEnd: '9' + }, + submissionRoot: { + gridColumnStart: '1', + gridColumnEnd: '13' + }, + textField: { + width: '100%' + } +}) + +function SimplePledge({ classes, pledge, values, handleChange }) { + const pledgeId = `pledge.${pledge.id}` + const keys = Object.keys(values) + const value = keys.find(k => values[k].id === pledgeId) + console.log({values}) + + return ( + + + + {toEther(pledge.amount)} {getTokenLabel(pledge.token)} + + + Pledge ID: {pledge.idPledge} + + + commit time {pledge.commitTime} + + + + + } + label="withdraw" + /> + + + ); +} + +SimplePledge.propTypes = { + classes: PropTypes.object.isRequired, + pledge: PropTypes.object.isRequired +}; +const PledgeInfo = withStyles(styles)(SimplePledge); + +const Title = ({ className, manifest }) => ( +
+
{manifest && manifest.title}
+
{manifest && `By ${manifest.creator}`}
+ +
+) +const SubmissionSection = ({ classes, delegatePledges, projectId, openSnackBar, pledges }) => { + return ( + { + const { amount, delegateProfile, delegatePledge } = values + const dPledge = delegatePledges.find(d => d.idPledge === delegatePledge) + const pledge = await dPledge.pledge.fetch() + const args = [delegateProfile.idProfile, delegatePledge, toWei(amount), projectId] + console.log({values, args, pledge, delegatePledge}) + const toSend = transfer(...args) + const estimatedGas = await toSend.estimateGas() + console.log({estimatedGas, openSnackBar, resetForm}) + + }} + > + {({ + values, + errors: _errors, + touched: _touched, + handleChange, + //handleBlur, + handleSubmit, + setFieldValue: _setFieldValue, + setStatus: _setStatus, + status: _status + }) => { + const filterPledges = delegateProfile => delegatePledges.filter( + d => d.profile.id === delegateProfile.id && d.pledgeData.amount !== '0' && d.pledgeData.pledgeState === 0 && d.pledgeData.intendedProject === 0 + ) + const filteredPledges = values.delegateProfile ? filterPledges(values.delegateProfile) : null + console.log({filteredPledges}) + return ( +
+ {pledges.map(pledge => )} + + + ) + } + } +
+ ) +} + +function ProjectPledges({classes, match, delegates: _delegates, projectAddedEvents, delegateAddedEvents: _delegateAddedEvents, pledges}) { + const projectId = match.params.id + const { manifest, delegateProfiles, openSnackBar } = useProjectData(projectId, projectAddedEvents) + const delegatePledges = useProfileData(delegateProfiles) + console.log('pledges', {pledges}) + return ( +
+ + <SubmissionSection + classes={classes} + profiles={delegateProfiles} + delegatePledges={delegatePledges} + projectId={projectId} + openSnackBar={openSnackBar} + pledges={pledges} + /> + </div> + ) +} + +const StyledPledges = withStyles(styles)(ProjectPledges) +export default withDatabase(withObservables([], ({ database, match }) => ({ + profile: database.collections.get('profiles').query( + Q.where('id_profile', match.params.id) + ).observe(), + projectAddedEvents: database.collections.get('lp_events').query( + Q.where('event', 'ProjectAdded') + ).observe(), + delegateAddedEvents: database.collections.get('lp_events').query( + Q.where('event', 'DelegateAdded') + ).observe(), + pledges: database.collections.get('pledges').query( + Q.where('intended_project', match.params.id) + ).observe() +}))(StyledPledges)) +