Skip to content

Commit 09c40b3

Browse files
committed
Bug fix: Outgoing payments are properly linked with the associated card again
1 parent e85329c commit 09c40b3

3 files changed

Lines changed: 26 additions & 15 deletions

File tree

phoenix-ios/phoenix-ios/officers/BusinessManager.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -789,16 +789,14 @@ class BusinessManager {
789789
case .abortHandledElsewhere(_):
790790
log.warning("handleCardReqeust: abort: handled elsewhere")
791791

792-
case .continueAndSendPayment(_, _, _):
792+
case .continueAndSendPayment(let card, _, _):
793793
log.debug("handleCardReqeust: continue: send payment")
794794

795-
guard let peer = business.peerManager.peerStateValue() else {
796-
log.error("handleCardReqeust: peer is nil")
797-
return
798-
}
799-
800795
do {
801-
try await peer.payUnsolicitedInvoice(invoice: cardRequest.invoice)
796+
try await business.sendManager.payUnsolicitedInvoice(
797+
invoice: cardRequest.invoice,
798+
metadata: WalletPaymentMetadata.withCard(card.id)
799+
)
802800
} catch {
803801
log.error("peer.payUnsolicitedInvoice(): error: \(error)")
804802
}

phoenix-ios/phoenix-notifySrvExt/NotificationService.swift

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -553,23 +553,20 @@ class NotificationService: UNNotificationServiceExtension {
553553
case .abortHandledElsewhere(_):
554554
log.warning("handleCardReqeust: abort: handled elsewhere")
555555

556-
case .continueAndSendPayment(_, _, _):
556+
case .continueAndSendPayment(let card, _, _):
557557
log.debug("handleCardReqeust: continue: send payment")
558558

559-
guard let peer = business.peerManager.peerStateValue() else {
560-
log.error("handleCardReqeust: peer is nil")
561-
return
562-
}
563-
564559
// Send the payment
565560
do {
566-
try await peer.payUnsolicitedInvoice(invoice: cardRequest.invoice)
561+
try await business.sendManager.payUnsolicitedInvoice(
562+
invoice: cardRequest.invoice,
563+
metadata: WalletPaymentMetadata.withCard(card.id)
564+
)
567565
} catch {
568566
log.error("peer.payUnsolicitedInvoice(): error: \(error)")
569567
}
570568

571569
// Wait for the outgoing payment to complete
572-
let paymentHash = cardRequest.invoice.paymentHash
573570
business.paymentsManager.lastCompletedPaymentPublisher().sink { payment in
574571
if let lnPayment = payment as? Lightning_kmpLightningOutgoingPayment {
575572
if lnPayment.details.paymentHash == cardRequest.invoice.paymentHash {

phoenix-shared/src/commonMain/kotlin/fr.acinq.phoenix/managers/SendManager.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import fr.acinq.lightning.MilliSatoshi
99
import fr.acinq.lightning.TrampolineFees
1010
import fr.acinq.lightning.db.LightningOutgoingPayment
1111
import fr.acinq.lightning.io.PayInvoice
12+
import fr.acinq.lightning.io.SendPaymentResult
1213
import fr.acinq.lightning.logging.LoggerFactory
1314
import fr.acinq.lightning.logging.debug
1415
import fr.acinq.lightning.logging.error
@@ -477,6 +478,21 @@ class SendManager(
477478
)
478479
}
479480

481+
suspend fun payUnsolicitedInvoice(
482+
invoice: Bolt12Invoice,
483+
metadata: WalletPaymentMetadata?
484+
): SendPaymentResult {
485+
val paymentId: UUID = UUID.randomUUID()
486+
val peer = peerManager.getPeer()
487+
488+
// save card metadata if any
489+
metadata?.let { row ->
490+
databaseManager.metadataQueue.enqueue(row = row, id = paymentId)
491+
}
492+
493+
return peer.payUnsolicitedInvoice(invoice, paymentId)
494+
}
495+
480496
/**
481497
* Step 1 of 2:
482498
* First call this function to convert the LnurlPay.Intent into a LnurlPay.Invoice.

0 commit comments

Comments
 (0)