import { EncodeObject } from "@cosmjs/proto-signing"; import { assert } from "@cosmjs/utils"; import { useEffect, useState } from "react"; import { MsgGetter } from ".."; import { useAppContext } from "../../../../context/AppContext"; 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 { state } = useAppContext(); assert(state.chain.addressPrefix, "addressPrefix missing"); const [withdrawAddress, setWithdrawAddress] = useState(""); const [withdrawAddressError, setWithdrawAddressError] = useState(""); useEffect(() => { try { setWithdrawAddressError(""); const isMsgValid = (): boolean => { assert(state.chain.addressPrefix, "addressPrefix missing"); const addressErrorMsg = checkAddress(withdrawAddress, state.chain.addressPrefix); if (addressErrorMsg) { setWithdrawAddressError( `Invalid address for network ${state.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 {} }, [ delegatorAddress, setMsgGetter, state.chain.addressPrefix, state.chain.chainId, withdrawAddress, ]); return (

MsgSetWithdrawAddress

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