Add label validation to instantiate

This commit is contained in:
abefernan 2023-07-14 11:54:02 +02:00
parent ff805e34b1
commit fa77bc3ffa
2 changed files with 16 additions and 0 deletions

View File

@ -50,12 +50,14 @@ const MsgInstantiateContract2Form = ({
const [amount, setAmount] = useState("0");
const [codeIdError, setCodeIdError] = useState("");
const [labelError, setLabelError] = useState("");
const [adminAddressError, setAdminAddressError] = useState("");
const [customDenomError, setCustomDenomError] = useState("");
const [amountError, setAmountError] = useState("");
useEffect(() => {
setCodeIdError("");
setLabelError("");
setAdminAddressError("");
setCustomDenomError("");
setAmountError("");
@ -66,6 +68,11 @@ const MsgInstantiateContract2Form = ({
return false;
}
if (!label) {
setLabelError("Label is required");
return false;
}
const addressErrorMsg = checkAddress(adminAddress, chain.addressPrefix);
if (adminAddress && addressErrorMsg) {
setAdminAddressError(`Invalid address for network ${chain.chainId}: ${addressErrorMsg}`);
@ -174,6 +181,7 @@ const MsgInstantiateContract2Form = ({
name="label"
value={label}
onChange={({ target }) => setLabel(target.value)}
error={labelError}
/>
</div>
<div className="form-item">

View File

@ -48,12 +48,14 @@ const MsgInstantiateContractForm = ({
const [amount, setAmount] = useState("0");
const [codeIdError, setCodeIdError] = useState("");
const [labelError, setLabelError] = useState("");
const [adminAddressError, setAdminAddressError] = useState("");
const [customDenomError, setCustomDenomError] = useState("");
const [amountError, setAmountError] = useState("");
useEffect(() => {
setCodeIdError("");
setLabelError("");
setAdminAddressError("");
setCustomDenomError("");
setAmountError("");
@ -64,6 +66,11 @@ const MsgInstantiateContractForm = ({
return false;
}
if (!label) {
setLabelError("Label is required");
return false;
}
const addressErrorMsg = checkAddress(adminAddress, chain.addressPrefix);
if (adminAddress && addressErrorMsg) {
setAdminAddressError(`Invalid address for network ${chain.chainId}: ${addressErrorMsg}`);
@ -168,6 +175,7 @@ const MsgInstantiateContractForm = ({
name="label"
value={label}
onChange={({ target }) => setLabel(target.value)}
error={labelError}
/>
</div>
<div className="form-item">