From e638a1cc1ebd279f35b0ed4d97e361a1f0a9aacf Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Fri, 15 Dec 2023 15:50:02 +0700 Subject: [PATCH] fix: convert transaction amount from millisats to sats --- examples/nwc/make-invoice.js | 6 +++--- src/webln/NostrWeblnProvider.ts | 9 +++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/examples/nwc/make-invoice.js b/examples/nwc/make-invoice.js index a8a931a..e147cac 100644 --- a/examples/nwc/make-invoice.js +++ b/examples/nwc/make-invoice.js @@ -9,9 +9,9 @@ import { webln as providers } from "../../dist/index.module.js"; const rl = readline.createInterface({ input, output }); -const nwcUrl = await rl.question( - "Nostr Wallet Connect URL (nostr+walletconnect://...): ", -); +const nwcUrl = + process.env.NWC_URL || + (await rl.question("Nostr Wallet Connect URL (nostr+walletconnect://...): ")); rl.close(); const webln = new providers.NostrWebLNProvider({ diff --git a/src/webln/NostrWeblnProvider.ts b/src/webln/NostrWeblnProvider.ts index e52dc5d..7bad92c 100644 --- a/src/webln/NostrWeblnProvider.ts +++ b/src/webln/NostrWeblnProvider.ts @@ -409,8 +409,13 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider { "list_transactions", args, (response) => !!response.transactions, - // TODO: consider mapping NWC response - (response) => response, + (response) => ({ + transactions: response.transactions.map((transaction) => ({ + ...transaction, + // NWC uses msats - convert to sats for webln + amount: Math.floor(transaction.amount / 1000), + })), + }), ); }