Skip to content

Commit

Permalink
feat: test webhook and delete wallet (#5489)
Browse files Browse the repository at this point in the history
  • Loading branch information
arcoraven authored Nov 26, 2024
1 parent 46ef3e6 commit 1ad6983
Show file tree
Hide file tree
Showing 3 changed files with 434 additions and 147 deletions.
77 changes: 71 additions & 6 deletions apps/dashboard/src/@3rdweb-sdk/react/hooks/useEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function useEngineInstances() {
export type BackendWallet = {
address: string;
label?: string;
type: string;
type: EngineBackendWalletType;
awsKmsKeyId?: string | null;
awsKmsArn?: string | null;
gcpKmsKeyId?: string | null;
Expand Down Expand Up @@ -980,6 +980,39 @@ export function useEngineImportBackendWallet(instance: string) {
});
}

interface DeleteBackendWalletInput {
walletAddress: string;
}
export function useEngineDeleteBackendWallet(instance: string) {
const token = useLoggedInUser().user?.jwt ?? null;
const queryClient = useQueryClient();

return useMutation({
mutationFn: async (input: DeleteBackendWalletInput) => {
invariant(instance, "instance is required");

const res = await fetch(
`${instance}backend-wallet/${input.walletAddress}`,
{
method: "DELETE",
headers: getEngineRequestHeaders(token),
},
);
const json = await res.json();

if (json.error) {
throw new Error(json.error.message);
}
return json.result;
},
onSuccess: () => {
return queryClient.invalidateQueries({
queryKey: engineKeys.backendWallets(instance),
});
},
});
}

export function useEngineGrantPermissions(instance: string) {
const token = useLoggedInUser().user?.jwt ?? null;
const queryClient = useQueryClient();
Expand Down Expand Up @@ -1177,16 +1210,15 @@ export function useEngineCreateWebhook(instance: string) {
});
}

type RevokeWebhookInput = {
type DeleteWebhookInput = {
id: number;
};

export function useEngineRevokeWebhook(instance: string) {
export function useEngineDeleteWebhook(instance: string) {
const token = useLoggedInUser().user?.jwt ?? null;
const queryClient = useQueryClient();

return useMutation({
mutationFn: async (input: RevokeWebhookInput) => {
mutationFn: async (input: DeleteWebhookInput) => {
invariant(instance, "instance is required");

const res = await fetch(`${instance}webhooks/revoke`, {
Expand All @@ -1195,11 +1227,44 @@ export function useEngineRevokeWebhook(instance: string) {
body: JSON.stringify(input),
});
const json = await res.json();

if (json.error) {
throw new Error(json.error.message);
}
return json.result;
},
onSuccess: () => {
return queryClient.invalidateQueries({
queryKey: engineKeys.webhooks(instance),
});
},
});
}

interface TestWebhookInput {
id: number;
}
interface TestWebhookResponse {
ok: boolean;
status: number;
body: string;
}
export function useEngineTestWebhook(instance: string) {
const token = useLoggedInUser().user?.jwt ?? null;
const queryClient = useQueryClient();

return useMutation<TestWebhookResponse, Error, TestWebhookInput>({
mutationFn: async (input: TestWebhookInput) => {
invariant(instance, "instance is required");

const res = await fetch(`${instance}webhooks/${input.id}/test`, {
method: "POST",
headers: getEngineRequestHeaders(token),
body: JSON.stringify({}),
});
const json = await res.json();
if (json.error) {
throw new Error(json.error.message);
}
return json.result;
},
onSuccess: () => {
Expand Down
Loading

0 comments on commit 1ad6983

Please sign in to comment.