Skip to content

Commit f765214

Browse files
committed
add optional config to webhooks in engine + backwards compatibility
1 parent fa26eef commit f765214

File tree

4 files changed

+166
-72
lines changed

4 files changed

+166
-72
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ type EngineFeature =
118118
| "CONTRACT_SUBSCRIPTIONS"
119119
| "IP_ALLOWLIST"
120120
| "HETEROGENEOUS_WALLET_TYPES"
121-
| "SMART_BACKEND_WALLETS";
121+
| "SMART_BACKEND_WALLETS"
122+
| "WEBHOOK_CONFIG";
122123

123124
interface EngineSystemHealth {
124125
status: string;
@@ -835,6 +836,7 @@ export interface EngineWebhook {
835836
active: boolean;
836837
createdAt: string;
837838
id: number;
839+
config?: string;
838840
}
839841

840842
export function useEngineWebhooks(params: {
@@ -1246,6 +1248,7 @@ export type CreateWebhookInput = {
12461248
url: string;
12471249
name: string;
12481250
eventType: string;
1251+
config?: string;
12491252
};
12501253

12511254
export function useEngineCreateWebhook(params: {

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ 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

2627
interface AddWebhookButtonProps {
2728
instanceUrl: string;
2829
authToken: string;
30+
supportedWebhookConfig: boolean;
2931
}
3032

3133
const WEBHOOK_EVENT_TYPES = [
@@ -41,6 +43,7 @@ const WEBHOOK_EVENT_TYPES = [
4143
export const AddWebhookButton: React.FC<AddWebhookButtonProps> = ({
4244
instanceUrl,
4345
authToken,
46+
supportedWebhookConfig = false,
4447
}) => {
4548
const { isOpen, onOpen, onClose } = useDisclosure();
4649
const { mutate: createWebhook } = useEngineCreateWebhook({
@@ -74,7 +77,22 @@ export const AddWebhookButton: React.FC<AddWebhookButtonProps> = ({
7477
className="!bg-background rounded-lg border border-border"
7578
as="form"
7679
onSubmit={form.handleSubmit((data) => {
77-
createWebhook(data, {
80+
let finalData: CreateWebhookInput = data;
81+
82+
if (supportedWebhookConfig) {
83+
const { config, ..._data } = data;
84+
finalData = _data;
85+
if (config) {
86+
try {
87+
finalData.config = JSON.parse(config);
88+
} catch (_) {
89+
toast.error("Config must be a valid json string");
90+
return;
91+
}
92+
}
93+
}
94+
95+
createWebhook(finalData, {
7896
onSuccess: () => {
7997
onSuccess();
8098
onClose();
@@ -128,6 +146,16 @@ export const AddWebhookButton: React.FC<AddWebhookButtonProps> = ({
128146
{...form.register("url", { required: true })}
129147
/>
130148
</FormControl>
149+
{supportedWebhookConfig && (
150+
<FormControl>
151+
<FormLabel>Config</FormLabel>
152+
<Input
153+
type="text"
154+
placeholder={`{"address": "0x1234...5678", "chainId": 1, "threshold": 200.5}`}
155+
{...form.register("config")}
156+
/>
157+
</FormControl>
158+
)}
131159
</Flex>
132160
</ModalBody>
133161

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
"use client";
22

3-
import { useEngineWebhooks } from "@3rdweb-sdk/react/hooks/useEngine";
3+
import {
4+
useEngineSystemHealth,
5+
useEngineWebhooks,
6+
} from "@3rdweb-sdk/react/hooks/useEngine";
47
import { Heading, Link, Text } from "tw-components";
58
import { AddWebhookButton } from "./add-webhook-button";
69
import { WebhooksTable } from "./webhooks-table";
@@ -18,6 +21,10 @@ export const EngineWebhooks: React.FC<EngineWebhooksProps> = ({
1821
authToken,
1922
instanceUrl,
2023
});
24+
const healthQuery = useEngineSystemHealth(instanceUrl);
25+
26+
const supportedWebhookConfig =
27+
healthQuery.data?.features?.includes("WEBHOOK_CONFIG") || false;
2128

2229
return (
2330
<div className="flex flex-col gap-4">
@@ -42,8 +49,13 @@ export const EngineWebhooks: React.FC<EngineWebhooksProps> = ({
4249
isPending={webhooks.isPending}
4350
isFetched={webhooks.isFetched}
4451
authToken={authToken}
52+
supportedWebhookConfig={supportedWebhookConfig}
53+
/>
54+
<AddWebhookButton
55+
instanceUrl={instanceUrl}
56+
authToken={authToken}
57+
supportedWebhookConfig={supportedWebhookConfig}
4558
/>
46-
<AddWebhookButton instanceUrl={instanceUrl} authToken={authToken} />
4759
</div>
4860
);
4961
};

0 commit comments

Comments
 (0)