Removes the need for the payment popup for only one invoice.
This commit is contained in:
@@ -413,10 +413,21 @@ fun ZapVote(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (wantsToPay.isNotEmpty()) {
|
if (wantsToPay.isNotEmpty()) {
|
||||||
PayViaIntentDialog(payingInvoices = wantsToPay, accountViewModel = accountViewModel) {
|
PayViaIntentDialog(
|
||||||
|
payingInvoices = wantsToPay,
|
||||||
|
accountViewModel = accountViewModel,
|
||||||
|
onClose = {
|
||||||
wantsToPay = persistentListOf()
|
wantsToPay = persistentListOf()
|
||||||
|
},
|
||||||
|
onError = {
|
||||||
|
wantsToPay = persistentListOf()
|
||||||
|
scope.launch {
|
||||||
|
zappingProgress = 0f
|
||||||
|
showErrorMessageDialog = it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (showErrorMessageDialog != null) {
|
if (showErrorMessageDialog != null) {
|
||||||
ErrorMessageDialog(
|
ErrorMessageDialog(
|
||||||
|
|||||||
@@ -1056,10 +1056,21 @@ fun ZapReaction(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (wantsToPay.isNotEmpty()) {
|
if (wantsToPay.isNotEmpty()) {
|
||||||
PayViaIntentDialog(payingInvoices = wantsToPay, accountViewModel = accountViewModel) {
|
PayViaIntentDialog(
|
||||||
|
payingInvoices = wantsToPay,
|
||||||
|
accountViewModel = accountViewModel,
|
||||||
|
onClose = {
|
||||||
wantsToPay = persistentListOf()
|
wantsToPay = persistentListOf()
|
||||||
|
},
|
||||||
|
onError = {
|
||||||
|
wantsToPay = persistentListOf()
|
||||||
|
scope.launch {
|
||||||
|
zappingProgress = 0f
|
||||||
|
showErrorMessageDialog = it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (wantsToSetCustomZap) {
|
if (wantsToSetCustomZap) {
|
||||||
ZapCustomDialog(
|
ZapCustomDialog(
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.vitorpamplona.amethyst.ui.note
|
package com.vitorpamplona.amethyst.ui.note
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
@@ -144,6 +145,7 @@ fun ZapCustomDialog(
|
|||||||
onPayViaIntent = onPayViaIntent,
|
onPayViaIntent = onPayViaIntent,
|
||||||
zapType = selectedZapType
|
zapType = selectedZapType
|
||||||
)
|
)
|
||||||
|
onClose()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,10 +300,14 @@ fun ErrorMessageDialog(
|
|||||||
fun PayViaIntentDialog(
|
fun PayViaIntentDialog(
|
||||||
payingInvoices: ImmutableList<ZapPaymentHandler.Payable>,
|
payingInvoices: ImmutableList<ZapPaymentHandler.Payable>,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
onClose: () -> Unit
|
onClose: () -> Unit,
|
||||||
|
onError: (String) -> Unit
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
|
||||||
|
if (payingInvoices.size == 1) {
|
||||||
|
payViaIntent(payingInvoices.first().invoice, context, onError)
|
||||||
|
} else {
|
||||||
Dialog(
|
Dialog(
|
||||||
onDismissRequest = onClose,
|
onDismissRequest = onClose,
|
||||||
properties = DialogProperties(
|
properties = DialogProperties(
|
||||||
@@ -370,16 +376,27 @@ fun PayViaIntentDialog(
|
|||||||
PayButton(isActive = !paid.value) {
|
PayButton(isActive = !paid.value) {
|
||||||
paid.value = true
|
paid.value = true
|
||||||
|
|
||||||
val uri = "lightning:" + it.invoice
|
payViaIntent(it.invoice, context, onError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(uri))
|
fun payViaIntent(invoice: String, context: Context, onError: (String) -> Unit) {
|
||||||
|
try {
|
||||||
|
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("lightning:$invoice"))
|
||||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||||
|
|
||||||
ContextCompat.startActivity(context, intent, null)
|
ContextCompat.startActivity(context, intent, null)
|
||||||
}
|
} catch (e: Exception) {
|
||||||
}
|
if (e.message != null) {
|
||||||
}
|
onError(context.getString(R.string.no_wallet_found_with_error, e.message!!))
|
||||||
}
|
} else {
|
||||||
|
onError(context.getString(R.string.no_wallet_found))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -590,4 +590,7 @@
|
|||||||
<string name="wallet_number">Wallet %1$s</string>
|
<string name="wallet_number">Wallet %1$s</string>
|
||||||
<string name="error_opening_external_signer">Error opening signer app</string>
|
<string name="error_opening_external_signer">Error opening signer app</string>
|
||||||
<string name="sign_request_rejected">Sign request rejected</string>
|
<string name="sign_request_rejected">Sign request rejected</string>
|
||||||
|
|
||||||
|
<string name="no_wallet_found_with_error">No Wallets found to pay a lightning invoice (Error: %1$s). Please install a Lightning wallet to use zaps</string>
|
||||||
|
<string name="no_wallet_found">No Wallets found to pay a lightning invoice. Please install a Lightning wallet to use zaps</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user