From 07d88c821cbb4aecb010d0f78d25fc2f8580a4ad Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Wed, 18 Sep 2024 11:33:44 +0700 Subject: [PATCH 1/2] fix: lnurl pay to use existing lightning address --- frontend/src/screens/wallet/Send.tsx | 2 +- frontend/src/screens/wallet/send/LnurlPay.tsx | 29 ++++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/frontend/src/screens/wallet/Send.tsx b/frontend/src/screens/wallet/Send.tsx index 76fcee2b..b351e7ca 100644 --- a/frontend/src/screens/wallet/Send.tsx +++ b/frontend/src/screens/wallet/Send.tsx @@ -35,7 +35,7 @@ export default function Send() { if (lnAddress.lnurlpData) { navigate(`/wallet/send/lnurl-pay`, { state: { - args: { lnurlDetails: lnAddress.lnurlpData }, + args: { lnAddress }, }, }); return; diff --git a/frontend/src/screens/wallet/send/LnurlPay.tsx b/frontend/src/screens/wallet/send/LnurlPay.tsx index 77e60a59..6cd30d1c 100644 --- a/frontend/src/screens/wallet/send/LnurlPay.tsx +++ b/frontend/src/screens/wallet/send/LnurlPay.tsx @@ -5,7 +5,7 @@ import { Label } from "src/components/ui/label"; import { LoadingButton } from "src/components/ui/loading-button"; import { useToast } from "src/components/ui/use-toast"; -import { LightningAddress, LnUrlPayResponse } from "@getalby/lightning-tools"; +import { LightningAddress } from "@getalby/lightning-tools"; import { Link, useLocation, useNavigate } from "react-router-dom"; import Loading from "src/components/Loading"; @@ -14,7 +14,7 @@ export default function LnurlPay() { const navigate = useNavigate(); const { toast } = useToast(); - const lnurlDetails = state?.args?.lnurlDetails as LnUrlPayResponse; + const lnAddress = state?.args?.lnAddress as LightningAddress; const [amount, setAmount] = React.useState(""); const [comment, setComment] = React.useState(""); const [isLoading, setLoading] = React.useState(false); @@ -22,11 +22,10 @@ export default function LnurlPay() { const onSubmit = async (event: React.FormEvent) => { event.preventDefault(); try { + if (!lnAddress) { + throw new Error("no lightning address set"); + } setLoading(true); - const lnAddress = new LightningAddress(lnurlDetails.identifier); - // this is set instead of calling fetch because - // requestInvoice uses lnurlpData.callback - lnAddress.lnurlpData = lnurlDetails; const invoice = await lnAddress.requestInvoice({ satoshi: parseInt(amount), comment, @@ -49,23 +48,27 @@ export default function LnurlPay() { }; React.useEffect(() => { - if (!lnurlDetails) { + if (!lnAddress) { navigate("/wallet/send"); } - }, [navigate, lnurlDetails]); + }, [navigate, lnAddress]); - if (!lnurlDetails) { + if (!lnAddress) { return ; } return (
-

{lnurlDetails.identifier}

- {lnurlDetails?.description && ( +

+ {lnAddress.lnurlpData?.identifier} +

+ {lnAddress.lnurlpData?.description && (
-

{lnurlDetails.description}

+

+ {lnAddress.lnurlpData?.description} +

)}
@@ -83,7 +86,7 @@ export default function LnurlPay() { autoFocus />
- {!!lnurlDetails?.commentAllowed && ( + {!!lnAddress.lnurlpData?.commentAllowed && (
Date: Wed, 18 Sep 2024 11:36:39 +0700 Subject: [PATCH 2/2] fix: cleanup --- frontend/src/screens/wallet/send/LnurlPay.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/frontend/src/screens/wallet/send/LnurlPay.tsx b/frontend/src/screens/wallet/send/LnurlPay.tsx index 6cd30d1c..3b75154b 100644 --- a/frontend/src/screens/wallet/send/LnurlPay.tsx +++ b/frontend/src/screens/wallet/send/LnurlPay.tsx @@ -60,14 +60,12 @@ export default function LnurlPay() { return (
-

- {lnAddress.lnurlpData?.identifier} -

+

{lnAddress.address}

{lnAddress.lnurlpData?.description && (

- {lnAddress.lnurlpData?.description} + {lnAddress.lnurlpData.description}

)}