Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions core/api/src/app/payments/index.types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type LnSendAttemptResult =
| {
type: PaymentSendAttemptResultTypeObj["Ok"]
journalId: LedgerJournalId
revealedPreImage?: RevealedPreImage
}
| {
type: PaymentSendAttemptResultTypeObj["Pending"]
Expand Down
3 changes: 2 additions & 1 deletion core/api/src/app/payments/ln-send-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ export const IntraLedgerSendAttemptResult = {
}

export const LnSendAttemptResult = {
ok: (journalId: LedgerJournalId): LnSendAttemptResult => ({
ok: (journalId: LedgerJournalId, revealedPreImage?: RevealedPreImage): LnSendAttemptResult => ({
type: PaymentSendAttemptResultType.Ok,
journalId,
revealedPreImage,
}),
pending: (journalId: LedgerJournalId): LnSendAttemptResult => ({
type: PaymentSendAttemptResultType.Pending,
Expand Down
13 changes: 12 additions & 1 deletion core/api/src/app/payments/send-lightning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,17 @@ const executePaymentViaLn = async ({
journalId: paymentSendAttemptResult.journalId,
})
if (walletTransaction instanceof Error) return walletTransaction

// Inject revealedPreImage into settlementVia if available and this was a successful Lightning payment
if (
paymentSendAttemptResult.type === PaymentSendAttemptResultType.Ok &&
paymentSendAttemptResult.revealedPreImage &&
walletTransaction.settlementVia.type === "lightning"
) {
// Type assertion is safe here because we've checked the transaction is Lightning
(walletTransaction.settlementVia as any).revealedPreImage = paymentSendAttemptResult.revealedPreImage
}

NotificationsService().sendTransaction({
recipient: notificationRecipient,
transaction: walletTransaction,
Expand Down Expand Up @@ -1050,7 +1061,7 @@ const lockedPaymentViaLnSteps = async ({
if (updateJournalTxnsState instanceof Error) {
return LnSendAttemptResult.err(updateJournalTxnsState)
}
return LnSendAttemptResult.ok(journalId)
return LnSendAttemptResult.ok(journalId, payResult.revealedPreImage)
}

const getAlreadyPaidResponse = async (args: {
Expand Down
2 changes: 1 addition & 1 deletion core/api/src/services/ledger/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const persistAndReturnEntry = async ({
hash,
revealedPreImage,
}))
txMetadataRepo.persistAll(txsMetadataToPersist)
await txMetadataRepo.persistAll(txsMetadataToPersist)

return journalEntry
} catch (err) {
Expand Down
Loading