EthAddress.jsx
1 import React, { useState } from "react"; 2 import { useAuth } from "@/auth/hooks/useAuth"; 3 import styles from "@/styles/Home.module.scss"; 4 5 const EthWallet = () => { 6 const [ethWallet, setEthWallet] = useState(""); 7 const { walletCanister } = useAuth(); 8 9 const handleInputChange = (event) => { 10 setEthWallet(event.target.value); 11 }; 12 13 const handleWalletSubmit = async (ethWallet, walletCanister) => { 14 if (!ethWallet) { 15 console.log("Please enter an ethereum wallet address"); 16 return; 17 } 18 console.log("Ethereum wallet address found: ", ethWallet); 19 20 if (!walletCanister) { 21 console.log("Wallet canister was not initialized"); 22 return; 23 } 24 console.log( 25 "Wallet canister was initialized succesfully: ", 26 walletCanister, 27 ); 28 29 try { 30 await walletCanister.update_eth_address(ethWallet); 31 console.log("Successfully submitted eth wallet: "); 32 } catch (error) { 33 console.error("Could not submit eth wallet: ", error); 34 } 35 }; 36 37 const handleSubmit = (event) => { 38 event.preventDefault(); 39 handleWalletSubmit(ethWallet, walletCanister); 40 }; 41 42 return ( 43 <form onSubmit={handleSubmit} className={styles.uploadForm}> 44 <input 45 type="text" 46 placeholder="Enter eth wallet address" 47 value={ethWallet} 48 onChange={handleInputChange} 49 className={styles.uploadInput} 50 /> 51 <button type="submit" className={styles.ethSubmitbtn}> 52 Submit 53 </button> 54 </form> 55 ); 56 }; 57 58 export default EthWallet;