Skip to content
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
50 changes: 40 additions & 10 deletions app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import to.bitkit.ext.rawId
import to.bitkit.ext.removeSpaces
import to.bitkit.ext.setClipboardText
import to.bitkit.ext.totalValue
import to.bitkit.ext.watchUntil
import to.bitkit.models.FeeRate
import to.bitkit.models.NewTransactionSheetDetails
Expand Down Expand Up @@ -137,6 +138,8 @@
private val _showForgotPinSheet = MutableStateFlow(false)
val showForgotPinSheet = _showForgotPinSheet.asStateFlow()

private val processedPayments = mutableSetOf<String>()

fun setShowForgotPin(value: Boolean) {
_showForgotPinSheet.value = value
}
Expand Down Expand Up @@ -236,16 +239,27 @@
}

is Event.PaymentSuccessful -> {
// TODO: fee is not the sats sent. Need to get this amount from elsewhere like send flow or something.
handlePaymentSuccess(
NewTransactionSheetDetails(
type = NewTransactionSheetType.LIGHTNING,
direction = NewTransactionSheetDirection.SENT,
paymentHashOrTxId = event.paymentHash,
sats = ((event.feePaidMsat ?: 0u) / 1000u).toLong(),
),
)
val paymentHash = event.paymentHash
// TODO Temporary solution while LDK node don't returns the sent value in the event
activityRepo.findActivityByPaymentId(
paymentHashOrTxId = paymentHash,
type = ActivityFilter.LIGHTNING,
txType = PaymentType.SENT,
retry = true
).onSuccess { activity ->
handlePaymentSuccess(
NewTransactionSheetDetails(
type = NewTransactionSheetType.LIGHTNING,
direction = NewTransactionSheetDirection.SENT,
paymentHashOrTxId = event.paymentHash,
sats = activity.totalValue().toLong(),
),
)
}.onFailure { e ->
Logger.warn("Failed displaying sheet for event: $Event", e)
}

}

Check warning

Code scanning / detekt

Detects blank lines before rbraces Warning

Unexpected blank line(s) before "}"

is Event.PaymentClaimable -> Unit
is Event.PaymentFailed -> Unit
Expand Down Expand Up @@ -973,7 +987,14 @@
isReceive = false,
tags = tags
)
setSendEffect(SendEffect.PaymentSuccess())
handlePaymentSuccess(
NewTransactionSheetDetails(
type = NewTransactionSheetType.LIGHTNING,
direction = NewTransactionSheetDirection.SENT,
paymentHashOrTxId = paymentHash,
sats = paymentAmount.toLong(), // TODO Add fee when available
),
)
}.onFailure { e ->
Logger.error("Error sending lightning payment", e, context = TAG)
toast(e)
Expand Down Expand Up @@ -1225,6 +1246,8 @@
feeRates = rates,
)
}

processedPayments.clear()
}
// endregion

Expand Down Expand Up @@ -1441,6 +1464,13 @@
}

private fun handlePaymentSuccess(details: NewTransactionSheetDetails) {
details.paymentHashOrTxId?.let {
if (!processedPayments.add(it)) {
Logger.debug("Payment $it already processed, skipping duplicate", context = TAG)
return
}
}

_successSendUiState.update { details }
setSendEffect(SendEffect.PaymentSuccess(details))
}
Expand Down