Using LNURLTip to show the QR
This commit is contained in:
@ -3,11 +3,11 @@ import { useState } from "react";
|
|||||||
import { decode as invoiceDecode } from "light-bolt11-decoder";
|
import { decode as invoiceDecode } from "light-bolt11-decoder";
|
||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import NoteTime from "./NoteTime";
|
import NoteTime from "./NoteTime";
|
||||||
import QrCode from "./QrCode";
|
import LNURLTip from "./LNURLTip";
|
||||||
|
|
||||||
export default function Invoice(props) {
|
export default function Invoice(props) {
|
||||||
const invoice = props.invoice;
|
const invoice = props.invoice;
|
||||||
const [showLnQr, setShowLnQr] = useState(false);
|
const [showInvoice, setShowInvoice] = useState(false);
|
||||||
|
|
||||||
const info = useMemo(() => {
|
const info = useMemo(() => {
|
||||||
try {
|
try {
|
||||||
@ -37,37 +37,30 @@ export default function Invoice(props) {
|
|||||||
<>
|
<>
|
||||||
<h4>⚡️ Invoice for {info?.amount?.toLocaleString()} sats</h4>
|
<h4>⚡️ Invoice for {info?.amount?.toLocaleString()} sats</h4>
|
||||||
<p>{info?.description}</p>
|
<p>{info?.description}</p>
|
||||||
{ showLnQr ? <p><QrCode data={invoice} link={"lightning:${invoice}"} /></p> : null }
|
{showInvoice && <LNURLTip lnInvoice={invoice} show={true} /> }
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h4>⚡️ Invoice for {info?.amount?.toLocaleString()} sats</h4>
|
<h4>⚡️ Invoice for {info?.amount?.toLocaleString()} sats</h4>
|
||||||
{ showLnQr ? <p><QrCode data={invoice} link={"lightning:${invoice}"} /></p> : null }
|
{showInvoice && <LNURLTip lnInvoice={invoice} show={true} /> }
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function pay(){
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{ showLnQr ? <div className="btn" onClick={() => window.open(`lightning:${invoice}`)}>Pay</div> :
|
|
||||||
<div className="btn" onClick={(e) => setShowLnQr(true)}>Pay</div> }
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="note-invoice flex">
|
<div className="note-invoice flex">
|
||||||
<div className="f-grow flex f-col">
|
<div className="f-grow flex f-col">
|
||||||
{header()}
|
{header()}
|
||||||
{info?.expire ? <small>{info?.expired ? "Expired" : "Expires"} <NoteTime from={info.expire * 1000} /></small> : null}
|
{info?.expire ? <small>{info?.expired ? "Expired" : "Expires"} <NoteTime from={info.expire * 1000} /></small> : null}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{info?.expired ? <div className="btn">Expired</div> : pay() }
|
{info?.expired ? <div className="btn">Expired</div> : <div className="btn" onClick={(e) => setShowInvoice(true)}>Pay</div> }
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
@ -8,6 +8,7 @@ export default function LNURLTip(props) {
|
|||||||
const onClose = props.onClose || (() => { });
|
const onClose = props.onClose || (() => { });
|
||||||
const service = props.svc;
|
const service = props.svc;
|
||||||
const show = props.show || false;
|
const show = props.show || false;
|
||||||
|
const lnInvoice = props.lnInvoice
|
||||||
const amounts = [50, 100, 500, 1_000, 5_000, 10_000];
|
const amounts = [50, 100, 500, 1_000, 5_000, 10_000];
|
||||||
const [payService, setPayService] = useState("");
|
const [payService, setPayService] = useState("");
|
||||||
const [amount, setAmount] = useState(0);
|
const [amount, setAmount] = useState(0);
|
||||||
@ -18,7 +19,7 @@ export default function LNURLTip(props) {
|
|||||||
const [success, setSuccess] = useState(null);
|
const [success, setSuccess] = useState(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (show) {
|
if (show && !lnInvoice) {
|
||||||
loadService()
|
loadService()
|
||||||
.then(a => setPayService(a))
|
.then(a => setPayService(a))
|
||||||
.catch(() => setError("Failed to load LNURL service"));
|
.catch(() => setError("Failed to load LNURL service"));
|
||||||
@ -164,7 +165,7 @@ export default function LNURLTip(props) {
|
|||||||
|
|
||||||
function payInvoice() {
|
function payInvoice() {
|
||||||
if(success) return null;
|
if(success) return null;
|
||||||
const pr = invoice.pr;
|
const pr = lnInvoice ? lnInvoice : invoice.pr;
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="invoice">
|
<div className="invoice">
|
||||||
|
Reference in New Issue
Block a user