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
17 changes: 17 additions & 0 deletions app/src/main/java/to/bitkit/ext/PaymentFailureReasonExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package to.bitkit.ext

import android.content.Context
import org.lightningdevkit.ldknode.PaymentFailureReason
import to.bitkit.R

fun PaymentFailureReason?.toUserMessage(context: Context): String = when (this) {
PaymentFailureReason.RECIPIENT_REJECTED ->
context.getString(R.string.wallet__toast_payment_failed_recipient_rejected)
PaymentFailureReason.RETRIES_EXHAUSTED ->
context.getString(R.string.wallet__toast_payment_failed_retries_exhausted)
PaymentFailureReason.ROUTE_NOT_FOUND ->
context.getString(R.string.wallet__toast_payment_failed_route_not_found)
PaymentFailureReason.PAYMENT_EXPIRED ->
context.getString(R.string.wallet__toast_payment_failed_timeout)
else -> context.getString(R.string.wallet__toast_payment_failed_description)
}
3 changes: 2 additions & 1 deletion app/src/main/java/to/bitkit/fcm/WakeNodeWorker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import to.bitkit.data.CacheStore
import to.bitkit.data.SettingsStore
import to.bitkit.di.json
import to.bitkit.ext.amountOnClose
import to.bitkit.ext.toUserMessage
import to.bitkit.models.BITCOIN_SYMBOL
import to.bitkit.models.BlocktankNotificationType
import to.bitkit.models.BlocktankNotificationType.cjitPaymentArrived
Expand Down Expand Up @@ -153,7 +154,7 @@ class WakeNodeWorker @AssistedInject constructor(
is Event.PaymentFailed -> {
bestAttemptContent = NotificationDetails(
title = appContext.getString(R.string.notification__payment_failed_title),
body = "⚡ ${event.reason}",
body = "⚡ ${event.reason.toUserMessage(appContext)}",
)

if (notificationType == wakeToTimeout) {
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import kotlinx.coroutines.withContext
import kotlinx.coroutines.withTimeout
import org.lightningdevkit.ldknode.ChannelDataMigration
import org.lightningdevkit.ldknode.Event
import org.lightningdevkit.ldknode.PaymentFailureReason
import org.lightningdevkit.ldknode.PaymentId
import org.lightningdevkit.ldknode.SpendableUtxo
import org.lightningdevkit.ldknode.Txid
Expand All @@ -74,6 +75,7 @@ import to.bitkit.ext.rawId
import to.bitkit.ext.removeSpaces
import to.bitkit.ext.setClipboardText
import to.bitkit.ext.toHex
import to.bitkit.ext.toUserMessage
import to.bitkit.ext.totalValue
import to.bitkit.ext.watchUntil
import to.bitkit.models.FeeRate
Expand Down Expand Up @@ -537,7 +539,7 @@ class AppViewModel @Inject constructor(
event.paymentHash?.let { paymentHash ->
activityRepo.handlePaymentEvent(paymentHash)
}
notifyPaymentFailed()
notifyPaymentFailed(event.reason)
}

private suspend fun handlePaymentReceived(event: Event.PaymentReceived) {
Expand Down Expand Up @@ -625,10 +627,10 @@ class AppViewModel @Inject constructor(
)
}

private fun notifyPaymentFailed() = toast(
private fun notifyPaymentFailed(reason: PaymentFailureReason? = null) = toast(
type = Toast.ToastType.ERROR,
title = context.getString(R.string.wallet__toast_payment_failed_title),
description = context.getString(R.string.wallet__toast_payment_failed_description),
description = reason.toUserMessage(context),
testTag = "PaymentFailedToast",
)

Expand Down Expand Up @@ -1786,7 +1788,7 @@ class AppViewModel @Inject constructor(

is Event.PaymentFailed -> {
if (event.paymentHash == hash) {
val error = Exception(event.reason?.name ?: "Unknown payment failure reason")
val error = Exception(event.reason.toUserMessage(context))
WatchResult.Complete(Result.failure(error))
} else {
WatchResult.Continue()
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/to/bitkit/viewmodels/QuickPayViewModel.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
package to.bitkit.viewmodels

import android.content.Context
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import org.lightningdevkit.ldknode.Event
import org.lightningdevkit.ldknode.PaymentId
import to.bitkit.ext.WatchResult
import to.bitkit.ext.toUserMessage
import to.bitkit.ext.watchUntil
import to.bitkit.repositories.LightningRepo
import to.bitkit.utils.Logger
import javax.inject.Inject

@HiltViewModel
class QuickPayViewModel @Inject constructor(
@ApplicationContext private val context: Context,
private val lightningRepo: LightningRepo,
) : ViewModel() {

Expand Down Expand Up @@ -90,7 +94,7 @@ class QuickPayViewModel @Inject constructor(

is Event.PaymentFailed -> {
if (event.paymentHash == hash) {
val error = Exception(event.reason?.name ?: "Unknown payment failure reason")
val error = Exception(event.reason.toUserMessage(context))
WatchResult.Complete(Result.failure(error))
} else {
WatchResult.Continue()
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,10 @@
<string name="wallet__tags_new_enter">Enter a new tag</string>
<string name="wallet__tags_previously">Previously used tags</string>
<string name="wallet__toast_payment_failed_description">Your instant payment failed. Please try again.</string>
<string name="wallet__toast_payment_failed_recipient_rejected">The recipient rejected this payment. Try a different amount.</string>
<string name="wallet__toast_payment_failed_retries_exhausted">Could not find a route with sufficient liquidity. Try a smaller amount or wait and try again.</string>
<string name="wallet__toast_payment_failed_route_not_found">Could not find a payment path to the recipient.</string>
<string name="wallet__toast_payment_failed_timeout">Payment timed out. Please try again.</string>
<string name="wallet__toast_payment_failed_title">Payment Failed</string>
<string name="wallet__toast_received_transaction_replaced_description">Your received transaction was replaced by a fee bump</string>
<string name="wallet__toast_received_transaction_replaced_title">Received Transaction Replaced</string>
Expand Down
Loading