/web3js@4-dapp-add-token.tsx Secret
Created
June 19, 2023 09:48
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {useState, useCallback, ChangeEvent} from 'react' | |
import {Input} from '../common/Input' | |
import {Button} from '../common/Button' | |
import {useSessionContext} from "../../context"; | |
import {ERC20Token} from "../../web3/erc20"; | |
export const AddToken = () => { | |
const {setTokenList, tokenList = []} = useSessionContext() | |
const [newAddress, setNewAddress] = useState<string>('') | |
const onChangeNewAddress = useCallback((e: ChangeEvent<HTMLInputElement>) => { | |
setNewAddress(e.target.value) | |
}, [setNewAddress]) | |
const addTokenContract = useCallback(async () => { | |
const contract = await ERC20Token.factory(newAddress) | |
setTokenList([...tokenList, contract]) | |
}, [setTokenList, newAddress, tokenList]) | |
return ( | |
<div className='Card'> | |
<div className='CardHead'> | |
<h2>Add new ERC20 Token</h2> | |
</div> | |
<div className='CardBody'> | |
<div> | |
<div className='Block'> | |
<Input label='ERC20 token address:' value={newAddress} onChange={onChangeNewAddress}/> | |
</div> | |
<div className='Block'> | |
<Button label='Add new token' onClick={addTokenContract}/> | |
</div> | |
</div> | |
</div> | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment