2018-12-18 19:30:50 +00:00
|
|
|
import React from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
2019-01-24 13:32:11 +00:00
|
|
|
import withObservables from '@nozbe/with-observables'
|
|
|
|
import { Q } from '@nozbe/watermelondb'
|
|
|
|
import { withDatabase } from '@nozbe/watermelondb/DatabaseProvider'
|
2018-12-18 19:30:50 +00:00
|
|
|
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'
|
2019-01-11 20:55:42 +00:00
|
|
|
import { getDepositWithdrawTotals, getPledgesWaitingCommit } from '../../selectors/pledging'
|
|
|
|
import { getTokenAddress } from '../../utils/currencies'
|
2018-12-18 19:30:50 +00:00
|
|
|
|
|
|
|
const styles = {
|
|
|
|
card: {
|
|
|
|
minWidth: 275,
|
|
|
|
},
|
2018-12-20 16:23:05 +00:00
|
|
|
cardTitle: {
|
|
|
|
paddingBottom: '1rem'
|
|
|
|
},
|
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-19 20:54:12 +00:00
|
|
|
titleText: {
|
|
|
|
textAlign: 'center',
|
|
|
|
paddingTop: '2rem'
|
|
|
|
}
|
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) {
|
2019-01-24 13:32:11 +00:00
|
|
|
const { classes, title, transfers, pledges } = props
|
2018-12-18 19:30:50 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<FundingContext.Consumer>
|
2019-01-24 13:32:11 +00:00
|
|
|
{({ vaultEvents }) =>
|
2018-12-18 19:30:50 +00:00
|
|
|
<Card className={classes.card}>
|
|
|
|
<CardContent>
|
2018-12-20 16:23:05 +00:00
|
|
|
<Typography variant="h5" className={classes.cardTitle}>
|
2018-12-18 19:30:50 +00:00
|
|
|
{title}
|
|
|
|
</Typography>
|
2019-01-24 13:32:11 +00:00
|
|
|
{!!transfers &&
|
|
|
|
Object.entries(getDepositWithdrawTotals({ transfers, pledges, vaultEvents }))
|
2018-12-19 14:27:09 +00:00
|
|
|
.map(token => {
|
|
|
|
const [name, amounts] = token
|
|
|
|
const { deposits, withdraws } = amounts
|
2019-01-11 20:55:42 +00:00
|
|
|
const address = getTokenAddress(name)
|
2019-01-24 13:32:11 +00:00
|
|
|
const pledgesForCommit = getPledgesWaitingCommit({ pledges }).filter(p => p.token == address)
|
2018-12-19 14:27:09 +00:00
|
|
|
return (
|
2018-12-19 20:54:12 +00:00
|
|
|
<Card key={name}>
|
|
|
|
<Typography variant="h5" className={classes.titleText}>
|
2018-12-19 15:43:47 +00:00
|
|
|
{name}
|
|
|
|
</Typography>
|
2018-12-19 20:54:12 +00:00
|
|
|
<CardContent className={classes.fundingSummaries}>
|
2019-01-11 20:55:42 +00:00
|
|
|
<Typography variant="h3">
|
2019-01-04 21:34:26 +00:00
|
|
|
{Number(deposits) - Number(withdraws || 0)}
|
2018-12-20 16:23:05 +00:00
|
|
|
</Typography>
|
2019-01-11 20:55:42 +00:00
|
|
|
<Typography variant="h6" key={name + 'total'} className={classes.pos} color="textSecondary">
|
2018-12-20 16:23:05 +00:00
|
|
|
Remaining In Pledges
|
|
|
|
</Typography>
|
2018-12-19 20:54:12 +00:00
|
|
|
<Typography variant="h3" >
|
|
|
|
{deposits}
|
2018-12-19 19:42:04 +00:00
|
|
|
</Typography>
|
2018-12-19 20:54:12 +00:00
|
|
|
<Typography variant="h6" key={name + 'withdraw'} className={classes.pos} color="textSecondary">
|
|
|
|
Funded
|
2018-12-19 19:42:04 +00:00
|
|
|
</Typography>
|
2018-12-19 20:54:12 +00:00
|
|
|
<Typography variant="h3">
|
2019-01-04 21:34:26 +00:00
|
|
|
{withdraws || 0}
|
2018-12-19 20:54:12 +00:00
|
|
|
</Typography>
|
|
|
|
<Typography variant="h6" key={name + 'deposit'} className={classes.pos} color="textSecondary">
|
|
|
|
Withdrawn
|
|
|
|
</Typography>
|
2019-01-11 20:55:42 +00:00
|
|
|
<Typography variant="h3">
|
|
|
|
{pledgesForCommit.length}
|
|
|
|
</Typography>
|
2019-01-24 13:32:11 +00:00
|
|
|
<Typography variant="h6" key={name + 'veto/approve'} className={classes.pos} color="textSecondary">
|
2019-01-11 20:55:42 +00:00
|
|
|
Pledges that can be vetoed / approved
|
|
|
|
</Typography>
|
2018-12-19 19:42:04 +00:00
|
|
|
</CardContent>
|
2018-12-19 20:54:12 +00:00
|
|
|
<LinearProgress
|
|
|
|
classes={{
|
|
|
|
colorPrimary: classes.linearColorPrimary,
|
|
|
|
barColorPrimary: classes.linearBarColorPrimary,
|
|
|
|
}}
|
|
|
|
color="primary"
|
|
|
|
variant="buffer"
|
|
|
|
value={getValue(deposits, withdraws)}
|
2018-12-20 16:23:05 +00:00
|
|
|
valueBuffer={100}
|
|
|
|
/>
|
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
|
|
|
|
}
|
|
|
|
|
2019-01-24 13:32:11 +00:00
|
|
|
const styledCard = withStyles(styles)(SimpleCard)
|
|
|
|
export default withDatabase(withObservables([], ({ database }) => ({
|
|
|
|
transfers: database.collections.get('lp_events').query(
|
|
|
|
Q.where('event', 'Transfer')
|
|
|
|
).observe(),
|
|
|
|
pledges: database.collections.get('pledges').query().observe()
|
|
|
|
}))(styledCard))
|
|
|
|
|