feat(bolt11): create getAmount function

This commit is contained in:
P. Reis 2024-06-17 14:38:04 -03:00
parent d33ecdc0f6
commit 82bf36f064

15
src/utils/bolt11.ts Normal file
View file

@ -0,0 +1,15 @@
import bolt11 from 'bolt11';
/** Decodes the invoice and returns the amount in millisatoshis */
function getAmount(invoice: string | undefined): string | undefined {
if (!invoice) return;
try {
const decoded = bolt11.decode(invoice);
return decoded?.millisatoshis ?? undefined;
} catch {
return;
}
}
export { getAmount };