WA-232 Fix fetching human readable data on empty contracts

This commit is contained in:
apanizo 2018-07-25 15:26:49 +02:00
parent 84c8bc7230
commit c086b53433
1 changed files with 20 additions and 4 deletions

View File

@ -6,6 +6,9 @@ import FirstPage, { TOKEN_ADRESS_PARAM } from '~/routes/tokens/component/AddToke
import SecondPage, { TOKEN_SYMBOL_PARAM, TOKEN_DECIMALS_PARAM, TOKEN_LOGO_URL_PARAM, TOKEN_NAME_PARAM } from '~/routes/tokens/component/AddToken/SecondPage'
import { makeToken, type Token } from '~/routes/tokens/store/model/token'
import addTokenAction from '~/routes/tokens/store/actions/addToken'
import { getWeb3 } from '~/wallets/getWeb3'
import { promisify } from '~/utils/promisify'
import { EMPTY_DATA } from '~/wallets/ethTransactions'
import Review from './Review'
export const getSteps = () => [
@ -67,13 +70,26 @@ class AddToken extends React.Component<Props, State> {
const erc20Token = await getHumanFriendlyToken()
const instance = await erc20Token.at(tokenAddress)
const name = await instance.name()
const symbol = await instance.symbol()
const decimals = await instance.decimals()
const dataName = await instance.contract.name.getData()
const nameResult = await promisify(cb => getWeb3().eth.call({ to: tokenAddress, data: dataName }, cb))
const hasName = nameResult !== EMPTY_DATA
const dataSymbol = await instance.contract.symbol.getData()
const symbolResult = await promisify(cb => getWeb3().eth.call({ to: tokenAddress, data: dataSymbol }, cb))
const hasSymbol = symbolResult !== EMPTY_DATA
const dataDecimals = await instance.contract.decimals.getData()
const decimalsResult = await promisify(cb => getWeb3().eth.call({ to: tokenAddress, data: dataDecimals }, cb))
const hasDecimals = decimalsResult !== EMPTY_DATA
const name = hasName ? await instance.name() : undefined
const symbol = hasSymbol ? await instance.symbol() : undefined
const decimals = hasDecimals ? `${await instance.decimals()}` : undefined
return ({
[TOKEN_SYMBOL_PARAM]: symbol,
[TOKEN_DECIMALS_PARAM]: `${decimals}`,
[TOKEN_DECIMALS_PARAM]: decimals,
[TOKEN_NAME_PARAM]: name,
})
}