Commit eb394ee8 authored by Noah Zinsmeister's avatar Noah Zinsmeister

fix exchange address logic

parent 44d77ce9
...@@ -3,10 +3,10 @@ import classnames from 'classnames' ...@@ -3,10 +3,10 @@ import classnames from 'classnames'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { useWeb3Context } from 'web3-react' import { useWeb3Context } from 'web3-react'
import { isAddress } from '../../utils'
// import QrCode from '../QrCode' // commented out pending further review // import QrCode from '../QrCode' // commented out pending further review
import './address-input-panel.scss' import './address-input-panel.scss'
import { isAddress } from '../../utils'
export default function AddressInputPanel({ title, onChange = () => {}, onError = () => {} }) { export default function AddressInputPanel({ title, onChange = () => {}, onError = () => {} }) {
const { t } = useTranslation() const { t } = useTranslation()
...@@ -41,20 +41,22 @@ export default function AddressInputPanel({ title, onChange = () => {}, onError ...@@ -41,20 +41,22 @@ export default function AddressInputPanel({ title, onChange = () => {}, onError
} }
}) })
} else { } else {
try { if (input !== '') {
library.resolveName(input).then(address => { try {
if (!stale) { library.resolveName(input).then(address => {
// if the input name resolves to an address if (!stale) {
if (address) { // if the input name resolves to an address
setData({ address: address, name: input }) if (address) {
setError(null) setData({ address: address, name: input })
} else { setError(null)
setError(true) } else {
setError(true)
}
} }
} })
}) } catch {
} catch { setError(true)
setError(true) }
} }
} }
......
...@@ -11,15 +11,19 @@ import OversizedPanel from '../../components/OversizedPanel' ...@@ -11,15 +11,19 @@ import OversizedPanel from '../../components/OversizedPanel'
import { useTokenDetails } from '../../contexts/Static' import { useTokenDetails } from '../../contexts/Static'
import { useTransactionContext } from '../../contexts/Transaction' import { useTransactionContext } from '../../contexts/Transaction'
import { useFactoryContract } from '../../hooks' import { useFactoryContract } from '../../hooks'
import { isAddress } from '../../utils'
function CreateExchange({ history, location }) { function CreateExchange({ history, location }) {
const { t } = useTranslation() const { t } = useTranslation()
const { account } = useWeb3Context() const { account } = useWeb3Context()
const factory = useFactoryContract() const factory = useFactoryContract()
const [tokenAddress, setTokenAddress] = useState((location.state && location.state.tokenAddress) || '') const [tokenAddress, setTokenAddress] = useState({
const { name, symbol, decimals, exchangeAddress } = useTokenDetails(tokenAddress) address: (location.state && location.state.tokenAddress) || '',
name: ''
})
const [tokenAddressError, setTokenAddressError] = useState()
const { name, symbol, decimals, exchangeAddress } = useTokenDetails(tokenAddress.address)
const { addTransaction } = useTransactionContext() const { addTransaction } = useTransactionContext()
// clear location state, if it exists // clear location state, if it exists
...@@ -32,9 +36,9 @@ function CreateExchange({ history, location }) { ...@@ -32,9 +36,9 @@ function CreateExchange({ history, location }) {
// validate everything // validate everything
const [errorMessage, setErrorMessage] = useState(!account && t('noWallet')) const [errorMessage, setErrorMessage] = useState(!account && t('noWallet'))
useEffect(() => { useEffect(() => {
if (tokenAddress && !isAddress(tokenAddress)) { if (tokenAddressError) {
setErrorMessage(t('invalidTokenAddress')) setErrorMessage(t('invalidTokenAddress'))
} else if (!tokenAddress || symbol === undefined || decimals === undefined || exchangeAddress === undefined) { } else if (symbol === undefined || decimals === undefined || exchangeAddress === undefined) {
setErrorMessage() setErrorMessage()
} else if (symbol === null) { } else if (symbol === null) {
setErrorMessage(t('invalidSymbol')) setErrorMessage(t('invalidSymbol'))
...@@ -51,12 +55,12 @@ function CreateExchange({ history, location }) { ...@@ -51,12 +55,12 @@ function CreateExchange({ history, location }) {
return () => { return () => {
setErrorMessage() setErrorMessage()
} }
}, [tokenAddress, symbol, decimals, exchangeAddress, account, t]) }, [tokenAddress.address, symbol, decimals, exchangeAddress, account, t, tokenAddressError])
async function createExchange() { async function createExchange() {
const estimatedGasLimit = await factory.estimate.createExchange(tokenAddress) const estimatedGasLimit = await factory.estimate.createExchange(tokenAddress.address)
factory.createExchange(tokenAddress, { gasLimit: estimatedGasLimit }).then(response => { factory.createExchange(tokenAddress.address, { gasLimit: estimatedGasLimit }).then(response => {
addTransaction(response.hash, response) addTransaction(response.hash, response)
ReactGA.event({ ReactGA.event({
category: 'Pool', category: 'Pool',
...@@ -69,14 +73,7 @@ function CreateExchange({ history, location }) { ...@@ -69,14 +73,7 @@ function CreateExchange({ history, location }) {
return ( return (
<> <>
<AddressInputPanel <AddressInputPanel title={t('tokenAddress')} onChange={setTokenAddress} onError={setTokenAddressError} />
title={t('tokenAddress')}
value={tokenAddress}
onChange={input => {
setTokenAddress(input)
}}
errorMessage={errorMessage === t('noWallet') ? '' : errorMessage}
/>
<OversizedPanel hideBottom> <OversizedPanel hideBottom>
<div className="pool__summary-panel"> <div className="pool__summary-panel">
<div className="pool__exchange-rate-wrapper"> <div className="pool__exchange-rate-wrapper">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment