useDeleteLightningAddress.ts raw
1 import React from "react";
2 import { toast } from "sonner";
3 import { useApp } from "src/hooks/useApp";
4 import { request } from "src/utils/request";
5
6 export function useDeleteLightningAddress(appId?: number) {
7 const { data: app, mutate: refetchApp } = useApp(appId);
8 const [deletingLightningAddress, setDeletingLightningAddress] =
9 React.useState(false);
10
11 async function deleteLightningAddress() {
12 try {
13 if (!app) {
14 throw new Error("app not found");
15 }
16 setDeletingLightningAddress(true);
17 await request(`/api/lightning-addresses/${app.id}`, {
18 method: "DELETE",
19 headers: {
20 "Content-Type": "application/json",
21 },
22 });
23 await refetchApp();
24 toast("Successfully deleted lightning address");
25 } catch (error) {
26 toast.error("Failed to delete lightning address", {
27 description: (error as Error).message,
28 });
29 }
30 setDeletingLightningAddress(false);
31 }
32 return {
33 deleteLightningAddress,
34 deletingLightningAddress,
35 };
36 }
37