Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import to.bitkit.viewmodels.QuickPayViewModel
@Composable
fun SendQuickPayScreen(
quickPayData: QuickPayData,
onPaymentComplete: () -> Unit,
onPaymentComplete: (String, Long) -> Unit,
onShowError: (String) -> Unit,
viewModel: QuickPayViewModel = hiltViewModel(),
) {
Expand All @@ -60,7 +60,7 @@ fun SendQuickPayScreen(

LaunchedEffect(uiState.result) {
when (val result = uiState.result) {
is QuickPayResult.Success -> onPaymentComplete()
is QuickPayResult.Success -> onPaymentComplete(result.paymentHash, result.amountWithFee)
is QuickPayResult.Error -> onShowError(result.message)
null -> Unit // continue showing loading state
}
Expand Down
23 changes: 20 additions & 3 deletions app/src/main/java/to/bitkit/ui/sheets/SendSheet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import androidx.navigation.compose.NavHost
import androidx.navigation.compose.rememberNavController
import androidx.navigation.toRoute
import kotlinx.serialization.Serializable
import to.bitkit.models.NewTransactionSheetDetails
import to.bitkit.models.NewTransactionSheetDirection
import to.bitkit.models.NewTransactionSheetType
import to.bitkit.ui.screens.scanner.QrScanningScreen
import to.bitkit.ui.screens.wallets.send.AddTagScreen
import to.bitkit.ui.screens.wallets.send.PIN_CHECK_RESULT_KEY
Expand Down Expand Up @@ -72,8 +75,11 @@ fun SendSheet(
is SendEffect.PopBack -> navController.popBackStack(it.route, inclusive = false)
is SendEffect.PaymentSuccess -> {
appViewModel.clearClipboardForAutoRead()
navController.navigate(SendRoute.Success)
navController.navigate(SendRoute.Success) {
popUpTo(startDestination) { inclusive = true }
}
}

is SendEffect.NavigateToQuickPay -> navController.navigate(SendRoute.QuickPay)
is SendEffect.NavigateToWithdrawConfirm -> navController.navigate(SendRoute.WithdrawConfirm)
is SendEffect.NavigateToWithdrawError -> navController.navigate(SendRoute.WithdrawError)
Expand Down Expand Up @@ -218,8 +224,19 @@ fun SendSheet(
val quickPayData by appViewModel.quickPayData.collectAsStateWithLifecycle()
SendQuickPayScreen(
quickPayData = requireNotNull(quickPayData),
onPaymentComplete = {
navController.navigate(SendRoute.Success)
onPaymentComplete = { paymentHash, amountWithFee ->
appViewModel.handlePaymentSuccess(
NewTransactionSheetDetails(
type = NewTransactionSheetType.LIGHTNING,
direction = NewTransactionSheetDirection.SENT,
paymentHashOrTxId = paymentHash,
sats = amountWithFee,
),
)

navController.navigate(SendRoute.Success) {
popUpTo(startDestination) { inclusive = true }
}
},
onShowError = { errorMessage ->
navController.navigate(SendRoute.Error(errorMessage))
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1463,7 +1463,7 @@ class AppViewModel @Inject constructor(
}
}

private fun handlePaymentSuccess(details: NewTransactionSheetDetails) {
fun handlePaymentSuccess(details: NewTransactionSheetDetails) {
details.paymentHashOrTxId?.let {
if (!processedPayments.add(it)) {
Logger.debug("Payment $it already processed, skipping duplicate", context = TAG)
Expand Down
17 changes: 14 additions & 3 deletions app/src/main/java/to/bitkit/viewmodels/QuickPayViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,16 @@ class QuickPayViewModel @Inject constructor(
}

sendLightning(bolt11, amount)
.onSuccess {
.onSuccess { paymentHash ->
Logger.info("QuickPay lightning payment successful")
_uiState.update { it.copy(result = QuickPayResult.Success) }
_uiState.update {
it.copy(
result = QuickPayResult.Success(
paymentHash = paymentHash,
amountWithFee = amount.toLong() // TODO GET FEE WHEN AVAILABLE
)
)
}
}.onFailure { error ->
Logger.error("QuickPay lightning payment failed", error)

Expand Down Expand Up @@ -96,7 +103,11 @@ class QuickPayViewModel @Inject constructor(
}

sealed class QuickPayResult {
data object Success : QuickPayResult()
data class Success(
val paymentHash: String,
val amountWithFee: Long,
) : QuickPayResult()

data class Error(val message: String) : QuickPayResult()
}

Expand Down