Skip to content

Commit 97cf9bb

Browse files
committed
feat: test webhook and delete wallet
1 parent d98c133 commit 97cf9bb

File tree

3 files changed

+407
-116
lines changed

3 files changed

+407
-116
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;
@@ -964,6 +964,39 @@ export function useEngineImportBackendWallet(instance: string) {
964964
});
965965
}
966966

967+
interface DeleteBackendWalletInput {
968+
walletAddress: string;
969+
}
970+
export function useEngineDeleteBackendWallet(instance: string) {
971+
const token = useLoggedInUser().user?.jwt ?? null;
972+
const queryClient = useQueryClient();
973+
974+
return useMutation({
975+
mutationFn: async (input: DeleteBackendWalletInput) => {
976+
invariant(instance, "instance is required");
977+
978+
const res = await fetch(
979+
`${instance}backend-wallet/${input.walletAddress}`,
980+
{
981+
method: "DELETE",
982+
headers: getEngineRequestHeaders(token),
983+
},
984+
);
985+
const json = await res.json();
986+
987+
if (json.error) {
988+
throw new Error(json.error.message);
989+
}
990+
return json.result;
991+
},
992+
onSuccess: () => {
993+
return queryClient.invalidateQueries({
994+
queryKey: engineKeys.backendWallets(instance),
995+
});
996+
},
997+
});
998+
}
999+
9671000
export function useEngineGrantPermissions(instance: string) {
9681001
const token = useLoggedInUser().user?.jwt ?? null;
9691002
const queryClient = useQueryClient();
@@ -1161,16 +1194,15 @@ export function useEngineCreateWebhook(instance: string) {
11611194
});
11621195
}
11631196

1164-
type RevokeWebhookInput = {
1197+
type DeleteWebhookInput = {
11651198
id: number;
11661199
};
1167-
1168-
export function useEngineRevokeWebhook(instance: string) {
1200+
export function useEngineDeleteWebhook(instance: string) {
11691201
const token = useLoggedInUser().user?.jwt ?? null;
11701202
const queryClient = useQueryClient();
11711203

11721204
return useMutation({
1173-
mutationFn: async (input: RevokeWebhookInput) => {
1205+
mutationFn: async (input: DeleteWebhookInput) => {
11741206
invariant(instance, "instance is required");
11751207

11761208
const res = await fetch(`${instance}webhooks/revoke`, {
@@ -1179,11 +1211,44 @@ export function useEngineRevokeWebhook(instance: string) {
11791211
body: JSON.stringify(input),
11801212
});
11811213
const json = await res.json();
1182-
11831214
if (json.error) {
11841215
throw new Error(json.error.message);
11851216
}
1217+
return json.result;
1218+
},
1219+
onSuccess: () => {
1220+
return queryClient.invalidateQueries({
1221+
queryKey: engineKeys.webhooks(instance),
1222+
});
1223+
},
1224+
});
1225+
}
1226+
1227+
interface TestWebhookInput {
1228+
id: number;
1229+
}
1230+
interface TestWebhookResponse {
1231+
ok: boolean;
1232+
status: number;
1233+
body: string;
1234+
}
1235+
export function useEngineTestWebhook(instance: string) {
1236+
const token = useLoggedInUser().user?.jwt ?? null;
1237+
const queryClient = useQueryClient();
11861238

1239+
return useMutation<TestWebhookResponse, Error, TestWebhookInput>({
1240+
mutationFn: async (input: TestWebhookInput) => {
1241+
invariant(instance, "instance is required");
1242+
1243+
const res = await fetch(`${instance}webhooks/${input.id}/test`, {
1244+
method: "POST",
1245+
headers: getEngineRequestHeaders(token),
1246+
body: JSON.stringify({}),
1247+
});
1248+
const json = await res.json();
1249+
if (json.error) {
1250+
throw new Error(json.error.message);
1251+
}
11871252
return json.result;
11881253
},
11891254
onSuccess: () => {

0 commit comments

Comments
 (0)