Skip to content

Commit 1ad6983

Browse files
authored
feat: test webhook and delete wallet (#5489)
1 parent 46ef3e6 commit 1ad6983

File tree

3 files changed

+434
-147
lines changed

3 files changed

+434
-147
lines changed

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

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export function useEngineInstances() {
8383
export type BackendWallet = {
8484
address: string;
8585
label?: string;
86-
type: string;
86+
type: EngineBackendWalletType;
8787
awsKmsKeyId?: string | null;
8888
awsKmsArn?: string | null;
8989
gcpKmsKeyId?: string | null;
@@ -980,6 +980,39 @@ export function useEngineImportBackendWallet(instance: string) {
980980
});
981981
}
982982

983+
interface DeleteBackendWalletInput {
984+
walletAddress: string;
985+
}
986+
export function useEngineDeleteBackendWallet(instance: string) {
987+
const token = useLoggedInUser().user?.jwt ?? null;
988+
const queryClient = useQueryClient();
989+
990+
return useMutation({
991+
mutationFn: async (input: DeleteBackendWalletInput) => {
992+
invariant(instance, "instance is required");
993+
994+
const res = await fetch(
995+
`${instance}backend-wallet/${input.walletAddress}`,
996+
{
997+
method: "DELETE",
998+
headers: getEngineRequestHeaders(token),
999+
},
1000+
);
1001+
const json = await res.json();
1002+
1003+
if (json.error) {
1004+
throw new Error(json.error.message);
1005+
}
1006+
return json.result;
1007+
},
1008+
onSuccess: () => {
1009+
return queryClient.invalidateQueries({
1010+
queryKey: engineKeys.backendWallets(instance),
1011+
});
1012+
},
1013+
});
1014+
}
1015+
9831016
export function useEngineGrantPermissions(instance: string) {
9841017
const token = useLoggedInUser().user?.jwt ?? null;
9851018
const queryClient = useQueryClient();
@@ -1177,16 +1210,15 @@ export function useEngineCreateWebhook(instance: string) {
11771210
});
11781211
}
11791212

1180-
type RevokeWebhookInput = {
1213+
type DeleteWebhookInput = {
11811214
id: number;
11821215
};
1183-
1184-
export function useEngineRevokeWebhook(instance: string) {
1216+
export function useEngineDeleteWebhook(instance: string) {
11851217
const token = useLoggedInUser().user?.jwt ?? null;
11861218
const queryClient = useQueryClient();
11871219

11881220
return useMutation({
1189-
mutationFn: async (input: RevokeWebhookInput) => {
1221+
mutationFn: async (input: DeleteWebhookInput) => {
11901222
invariant(instance, "instance is required");
11911223

11921224
const res = await fetch(`${instance}webhooks/revoke`, {
@@ -1195,11 +1227,44 @@ export function useEngineRevokeWebhook(instance: string) {
11951227
body: JSON.stringify(input),
11961228
});
11971229
const json = await res.json();
1198-
11991230
if (json.error) {
12001231
throw new Error(json.error.message);
12011232
}
1233+
return json.result;
1234+
},
1235+
onSuccess: () => {
1236+
return queryClient.invalidateQueries({
1237+
queryKey: engineKeys.webhooks(instance),
1238+
});
1239+
},
1240+
});
1241+
}
1242+
1243+
interface TestWebhookInput {
1244+
id: number;
1245+
}
1246+
interface TestWebhookResponse {
1247+
ok: boolean;
1248+
status: number;
1249+
body: string;
1250+
}
1251+
export function useEngineTestWebhook(instance: string) {
1252+
const token = useLoggedInUser().user?.jwt ?? null;
1253+
const queryClient = useQueryClient();
12021254

1255+
return useMutation<TestWebhookResponse, Error, TestWebhookInput>({
1256+
mutationFn: async (input: TestWebhookInput) => {
1257+
invariant(instance, "instance is required");
1258+
1259+
const res = await fetch(`${instance}webhooks/${input.id}/test`, {
1260+
method: "POST",
1261+
headers: getEngineRequestHeaders(token),
1262+
body: JSON.stringify({}),
1263+
});
1264+
const json = await res.json();
1265+
if (json.error) {
1266+
throw new Error(json.error.message);
1267+
}
12031268
return json.result;
12041269
},
12051270
onSuccess: () => {

0 commit comments

Comments
 (0)