add amount field

This commit is contained in:
Barry Gitarts 2018-11-30 16:19:46 -05:00
parent 66c8a470d9
commit f3499e69be
2 changed files with 29 additions and 9 deletions

View File

@ -9,9 +9,9 @@ import Snackbar from '@material-ui/core/Snackbar';
import MenuItem from '@material-ui/core/MenuItem'; import MenuItem from '@material-ui/core/MenuItem';
import web3 from 'Embark/web3'; import web3 from 'Embark/web3';
import { MySnackbarContentWrapper } from './base/SnackBars'; import { MySnackbarContentWrapper } from './base/SnackBars';
import { currencies, TOKEN_ICON_API } from '../utils/currencies' import { currencies, TOKEN_ICON_API, getTokenLabel } from '../utils/currencies'
const { addGiver } = LiquidPledgingMock.methods const { donate } = LiquidPledgingMock.methods
const hoursToSeconds = hours => hours * 60 * 60 const hoursToSeconds = hours => hours * 60 * 60
const addFunderSucessMsg = response => { const addFunderSucessMsg = response => {
const { events: { GiverAdded: { returnValues: { idGiver } } } } = response const { events: { GiverAdded: { returnValues: { idGiver } } } } = response
@ -20,20 +20,21 @@ const addFunderSucessMsg = response => {
const CreateFunding = () => ( const CreateFunding = () => (
<Formik <Formik
initialValues={{ funderId: '', receiverId: '', tokenAddress : '' }} initialValues={{ funderId: '', receiverId: '', tokenAddress : '', amount: '' }}
onSubmit={async (values, { setSubmitting, resetForm, setStatus }) => { onSubmit={async (values, { setSubmitting, resetForm, setStatus }) => {
const { funderId, receiverId, tokenAddress } = values const { funderId, receiverId, tokenAddress, amount } = values
const account = await web3.eth.getCoinbase() const account = await web3.eth.getCoinbase()
const args = [funderId, receiverId, tokenAddress, 0] const args = [funderId, receiverId, tokenAddress, web3.utils.toWei(amount, 'ether')]
addGiver(...args) console.log({args, donate, LiquidPledgingMock})
donate(...args)
.estimateGas({ from: account }) .estimateGas({ from: account })
.then(async gas => { .then(async gas => {
addGiver(...args) donate(...args)
.send({ from: account, gas: gas + 100 }) .send({ from: account, gas: gas + 100 })
.then(res => { .then(res => {
console.log({res}) console.log({res})
setStatus({ setStatus({
snackbar: { variant: 'success', message: addFunderSucessMsg(res) } snackbar: { variant: 'success', message: 'funding provided!' }
}) })
}) })
.catch(e => { .catch(e => {
@ -102,7 +103,17 @@ const CreateFunding = () => (
</MenuItem> </MenuItem>
))} ))}
</TextField> </TextField>
{/* TODO ADD Amount TextField */} <TextField
id="amount"
name="amount"
label={`Amount of ${getTokenLabel(values.tokenAddress) || 'tokens'} to provide`}
placeholder="Amount of tokens to provide"
margin="normal"
variant="outlined"
onChange={handleChange}
onBlur={handleBlur}
value={values.amount || ''}
/>
<Button variant="contained" color="primary" type="submit"> <Button variant="contained" color="primary" type="submit">
PROVIDE FUNDING PROVIDE FUNDING
</Button> </Button>

View File

@ -14,4 +14,13 @@ export const currencies = [
value: '0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359', value: '0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359',
label: 'DAI', label: 'DAI',
}, },
{
value: '0xd8a512EBD6fd82f44dFFD968EEB0835265497d20',
label: 'Standard Token'
}
] ]
export const getTokenLabel = value => {
const token = currencies.find(currency => currency.value === value)
return token ? token.label : null
}