Skip to content

Commit

Permalink
fix: return preimage for ln settlement
Browse files Browse the repository at this point in the history
  • Loading branch information
openoms committed Dec 21, 2023
1 parent a5181a7 commit 935895c
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 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,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.");
Expand All @@ -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 },
},
Expand Down

0 comments on commit 935895c

Please sign in to comment.