Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix lnurl channel #3046

Merged
merged 8 commits into from
Feb 23, 2024
Merged
27 changes: 26 additions & 1 deletion src/app/screens/LNURLChannel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";
import ScreenHeader from "~/app/components/ScreenHeader";
import toast from "~/app/components/Toast";
import Checkbox from "~/app/components/form/Checkbox";
import { useNavigationState } from "~/app/hooks/useNavigationState";
import { USER_REJECTED_ERROR } from "~/common/constants";
import api from "~/common/lib/api";
Expand All @@ -30,6 +31,7 @@ function LNURLChannel() {

const [loadingConfirm, setLoadingConfirm] = useState(false);
const [successMessage, setSuccessMessage] = useState("");
const [privateChannel, setPrivateChannel] = useState(false);

async function confirm() {
try {
Expand All @@ -54,6 +56,7 @@ function LNURLChannel() {
params: {
k1: details.k1,
remoteid: nodeId,
private: privateChannel ? 1 : 0,
},
adapter: fetchAdapter,
});
Expand All @@ -74,7 +77,13 @@ function LNURLChannel() {
}
} catch (e) {
console.error(e);
if (e instanceof Error) toast.error(`Error: ${e.message}`);
if (axios.isAxiosError(e)) {
pavanjoshi914 marked this conversation as resolved.
Show resolved Hide resolved
const error =
(e.response?.data as { reason?: string })?.reason || e.message;
toast.error(`Error: ${error}`);
} else if (e instanceof Error) {
toast.error(`Error: ${e.message}`);
pavanjoshi914 marked this conversation as resolved.
Show resolved Hide resolved
}
} finally {
setLoadingConfirm(false);
}
Expand Down Expand Up @@ -115,6 +124,22 @@ function LNURLChannel() {
heading={`${t("content_message.heading")}:`}
content={uri}
/>
<div className="flex">
<Checkbox
id="open_private_channel"
name="open_private_channel"
checked={privateChannel}
onChange={(event) => {
setPrivateChannel(event.target.checked);
}}
/>
<label
htmlFor="open_private_channel"
className="cursor-pointer ml-2 block text-sm text-gray-900 font-medium dark:text-white"
>
{t("private_channel.label")}
</label>
</div>
</div>
<ConfirmOrCancel
disabled={loadingConfirm || !uri}
Expand Down
3 changes: 3 additions & 0 deletions src/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,9 @@
"content_message": {
"heading": "Request a channel from the node"
},
"private_channel": {
"label": "Open a private channel?"
},
"success": "Channel request sent successfully to {{name}}"
},
"lnurlwithdraw": {
Expand Down
Loading