From 98565efa12a5e06533a7b81e5a6297ec81502e9a Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Mon, 17 Jun 2024 19:49:18 -0300 Subject: [PATCH] refactor(bolt11): get amount with new library --- src/utils/bolt11.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/utils/bolt11.ts b/src/utils/bolt11.ts index ba3dbe93..eef60684 100644 --- a/src/utils/bolt11.ts +++ b/src/utils/bolt11.ts @@ -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; } }