kopia lustrzana https://github.com/vitorpamplona/amethyst
only allow one vote per option on atomic (main==max) polls
fix buggy click event on disabled zap buttonpull/283/head
rodzic
62ff9ac94b
commit
b65139f520
|
@ -138,7 +138,16 @@ fun ZapVote(
|
|||
)
|
||||
.show()
|
||||
}
|
||||
} else if (pollViewModel.isVoteAmountAtomic) {
|
||||
} else if (pollViewModel.isVoteAmountAtomic()) {
|
||||
// only allow one vote per option when min==max, i.e. atomic vote amount specified
|
||||
if (pollViewModel.isPollOptionZappedBy(pollOption, account.userProfile())) {
|
||||
scope.launch {
|
||||
Toast
|
||||
.makeText(context, R.string.one_vote_per_user_on_atomic_votes, Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
}
|
||||
return@combinedClickable
|
||||
}
|
||||
accountViewModel.zap(
|
||||
baseNote,
|
||||
pollViewModel.valueMaximum!!.toLong() * 1000,
|
||||
|
@ -263,11 +272,12 @@ fun ZapVoteAmountChoicePopup(
|
|||
}
|
||||
)
|
||||
|
||||
val isValidInputAmount = pollViewModel.isValidInputVoteAmount(amount)
|
||||
Button(
|
||||
modifier = Modifier.padding(horizontal = 3.dp),
|
||||
enabled = pollViewModel.isValidInputVoteAmount(amount),
|
||||
enabled = isValidInputAmount,
|
||||
onClick = {
|
||||
if (amount != null) {
|
||||
if (amount != null && isValidInputAmount) {
|
||||
accountViewModel.zap(
|
||||
baseNote,
|
||||
amount * 1000,
|
||||
|
@ -276,8 +286,8 @@ fun ZapVoteAmountChoicePopup(
|
|||
context,
|
||||
onError
|
||||
)
|
||||
onDismiss()
|
||||
}
|
||||
onDismiss()
|
||||
},
|
||||
shape = RoundedCornerShape(20.dp),
|
||||
colors = ButtonDefaults
|
||||
|
@ -291,7 +301,7 @@ fun ZapVoteAmountChoicePopup(
|
|||
textAlign = TextAlign.Center,
|
||||
modifier = Modifier.combinedClickable(
|
||||
onClick = {
|
||||
if (amount != null) {
|
||||
if (amount != null && isValidInputAmount) {
|
||||
accountViewModel.zap(
|
||||
baseNote,
|
||||
amount * 1000,
|
||||
|
@ -300,8 +310,8 @@ fun ZapVoteAmountChoicePopup(
|
|||
context,
|
||||
onError
|
||||
)
|
||||
onDismiss()
|
||||
}
|
||||
onDismiss()
|
||||
},
|
||||
onLongClick = {}
|
||||
)
|
||||
|
|
|
@ -28,12 +28,12 @@ class PollNoteViewModel {
|
|||
closedAt = pollEvent?.getTagInt(CLOSED_AT)
|
||||
}
|
||||
|
||||
fun isVoteAmountAtomic() = valueMaximum != null && valueMinimum != null && valueMinimum == valueMaximum
|
||||
|
||||
val isPollClosed: Boolean = closedAt?.let { // allow 2 minute leeway for zap to propagate
|
||||
pollNote?.createdAt()?.plus(it * (86400 + 120))!! > Date().time / 1000
|
||||
} == true
|
||||
|
||||
val isVoteAmountAtomic = valueMaximum != null && valueMinimum != null && valueMinimum == valueMaximum
|
||||
|
||||
fun voteAmountPlaceHolderText(sats: String): String = if (valueMinimum == null && valueMaximum == null) {
|
||||
sats
|
||||
} else if (valueMinimum == null) {
|
||||
|
|
|
@ -235,5 +235,6 @@
|
|||
<string name="poll_closing_time_days">days</string>
|
||||
<string name="poll_is_closed">Poll is closed to new votes</string>
|
||||
<string name="poll_zap_amount">Zap amount</string>
|
||||
<string name="one_vote_per_user_on_atomic_votes">Only one vote per user is allowed on this type of poll</string>
|
||||
|
||||
</resources>
|
||||
|
|
Ładowanie…
Reference in New Issue