diff --git a/src/components/CreateFunding.jsx b/src/components/CreateFunding.jsx index 4ec51d8..51f888f 100644 --- a/src/components/CreateFunding.jsx +++ b/src/components/CreateFunding.jsx @@ -1,4 +1,3 @@ -/*global web3*/ import React, { useContext } from 'react'; import { Formik } from 'formik'; import LiquidPledging from '../embarkArtifacts/contracts/LiquidPledging'; @@ -6,7 +5,7 @@ import Button from '@material-ui/core/Button'; import TextField from '@material-ui/core/TextField'; import Snackbar from '@material-ui/core/Snackbar'; import { MySnackbarContentWrapper } from './base/SnackBars' -import { getTokenLabel } from '../utils/currencies' +import { getTokenLabel, getTokenByAddress } from '../utils/currencies' import { FundingContext } from '../context' import CurrencySelect from './base/CurrencySelect' @@ -26,7 +25,8 @@ const CreateFunding = ({ refreshTable }) => { initialValues={{ funderId: '', receiverId: '', tokenAddress : '', amount: '' }} onSubmit={async (values, { setSubmitting: _setSubmitting, resetForm: _resetForm, setStatus }) => { const { funderId, receiverId, tokenAddress, amount } = values - const args = [funderId, receiverId, tokenAddress, web3.utils.toWei(amount, 'ether')]; + const { chainReadibleFn } = getTokenByAddress(tokenAddress) + const args = [funderId, receiverId, tokenAddress, chainReadibleFn(amount)] const toSend = donate(...args); diff --git a/src/utils/conversions.js b/src/utils/conversions.js index bf47220..f45d355 100644 --- a/src/utils/conversions.js +++ b/src/utils/conversions.js @@ -3,3 +3,4 @@ export const toEther = (amount, scale = 'ether') => web3.utils.fromWei(amount, scale) export const toWei = (amount, scale = 'ether') => web3.utils.toWei(amount, scale) export const compoundWhole = amount => (Number(amount) / (10**8)).toString() +export const compoundToChain = amount => (Number(amount) * (10**8)).toString() diff --git a/src/utils/currencies.js b/src/utils/currencies.js index c90d363..a2e1d9b 100644 --- a/src/utils/currencies.js +++ b/src/utils/currencies.js @@ -3,7 +3,7 @@ import DAI from '../embarkArtifacts/contracts/DAI' import cDAI from '../embarkArtifacts/contracts/cDAI' import cETH from '../embarkArtifacts/contracts/cETH' import sntIco from 'cryptocurrency-icons/svg/color/snt.svg' -import { toEther, compoundWhole } from './conversions' +import { toEther, toWei, compoundWhole, compoundToChain } from './conversions' export const TOKEN_ICON_API = 'https://raw.githubusercontent.com/TrustWallet/tokens/master/images' export const TOKEN_COIN_API = 'https://raw.githubusercontent.com/TrustWallet/tokens/master/coins' @@ -16,6 +16,7 @@ export const currencies = [ width: '5%', contract: cETH, humanReadibleFn: compoundWhole, + chainReadibleFn: compoundToChain }, { value: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', @@ -23,6 +24,7 @@ export const currencies = [ img: `${TOKEN_COIN_API}/60.png`, width: '5%', humanReadibleFn: toEther, + chainReadibleFn: toWei }, { value: SNT._address, @@ -30,6 +32,7 @@ export const currencies = [ img: sntIco, contract: SNT, humanReadibleFn: toEther, + chainReadibleFn: toWei }, { value: '0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359', @@ -38,6 +41,7 @@ export const currencies = [ width: '5%', contract: DAI, humanReadibleFn: toEther, + chainReadibleFn: toWei }, { value: '0xf5dce57282a584d2746faf1593d3121fcac444dc', @@ -46,11 +50,13 @@ export const currencies = [ width: '5%', contract: cDAI, humanReadibleFn: compoundWhole, + chainReadibleFn: compoundToChain } ] +export const getTokenByAddress = value => currencies.find(currency => currency.value === value) export const getTokenLabel = value => { - const token = currencies.find(currency => currency.value === value) + const token = getTokenByAddress(value) return token ? token.label : null }