import { Connection } from "@solana/web3.js" ; import React , { FC , useState } from "react" ; import arweaveService from "../arweave/arweave" ; import messageService from "../solana/messages" ; import { WalletAdapter } from "../solana/wallet" ; import "./MessageSender.css" ; interface MessageSenderProps { connection ? : Connection ; wallet ? : WalletAdapter ; destPubkeyStr : string ; getMessages : ( ) => void ; } const MessageSender = ( { connection , wallet , destPubkeyStr , getMessages , } ) => { const [ message , setMessage ] = useState ( "" ) ; const onChangeMessage = ( e ) => { setMessage ( e . target . value ) ; } ; const onClickSubmit = async ( e ) => { e . preventDefault ( ) ; if ( ! connection || ! wallet ) { return ; } const txid = await arweaveService . saveData ( message ) ; console . log ( "saved txid" , txid ) ; const result = await messageService . sendMessage ( connection , wallet , destPubkeyStr , txid ) ; console . log ( "onClickSubmit message sent successfully" , result ) ; getMessages ( ) ; } ; return ( < div className = "panel" > < input className = "msg-input" type = "text" value = { message } onChange = { onChangeMessage } / > < button onClick = { onClickSubmit } > Submit < /button> < /div>); } ; export default MessageSender ;