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: {