zaps in background
This commit is contained in:
@@ -454,7 +454,7 @@ class Account(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
LnZapEvent.ZapType.PUBLIC -> {
|
LnZapEvent.ZapType.PUBLIC -> {
|
||||||
return LnZapRequestEvent.createPublic(
|
val unsignedEvent = LnZapRequestEvent.createPublic(
|
||||||
event,
|
event,
|
||||||
userProfile().latestContactList?.relays()?.keys?.ifEmpty { null }
|
userProfile().latestContactList?.relays()?.keys?.ifEmpty { null }
|
||||||
?: localRelays.map { it.url }.toSet(),
|
?: localRelays.map { it.url }.toSet(),
|
||||||
@@ -462,10 +462,18 @@ class Account(
|
|||||||
pollOption,
|
pollOption,
|
||||||
message
|
message
|
||||||
)
|
)
|
||||||
|
AmberUtils.openAmber(unsignedEvent)
|
||||||
|
val content = AmberUtils.content[unsignedEvent.id] ?: ""
|
||||||
|
if (content.isBlank()) return null
|
||||||
|
|
||||||
|
return LnZapRequestEvent.create(
|
||||||
|
unsignedEvent,
|
||||||
|
content
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
LnZapEvent.ZapType.PRIVATE -> {
|
LnZapEvent.ZapType.PRIVATE -> {
|
||||||
return LnZapRequestEvent.createPrivateZap(
|
val unsignedEvent = LnZapRequestEvent.createPrivateZap(
|
||||||
event,
|
event,
|
||||||
userProfile().latestContactList?.relays()?.keys?.ifEmpty { null }
|
userProfile().latestContactList?.relays()?.keys?.ifEmpty { null }
|
||||||
?: localRelays.map { it.url }.toSet(),
|
?: localRelays.map { it.url }.toSet(),
|
||||||
@@ -473,6 +481,11 @@ class Account(
|
|||||||
pollOption,
|
pollOption,
|
||||||
message
|
message
|
||||||
)
|
)
|
||||||
|
AmberUtils.openAmber(unsignedEvent)
|
||||||
|
val content = AmberUtils.content[unsignedEvent.id] ?: ""
|
||||||
|
if (content.isBlank()) return null
|
||||||
|
|
||||||
|
return Event.fromJson(content) as LnZapRequestEvent
|
||||||
}
|
}
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -466,7 +466,6 @@ object LocalCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun consume(event: PrivateDmEvent, relay: Relay?): Note {
|
fun consume(event: PrivateDmEvent, relay: Relay?): Note {
|
||||||
Log.e("isRunning", event.toJson())
|
|
||||||
val note = getOrCreateNote(event.id)
|
val note = getOrCreateNote(event.id)
|
||||||
val author = getOrCreateUser(event.pubKey)
|
val author = getOrCreateUser(event.pubKey)
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
package com.vitorpamplona.amethyst.ui.note
|
package com.vitorpamplona.amethyst.ui.note
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
|
||||||
import androidx.compose.foundation.*
|
import androidx.compose.foundation.*
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.material.*
|
import androidx.compose.material.*
|
||||||
@@ -25,12 +22,8 @@ import androidx.compose.ui.unit.IntOffset
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.window.Popup
|
import androidx.compose.ui.window.Popup
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
import com.vitorpamplona.amethyst.Amethyst
|
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.ServiceManager
|
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.service.AmberUtils
|
|
||||||
import com.vitorpamplona.amethyst.ui.actions.SignerType
|
|
||||||
import com.vitorpamplona.amethyst.ui.components.TranslatableRichTextViewer
|
import com.vitorpamplona.amethyst.ui.components.TranslatableRichTextViewer
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
import com.vitorpamplona.amethyst.ui.theme.BitcoinOrange
|
import com.vitorpamplona.amethyst.ui.theme.BitcoinOrange
|
||||||
@@ -39,10 +32,8 @@ import com.vitorpamplona.amethyst.ui.theme.Font14SP
|
|||||||
import com.vitorpamplona.amethyst.ui.theme.QuoteBorder
|
import com.vitorpamplona.amethyst.ui.theme.QuoteBorder
|
||||||
import com.vitorpamplona.amethyst.ui.theme.mediumImportanceLink
|
import com.vitorpamplona.amethyst.ui.theme.mediumImportanceLink
|
||||||
import com.vitorpamplona.amethyst.ui.theme.placeholderText
|
import com.vitorpamplona.amethyst.ui.theme.placeholderText
|
||||||
import com.vitorpamplona.quartz.events.Event
|
|
||||||
import com.vitorpamplona.quartz.events.ImmutableListOfLists
|
import com.vitorpamplona.quartz.events.ImmutableListOfLists
|
||||||
import com.vitorpamplona.quartz.events.LnZapEvent
|
import com.vitorpamplona.quartz.events.LnZapEvent
|
||||||
import com.vitorpamplona.quartz.events.LnZapRequestEvent
|
|
||||||
import com.vitorpamplona.quartz.events.toImmutableListOfLists
|
import com.vitorpamplona.quartz.events.toImmutableListOfLists
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -300,60 +291,6 @@ fun ZapVote(
|
|||||||
|
|
||||||
nonClickablePrepend()
|
nonClickablePrepend()
|
||||||
|
|
||||||
val event = remember { mutableStateOf<LnZapRequestEvent?>(null) }
|
|
||||||
val activityResult = rememberLauncherForActivityResult(
|
|
||||||
contract = ActivityResultContracts.StartActivityForResult(),
|
|
||||||
onResult = {
|
|
||||||
if (it.resultCode != Activity.RESULT_OK) {
|
|
||||||
scope.launch(Dispatchers.Main) {
|
|
||||||
Toast.makeText(
|
|
||||||
Amethyst.instance,
|
|
||||||
"Sign request rejected",
|
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
).show()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
val json = it.data?.getStringExtra("event") ?: ""
|
|
||||||
val signedEvent = Event.fromJson(json) as LnZapRequestEvent
|
|
||||||
if (signedEvent.hasValidSignature()) {
|
|
||||||
accountViewModel.zap(
|
|
||||||
baseNote,
|
|
||||||
accountViewModel.account.zapAmountChoices.first() * 1000,
|
|
||||||
null,
|
|
||||||
"",
|
|
||||||
context,
|
|
||||||
{
|
|
||||||
scope.launch {
|
|
||||||
zappingProgress = 0f
|
|
||||||
showErrorMessageDialog = it
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ progress: Float ->
|
|
||||||
zappingProgress = progress
|
|
||||||
},
|
|
||||||
accountViewModel.account.defaultZapType,
|
|
||||||
null
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AmberUtils.isActivityRunning = false
|
|
||||||
ServiceManager.shouldPauseService = true
|
|
||||||
event.value = null
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
LaunchedEffect(event.value) {
|
|
||||||
if (event.value != null) {
|
|
||||||
AmberUtils.openAmber(
|
|
||||||
event.value!!.toJson(),
|
|
||||||
SignerType.SIGN_EVENT,
|
|
||||||
activityResult,
|
|
||||||
"",
|
|
||||||
event.value!!.id()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
modifier = Modifier.combinedClickable(
|
modifier = Modifier.combinedClickable(
|
||||||
@@ -361,7 +298,7 @@ fun ZapVote(
|
|||||||
// interactionSource = remember { MutableInteractionSource() },
|
// interactionSource = remember { MutableInteractionSource() },
|
||||||
// indication = rememberRipple(bounded = false, radius = 24.dp),
|
// indication = rememberRipple(bounded = false, radius = 24.dp),
|
||||||
onClick = {
|
onClick = {
|
||||||
if (!accountViewModel.isWriteable()) {
|
if (!accountViewModel.isWriteable() && !accountViewModel.loggedInWithAmber()) {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
Toast
|
Toast
|
||||||
.makeText(
|
.makeText(
|
||||||
@@ -425,8 +362,7 @@ fun ZapVote(
|
|||||||
zappingProgress = it
|
zappingProgress = it
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
zapType = accountViewModel.account.defaultZapType,
|
zapType = accountViewModel.account.defaultZapType
|
||||||
null
|
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
wantsToZap = true
|
wantsToZap = true
|
||||||
@@ -566,8 +502,7 @@ fun FilteredZapAmountChoicePopup(
|
|||||||
context,
|
context,
|
||||||
onError,
|
onError,
|
||||||
onProgress,
|
onProgress,
|
||||||
defaultZapType,
|
defaultZapType
|
||||||
null
|
|
||||||
)
|
)
|
||||||
onDismiss()
|
onDismiss()
|
||||||
},
|
},
|
||||||
@@ -591,8 +526,7 @@ fun FilteredZapAmountChoicePopup(
|
|||||||
context,
|
context,
|
||||||
onError,
|
onError,
|
||||||
onProgress,
|
onProgress,
|
||||||
defaultZapType,
|
defaultZapType
|
||||||
null
|
|
||||||
)
|
)
|
||||||
onDismiss()
|
onDismiss()
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
package com.vitorpamplona.amethyst.ui.note
|
package com.vitorpamplona.amethyst.ui.note
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
|
||||||
import androidx.compose.animation.AnimatedContent
|
import androidx.compose.animation.AnimatedContent
|
||||||
import androidx.compose.animation.AnimatedContentTransitionScope
|
import androidx.compose.animation.AnimatedContentTransitionScope
|
||||||
import androidx.compose.animation.ContentTransform
|
import androidx.compose.animation.ContentTransform
|
||||||
@@ -49,7 +46,6 @@ import androidx.compose.runtime.MutableState
|
|||||||
import androidx.compose.runtime.derivedStateOf
|
import androidx.compose.runtime.derivedStateOf
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.livedata.observeAsState
|
import androidx.compose.runtime.livedata.observeAsState
|
||||||
import androidx.compose.runtime.mutableLongStateOf
|
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
@@ -80,13 +76,9 @@ import androidx.lifecycle.map
|
|||||||
import coil.compose.AsyncImage
|
import coil.compose.AsyncImage
|
||||||
import coil.request.CachePolicy
|
import coil.request.CachePolicy
|
||||||
import coil.request.ImageRequest
|
import coil.request.ImageRequest
|
||||||
import com.vitorpamplona.amethyst.Amethyst
|
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.ServiceManager
|
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.service.AmberUtils
|
|
||||||
import com.vitorpamplona.amethyst.ui.actions.NewPostView
|
import com.vitorpamplona.amethyst.ui.actions.NewPostView
|
||||||
import com.vitorpamplona.amethyst.ui.actions.SignerType
|
|
||||||
import com.vitorpamplona.amethyst.ui.components.ImageUrlType
|
import com.vitorpamplona.amethyst.ui.components.ImageUrlType
|
||||||
import com.vitorpamplona.amethyst.ui.components.InLineIconRenderer
|
import com.vitorpamplona.amethyst.ui.components.InLineIconRenderer
|
||||||
import com.vitorpamplona.amethyst.ui.components.TextType
|
import com.vitorpamplona.amethyst.ui.components.TextType
|
||||||
@@ -115,9 +107,6 @@ import com.vitorpamplona.amethyst.ui.theme.TinyBorders
|
|||||||
import com.vitorpamplona.amethyst.ui.theme.mediumImportanceLink
|
import com.vitorpamplona.amethyst.ui.theme.mediumImportanceLink
|
||||||
import com.vitorpamplona.amethyst.ui.theme.placeholderText
|
import com.vitorpamplona.amethyst.ui.theme.placeholderText
|
||||||
import com.vitorpamplona.amethyst.ui.theme.placeholderTextColorFilter
|
import com.vitorpamplona.amethyst.ui.theme.placeholderTextColorFilter
|
||||||
import com.vitorpamplona.quartz.events.Event
|
|
||||||
import com.vitorpamplona.quartz.events.LnZapEvent
|
|
||||||
import com.vitorpamplona.quartz.events.LnZapRequestEvent
|
|
||||||
import kotlinx.collections.immutable.toImmutableList
|
import kotlinx.collections.immutable.toImmutableList
|
||||||
import kotlinx.collections.immutable.toImmutableMap
|
import kotlinx.collections.immutable.toImmutableMap
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
@@ -962,63 +951,6 @@ fun ZapReaction(
|
|||||||
|
|
||||||
var zappingProgress by remember { mutableStateOf(0f) }
|
var zappingProgress by remember { mutableStateOf(0f) }
|
||||||
|
|
||||||
val event = remember { mutableStateOf<LnZapRequestEvent?>(null) }
|
|
||||||
val activityResult = rememberLauncherForActivityResult(
|
|
||||||
contract = ActivityResultContracts.StartActivityForResult(),
|
|
||||||
onResult = {
|
|
||||||
if (it.resultCode != Activity.RESULT_OK) {
|
|
||||||
wantsToZap = false
|
|
||||||
zappingProgress = 0f
|
|
||||||
scope.launch(Dispatchers.Main) {
|
|
||||||
Toast.makeText(
|
|
||||||
Amethyst.instance,
|
|
||||||
"Sign request rejected",
|
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
).show()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
val json = it.data?.getStringExtra("event") ?: ""
|
|
||||||
val signedEvent = Event.fromJson(json) as LnZapRequestEvent
|
|
||||||
if (signedEvent.hasValidSignature()) {
|
|
||||||
accountViewModel.zap(
|
|
||||||
baseNote,
|
|
||||||
accountViewModel.account.zapAmountChoices.first() * 1000,
|
|
||||||
null,
|
|
||||||
"",
|
|
||||||
context,
|
|
||||||
{
|
|
||||||
scope.launch {
|
|
||||||
zappingProgress = 0f
|
|
||||||
showErrorMessageDialog = it
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ progress: Float ->
|
|
||||||
zappingProgress = progress
|
|
||||||
},
|
|
||||||
accountViewModel.account.defaultZapType,
|
|
||||||
signedEvent
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AmberUtils.isActivityRunning = false
|
|
||||||
ServiceManager.shouldPauseService = true
|
|
||||||
event.value = null
|
|
||||||
wantsToZap = false
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
LaunchedEffect(event.value) {
|
|
||||||
if (event.value != null) {
|
|
||||||
AmberUtils.openAmber(
|
|
||||||
event.value!!.toJson(),
|
|
||||||
SignerType.SIGN_EVENT,
|
|
||||||
activityResult,
|
|
||||||
"",
|
|
||||||
event.value!!.id()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
verticalAlignment = CenterVertically,
|
verticalAlignment = CenterVertically,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@@ -1044,8 +976,7 @@ fun ZapReaction(
|
|||||||
zappingProgress = 0f
|
zappingProgress = 0f
|
||||||
showErrorMessageDialog = it
|
showErrorMessageDialog = it
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
event
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
onLongClick = {
|
onLongClick = {
|
||||||
@@ -1152,8 +1083,7 @@ private fun zapClick(
|
|||||||
context: Context,
|
context: Context,
|
||||||
onZappingProgress: (Float) -> Unit,
|
onZappingProgress: (Float) -> Unit,
|
||||||
onMultipleChoices: () -> Unit,
|
onMultipleChoices: () -> Unit,
|
||||||
onError: (String) -> Unit,
|
onError: (String) -> Unit
|
||||||
event: MutableState<LnZapRequestEvent?>
|
|
||||||
) {
|
) {
|
||||||
if (accountViewModel.account.zapAmountChoices.isEmpty()) {
|
if (accountViewModel.account.zapAmountChoices.isEmpty()) {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
@@ -1165,46 +1095,15 @@ private fun zapClick(
|
|||||||
)
|
)
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
} else if (!accountViewModel.isWriteable()) {
|
} else if (!accountViewModel.isWriteable() && !accountViewModel.loggedInWithAmber()) {
|
||||||
if (accountViewModel.loggedInWithAmber()) {
|
scope.launch {
|
||||||
if (accountViewModel.account.zapAmountChoices.size == 1) {
|
Toast
|
||||||
if (accountViewModel.account.defaultZapType != LnZapEvent.ZapType.ANONYMOUS && accountViewModel.account.defaultZapType != LnZapEvent.ZapType.NONZAP) {
|
.makeText(
|
||||||
event.value = accountViewModel.account.createZapRequestFor(
|
context,
|
||||||
baseNote,
|
context.getString(R.string.login_with_a_private_key_to_be_able_to_send_zaps),
|
||||||
null,
|
Toast.LENGTH_SHORT
|
||||||
"",
|
)
|
||||||
accountViewModel.account.defaultZapType
|
.show()
|
||||||
)
|
|
||||||
} else {
|
|
||||||
accountViewModel.zap(
|
|
||||||
baseNote,
|
|
||||||
accountViewModel.account.zapAmountChoices.first() * 1000,
|
|
||||||
null,
|
|
||||||
"",
|
|
||||||
context,
|
|
||||||
onError = onError,
|
|
||||||
onProgress = {
|
|
||||||
scope.launch(Dispatchers.Main) {
|
|
||||||
onZappingProgress(it)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
zapType = accountViewModel.account.defaultZapType,
|
|
||||||
null
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else if (accountViewModel.account.zapAmountChoices.size > 1) {
|
|
||||||
onMultipleChoices()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
scope.launch {
|
|
||||||
Toast
|
|
||||||
.makeText(
|
|
||||||
context,
|
|
||||||
context.getString(R.string.login_with_a_private_key_to_be_able_to_send_zaps),
|
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
)
|
|
||||||
.show()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (accountViewModel.account.zapAmountChoices.size == 1) {
|
} else if (accountViewModel.account.zapAmountChoices.size == 1) {
|
||||||
accountViewModel.zap(
|
accountViewModel.zap(
|
||||||
@@ -1219,8 +1118,7 @@ private fun zapClick(
|
|||||||
onZappingProgress(it)
|
onZappingProgress(it)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
zapType = accountViewModel.account.defaultZapType,
|
zapType = accountViewModel.account.defaultZapType
|
||||||
null
|
|
||||||
)
|
)
|
||||||
} else if (accountViewModel.account.zapAmountChoices.size > 1) {
|
} else if (accountViewModel.account.zapAmountChoices.size > 1) {
|
||||||
onMultipleChoices()
|
onMultipleChoices()
|
||||||
@@ -1543,55 +1441,6 @@ fun ZapAmountChoicePopup(
|
|||||||
val accountState by accountViewModel.accountLiveData.observeAsState()
|
val accountState by accountViewModel.accountLiveData.observeAsState()
|
||||||
val account = accountState?.account ?: return
|
val account = accountState?.account ?: return
|
||||||
val zapMessage = ""
|
val zapMessage = ""
|
||||||
var event by remember { mutableStateOf<LnZapRequestEvent?>(null) }
|
|
||||||
var amount by remember { mutableLongStateOf(0L) }
|
|
||||||
val activityResult = rememberLauncherForActivityResult(
|
|
||||||
contract = ActivityResultContracts.StartActivityForResult(),
|
|
||||||
onResult = {
|
|
||||||
if (it.resultCode != Activity.RESULT_OK) {
|
|
||||||
scope.launch(Dispatchers.Main) {
|
|
||||||
Toast.makeText(
|
|
||||||
Amethyst.instance,
|
|
||||||
"Sign request rejected",
|
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
).show()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
val json = it.data?.getStringExtra("event") ?: ""
|
|
||||||
val signedEvent = Event.fromJson(json) as LnZapRequestEvent
|
|
||||||
if (signedEvent.hasValidSignature()) {
|
|
||||||
accountViewModel.zap(
|
|
||||||
baseNote,
|
|
||||||
amount,
|
|
||||||
null,
|
|
||||||
zapMessage,
|
|
||||||
context,
|
|
||||||
onError,
|
|
||||||
onProgress,
|
|
||||||
account.defaultZapType,
|
|
||||||
signedEvent
|
|
||||||
)
|
|
||||||
amount = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AmberUtils.isActivityRunning = false
|
|
||||||
ServiceManager.shouldPauseService = true
|
|
||||||
event = null
|
|
||||||
onDismiss()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
LaunchedEffect(event) {
|
|
||||||
if (event != null) {
|
|
||||||
AmberUtils.openAmber(
|
|
||||||
event!!.toJson(),
|
|
||||||
SignerType.SIGN_EVENT,
|
|
||||||
activityResult,
|
|
||||||
"",
|
|
||||||
event!!.id()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Popup(
|
Popup(
|
||||||
alignment = Alignment.BottomCenter,
|
alignment = Alignment.BottomCenter,
|
||||||
@@ -1603,23 +1452,17 @@ fun ZapAmountChoicePopup(
|
|||||||
Button(
|
Button(
|
||||||
modifier = Modifier.padding(horizontal = 3.dp),
|
modifier = Modifier.padding(horizontal = 3.dp),
|
||||||
onClick = {
|
onClick = {
|
||||||
if (accountViewModel.loggedInWithAmber() && account.defaultZapType != LnZapEvent.ZapType.NONZAP && account.defaultZapType != LnZapEvent.ZapType.ANONYMOUS) {
|
accountViewModel.zap(
|
||||||
amount = amountInSats * 1000
|
baseNote,
|
||||||
event = account.createZapRequestFor(baseNote, null, zapMessage, account.defaultZapType)
|
amountInSats * 1000,
|
||||||
} else {
|
null,
|
||||||
accountViewModel.zap(
|
zapMessage,
|
||||||
baseNote,
|
context,
|
||||||
amountInSats * 1000,
|
onError,
|
||||||
null,
|
onProgress,
|
||||||
zapMessage,
|
account.defaultZapType
|
||||||
context,
|
)
|
||||||
onError,
|
onDismiss()
|
||||||
onProgress,
|
|
||||||
account.defaultZapType,
|
|
||||||
null
|
|
||||||
)
|
|
||||||
onDismiss()
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
shape = ButtonBorder,
|
shape = ButtonBorder,
|
||||||
colors = ButtonDefaults
|
colors = ButtonDefaults
|
||||||
@@ -1633,23 +1476,17 @@ fun ZapAmountChoicePopup(
|
|||||||
textAlign = TextAlign.Center,
|
textAlign = TextAlign.Center,
|
||||||
modifier = Modifier.combinedClickable(
|
modifier = Modifier.combinedClickable(
|
||||||
onClick = {
|
onClick = {
|
||||||
if (accountViewModel.loggedInWithAmber() && account.defaultZapType != LnZapEvent.ZapType.NONZAP && account.defaultZapType != LnZapEvent.ZapType.ANONYMOUS) {
|
accountViewModel.zap(
|
||||||
amount = amountInSats * 1000
|
baseNote,
|
||||||
event = account.createZapRequestFor(baseNote, null, zapMessage, account.defaultZapType)
|
amountInSats * 1000,
|
||||||
} else {
|
null,
|
||||||
accountViewModel.zap(
|
zapMessage,
|
||||||
baseNote,
|
context,
|
||||||
amountInSats * 1000,
|
onError,
|
||||||
null,
|
onProgress,
|
||||||
zapMessage,
|
account.defaultZapType
|
||||||
context,
|
)
|
||||||
onError,
|
onDismiss()
|
||||||
onProgress,
|
|
||||||
account.defaultZapType,
|
|
||||||
null
|
|
||||||
)
|
|
||||||
onDismiss()
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onLongClick = {
|
onLongClick = {
|
||||||
onChangeAmount()
|
onChangeAmount()
|
||||||
|
|||||||
@@ -1,15 +1,31 @@
|
|||||||
package com.vitorpamplona.amethyst.ui.note
|
package com.vitorpamplona.amethyst.ui.note
|
||||||
|
|
||||||
import android.app.Activity
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import android.widget.Toast
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.material.*
|
import androidx.compose.material.AlertDialog
|
||||||
|
import androidx.compose.material.Button
|
||||||
|
import androidx.compose.material.ButtonColors
|
||||||
|
import androidx.compose.material.ButtonDefaults
|
||||||
|
import androidx.compose.material.Icon
|
||||||
|
import androidx.compose.material.MaterialTheme
|
||||||
|
import androidx.compose.material.OutlinedTextField
|
||||||
|
import androidx.compose.material.Surface
|
||||||
|
import androidx.compose.material.Text
|
||||||
|
import androidx.compose.material.TextButton
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.outlined.Done
|
import androidx.compose.material.icons.outlined.Done
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
@@ -23,26 +39,17 @@ import androidx.compose.ui.unit.dp
|
|||||||
import androidx.compose.ui.window.Dialog
|
import androidx.compose.ui.window.Dialog
|
||||||
import androidx.compose.ui.window.DialogProperties
|
import androidx.compose.ui.window.DialogProperties
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
import com.vitorpamplona.amethyst.Amethyst
|
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.ServiceManager
|
|
||||||
import com.vitorpamplona.amethyst.model.Account
|
import com.vitorpamplona.amethyst.model.Account
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.service.AmberUtils
|
|
||||||
import com.vitorpamplona.amethyst.ui.actions.CloseButton
|
import com.vitorpamplona.amethyst.ui.actions.CloseButton
|
||||||
import com.vitorpamplona.amethyst.ui.actions.SignerType
|
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.TextSpinner
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.TextSpinner
|
||||||
import com.vitorpamplona.amethyst.ui.theme.ButtonBorder
|
import com.vitorpamplona.amethyst.ui.theme.ButtonBorder
|
||||||
import com.vitorpamplona.amethyst.ui.theme.placeholderText
|
import com.vitorpamplona.amethyst.ui.theme.placeholderText
|
||||||
import com.vitorpamplona.quartz.events.Event
|
|
||||||
import com.vitorpamplona.quartz.events.LnZapEvent
|
import com.vitorpamplona.quartz.events.LnZapEvent
|
||||||
import com.vitorpamplona.quartz.events.LnZapRequestEvent
|
|
||||||
import kotlinx.collections.immutable.toImmutableList
|
import kotlinx.collections.immutable.toImmutableList
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
|
|
||||||
class ZapOptionstViewModel : ViewModel() {
|
class ZapOptionstViewModel : ViewModel() {
|
||||||
private var account: Account? = null
|
private var account: Account? = null
|
||||||
@@ -96,55 +103,6 @@ fun ZapCustomDialog(
|
|||||||
val zapOptionExplainers = remember { zapTypes.map { it.third }.toImmutableList() }
|
val zapOptionExplainers = remember { zapTypes.map { it.third }.toImmutableList() }
|
||||||
var selectedZapType by remember(accountViewModel) { mutableStateOf(accountViewModel.account.defaultZapType) }
|
var selectedZapType by remember(accountViewModel) { mutableStateOf(accountViewModel.account.defaultZapType) }
|
||||||
|
|
||||||
val event = remember { mutableStateOf<LnZapRequestEvent?>(null) }
|
|
||||||
val activityResult = rememberLauncherForActivityResult(
|
|
||||||
contract = ActivityResultContracts.StartActivityForResult(),
|
|
||||||
onResult = {
|
|
||||||
if (it.resultCode != Activity.RESULT_OK) {
|
|
||||||
postViewModel.viewModelScope.launch(Dispatchers.Main) {
|
|
||||||
Toast.makeText(
|
|
||||||
Amethyst.instance,
|
|
||||||
"Sign request rejected",
|
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
).show()
|
|
||||||
}
|
|
||||||
event.value = null
|
|
||||||
} else {
|
|
||||||
val json = it.data?.getStringExtra("event") ?: ""
|
|
||||||
val signedEvent = Event.fromJson(json) as LnZapRequestEvent
|
|
||||||
if (signedEvent.hasValidSignature()) {
|
|
||||||
accountViewModel.zap(
|
|
||||||
baseNote,
|
|
||||||
postViewModel.value()!! * 1000L,
|
|
||||||
null,
|
|
||||||
postViewModel.customMessage.text,
|
|
||||||
context,
|
|
||||||
onError,
|
|
||||||
onProgress,
|
|
||||||
selectedZapType,
|
|
||||||
signedEvent
|
|
||||||
)
|
|
||||||
event.value = null
|
|
||||||
onClose()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AmberUtils.isActivityRunning = false
|
|
||||||
ServiceManager.shouldPauseService = true
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
LaunchedEffect(event.value) {
|
|
||||||
if (event.value != null) {
|
|
||||||
AmberUtils.openAmber(
|
|
||||||
event.value!!.toJson(),
|
|
||||||
SignerType.SIGN_EVENT,
|
|
||||||
activityResult,
|
|
||||||
"",
|
|
||||||
event.value!!.id()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Dialog(
|
Dialog(
|
||||||
onDismissRequest = { onClose() },
|
onDismissRequest = { onClose() },
|
||||||
properties = DialogProperties(
|
properties = DialogProperties(
|
||||||
@@ -167,22 +125,16 @@ fun ZapCustomDialog(
|
|||||||
ZapButton(
|
ZapButton(
|
||||||
isActive = postViewModel.canSend()
|
isActive = postViewModel.canSend()
|
||||||
) {
|
) {
|
||||||
if (accountViewModel.loggedInWithAmber() && selectedZapType != LnZapEvent.ZapType.ANONYMOUS && selectedZapType != LnZapEvent.ZapType.PUBLIC) {
|
accountViewModel.zap(
|
||||||
event.value = accountViewModel.account.createZapRequestFor(baseNote, null, postViewModel.customMessage.text, selectedZapType)
|
baseNote,
|
||||||
} else {
|
postViewModel.value()!! * 1000L,
|
||||||
accountViewModel.zap(
|
null,
|
||||||
baseNote,
|
postViewModel.customMessage.text,
|
||||||
postViewModel.value()!! * 1000L,
|
context,
|
||||||
null,
|
onError = onError,
|
||||||
postViewModel.customMessage.text,
|
onProgress = onProgress,
|
||||||
context,
|
zapType = selectedZapType
|
||||||
onError = onError,
|
)
|
||||||
onProgress = onProgress,
|
|
||||||
zapType = selectedZapType,
|
|
||||||
null
|
|
||||||
)
|
|
||||||
onClose()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-12
@@ -225,11 +225,10 @@ class AccountViewModel(val account: Account) : ViewModel() {
|
|||||||
context: Context,
|
context: Context,
|
||||||
onError: (String) -> Unit,
|
onError: (String) -> Unit,
|
||||||
onProgress: (percent: Float) -> Unit,
|
onProgress: (percent: Float) -> Unit,
|
||||||
zapType: LnZapEvent.ZapType,
|
zapType: LnZapEvent.ZapType
|
||||||
zapRequest: LnZapRequestEvent?
|
|
||||||
) {
|
) {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
innerZap(note, amount, pollOption, message, context, onError, onProgress, zapType, zapRequest)
|
innerZap(note, amount, pollOption, message, context, onError, onProgress, zapType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,8 +240,7 @@ class AccountViewModel(val account: Account) : ViewModel() {
|
|||||||
context: Context,
|
context: Context,
|
||||||
onError: (String) -> Unit,
|
onError: (String) -> Unit,
|
||||||
onProgress: (percent: Float) -> Unit,
|
onProgress: (percent: Float) -> Unit,
|
||||||
zapType: LnZapEvent.ZapType,
|
zapType: LnZapEvent.ZapType
|
||||||
zapRequest: LnZapRequestEvent?
|
|
||||||
) {
|
) {
|
||||||
val lud16 = note.event?.zapAddress() ?: note.author?.info?.lud16?.trim() ?: note.author?.info?.lud06?.trim()
|
val lud16 = note.event?.zapAddress() ?: note.author?.info?.lud16?.trim() ?: note.author?.info?.lud06?.trim()
|
||||||
|
|
||||||
@@ -253,13 +251,9 @@ class AccountViewModel(val account: Account) : ViewModel() {
|
|||||||
|
|
||||||
var zapRequestJson = ""
|
var zapRequestJson = ""
|
||||||
if (zapType != LnZapEvent.ZapType.NONZAP) {
|
if (zapType != LnZapEvent.ZapType.NONZAP) {
|
||||||
if (zapRequest != null) {
|
val localZapRequest = account.createZapRequestFor(note, pollOption, message, zapType)
|
||||||
zapRequestJson = zapRequest.toJson()
|
if (localZapRequest != null) {
|
||||||
} else {
|
zapRequestJson = localZapRequest.toJson()
|
||||||
val localZapRequest = account.createZapRequestFor(note, pollOption, message, zapType)
|
|
||||||
if (localZapRequest != null) {
|
|
||||||
zapRequestJson = localZapRequest.toJson()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -99,6 +99,13 @@ class LnZapRequestEvent(
|
|||||||
return LnZapRequestEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
return LnZapRequestEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun create(
|
||||||
|
unsignedEvent: LnZapRequestEvent,
|
||||||
|
signature: String
|
||||||
|
): LnZapRequestEvent {
|
||||||
|
return LnZapRequestEvent(unsignedEvent.id, unsignedEvent.pubKey, unsignedEvent.createdAt, unsignedEvent.tags, unsignedEvent.content, signature)
|
||||||
|
}
|
||||||
|
|
||||||
fun createPublic(
|
fun createPublic(
|
||||||
originalNote: EventInterface,
|
originalNote: EventInterface,
|
||||||
relays: Set<String>,
|
relays: Set<String>,
|
||||||
@@ -146,7 +153,7 @@ class LnZapRequestEvent(
|
|||||||
|
|
||||||
tags = tags + listOf(listOf("anon", ""))
|
tags = tags + listOf(listOf("anon", ""))
|
||||||
|
|
||||||
return LnZapRequestEvent("", pubKey, createdAt, tags, content, "")
|
return LnZapRequestEvent("zap", pubKey, createdAt, tags, content, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createAnonymous(
|
fun createAnonymous(
|
||||||
|
|||||||
Reference in New Issue
Block a user