From 935895c98687e20e8cd426ac4eed80df1b7dde5b Mon Sep 17 00:00:00 2001 From: openoms Date: Thu, 21 Dec 2023 10:21:15 +0100 Subject: [PATCH] fix: return preimage for ln settlement --- .../background-script/connectors/galoy.ts | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/extension/background-script/connectors/galoy.ts b/src/extension/background-script/connectors/galoy.ts index 26014d0e59..ed148d5c62 100644 --- a/src/extension/background-script/connectors/galoy.ts +++ b/src/extension/background-script/connectors/galoy.ts @@ -273,6 +273,21 @@ class Galoy implements Connector { errors { message } + transaction { + settlementVia { + ... on SettlementViaLn { + ${ + this.config.apiCompatibilityMode + ? "paymentSecret" + : "preImage" + } + } + ... on SettlementViaIntraLedger { + counterPartyUsername + counterPartyWalletId + } + } + } } } `, @@ -295,6 +310,17 @@ class Galoy implements Connector { throw new Error(errs[0].message || JSON.stringify(errs)); } + const transaction = data.lnInvoicePaymentSend.transaction; + let preimageMessage = "No preimage received"; + + if (transaction && transaction.settlementVia) { + if ('preImage' in transaction.settlementVia || 'paymentSecret' in transaction.settlementVia) { + preimageMessage = transaction.settlementVia.preImage || transaction.settlementVia.paymentSecret; + } else if ('counterPartyUsername' in transaction.settlementVia || 'counterPartyWalletId' in transaction.settlementVia) { + preimageMessage = "No preimage, the payment was settled intraledger"; + } + } + switch (data.lnInvoicePaymentSend.status) { case "ALREADY_PAID": throw new Error("Invoice was already paid."); @@ -311,7 +337,7 @@ class Galoy implements Connector { default: return { data: { - preimage: "No preimage received", + preimage: preimageMessage, paymentHash, route: { total_amt: amountInSats, total_fees: 0 }, },