Catch invoice parsing errors

This commit is contained in:
Kieran 2023-01-04 20:09:35 +00:00
parent b8a6ad3f0c
commit 7f5974c4ea
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941

View File

@ -1,18 +1,20 @@
import "./Invoice.css";
import { decode as invoiceDecode } from "light-bolt11-decoder";
import { useMemo } from "react";
import { useNavigate } from "react-router-dom";
export default function Invoice(props) {
const invoice = props.invoice;
const navigate = useNavigate();
const info = useMemo(() => {
let parsed = invoiceDecode(invoice);
try {
let parsed = invoiceDecode(invoice);
let amount = parseInt(parsed.sections.find(a => a.name === "amount")?.value);
return {
amount: !isNaN(amount) ? (amount / 1000) : null
let amount = parseInt(parsed.sections.find(a => a.name === "amount")?.value);
return {
amount: !isNaN(amount) ? (amount / 1000) : null
}
} catch (e) {
console.error(e);
}
}, [invoice]);