Pays zaps through LNURLs / lud06 fields

This commit is contained in:
Vitor Pamplona
2023-02-20 12:09:00 -05:00
parent 2eae1ad434
commit 892214ec27
3 changed files with 14 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
package com.vitorpamplona.amethyst.lnurl package com.vitorpamplona.amethyst.lnurl
import androidx.compose.ui.text.toLowerCase
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import java.net.URLEncoder import java.net.URLEncoder
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
@@ -20,11 +21,19 @@ class LightningAddressResolver {
fun assembleUrl(lnaddress: String): String? { fun assembleUrl(lnaddress: String): String? {
val parts = lnaddress.split("@") val parts = lnaddress.split("@")
if (parts.size != 2) { if (parts.size == 2) {
return null return "https://${parts[1]}/.well-known/lnurlp/${parts[0]}"
} }
return "https://${parts[1]}/.well-known/lnurlp/${parts[0]}" if (lnaddress.toLowerCase().startsWith("lnurl")) {
return try {
String(Bech32.decodeBytes(lnaddress, false).second)
} catch (e: Exception) {
null
}
}
return null
} }
fun fetchLightningAddressJson(lnaddress: String, onSuccess: (String) -> Unit, onError: (String) -> Unit) { fun fetchLightningAddressJson(lnaddress: String, onSuccess: (String) -> Unit, onError: (String) -> Unit) {

View File

@@ -25,7 +25,7 @@ class AccountViewModel(private val account: Account): ViewModel() {
} }
fun zap(note: Note, amount: Long, message: String, context: Context, onError: (String) -> Unit) { fun zap(note: Note, amount: Long, message: String, context: Context, onError: (String) -> Unit) {
val lud16 = note.author?.info?.lud16?.trim() val lud16 = note.author?.info?.lud16?.trim() ?: note.author?.info?.lud06?.trim()
if (lud16.isNullOrBlank()) { if (lud16.isNullOrBlank()) {
onError("User does not have a lightning address setup to receive sats") onError("User does not have a lightning address setup to receive sats")

View File

@@ -385,7 +385,7 @@ private fun DrawAdditionalInfo(baseUser: User, account: Account) {
var ZapExpanded by remember { mutableStateOf(false) } var ZapExpanded by remember { mutableStateOf(false) }
val lud16 = user.info?.lud16?.trim() val lud16 = user.info?.lud16?.trim() ?: user.info?.lud06?.trim()
if (!lud16.isNullOrEmpty()) { if (!lud16.isNullOrEmpty()) {
Row(verticalAlignment = Alignment.CenterVertically) { Row(verticalAlignment = Alignment.CenterVertically) {