Moves Zap amount Calculations to IO Thread
This commit is contained in:
@@ -72,7 +72,9 @@ import com.vitorpamplona.amethyst.ui.actions.NewPostView
|
|||||||
import com.vitorpamplona.amethyst.ui.actions.SaveButton
|
import com.vitorpamplona.amethyst.ui.actions.SaveButton
|
||||||
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
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import java.math.BigDecimal
|
import java.math.BigDecimal
|
||||||
import java.math.RoundingMode
|
import java.math.RoundingMode
|
||||||
|
|
||||||
@@ -99,7 +101,9 @@ fun ReactionsRow(baseNote: Note, accountViewModel: AccountViewModel) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.padding(top = 8.dp).fillMaxWidth(),
|
modifier = Modifier
|
||||||
|
.padding(top = 8.dp)
|
||||||
|
.fillMaxWidth(),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.SpaceBetween
|
horizontalArrangement = Arrangement.SpaceBetween
|
||||||
) {
|
) {
|
||||||
@@ -350,7 +354,12 @@ fun ZapReaction(
|
|||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
} else if (account.zapAmountChoices.size == 1) {
|
} else if (account.zapAmountChoices.size == 1) {
|
||||||
accountViewModel.zap(baseNote, account.zapAmountChoices.first() * 1000, "", context) {
|
accountViewModel.zap(
|
||||||
|
baseNote,
|
||||||
|
account.zapAmountChoices.first() * 1000,
|
||||||
|
"",
|
||||||
|
context
|
||||||
|
) {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
Toast
|
Toast
|
||||||
.makeText(context, it, Toast.LENGTH_SHORT)
|
.makeText(context, it, Toast.LENGTH_SHORT)
|
||||||
@@ -405,8 +414,16 @@ fun ZapReaction(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var zapAmount by remember { mutableStateOf<BigDecimal?>(null) }
|
||||||
|
|
||||||
|
LaunchedEffect(key1 = zappedNote) {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
zapAmount = zappedNote?.zappedAmount()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
showAmount(zappedNote?.zappedAmount()),
|
showAmount(zapAmount),
|
||||||
fontSize = 14.sp,
|
fontSize = 14.sp,
|
||||||
color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f),
|
color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f),
|
||||||
modifier = textModifier
|
modifier = textModifier
|
||||||
|
|||||||
@@ -9,9 +9,13 @@ import androidx.compose.material.Divider
|
|||||||
import androidx.compose.material.MaterialTheme
|
import androidx.compose.material.MaterialTheme
|
||||||
import androidx.compose.material.Text
|
import androidx.compose.material.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
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.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
|
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.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
@@ -31,6 +35,8 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.UnfollowButton
|
|||||||
import com.vitorpamplona.amethyst.ui.theme.BitcoinOrange
|
import com.vitorpamplona.amethyst.ui.theme.BitcoinOrange
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import java.math.BigDecimal
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ZapNoteCompose(baseNote: Pair<Note, Note>, accountViewModel: AccountViewModel, navController: NavController) {
|
fun ZapNoteCompose(baseNote: Pair<Note, Note>, accountViewModel: AccountViewModel, navController: NavController) {
|
||||||
@@ -88,15 +94,20 @@ fun ZapNoteCompose(baseNote: Pair<Note, Note>, accountViewModel: AccountViewMode
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val amount =
|
var zapAmount by remember { mutableStateOf<BigDecimal?>(null) }
|
||||||
(noteZap.event as? LnZapEvent)?.amount
|
|
||||||
|
LaunchedEffect(key1 = noteZap) {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
zapAmount = (noteZap.event as? LnZapEvent)?.amount
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.padding(start = 10.dp),
|
modifier = Modifier.padding(start = 10.dp),
|
||||||
verticalArrangement = Arrangement.Center
|
verticalArrangement = Arrangement.Center
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
"${showAmount(amount)} ${stringResource(R.string.sats)}",
|
"${showAmount(zapAmount)} ${stringResource(R.string.sats)}",
|
||||||
color = BitcoinOrange,
|
color = BitcoinOrange,
|
||||||
fontSize = 20.sp,
|
fontSize = 20.sp,
|
||||||
fontWeight = FontWeight.W500
|
fontWeight = FontWeight.W500
|
||||||
|
|||||||
@@ -89,6 +89,8 @@ import com.vitorpamplona.amethyst.ui.screen.UserFeedView
|
|||||||
import com.vitorpamplona.amethyst.ui.theme.BitcoinOrange
|
import com.vitorpamplona.amethyst.ui.theme.BitcoinOrange
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import java.math.BigDecimal
|
||||||
|
|
||||||
@OptIn(ExperimentalPagerApi::class)
|
@OptIn(ExperimentalPagerApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
@@ -210,9 +212,20 @@ fun ProfileScreen(userId: String?, accountViewModel: AccountViewModel, navContro
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
val userState by baseUser.live().zaps.observeAsState()
|
val userState by baseUser.live().zaps.observeAsState()
|
||||||
val userZaps = userState?.user?.zappedAmount()
|
val userZaps = userState?.user
|
||||||
|
|
||||||
Text(text = "${showAmount(userZaps)} ${stringResource(id = R.string.zaps)}")
|
var zapAmount by remember { mutableStateOf<BigDecimal?>(null) }
|
||||||
|
|
||||||
|
LaunchedEffect(key1 = userState) {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
val tempAmount = userZaps?.zappedAmount()
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
zapAmount = tempAmount
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Text(text = "${showAmount(zapAmount)} ${stringResource(id = R.string.zaps)}")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
val userState by baseUser.live().reports.observeAsState()
|
val userState by baseUser.live().reports.observeAsState()
|
||||||
|
|||||||
Reference in New Issue
Block a user