mirror of
https://github.com/aljazceru/ditto.git
synced 2026-01-01 04:34:24 +01:00
feat(bolt11): create getAmount function
This commit is contained in:
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 };
|
||||
Reference in New Issue
Block a user