Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(components): contract address controller input validation #1191

Merged
merged 4 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
17 changes: 15 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,19 @@ export const zEvmContractVerifyOptionForm = z.union([
]);

export const zEvmContractAddressAndLicenseForm = z.object({
contractAddress: zHexAddr20,
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
Loading