mirror of
https://github.com/status-im/safe-react.git
synced 2025-02-17 12:07:09 +00:00
WA-232 Adding token validation (deployed and real standard token)
This commit is contained in:
parent
16674b79a6
commit
1ccb735494
@ -5,6 +5,10 @@ import TextField from '~/components/forms/TextField'
|
|||||||
import { composeValidators, required, mustBeEthereumAddress, uniqueAddress } from '~/components/forms/validator'
|
import { composeValidators, required, mustBeEthereumAddress, uniqueAddress } from '~/components/forms/validator'
|
||||||
import Block from '~/components/layout/Block'
|
import Block from '~/components/layout/Block'
|
||||||
import Heading from '~/components/layout/Heading'
|
import Heading from '~/components/layout/Heading'
|
||||||
|
import { promisify } from '~/utils/promisify'
|
||||||
|
import { getWeb3 } from '~/wallets/getWeb3'
|
||||||
|
import { EMPTY_DATA } from '~/wallets/ethTransactions'
|
||||||
|
import { getHumanFriendlyToken } from '~/routes/tokens/store/actions/fetchTokens'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
addresses: string[],
|
addresses: string[],
|
||||||
@ -12,6 +16,25 @@ type Props = {
|
|||||||
|
|
||||||
export const TOKEN_ADRESS_PARAM = 'tokenAddress'
|
export const TOKEN_ADRESS_PARAM = 'tokenAddress'
|
||||||
|
|
||||||
|
export const token = async (tokenAddress: string) => {
|
||||||
|
const code = await promisify(cb => getWeb3().eth.getCode(tokenAddress, cb))
|
||||||
|
const isDeployed = code !== EMPTY_DATA
|
||||||
|
|
||||||
|
if (!isDeployed) {
|
||||||
|
return 'Specified address is not deployed on the current network'
|
||||||
|
}
|
||||||
|
|
||||||
|
const erc20Token = await getHumanFriendlyToken()
|
||||||
|
const instance = await erc20Token.at(tokenAddress)
|
||||||
|
const supply = await instance.totalSupply()
|
||||||
|
|
||||||
|
if (Number(supply) === 0) {
|
||||||
|
return 'Specified address is not a valid standard token'
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
const FirstPage = ({ addresses }: Props) => () => (
|
const FirstPage = ({ addresses }: Props) => () => (
|
||||||
<Block margin="md">
|
<Block margin="md">
|
||||||
<Heading tag="h2" margin="lg">
|
<Heading tag="h2" margin="lg">
|
||||||
@ -22,7 +45,7 @@ const FirstPage = ({ addresses }: Props) => () => (
|
|||||||
name={TOKEN_ADRESS_PARAM}
|
name={TOKEN_ADRESS_PARAM}
|
||||||
component={TextField}
|
component={TextField}
|
||||||
type="text"
|
type="text"
|
||||||
validate={composeValidators(required, mustBeEthereumAddress, uniqueAddress(addresses))}
|
validate={composeValidators(required, mustBeEthereumAddress, uniqueAddress(addresses), token)}
|
||||||
placeholder="ERC20 Token Address*"
|
placeholder="ERC20 Token Address*"
|
||||||
text="ERC20 Token Address"
|
text="ERC20 Token Address"
|
||||||
/>
|
/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user