Skip to content

Commit f0f8274

Browse files
authored
Merge pull request #527 from synonymdev/test/lnurl
Test/lnurl adjustments
2 parents fa63c71 + d3de7d1 commit f0f8274

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

app/src/main/java/to/bitkit/ui/sheets/LnurlAuthSheet.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private fun Content(
9191
fullWidth = false,
9292
modifier = Modifier
9393
.weight(1f)
94-
.testTag("cancel_button")
94+
.testTag("LnurlAuthCancel")
9595
)
9696
// TODO add missing localized text
9797
PrimaryButton(
@@ -100,7 +100,7 @@ private fun Content(
100100
fullWidth = false,
101101
modifier = Modifier
102102
.weight(1f)
103-
.testTag("continue_button")
103+
.testTag("LnurlAuthContinue")
104104
)
105105
}
106106
VerticalSpacer(16.dp)

app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,19 @@ class AppViewModel @Inject constructor(
598598
}
599599

600600
val lnurl = _sendUiState.value.lnurl
601+
if (lnurl is LnurlParams.LnurlPay) {
602+
val minSendable = lnurl.data.minSendableSat()
603+
if (_sendUiState.value.amount < minSendable) {
604+
toast(
605+
type = Toast.ToastType.ERROR,
606+
title = context.getString(R.string.wallet__lnurl_pay__error_min__title),
607+
description = context.getString(R.string.wallet__lnurl_pay__error_min__description)
608+
.replace("{amount}", minSendable.toString()),
609+
testTag = "LnurlPayAmountTooLowToast",
610+
)
611+
return
612+
}
613+
}
601614
if (lnurl is LnurlParams.LnurlWithdraw) {
602615
setSendEffect(SendEffect.NavigateToWithdrawConfirm)
603616
return
@@ -630,10 +643,9 @@ class AppViewModel @Inject constructor(
630643
null -> lightningRepo.canSend(amount)
631644
is LnurlParams.LnurlWithdraw -> amount < lnurl.data.maxWithdrawableSat()
632645
is LnurlParams.LnurlPay -> {
633-
val minSat = lnurl.data.minSendableSat()
634646
val maxSat = lnurl.data.maxSendableSat()
635647

636-
amount in minSat..maxSat && lightningRepo.canSend(amount)
648+
amount <= maxSat && lightningRepo.canSend(amount)
637649
}
638650
}
639651

@@ -823,15 +835,17 @@ class AppViewModel @Inject constructor(
823835
return
824836
}
825837

838+
val hasAmount = minSendable == maxSendable && minSendable > 0u
839+
val initialAmount = if (hasAmount) minSendable else 0u
840+
826841
_sendUiState.update {
827842
it.copy(
828-
amount = minSendable,
843+
amount = initialAmount,
829844
payMethod = SendMethod.LIGHTNING,
830845
lnurl = LnurlParams.LnurlPay(data),
831846
)
832847
}
833848

834-
val hasAmount = minSendable == maxSendable && minSendable > 0u
835849
if (hasAmount) {
836850
Logger.info("Found amount $$minSendable in lnurlPay, proceeding with payment", context = TAG)
837851

0 commit comments

Comments
 (0)