mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-07-21 13:03:37 +02:00
1. Triggers a Toast when no wallet is found to pay the invoice
2. Starts the wallet in a separate task to allow people to come back to Amethyst switching apps instead of the back button.
This commit is contained in:
@ -2,6 +2,7 @@ package com.vitorpamplona.amethyst.ui.components
|
|||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.compose.animation.Crossfade
|
import androidx.compose.animation.Crossfade
|
||||||
import androidx.compose.foundation.text.ClickableText
|
import androidx.compose.foundation.text.ClickableText
|
||||||
import androidx.compose.material.LocalTextStyle
|
import androidx.compose.material.LocalTextStyle
|
||||||
@ -12,6 +13,7 @@ import androidx.compose.ui.platform.LocalContext
|
|||||||
import androidx.compose.ui.text.AnnotatedString
|
import androidx.compose.ui.text.AnnotatedString
|
||||||
import androidx.compose.ui.text.style.TextDirection
|
import androidx.compose.ui.text.style.TextDirection
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.quartz.encoders.LnWithdrawalUtil
|
import com.vitorpamplona.quartz.encoders.LnWithdrawalUtil
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@ -41,10 +43,7 @@ fun MayBeWithdrawal(lnurlWord: String) {
|
|||||||
@Composable
|
@Composable
|
||||||
fun ClickableWithdrawal(withdrawalString: String) {
|
fun ClickableWithdrawal(withdrawalString: String) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
val scope = rememberCoroutineScope()
|
||||||
val uri = remember(withdrawalString) {
|
|
||||||
Uri.parse("lightning:$withdrawalString")
|
|
||||||
}
|
|
||||||
|
|
||||||
val withdraw = remember(withdrawalString) {
|
val withdraw = remember(withdrawalString) {
|
||||||
AnnotatedString("$withdrawalString ")
|
AnnotatedString("$withdrawalString ")
|
||||||
@ -53,9 +52,18 @@ fun ClickableWithdrawal(withdrawalString: String) {
|
|||||||
ClickableText(
|
ClickableText(
|
||||||
text = withdraw,
|
text = withdraw,
|
||||||
onClick = {
|
onClick = {
|
||||||
runCatching {
|
try {
|
||||||
val intent = Intent(Intent.ACTION_VIEW, uri)
|
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("lightning:$withdrawalString"))
|
||||||
|
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) {
|
||||||
|
scope.launch {
|
||||||
|
Toast.makeText(
|
||||||
|
context,
|
||||||
|
context.getString(R.string.lightning_wallets_not_found),
|
||||||
|
Toast.LENGTH_LONG
|
||||||
|
).show()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
style = LocalTextStyle.current.copy(color = MaterialTheme.colors.primary)
|
style = LocalTextStyle.current.copy(color = MaterialTheme.colors.primary)
|
||||||
|
@ -2,6 +2,7 @@ package com.vitorpamplona.amethyst.ui.components
|
|||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.compose.animation.Crossfade
|
import androidx.compose.animation.Crossfade
|
||||||
import androidx.compose.foundation.border
|
import androidx.compose.foundation.border
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
@ -66,6 +67,7 @@ fun MayBeInvoicePreview(lnbcWord: String) {
|
|||||||
@Composable
|
@Composable
|
||||||
fun InvoicePreview(lnInvoice: String, amount: String?) {
|
fun InvoicePreview(lnInvoice: String, amount: String?) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
val scope = rememberCoroutineScope()
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@ -118,9 +120,18 @@ fun InvoicePreview(lnInvoice: String, amount: String?) {
|
|||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(vertical = 10.dp),
|
.padding(vertical = 10.dp),
|
||||||
onClick = {
|
onClick = {
|
||||||
runCatching {
|
try {
|
||||||
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("lightning:$lnInvoice"))
|
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("lightning:$lnInvoice"))
|
||||||
|
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||||
startActivity(context, intent, null)
|
startActivity(context, intent, null)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
scope.launch {
|
||||||
|
Toast.makeText(
|
||||||
|
context,
|
||||||
|
context.getString(R.string.lightning_wallets_not_found),
|
||||||
|
Toast.LENGTH_LONG
|
||||||
|
).show()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
shape = QuoteBorder,
|
shape = QuoteBorder,
|
||||||
|
@ -186,9 +186,12 @@ class AccountViewModel(val account: Account) : ViewModel() {
|
|||||||
onProgress(0f)
|
onProgress(0f)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
runCatching {
|
try {
|
||||||
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("lightning:$it"))
|
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("lightning:$it"))
|
||||||
|
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) {
|
||||||
|
onError(context.getString(R.string.lightning_wallets_not_found))
|
||||||
}
|
}
|
||||||
onProgress(0f)
|
onProgress(0f)
|
||||||
}
|
}
|
||||||
|
@ -1050,9 +1050,18 @@ fun DisplayLNAddress(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
runCatching {
|
try {
|
||||||
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("lightning:$it"))
|
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("lightning:$it"))
|
||||||
|
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) {
|
||||||
|
scope.launch {
|
||||||
|
Toast.makeText(
|
||||||
|
context,
|
||||||
|
context.getString(R.string.lightning_wallets_not_found),
|
||||||
|
Toast.LENGTH_LONG
|
||||||
|
).show()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -552,5 +552,6 @@
|
|||||||
|
|
||||||
<string name="status_update">Update your status</string>
|
<string name="status_update">Update your status</string>
|
||||||
|
|
||||||
|
<string name="lightning_wallets_not_found">Error parsing error message</string>
|
||||||
<string name="poll_zap_value_min_max_explainer">Votes are weighted by the zap amount. You can set a minimum amount to avoid spammers and a maximum amount to avoid a large zappers taking over the poll. Use the same amount in both fields to make sure every vote is valued the same amount. Leave it empty to accept any amount.</string>
|
<string name="poll_zap_value_min_max_explainer">Votes are weighted by the zap amount. You can set a minimum amount to avoid spammers and a maximum amount to avoid a large zappers taking over the poll. Use the same amount in both fields to make sure every vote is valued the same amount. Leave it empty to accept any amount.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Reference in New Issue
Block a user