mirror of
https://github.com/getAlby/hub.git
synced 2026-08-13 12:33:39 +02:00
* fix: delete lightning address when deleting a sub-wallet * fix: pass app to useDeleteApp hook * fix: move deletion to server * fix: merge changes * Update frontend/src/components/connections/DisconnectApp.tsx Co-authored-by: Adithya Vardhan <imadithyavardhan@gmail.com> * fix: create helper function --------- Co-authored-by: Roland Bewick <roland.bewick@gmail.com> Co-authored-by: Adithya Vardhan <imadithyavardhan@gmail.com>
38 lines
967 B
TypeScript
38 lines
967 B
TypeScript
import React from "react";
|
|
import { toast } from "sonner";
|
|
|
|
import { App } from "src/types";
|
|
import { handleRequestError } from "src/utils/handleRequestError";
|
|
import { request } from "src/utils/request";
|
|
|
|
export function useDeleteApp(app: App, onSuccess?: () => void) {
|
|
const [isDeleting, setDeleting] = React.useState(false);
|
|
|
|
const deleteApp = React.useCallback(async () => {
|
|
setDeleting(true);
|
|
try {
|
|
// Delete the app/sub-wallet
|
|
await request(`/api/apps/${app.appPubkey}`, {
|
|
method: "DELETE",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
});
|
|
|
|
toast("Connection deleted");
|
|
|
|
if (onSuccess) {
|
|
onSuccess();
|
|
}
|
|
} catch (error) {
|
|
await handleRequestError("Failed to delete connection", error);
|
|
} finally {
|
|
setDeleting(false);
|
|
}
|
|
}, [onSuccess, app]);
|
|
|
|
return React.useMemo(
|
|
() => ({ deleteApp, isDeleting }),
|
|
[deleteApp, isDeleting]
|
|
);
|
|
}
|