import { EncodeObject } from "@cosmjs/proto-signing"; import { useEffect, useState } from "react"; import { MsgGetter } from ".."; import { useChains } from "../../../../context/ChainsContext"; import { checkAddress, exampleAddress } from "../../../../lib/displayHelpers"; import { MsgCodecs, MsgTypeUrls } from "../../../../types/txMsg"; import Input from "../../../inputs/Input"; import StackableContainer from "../../../layout/StackableContainer"; interface MsgSetWithdrawAddressFormProps { readonly delegatorAddress: string; readonly setMsgGetter: (msgGetter: MsgGetter) => void; readonly deleteMsg: () => void; } const MsgSetWithdrawAddressForm = ({ delegatorAddress, setMsgGetter, deleteMsg, }: MsgSetWithdrawAddressFormProps) => { const { chain } = useChains(); const [withdrawAddress, setWithdrawAddress] = useState(""); const [withdrawAddressError, setWithdrawAddressError] = useState(""); useEffect(() => { try { setWithdrawAddressError(""); const isMsgValid = (): boolean => { const addressErrorMsg = checkAddress(withdrawAddress, chain.addressPrefix); if (addressErrorMsg) { setWithdrawAddressError( `Invalid address for network ${chain.chainId}: ${addressErrorMsg}`, ); return false; } return true; }; const msgValue = MsgCodecs[MsgTypeUrls.SetWithdrawAddress].fromPartial({ delegatorAddress, withdrawAddress, }); const msg: EncodeObject = { typeUrl: MsgTypeUrls.SetWithdrawAddress, value: msgValue }; setMsgGetter({ isMsgValid, msg }); } catch {} }, [chain.addressPrefix, chain.chainId, delegatorAddress, setMsgGetter, withdrawAddress]); return (

MsgSetWithdrawAddress

setWithdrawAddress(target.value)} error={withdrawAddressError} placeholder={`E.g. ${exampleAddress(0, chain.addressPrefix)}`} />
); }; export default MsgSetWithdrawAddressForm;