NodeSettings.tsx raw
1 import { toast } from "sonner";
2 import ExternalLink from "src/components/ExternalLink";
3 import Loading from "src/components/Loading";
4 import SettingsHeader from "src/components/SettingsHeader";
5 import { Label } from "src/components/ui/label";
6 import { Switch } from "src/components/ui/switch";
7
8 import { useInfo } from "src/hooks/useInfo";
9 import { handleRequestError } from "src/utils/handleRequestError";
10 import { request } from "src/utils/request";
11
12 export function NodeSettings() {
13 const { data: info, mutate: refetchInfo } = useInfo();
14
15 if (!info) {
16 return <Loading />;
17 }
18 if (info.backendType !== "LDK") {
19 return <p>Your Hub does not support this feature.</p>;
20 }
21
22 const hasJitSource = !!info.jitChannelsLiquiditySource;
23
24 async function setJitChannelsEnabled(enabled: boolean) {
25 try {
26 await request("/api/settings", {
27 method: "PATCH",
28 headers: {
29 "Content-Type": "application/json",
30 },
31 body: JSON.stringify({ jitChannelsEnabled: enabled }),
32 });
33 await refetchInfo();
34 toast(
35 enabled
36 ? "Just-in-time channels enabled"
37 : "Just-in-time channels disabled"
38 );
39 } catch (error) {
40 handleRequestError("Failed to update just-in-time channels", error);
41 }
42 }
43
44 return (
45 <>
46 <SettingsHeader
47 pageTitle="Node"
48 title="Node"
49 description="Configure how your node handles channels and payments."
50 />
51 <div className="flex flex-col gap-4">
52 <div className="flex items-center justify-between gap-8">
53 <div className="flex flex-col gap-1">
54 <Label htmlFor="jit-channels" className="cursor-pointer">
55 Just-in-time channels
56 </Label>
57 <p className="text-sm text-muted-foreground">
58 Automatically open a new channel through a liquidity provider when
59 you receive a payment that exceeds your receive limit. The
60 provider's fee is deducted from that payment.{" "}
61 <ExternalLink
62 to="https://guides.getalby.com/user-guide/alby-hub/faq/what-are-just-in-time-channels"
63 className="underline"
64 >
65 Learn more
66 </ExternalLink>
67 </p>
68 </div>
69 <Switch
70 id="jit-channels"
71 checked={info.jitChannelsEnabled}
72 disabled={!hasJitSource && !info.jitChannelsEnabled}
73 onCheckedChange={setJitChannelsEnabled}
74 />
75 </div>
76 {!hasJitSource && (
77 <p className="text-sm text-muted-foreground">
78 Just-in-time channels are currently not available on your network.
79 </p>
80 )}
81 </div>
82 </>
83 );
84 }
85