Adding Zaps to the profile

This commit is contained in:
Vitor Pamplona 2023-02-14 11:37:41 -05:00
parent c3aa37534e
commit 76737e6b74
3 changed files with 12 additions and 6 deletions

View File

@ -137,9 +137,12 @@ class Account(
}
fun createZapRequestFor(user: User): LnZapRequestEvent? {
return createZapRequestFor(user.pubkeyHex)
}
fun createZapRequestFor(userPubKeyHex: String): LnZapRequestEvent? {
if (!isWriteable()) return null
return LnZapRequestEvent.create(user.pubkeyHex, userProfile().relays?.keys ?: localRelays.map { it.url }.toSet(), loggedIn.privKey!!)
return LnZapRequestEvent.create(userPubKeyHex, userProfile().relays?.keys ?: localRelays.map { it.url }.toSet(), loggedIn.privKey!!)
}
fun report(note: Note, type: ReportEvent.ReportType) {

View File

@ -38,10 +38,11 @@ import androidx.compose.ui.unit.sp
import androidx.core.content.ContextCompat.startActivity
import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.lnurl.LightningAddressResolver
import com.vitorpamplona.amethyst.model.Account
import kotlinx.coroutines.launch
@Composable
fun InvoiceRequest(lud16: String, onClose: () -> Unit ) {
fun InvoiceRequest(lud16: String, toUserPubKeyHex: String, account: Account, onClose: () -> Unit ) {
val context = LocalContext.current
val scope = rememberCoroutineScope()
@ -128,7 +129,9 @@ fun InvoiceRequest(lud16: String, onClose: () -> Unit ) {
Button(
modifier = Modifier.fillMaxWidth().padding(vertical = 10.dp),
onClick = {
LightningAddressResolver().lnAddressInvoice(lud16, amount * 1000, message,
val zapRequest = account.createZapRequestFor(toUserPubKeyHex)
LightningAddressResolver().lnAddressInvoice(lud16, amount * 1000, message, zapRequest?.toJson(),
onSuccess = {
runCatching {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("lightning:$it"))

View File

@ -332,7 +332,7 @@ private fun ProfileHeader(
}
}
DrawAdditionalInfo(baseUser)
DrawAdditionalInfo(baseUser, account)
Divider(modifier = Modifier.padding(top = 6.dp))
}
@ -340,7 +340,7 @@ private fun ProfileHeader(
}
@Composable
private fun DrawAdditionalInfo(baseUser: User) {
private fun DrawAdditionalInfo(baseUser: User, account: Account) {
val userState by baseUser.liveMetadata.observeAsState()
val user = userState?.user ?: return
@ -400,7 +400,7 @@ private fun DrawAdditionalInfo(baseUser: User) {
if (ZapExpanded) {
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.padding(vertical = 5.dp)) {
InvoiceRequest(lud16) {
InvoiceRequest(lud16, baseUser.pubkeyHex, account) {
ZapExpanded = false
}
}