mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
refactor(bolt11): get amount with new library
This commit is contained in:
parent
b237432312
commit
98565efa12
1 changed files with 6 additions and 5 deletions
|
|
@ -1,14 +1,15 @@
|
||||||
import bolt11 from 'bolt11';
|
import bolt11 from 'light-bolt11-decoder';
|
||||||
|
|
||||||
/** Decodes the invoice and returns the amount in millisatoshis */
|
/** Decodes the invoice and returns the amount in millisatoshis */
|
||||||
function getAmount(invoice: string | undefined): string | undefined {
|
function getAmount(invoice: string | undefined): string | undefined {
|
||||||
if (!invoice) return;
|
if (!invoice) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const decoded = bolt11.decode(invoice);
|
const amount = (bolt11.decode(invoice).sections as { name: string; value: string }[]).find(
|
||||||
return decoded?.millisatoshis ?? undefined;
|
({ name }) => name === 'amount',
|
||||||
} catch (e) {
|
)?.value;
|
||||||
console.log(e);
|
return amount;
|
||||||
|
} catch {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue