mirror of
https://github.com/aljazceru/ditto.git
synced 2026-02-23 14:06:58 +01:00
refactor(bolt11): get amount with new library
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
import bolt11 from 'bolt11';
|
||||
import bolt11 from 'light-bolt11-decoder';
|
||||
|
||||
/** 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 (e) {
|
||||
console.log(e);
|
||||
const amount = (bolt11.decode(invoice).sections as { name: string; value: string }[]).find(
|
||||
({ name }) => name === 'amount',
|
||||
)?.value;
|
||||
return amount;
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user