Skip to content

Commit c7e700b

Browse files
committed
add optional config to webhooks in engine
1 parent fa26eef commit c7e700b

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

apps/dashboard/src/@3rdweb-sdk/react/hooks/useEngine.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,7 @@ export interface EngineWebhook {
835835
active: boolean;
836836
createdAt: string;
837837
id: number;
838+
config?: string;
838839
}
839840

840841
export function useEngineWebhooks(params: {
@@ -1246,6 +1247,7 @@ export type CreateWebhookInput = {
12461247
url: string;
12471248
name: string;
12481249
eventType: string;
1250+
config?: string;
12491251
};
12501252

12511253
export function useEngineCreateWebhook(params: {

apps/dashboard/src/app/team/[team_slug]/(team)/~/engine/(instance)/[engineId]/webhooks/components/add-webhook-button.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { useTrack } from "hooks/analytics/useTrack";
2020
import { useTxNotifications } from "hooks/useTxNotifications";
2121
import { CirclePlusIcon } from "lucide-react";
2222
import { useForm } from "react-hook-form";
23+
import { toast } from "sonner";
2324
import { Button, FormLabel } from "tw-components";
2425
import { beautifyString } from "./webhooks-table";
2526

@@ -74,7 +75,18 @@ export const AddWebhookButton: React.FC<AddWebhookButtonProps> = ({
7475
className="!bg-background rounded-lg border border-border"
7576
as="form"
7677
onSubmit={form.handleSubmit((data) => {
77-
createWebhook(data, {
78+
const { config, ..._data } = data;
79+
const finalData: CreateWebhookInput = _data;
80+
if (config) {
81+
try {
82+
finalData.config = JSON.parse(config);
83+
} catch (_) {
84+
toast.error("Config must be a valid json string");
85+
return;
86+
}
87+
}
88+
89+
createWebhook(finalData, {
7890
onSuccess: () => {
7991
onSuccess();
8092
onClose();
@@ -128,6 +140,14 @@ export const AddWebhookButton: React.FC<AddWebhookButtonProps> = ({
128140
{...form.register("url", { required: true })}
129141
/>
130142
</FormControl>
143+
<FormControl>
144+
<FormLabel>Config</FormLabel>
145+
<Input
146+
type="json"
147+
placeholder={`{"address": "0x1234...5678", "chainId": 1, "threshold": 200.5}`}
148+
{...form.register("config")}
149+
/>
150+
</FormControl>
131151
</Flex>
132152
</ModalBody>
133153

apps/dashboard/src/app/team/[team_slug]/(team)/~/engine/(instance)/[engineId]/webhooks/components/webhooks-table.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ export function beautifyString(str: string): string {
3939
.join(" ");
4040
}
4141

42+
function jsonStringify(data: unknown | undefined): string {
43+
if (!data) return "";
44+
return JSON.stringify(data, null, 2);
45+
}
46+
4247
interface WebhooksTableProps {
4348
instanceUrl: string;
4449
webhooks: EngineWebhook[];
@@ -86,6 +91,13 @@ const columns = [
8691
);
8792
},
8893
}),
94+
columnHelper.accessor("config", {
95+
header: "Config",
96+
cell: (cell) => {
97+
const config = cell.getValue();
98+
return <Text>{jsonStringify(config)}</Text>;
99+
},
100+
}),
89101
columnHelper.accessor("createdAt", {
90102
header: "Created At",
91103
cell: (cell) => {
@@ -242,6 +254,10 @@ function DeleteWebhookModal({
242254
<FormLabel>URL</FormLabel>
243255
<Text>{webhook.url}</Text>
244256
</FormControl>
257+
<FormControl>
258+
<FormLabel>Config</FormLabel>
259+
<Text className="font-mono">{jsonStringify(webhook.config)}</Text>
260+
</FormControl>
245261
<FormControl>
246262
<FormLabel>Created at</FormLabel>
247263
<Text>
@@ -308,6 +324,10 @@ function TestWebhookModal({
308324
<FormLabel>URL</FormLabel>
309325
<span className="font-mono">{webhook.url}</span>
310326
</FormItem>
327+
<FormItem>
328+
<FormLabel>Config</FormLabel>
329+
<span className="font-mono">{webhook.config}</span>
330+
</FormItem>
311331

312332
<Button type="submit" onClick={onTest} disabled={isPending}>
313333
{isPending && <Spinner className="mr-2 size-4" />}

0 commit comments

Comments
 (0)