2018-12-18 19:30:50 +00:00
|
|
|
import React from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import { withStyles } from '@material-ui/core/styles'
|
|
|
|
import Card from '@material-ui/core/Card'
|
|
|
|
import CardContent from '@material-ui/core/CardContent'
|
|
|
|
import Typography from '@material-ui/core/Typography'
|
2018-12-19 19:42:04 +00:00
|
|
|
import LinearProgress from '@material-ui/core/LinearProgress'
|
2018-12-18 19:30:50 +00:00
|
|
|
import { FundingContext } from '../../context'
|
2018-12-19 14:27:09 +00:00
|
|
|
import { getDepositWithdrawTotals } from '../../selectors/pledging'
|
2018-12-18 19:30:50 +00:00
|
|
|
|
|
|
|
const styles = {
|
|
|
|
card: {
|
|
|
|
minWidth: 275,
|
|
|
|
},
|
2018-12-19 15:43:47 +00:00
|
|
|
fundingSummaries: {
|
|
|
|
display: 'flex',
|
|
|
|
flexDirection: 'column',
|
|
|
|
alignItems: 'center'
|
|
|
|
},
|
2018-12-18 19:30:50 +00:00
|
|
|
bullet: {
|
|
|
|
display: 'inline-block',
|
|
|
|
margin: '0 2px',
|
|
|
|
transform: 'scale(0.8)',
|
|
|
|
},
|
|
|
|
title: {
|
|
|
|
fontSize: 14,
|
|
|
|
},
|
|
|
|
pos: {
|
|
|
|
marginBottom: 12,
|
|
|
|
},
|
2018-12-19 19:42:04 +00:00
|
|
|
linearColorPrimary: {
|
|
|
|
backgroundColor: '#b2dfdb',
|
|
|
|
},
|
|
|
|
linearBarColorPrimary: {
|
|
|
|
backgroundColor: '#00695c',
|
|
|
|
},
|
2018-12-18 19:30:50 +00:00
|
|
|
}
|
|
|
|
|
2018-12-19 19:42:04 +00:00
|
|
|
const getNet = (deposits, withdraws) => Number(deposits) - Number(withdraws)
|
|
|
|
const getValue = (deposits, withdraws) => (getNet(deposits, withdraws) / Number(deposits)) * 100
|
2018-12-18 19:30:50 +00:00
|
|
|
function SimpleCard(props) {
|
|
|
|
const { classes, title } = props
|
|
|
|
|
|
|
|
return (
|
|
|
|
<FundingContext.Consumer>
|
2018-12-19 14:27:09 +00:00
|
|
|
{({ allPledges, allLpEvents, vaultEvents }) =>
|
2018-12-18 19:30:50 +00:00
|
|
|
<Card className={classes.card}>
|
|
|
|
<CardContent>
|
|
|
|
<Typography variant="h5" component="h2">
|
|
|
|
{title}
|
|
|
|
</Typography>
|
|
|
|
{!!allLpEvents &&
|
2018-12-19 14:27:09 +00:00
|
|
|
Object.entries(getDepositWithdrawTotals({ allLpEvents, allPledges, vaultEvents }))
|
|
|
|
.map(token => {
|
|
|
|
const [name, amounts] = token
|
|
|
|
const { deposits, withdraws } = amounts
|
|
|
|
return (
|
2018-12-19 15:43:47 +00:00
|
|
|
<Card key={name} className={classes.fundingSummaries}>
|
|
|
|
<Typography variant="h5" component="h2">
|
|
|
|
{name}
|
|
|
|
</Typography>
|
2018-12-19 19:42:04 +00:00
|
|
|
<CardContent>
|
|
|
|
<Typography key={name + 'withdraw'} className={classes.pos} color="textSecondary">
|
|
|
|
Funded: {deposits}
|
|
|
|
</Typography>
|
|
|
|
<Typography key={name + 'deposit'} className={classes.pos} color="textSecondary">
|
|
|
|
Withdrawn: {withdraws}
|
|
|
|
</Typography>
|
|
|
|
<Typography key={name + 'total'} className={classes.pos} color="textSecondary">
|
|
|
|
Net: {Number(deposits) - Number(withdraws)}
|
|
|
|
</Typography>
|
|
|
|
<LinearProgress
|
|
|
|
classes={{
|
|
|
|
colorPrimary: classes.linearColorPrimary,
|
|
|
|
barColorPrimary: classes.linearBarColorPrimary,
|
|
|
|
}}
|
|
|
|
color="primary"
|
|
|
|
variant="buffer"
|
|
|
|
value={getValue(deposits, withdraws)}
|
|
|
|
valueBuffer={100} />
|
|
|
|
</CardContent>
|
2018-12-19 15:43:47 +00:00
|
|
|
</Card>
|
2018-12-19 14:27:09 +00:00
|
|
|
)
|
|
|
|
})}
|
2018-12-18 19:30:50 +00:00
|
|
|
</CardContent>
|
|
|
|
</Card>
|
|
|
|
}
|
|
|
|
</FundingContext.Consumer>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleCard.propTypes = {
|
|
|
|
classes: PropTypes.object.isRequired,
|
|
|
|
title: PropTypes.string
|
|
|
|
}
|
|
|
|
|
|
|
|
export default withStyles(styles)(SimpleCard)
|