Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return preimage for ln settlement in galoy connector #2953

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading