import React from 'react' import PropTypes from 'prop-types' import { withStyles } from '@material-ui/core/styles' import { Formik } from 'formik' import LiquidPledging from 'Embark/contracts/LiquidPledging' import Button from '@material-ui/core/Button' import Typography from '@material-ui/core/Typography' import TextField from '@material-ui/core/TextField' import Card from '@material-ui/core/Card' import CardActions from '@material-ui/core/CardActions' import CardContent from '@material-ui/core/CardContent' import Collapse from '@material-ui/core/Collapse' import { getTokenLabel } from '../../utils/currencies' import { toWei } from '../../utils/conversions' import styles from './CardStyles' import { useRowData } from './hooks' const { transfer } = LiquidPledging.methods function TransferCard({ row, handleClose, classes }) { const { show, close } = useRowData(row, handleClose) return ( { const { pledgeId, pledge } = row const { idSender, amount, idReceiver } = values const args = [idSender, pledgeId, toWei(amount.toString()), idReceiver] const toSend = transfer(...args) const estimatedGas = await toSend.estimateGas() toSend .send({gas: estimatedGas + 1000}) .then(async res => { console.log({res}) const { events: { Transfer } } = res if (Array.isArray(Transfer)) { Transfer.forEach(async t => { const { to, amount } = t.returnValues await pledge.transferTo(to, amount) }) } else { const { to, amount } = Transfer.returnValues await pledge.transferTo(to, amount) } }) .catch(e => { console.log({e}) }) .finally(() => { close() resetForm() }) }} > {({ values, errors, touched, handleChange, handleBlur, handleSubmit, submitForm, setFieldValue, setStatus, status }) => (
Transfer Funds {`Transfer ${values.amount || ''} ${values.amount && row ? getTokenLabel(row.pledge.token) : ''} from Pledge ${row.pledgeId} ${values.idReceiver ? 'to Giver/Delegate/Project' : ''} ${values.idReceiver || ''}`}
)}
) } TransferCard.propTypes = { classes: PropTypes.object.isRequired, row: PropTypes.object.isRequired, handleClose: PropTypes.func.isRequired, } export default withStyles(styles)(TransferCard)