import React from "react"; import { toast } from "sonner"; import { LoadingButton } from "src/components/ui/custom/loading-button"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "src/components/ui/dialog"; import { Input } from "src/components/ui/input"; import { Label } from "src/components/ui/label"; import { useApp } from "src/hooks/useApp"; import { handleRequestError } from "src/utils/handleRequestError"; import { request } from "src/utils/request"; type IsolatedAppTopupProps = { appId: number; }; export function IsolatedAppTopupDialog({ appId, children, }: React.PropsWithChildren) { const { mutate: reloadApp } = useApp(appId); const [amountSat, setAmountSat] = React.useState(""); const [description, setDescription] = React.useState(""); const [loading, setLoading] = React.useState(false); const [open, setOpen] = React.useState(false); async function onSubmit(e: React.FormEvent) { e.preventDefault(); setLoading(true); try { await request(`/api/transfers`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ toAppId: appId, amountSat: +amountSat, description, }), }); await reloadApp(); toast(`Successfully increased balance by ${+amountSat} sats`); reset(); } catch (error) { handleRequestError("Failed to increase sub-wallet balance", error); } setLoading(false); } function reset() { setOpen(false); setAmountSat(""); setDescription(""); } return ( {children}
Increase Balance Increase the balance of this sub-wallet. Make sure you always maintain enough funds in your lightning balance to prevent sub-wallets becoming unspendable.
{ setAmountSat(e.target.value.trim()); }} />
{ setDescription(e.target.value); }} />
Increase
); }