Catch invoice parsing errors
This commit is contained in:
@ -1,19 +1,21 @@
|
|||||||
import "./Invoice.css";
|
import "./Invoice.css";
|
||||||
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 { useNavigate } from "react-router-dom";
|
|
||||||
|
|
||||||
export default function Invoice(props) {
|
export default function Invoice(props) {
|
||||||
const invoice = props.invoice;
|
const invoice = props.invoice;
|
||||||
const navigate = useNavigate();
|
|
||||||
|
|
||||||
const info = useMemo(() => {
|
const info = useMemo(() => {
|
||||||
|
try {
|
||||||
let parsed = invoiceDecode(invoice);
|
let parsed = invoiceDecode(invoice);
|
||||||
|
|
||||||
let amount = parseInt(parsed.sections.find(a => a.name === "amount")?.value);
|
let amount = parseInt(parsed.sections.find(a => a.name === "amount")?.value);
|
||||||
return {
|
return {
|
||||||
amount: !isNaN(amount) ? (amount / 1000) : null
|
amount: !isNaN(amount) ? (amount / 1000) : null
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
}, [invoice]);
|
}, [invoice]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Reference in New Issue
Block a user