From 1351f31fc1e6771bf184fdca86f87cde710d474b Mon Sep 17 00:00:00 2001 From: Barry Gitarts Date: Thu, 9 May 2019 13:10:28 -0400 Subject: [PATCH] use CurrencySelect in CreateFunding --- src/components/CreateFunding.jsx | 84 +++----------------------- src/components/base/CurrencySelect.jsx | 13 ++-- 2 files changed, 14 insertions(+), 83 deletions(-) diff --git a/src/components/CreateFunding.jsx b/src/components/CreateFunding.jsx index 8864810..4ec51d8 100644 --- a/src/components/CreateFunding.jsx +++ b/src/components/CreateFunding.jsx @@ -1,18 +1,14 @@ /*global web3*/ -import React, { useContext, useState, useEffect } from 'react'; +import React, { useContext } from 'react'; import { Formik } from 'formik'; import LiquidPledging from '../embarkArtifacts/contracts/LiquidPledging'; import Button from '@material-ui/core/Button'; import TextField from '@material-ui/core/TextField'; import Snackbar from '@material-ui/core/Snackbar'; -import MenuItem from '@material-ui/core/MenuItem'; -import FormControlLabel from '@material-ui/core/FormControlLabel' -import Switch from '@material-ui/core/Switch' import { MySnackbarContentWrapper } from './base/SnackBars' -import { currencies, TOKEN_ICON_API, getTokenLabel } from '../utils/currencies' -import { toEther } from '../utils/conversions' -import { getLpAllowance, standardTokenApproval } from '../utils/initialize' +import { getTokenLabel } from '../utils/currencies' import { FundingContext } from '../context' +import CurrencySelect from './base/CurrencySelect' const { donate } = LiquidPledging.methods const _hoursToSeconds = hours => hours * 60 * 60 @@ -24,42 +20,6 @@ const _addFunderSucessMsg = response => { const CreateFunding = ({ refreshTable }) => { const context = useContext(FundingContext) const { account } = context - const [balances, setBalances] = useState({}) - const [allowances, setAllowances] = useState({}) - - const updateBalancesAllowances = () => { - const latestBalances = {} - const latestAllowances = {} - currencies.forEach(async c => { - if (c.contract) { - const amount = await c.contract.methods.balanceOf(account).call() - const allowance = await getLpAllowance(c.contract) - latestBalances[c.value] = toEther(amount) - latestAllowances[c.value] = toEther(allowance) - } else { - latestBalances[c.value] = '0' - latestAllowances[c.value] = '0' - } - }) - setBalances(latestBalances) - setAllowances(latestAllowances) - } - - const toggleAllowance = e => { - const token = currencies[e.target.value] - const allowance = allowances[token.value] - standardTokenApproval( - token.contract, - Number(allowance) ? '0' : undefined - ).then(res => { - const { events: { Approval: { returnValues: { value } } } } = res - setAllowances(state => ({ ...state, [token.value]: toEther(value) })) - }) - } - - useEffect(() => { - if (account) updateBalancesAllowances() - }, [account]) return ( { onBlur={handleBlur} value={values.receiverId || ''} /> - - {currencies.map((option, idx) => ( - -
- {option.icon || } - {option.label} - Your Balance: {balances[option.value]} - e.stopPropagation()} - control={ - - } - label="Enabled" - /> -
-
- ))} -
+ value={values.tokenAddress} + showBalances + enableToggles + /> {currencies.map((option, idx) => (