mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
feat(bolt11): create getAmount function
This commit is contained in:
parent
d33ecdc0f6
commit
82bf36f064
1 changed files with 15 additions and 0 deletions
15
src/utils/bolt11.ts
Normal file
15
src/utils/bolt11.ts
Normal 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 };
|
||||||
Loading…
Add table
Reference in a new issue