Skip to content

Commit

Permalink
fix: return preimage for ln settlements in galoy connector (getAlby#2953
Browse files Browse the repository at this point in the history
)
  • Loading branch information
openoms authored Dec 22, 2023
1 parent 0fd87d8 commit 4555ba5
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/extension/background-script/connectors/galoy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,21 @@ class Galoy implements Connector {
errors {
message
}
transaction {
settlementVia {
... on SettlementViaLn {
${
this.config.apiCompatibilityMode
? "paymentSecret"
: "preImage"
}
}
... on SettlementViaIntraLedger {
counterPartyUsername
counterPartyWalletId
}
}
}
}
}
`,
Expand All @@ -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.");
Expand All @@ -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 },
},
Expand Down

0 comments on commit 4555ba5

Please sign in to comment.