diff --git a/src/actions/pledges.js b/src/actions/pledges.js index ad804b7..2bde98a 100644 --- a/src/actions/pledges.js +++ b/src/actions/pledges.js @@ -6,7 +6,7 @@ import { getProfilesById } from './profiles' const createPledge = (pledge, data, profiles) => { const { id, owner, amount, blockNumber, token, commitTime, nDelegates, pledgeState, intendedProject, delegates } = data - const profile = profiles.find(p => p.idProfile === owner) + const profile = profiles.find(p => p.idProfile === Number(owner)) pledge.idPledge = Number(id) pledge.owner = Number(owner) pledge.amount = amount diff --git a/src/components/projects/ProjectPledges.jsx b/src/components/projects/ProjectPledges.jsx index 184cc7c..f80f5b3 100644 --- a/src/components/projects/ProjectPledges.jsx +++ b/src/components/projects/ProjectPledges.jsx @@ -1,4 +1,4 @@ -import React from 'react' +import React, { useState, useEffect } from 'react' import PropTypes from 'prop-types' import { Formik } from 'formik' import LiquidPledging from '../../embarkArtifacts/contracts/LiquidPledging' @@ -11,10 +11,23 @@ import { Button, Divider, Typography, Card, CardActions, CardContent, FormContro 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 pledgeStateMap = { + 0: 'Pledged', + 1: 'Paying', + 2: 'Paid' +} + +const getCommitTime = async (pledge, setState) => { + const { commitTime } = pledge + const profile = await pledge.profile.fetch() + if (!profile || Number(commitTime) === 0) return 0 + const time = Number(commitTime) + Number(profile.commitTime) + const date = new Date(time * 1000) + setState(`${date.toLocaleDateString()} ${date.toLocaleTimeString()}`) +} const styles = theme => ({ card: { @@ -41,7 +54,8 @@ const styles = theme => ({ textAlign: 'center' }, subText: { - textAlign: 'center' + textAlign: 'center', + marginBottom: '0.5em' }, switchSelect: { display: 'grid', @@ -49,6 +63,8 @@ const styles = theme => ({ gridColumnEnd: '9' }, submissionRoot: { + display: 'grid', + gridRowGap: '36px', gridColumnStart: '1', gridColumnEnd: '13' }, @@ -58,10 +74,14 @@ const styles = theme => ({ }) function SimplePledge({ classes, pledge, values, handleChange }) { + const [commitTime, setCommitTime] = useState(0); const pledgeId = `pledge.${pledge.id}` const keys = Object.keys(values) const value = keys.find(k => values[k].id === pledgeId) - console.log({values}) + + useEffect(() => { + getCommitTime(pledge, setCommitTime) + }, [pledge]) return ( @@ -72,8 +92,11 @@ function SimplePledge({ classes, pledge, values, handleChange }) { Pledge ID: {pledge.idPledge} - - commit time {pledge.commitTime} + + Pledge Status: {pledgeStateMap[pledge.pledgeState]} + + + Commit Time: {commitTime} @@ -142,7 +165,7 @@ const SubmissionSection = ({ classes, delegatePledges, projectId, openSnackBar,
{pledges.map(pledge => )} + withdraw ) }