From 4555ba576350fd41f3fd39806d0d71a31b2ae52e Mon Sep 17 00:00:00 2001 From: openoms <43343391+openoms@users.noreply.github.com> Date: Fri, 22 Dec 2023 13:06:48 +0100 Subject: [PATCH] fix: return preimage for ln settlements in galoy connector (#2953) --- .../background-script/connectors/galoy.ts | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/extension/background-script/connectors/galoy.ts b/src/extension/background-script/connectors/galoy.ts index 26014d0e59..53e4c2170a 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,25 @@ 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 +345,7 @@ class Galoy implements Connector { default: return { data: { - preimage: "No preimage received", + preimage: preimageMessage, paymentHash, route: { total_amt: amountInSats, total_fees: 0 }, },