From 626b6148aebd7144d08913431dcae6d188965e1e Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Fri, 12 Apr 2024 14:55:15 -0500 Subject: [PATCH] handle invoices inside of message --- src/routes/Chat.tsx | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/routes/Chat.tsx b/src/routes/Chat.tsx index 1576c21e..aab1b87a 100644 --- a/src/routes/Chat.tsx +++ b/src/routes/Chat.tsx @@ -76,9 +76,20 @@ function SingleMessage(props: { const parsed = createAsync( async () => { - const result = toParsedParams(props.dm.message, network); + let result = undefined; + + // Look for a long word that might be an invoice + const split_message_by_whitespace = props.dm.message.split(/\s+/g); + for (const word of split_message_by_whitespace) { + if (word.length > 15) { + result = toParsedParams(word, network); + if (result.ok) { + break; + } + } + } - if (!result.ok) { + if (!result || !result.ok) { return undefined; } @@ -92,6 +103,10 @@ function SingleMessage(props: { return { type: "invoice", status: "paid", + message_without_invoice: props.dm.message.replace( + result.value.original, + "" + ), value: result.value.invoice, amount: result.value.amount_sats }; @@ -103,6 +118,10 @@ function SingleMessage(props: { return { type: "invoice", status: "unpaid", + message_without_invoice: props.dm.message.replace( + result.value.original, + "" + ), from: props.dm.from, value: result.value.invoice, amount: result.value.amount_sats @@ -130,9 +149,9 @@ function SingleMessage(props: { navWithContactId(); } - function handlePay() { + function handlePay(invoice: string) { actions.handleIncomingString( - props.dm.message, + invoice, (error) => { showToast(error); }, @@ -153,6 +172,11 @@ function SingleMessage(props: {
+ +

+ {parsed()?.message_without_invoice} +

+
Lightning Invoice @@ -167,7 +191,7 @@ function SingleMessage(props: {