Skip to content

Commit 1e47014

Browse files
committed
webhook config backwards compatible
1 parent c7e700b commit 1e47014

File tree

4 files changed

+154
-102
lines changed

4 files changed

+154
-102
lines changed

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

Lines changed: 2 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;

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

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { beautifyString } from "./webhooks-table";
2727
interface AddWebhookButtonProps {
2828
instanceUrl: string;
2929
authToken: string;
30+
supportesWebhookConfig: boolean;
3031
}
3132

3233
const WEBHOOK_EVENT_TYPES = [
@@ -42,6 +43,7 @@ const WEBHOOK_EVENT_TYPES = [
4243
export const AddWebhookButton: React.FC<AddWebhookButtonProps> = ({
4344
instanceUrl,
4445
authToken,
46+
supportesWebhookConfig = false,
4547
}) => {
4648
const { isOpen, onOpen, onClose } = useDisclosure();
4749
const { mutate: createWebhook } = useEngineCreateWebhook({
@@ -75,14 +77,18 @@ export const AddWebhookButton: React.FC<AddWebhookButtonProps> = ({
7577
className="!bg-background rounded-lg border border-border"
7678
as="form"
7779
onSubmit={form.handleSubmit((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;
80+
let finalData: CreateWebhookInput = data;
81+
82+
if (supportesWebhookConfig) {
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+
}
8692
}
8793
}
8894

@@ -140,14 +146,16 @@ export const AddWebhookButton: React.FC<AddWebhookButtonProps> = ({
140146
{...form.register("url", { required: true })}
141147
/>
142148
</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>
149+
{supportesWebhookConfig && (
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+
)}
151159
</Flex>
152160
</ModalBody>
153161

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 supportesWebhookConfig =
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+
supportesWebhookConfig={supportesWebhookConfig}
53+
/>
54+
<AddWebhookButton
55+
instanceUrl={instanceUrl}
56+
authToken={authToken}
57+
supportesWebhookConfig={supportesWebhookConfig}
4558
/>
46-
<AddWebhookButton instanceUrl={instanceUrl} authToken={authToken} />
4759
</div>
4860
);
4961
};

0 commit comments

Comments
 (0)