remember default ZapType
Based on last selection in ZapCustomDialog, Reaction Row Zaps will use the same zap type Currently Zaps in Polls are always public.
This commit is contained in:
@@ -11,6 +11,7 @@ import com.vitorpamplona.amethyst.model.toByteArray
|
|||||||
import com.vitorpamplona.amethyst.service.model.ContactListEvent
|
import com.vitorpamplona.amethyst.service.model.ContactListEvent
|
||||||
import com.vitorpamplona.amethyst.service.model.Event
|
import com.vitorpamplona.amethyst.service.model.Event
|
||||||
import com.vitorpamplona.amethyst.service.model.Event.Companion.getRefinedEvent
|
import com.vitorpamplona.amethyst.service.model.Event.Companion.getRefinedEvent
|
||||||
|
import com.vitorpamplona.amethyst.service.model.LnZapEvent
|
||||||
import com.vitorpamplona.amethyst.ui.note.Nip47URI
|
import com.vitorpamplona.amethyst.ui.note.Nip47URI
|
||||||
import fr.acinq.secp256k1.Hex
|
import fr.acinq.secp256k1.Hex
|
||||||
import nostr.postr.Persona
|
import nostr.postr.Persona
|
||||||
@@ -42,6 +43,7 @@ private object PrefKeys {
|
|||||||
const val LANGUAGE_PREFS = "languagePreferences"
|
const val LANGUAGE_PREFS = "languagePreferences"
|
||||||
const val TRANSLATE_TO = "translateTo"
|
const val TRANSLATE_TO = "translateTo"
|
||||||
const val ZAP_AMOUNTS = "zapAmounts"
|
const val ZAP_AMOUNTS = "zapAmounts"
|
||||||
|
const val DEFAULT_ZAPTYPE = "defaultZapType"
|
||||||
const val ZAP_PAYMENT_REQUEST_SERVER = "zapPaymentServer"
|
const val ZAP_PAYMENT_REQUEST_SERVER = "zapPaymentServer"
|
||||||
const val LATEST_CONTACT_LIST = "latestContactList"
|
const val LATEST_CONTACT_LIST = "latestContactList"
|
||||||
const val HIDE_DELETE_REQUEST_DIALOG = "hide_delete_request_dialog"
|
const val HIDE_DELETE_REQUEST_DIALOG = "hide_delete_request_dialog"
|
||||||
@@ -191,6 +193,7 @@ object LocalPreferences {
|
|||||||
putString(PrefKeys.LANGUAGE_PREFS, gson.toJson(account.languagePreferences))
|
putString(PrefKeys.LANGUAGE_PREFS, gson.toJson(account.languagePreferences))
|
||||||
putString(PrefKeys.TRANSLATE_TO, account.translateTo)
|
putString(PrefKeys.TRANSLATE_TO, account.translateTo)
|
||||||
putString(PrefKeys.ZAP_AMOUNTS, gson.toJson(account.zapAmountChoices))
|
putString(PrefKeys.ZAP_AMOUNTS, gson.toJson(account.zapAmountChoices))
|
||||||
|
putString(PrefKeys.DEFAULT_ZAPTYPE, gson.toJson(account.defaultZapType))
|
||||||
putString(PrefKeys.ZAP_PAYMENT_REQUEST_SERVER, gson.toJson(account.zapPaymentRequest))
|
putString(PrefKeys.ZAP_PAYMENT_REQUEST_SERVER, gson.toJson(account.zapPaymentRequest))
|
||||||
putString(PrefKeys.LATEST_CONTACT_LIST, Event.gson.toJson(account.backupContactList))
|
putString(PrefKeys.LATEST_CONTACT_LIST, Event.gson.toJson(account.backupContactList))
|
||||||
putBoolean(PrefKeys.HIDE_DELETE_REQUEST_DIALOG, account.hideDeleteRequestDialog)
|
putBoolean(PrefKeys.HIDE_DELETE_REQUEST_DIALOG, account.hideDeleteRequestDialog)
|
||||||
@@ -217,6 +220,11 @@ object LocalPreferences {
|
|||||||
object : TypeToken<List<Long>>() {}.type
|
object : TypeToken<List<Long>>() {}.type
|
||||||
) ?: listOf(500L, 1000L, 5000L)
|
) ?: listOf(500L, 1000L, 5000L)
|
||||||
|
|
||||||
|
val defaultZapType = gson.fromJson(
|
||||||
|
getString(PrefKeys.DEFAULT_ZAPTYPE, "PUBLIC"),
|
||||||
|
object : TypeToken<LnZapEvent.ZapType>() {}.type
|
||||||
|
) ?: LnZapEvent.ZapType.PUBLIC
|
||||||
|
|
||||||
val zapPaymentRequestServer = try {
|
val zapPaymentRequestServer = try {
|
||||||
getString(PrefKeys.ZAP_PAYMENT_REQUEST_SERVER, null)?.let {
|
getString(PrefKeys.ZAP_PAYMENT_REQUEST_SERVER, null)?.let {
|
||||||
gson.fromJson(it, Nip47URI::class.java)
|
gson.fromJson(it, Nip47URI::class.java)
|
||||||
@@ -260,6 +268,7 @@ object LocalPreferences {
|
|||||||
languagePreferences,
|
languagePreferences,
|
||||||
translateTo,
|
translateTo,
|
||||||
zapAmountChoices,
|
zapAmountChoices,
|
||||||
|
defaultZapType,
|
||||||
zapPaymentRequestServer,
|
zapPaymentRequestServer,
|
||||||
hideDeleteRequestDialog,
|
hideDeleteRequestDialog,
|
||||||
hideBlockAlertDialog,
|
hideBlockAlertDialog,
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ class Account(
|
|||||||
var languagePreferences: Map<String, String> = mapOf(),
|
var languagePreferences: Map<String, String> = mapOf(),
|
||||||
var translateTo: String = Locale.getDefault().language,
|
var translateTo: String = Locale.getDefault().language,
|
||||||
var zapAmountChoices: List<Long> = listOf(500L, 1000L, 5000L),
|
var zapAmountChoices: List<Long> = listOf(500L, 1000L, 5000L),
|
||||||
|
var defaultZapType: LnZapEvent.ZapType = LnZapEvent.ZapType.PUBLIC,
|
||||||
var zapPaymentRequest: Nip47URI? = null,
|
var zapPaymentRequest: Nip47URI? = null,
|
||||||
var hideDeleteRequestDialog: Boolean = false,
|
var hideDeleteRequestDialog: Boolean = false,
|
||||||
var hideBlockAlertDialog: Boolean = false,
|
var hideBlockAlertDialog: Boolean = false,
|
||||||
@@ -625,6 +626,12 @@ class Account(
|
|||||||
saveable.invalidateData()
|
saveable.invalidateData()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun changeDefaultZapType(zapType: LnZapEvent.ZapType) {
|
||||||
|
defaultZapType = zapType
|
||||||
|
live.invalidateData()
|
||||||
|
saveable.invalidateData()
|
||||||
|
}
|
||||||
|
|
||||||
fun changeZapAmounts(newAmounts: List<Long>) {
|
fun changeZapAmounts(newAmounts: List<Long>) {
|
||||||
zapAmountChoices = newAmounts
|
zapAmountChoices = newAmounts
|
||||||
live.invalidateData()
|
live.invalidateData()
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ import androidx.compose.ui.unit.sp
|
|||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.model.Account
|
import com.vitorpamplona.amethyst.model.Account
|
||||||
import com.vitorpamplona.amethyst.service.lnurl.LightningAddressResolver
|
import com.vitorpamplona.amethyst.service.lnurl.LightningAddressResolver
|
||||||
import com.vitorpamplona.amethyst.service.model.LnZapEvent
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -136,7 +135,7 @@ fun InvoiceRequest(
|
|||||||
Button(
|
Button(
|
||||||
modifier = Modifier.fillMaxWidth().padding(vertical = 10.dp),
|
modifier = Modifier.fillMaxWidth().padding(vertical = 10.dp),
|
||||||
onClick = {
|
onClick = {
|
||||||
val zapRequest = account.createZapRequestFor(toUserPubKeyHex, message, LnZapEvent.ZapType.PUBLIC)
|
val zapRequest = account.createZapRequestFor(toUserPubKeyHex, message, account.defaultZapType)
|
||||||
|
|
||||||
LightningAddressResolver().lnAddressInvoice(
|
LightningAddressResolver().lnAddressInvoice(
|
||||||
lud16,
|
lud16,
|
||||||
|
|||||||
@@ -250,7 +250,7 @@ fun ZapVote(
|
|||||||
zappingProgress = it
|
zappingProgress = it
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
zapType = LnZapEvent.ZapType.PUBLIC
|
zapType = account.defaultZapType
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ import coil.request.CachePolicy
|
|||||||
import coil.request.ImageRequest
|
import coil.request.ImageRequest
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.service.model.LnZapEvent
|
|
||||||
import com.vitorpamplona.amethyst.ui.actions.NewPostView
|
import com.vitorpamplona.amethyst.ui.actions.NewPostView
|
||||||
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
|
||||||
@@ -364,7 +363,7 @@ fun ZapReaction(
|
|||||||
zappingProgress = it
|
zappingProgress = it
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
zapType = LnZapEvent.ZapType.PUBLIC
|
zapType = account.defaultZapType
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else if (account.zapAmountChoices.size > 1) {
|
} else if (account.zapAmountChoices.size > 1) {
|
||||||
@@ -561,7 +560,7 @@ fun ZapAmountChoicePopup(
|
|||||||
context,
|
context,
|
||||||
onError,
|
onError,
|
||||||
onProgress,
|
onProgress,
|
||||||
LnZapEvent.ZapType.PUBLIC
|
account.defaultZapType
|
||||||
)
|
)
|
||||||
onDismiss()
|
onDismiss()
|
||||||
}
|
}
|
||||||
@@ -587,7 +586,7 @@ fun ZapAmountChoicePopup(
|
|||||||
context,
|
context,
|
||||||
onError,
|
onError,
|
||||||
onProgress,
|
onProgress,
|
||||||
LnZapEvent.ZapType.PUBLIC
|
account.defaultZapType
|
||||||
)
|
)
|
||||||
onDismiss()
|
onDismiss()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import kotlinx.coroutines.launch
|
|||||||
|
|
||||||
class ZapOptionstViewModel : ViewModel() {
|
class ZapOptionstViewModel : ViewModel() {
|
||||||
private var account: Account? = null
|
private var account: Account? = null
|
||||||
|
|
||||||
var customAmount by mutableStateOf(TextFieldValue("21"))
|
var customAmount by mutableStateOf(TextFieldValue("21"))
|
||||||
var customMessage by mutableStateOf(TextFieldValue(""))
|
var customMessage by mutableStateOf(TextFieldValue(""))
|
||||||
|
|
||||||
@@ -73,7 +74,7 @@ fun ZapCustomDialog(onClose: () -> Unit, account: Account, accountViewModel: Acc
|
|||||||
)
|
)
|
||||||
|
|
||||||
val zapOptions = zapTypes.map { it.second }
|
val zapOptions = zapTypes.map { it.second }
|
||||||
var selectedZapType by remember { mutableStateOf(zapTypes[0]) }
|
var selectedZapType by remember { mutableStateOf(account.defaultZapType) }
|
||||||
|
|
||||||
Dialog(
|
Dialog(
|
||||||
onDismissRequest = { onClose() },
|
onDismissRequest = { onClose() },
|
||||||
@@ -116,7 +117,7 @@ fun ZapCustomDialog(onClose: () -> Unit, account: Account, accountViewModel: Acc
|
|||||||
zappingProgress = it
|
zappingProgress = it
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
zapType = selectedZapType.first
|
zapType = selectedZapType
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
onClose()
|
onClose()
|
||||||
@@ -186,10 +187,11 @@ fun ZapCustomDialog(onClose: () -> Unit, account: Account, accountViewModel: Acc
|
|||||||
}
|
}
|
||||||
TextSpinner(
|
TextSpinner(
|
||||||
label = "Zap Type",
|
label = "Zap Type",
|
||||||
placeholder = "Public",
|
placeholder = zapTypes.filter { it.first == account.defaultZapType }.first().second,
|
||||||
options = zapOptions,
|
options = zapOptions,
|
||||||
onSelect = {
|
onSelect = {
|
||||||
selectedZapType = zapTypes[it]
|
selectedZapType = zapTypes[it].first
|
||||||
|
account.changeDefaultZapType(selectedZapType)
|
||||||
},
|
},
|
||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier.fillMaxWidth()
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user