Skip to content

Commit 62a3cd8

Browse files
committed
fix: make contract and to addresses optional in webhook form (#7294)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on improving the handling of contract addresses in the `CreateWebhookModal` and `FilterDetailsStep` components, as well as refining validation logic for addresses in `webhookTypes.ts`. It enhances user experience by clarifying requirements and allowing optional inputs. ### Detailed summary - In `CreateWebhookModal.tsx`, the `addresses` property now defaults to an empty string if not provided. - In `FilterDetailsStep.tsx`, the `FormLabel` for "Contract Addresses" and "To Address" no longer includes a required indicator. - Validation in `webhookTypes.ts` for `addresses`, `fromAddresses`, and `toAddresses` is updated to allow empty inputs and provide clearer error messages. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Removed the required field indicator from "Contract Addresses" and "To Address" labels in the form UI. - **New Features** - Updated form validation to allow "Contract Addresses", "From Address", and "To Address" fields to be optional and accept empty values, with improved error messages for clarity. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 2a4195b commit 62a3cd8

File tree

3 files changed

+39
-15
lines changed

3 files changed

+39
-15
lines changed

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/webhooks/components/CreateWebhookModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export function CreateWebhookModal({
8686
isOpen,
8787
thirdwebClient: client,
8888
chainIds,
89-
addresses,
89+
addresses: addresses || "",
9090
extractSignatures: extractEventSignatures,
9191
type: "event",
9292
});

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/webhooks/components/FilterDetailsStep.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,7 @@ export function FilterDetailsStep({
191191
render={({ field }) => (
192192
<FormItem className="flex flex-col">
193193
<div className="flex items-center justify-between text-xs">
194-
<FormLabel>
195-
Contract Addresses <span className="text-red-500">*</span>
196-
</FormLabel>
194+
<FormLabel>Contract Addresses</FormLabel>
197195
<p className="text-muted-foreground">
198196
Enter a contract address
199197
</p>
@@ -281,9 +279,7 @@ export function FilterDetailsStep({
281279
render={({ field }) => (
282280
<FormItem className="flex flex-col">
283281
<div className="flex items-center justify-between text-xs">
284-
<FormLabel>
285-
To Address <span className="text-red-500">*</span>
286-
</FormLabel>
282+
<FormLabel>To Address</FormLabel>
287283
<p className="text-muted-foreground">Enter a to address</p>
288284
</div>
289285
<FormControl>

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/webhooks/utils/webhookTypes.ts

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,53 @@ export const webhookFormSchema = z.object({
3636
.min(1, { message: "Select at least one chain" }),
3737
addresses: z
3838
.string()
39-
.min(1, { message: "Addresses is required" })
40-
.refine((val) => val.split(/[\,\s]+/).every((a) => isAddress(a.trim())), {
41-
message: "Enter a valid address",
42-
}),
39+
.optional()
40+
.refine(
41+
(val) => {
42+
if (val === undefined || val.trim() === "") {
43+
return true;
44+
}
45+
return val
46+
.split(/[\,\s]+/)
47+
.filter(Boolean)
48+
.every((a) => isAddress(a.trim()));
49+
},
50+
{
51+
message: "Enter valid addresses (comma-separated) or leave empty",
52+
},
53+
),
4354
fromAddresses: z
4455
.string()
4556
.optional()
4657
.refine(
47-
(val) => !val || val.split(/[,\s]+/).every((a) => isAddress(a.trim())),
58+
(val) => {
59+
if (val === undefined || val.trim() === "") {
60+
return true;
61+
}
62+
return val
63+
.split(/[\,\s]+/)
64+
.filter(Boolean)
65+
.every((a) => isAddress(a.trim()));
66+
},
4867
{
49-
message: "Enter a valid address",
68+
message: "Enter valid addresses (comma-separated) or leave empty",
5069
},
5170
),
5271
toAddresses: z
5372
.string()
73+
.optional()
5474
.refine(
55-
(val) => !val || val.split(/[,\s]+/).every((a) => isAddress(a.trim())),
75+
(val) => {
76+
if (val === undefined || val.trim() === "") {
77+
return true;
78+
}
79+
return val
80+
.split(/[\,\s]+/)
81+
.filter(Boolean)
82+
.every((a) => isAddress(a.trim()));
83+
},
5684
{
57-
message: "Enter a valid address (comma-separated)",
85+
message: "Enter valid addresses (comma-separated) or leave empty",
5886
},
5987
),
6088
sigHash: z.string().optional(),

0 commit comments

Comments
 (0)