From 0e89a176a9c4290e1f4fcca425fdefbb90faeaea Mon Sep 17 00:00:00 2001 From: kiwiidb Date: Wed, 23 Mar 2022 09:24:19 +0100 Subject: [PATCH] fix: keysend API These fixes should be backwards compatible. --- src/extension/background-script/actions/ln/keysend.ts | 7 +++++-- .../background-script/actions/webln/keysendOrPrompt.ts | 8 +++++--- src/extension/ln/webln/index.ts | 4 ++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/extension/background-script/actions/ln/keysend.ts b/src/extension/background-script/actions/ln/keysend.ts index c3eb02f800..9d327bd67f 100644 --- a/src/extension/background-script/actions/ln/keysend.ts +++ b/src/extension/background-script/actions/ln/keysend.ts @@ -7,7 +7,10 @@ import utils from "../../../../common/lib/utils"; export default async function keysend(message: Message) { PubSub.publish(`ln.keysend.start`, message); const { destination, amount, customRecords } = message.args; - if (typeof destination !== "string" || typeof amount !== "string") { + if ( + typeof destination !== "string" || + (typeof amount !== "string" && typeof amount !== "number") + ) { return { error: "destination or amount missing.", }; @@ -19,7 +22,7 @@ export default async function keysend(message: Message) { try { response = await connector.keysend({ pubkey: destination, - amount: parseInt(amount), + amount: parseInt(amount as string), customRecords: customRecords as Record, }); } catch (e) { diff --git a/src/extension/background-script/actions/webln/keysendOrPrompt.ts b/src/extension/background-script/actions/webln/keysendOrPrompt.ts index 58c35fc9df..8219ca447f 100644 --- a/src/extension/background-script/actions/webln/keysendOrPrompt.ts +++ b/src/extension/background-script/actions/webln/keysendOrPrompt.ts @@ -8,13 +8,15 @@ import { checkAllowance } from "./sendPaymentOrPrompt"; const keysendOrPrompt = async (message: Message) => { const destination = message.args.destination; const amount = message.args.amount; - if (typeof destination !== "string" || typeof amount !== "string") { + if ( + typeof destination !== "string" || + (typeof amount !== "string" && typeof amount !== "number") + ) { return { error: "Destination or amount missing.", }; } - - if (await checkAllowance(message.origin.host, parseInt(amount))) { + if (await checkAllowance(message.origin.host, parseInt(amount as string))) { return keysendWithAllowance(message); } else { return keysendWithPrompt(message); diff --git a/src/extension/ln/webln/index.ts b/src/extension/ln/webln/index.ts index 55e5a61c19..2904a82de4 100644 --- a/src/extension/ln/webln/index.ts +++ b/src/extension/ln/webln/index.ts @@ -8,8 +8,8 @@ type RequestInvoiceArgs = { type KeysendArgs = { destination: string; - customRecords: Record; - amount: string; + customRecords?: Record; + amount: string | number; }; export default class WebLNProvider {