Skip to content

Commit

Permalink
Merge pull request #1191 from alleslabs/fix/contract-address-validati…
Browse files Browse the repository at this point in the history
…on-verify

fix(components): contract address controller input validation
  • Loading branch information
Poafs1 authored Jan 14, 2025
2 parents a893015 + 51a98ea commit 4febaf0
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Bug fixes

- [#1191](https://github.com/alleslabs/celatone-frontend/pull/1191) Fix contract address form validation
- [#1190](https://github.com/alleslabs/celatone-frontend/pull/1190) Fix EVM contract details verify boarding and verification page

## v1.9.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export const EvmContractFooter = ({
borderColor: "gray.700",
display: "grid",
gridTemplateColumns: "6fr 4fr",
px: "96px",
pl: 12,
gap: 0,
pr: 24,
"> div": {
width: "100%",
},
Expand Down
29 changes: 17 additions & 12 deletions src/lib/pages/evm-contract-verify/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,22 @@ export const EvmContractVerify = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [router.isReady]);

const { control, watch, handleSubmit, setValue } =
useForm<EvmContractVerifyForm>({
resolver: zodResolver(zEvmContractVerifyForm),
mode: "all",
reValidateMode: "onChange",
defaultValues: {
contractAddress: isHexWalletAddress(String(contractAddressQueryParam))
? contractAddressQueryParam
: "",
compilerVersion: "",
},
});
const {
control,
watch,
setValue,
formState: { errors },
} = useForm<EvmContractVerifyForm>({
resolver: zodResolver(zEvmContractVerifyForm),
mode: "all",
reValidateMode: "onChange",
defaultValues: {
contractAddress: isHexWalletAddress(String(contractAddressQueryParam))
? contractAddressQueryParam
: "",
compilerVersion: "",
},
});
const { licenseType, contractAddress, language, compilerVersion } = watch();

const { handleNext, handlePrevious, hasNext, hasPrevious } = useStepper(
Expand Down Expand Up @@ -153,6 +157,7 @@ export const EvmContractVerify = () => {
? "success"
: "init",
}}
error={errors.contractAddress?.message}
/>
</GridItem>
<GridItem colSpan={1} colStart={1}>
Expand Down
18 changes: 16 additions & 2 deletions src/lib/pages/evm-contract-verify/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { zHexAddr20 } from "lib/types";
import { z } from "zod";
import { isHexWalletAddress } from "lib/utils";
import { z, ZodIssueCode } from "zod";

export enum EvmProgrammingLanguage {
Solidity = "solidity",
Expand Down Expand Up @@ -67,7 +68,20 @@ export const zEvmContractVerifyOptionForm = z.union([
]);

export const zEvmContractAddressAndLicenseForm = z.object({
contractAddress: zHexAddr20,
// TODO: refactor later
contractAddress: zHexAddr20.superRefine((val, ctx) => {
if (val === "")
ctx.addIssue({
code: ZodIssueCode.custom,
message: " ",
});

if (!isHexWalletAddress(val))
ctx.addIssue({
code: ZodIssueCode.custom,
message: "Invalid address",
});
}),
licenseType: z.string().refine((val) => val !== ""),
language: z.nativeEnum(EvmProgrammingLanguage),
compilerVersion: z.string().refine((val) => val !== ""),
Expand Down

0 comments on commit 4febaf0

Please sign in to comment.