Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions app/src/main/java/to/bitkit/ui/components/WalletBalanceView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.unit.dp
import to.bitkit.models.ConvertedAmount
import to.bitkit.models.PrimaryDisplay
import to.bitkit.ui.LocalCurrencies
import to.bitkit.ui.currencyViewModel
import to.bitkit.ui.theme.Colors
import to.bitkit.models.PrimaryDisplay

@Composable
fun RowScope.WalletBalanceView(
Expand All @@ -30,8 +29,8 @@ fun RowScope.WalletBalanceView(
modifier: Modifier,
) {
val currency = currencyViewModel ?: return
val (rates, _, _, _, displayUnit, primaryDisplay) = LocalCurrencies.current
val converted: ConvertedAmount? = if (rates.isNotEmpty()) currency.convert(sats = sats) else null
val (_, _, _, _, displayUnit, primaryDisplay) = LocalCurrencies.current
val converted: ConvertedAmount? = currency.convert(sats = sats)

Column(
modifier = Modifier
Expand All @@ -43,6 +42,7 @@ fun RowScope.WalletBalanceView(
color = Colors.White64,
)
Spacer(modifier = Modifier.height(8.dp))

converted?.let { converted ->
if (primaryDisplay == PrimaryDisplay.BITCOIN) {
val btcComponents = converted.bitcoinDisplay(displayUnit)
Expand Down Expand Up @@ -73,10 +73,7 @@ fun RowScope.WalletBalanceView(
.padding(end = 4.dp)
.size(24.dp)
)
BodyMSB(
text = converted.symbol,
modifier = Modifier.alpha(0.6f)
)
BodyMSB(text = converted.symbol)
BodyMSB(text = converted.formatted)
}
}
Expand Down
21 changes: 11 additions & 10 deletions app/src/main/java/to/bitkit/ui/screens/wallets/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.pullrefresh.PullRefreshIndicator
import androidx.compose.material.pullrefresh.pullRefresh
import androidx.compose.material.pullrefresh.rememberPullRefreshState
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.VerticalDivider
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -37,6 +35,7 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
Expand Down Expand Up @@ -78,15 +77,14 @@ import to.bitkit.viewmodels.AppViewModel
import to.bitkit.viewmodels.MainUiState
import to.bitkit.viewmodels.WalletViewModel

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun HomeScreen(
walletViewModel: WalletViewModel,
appViewModel: AppViewModel,
activityListViewModel: ActivityListViewModel,
rootNavController: NavController,
) {
val uiState: MainUiState by walletViewModel.uiState.collectAsState()
val uiState: MainUiState by walletViewModel.uiState.collectAsStateWithLifecycle()
val currentSheet by appViewModel.currentSheet

SheetHost(
Expand Down Expand Up @@ -143,10 +141,11 @@ fun HomeScreen(
enterTransition = { screenSlideIn },
exitTransition = { screenSlideOut },
) {
val hasSeenSpendingIntro by appViewModel.hasSeenSpendingIntro.collectAsState()
val hasSeenSpendingIntro by appViewModel.hasSeenSpendingIntro.collectAsStateWithLifecycle()
SavingsWalletScreen(
onAllActivityButtonClick = { walletNavController.navigate(HomeRoutes.AllActivity) },
onActivityItemClick = { rootNavController.navigateToActivityItem(it) },
onEmptyActivityRowClick = { appViewModel.showSheet(BottomSheetType.Receive) },
onTransferToSpendingClick = {
if (!hasSeenSpendingIntro) {
rootNavController.navigateToTransferSpendingIntro()
Expand All @@ -161,19 +160,20 @@ fun HomeScreen(
enterTransition = { screenSlideIn },
exitTransition = { screenSlideOut },
) {
val hasSeenSavingsIntro by appViewModel.hasSeenSavingsIntro.collectAsState()
val hasSeenSavingsIntro by appViewModel.hasSeenSavingsIntro.collectAsStateWithLifecycle()
SpendingWalletScreen(
uiState = uiState,
onAllActivityButtonClick = { walletNavController.navigate(HomeRoutes.AllActivity) },
onActivityItemClick = { rootNavController.navigateToActivityItem(it) },
onEmptyActivityRowClick = { appViewModel.showSheet(BottomSheetType.Receive) },
onTransferToSavingsClick = {
if (!hasSeenSavingsIntro) {
rootNavController.navigateToTransferSavingsIntro()
} else {
rootNavController.navigateToTransferSavingsAvailability()
}
},
onBackCLick = { walletNavController.popBackStack() },
onBackClick = { walletNavController.popBackStack() },
)
}
composable<HomeRoutes.AllActivity>(
Expand All @@ -182,7 +182,7 @@ fun HomeScreen(
) {
AllActivityScreen(
viewModel = activityListViewModel,
onBackCLick = { walletNavController.popBackStack() },
onBackClick = { walletNavController.popBackStack() },
onActivityItemClick = { rootNavController.navigateToActivityItem(it) },
)
}
Expand Down Expand Up @@ -215,7 +215,7 @@ private fun HomeContentView(
RequestNotificationPermissions()
val balances = LocalBalances.current
val app = appViewModel ?: return@AppScaffold
val showEmptyStateSetting by app.showEmptyState.collectAsState()
val showEmptyStateSetting by app.showEmptyState.collectAsStateWithLifecycle()
val showEmptyState by remember(balances.totalSats, showEmptyStateSetting) {
derivedStateOf {
showEmptyStateSetting && balances.totalSats == 0uL
Expand Down Expand Up @@ -265,11 +265,12 @@ private fun HomeContentView(
Text13Up(stringResource(R.string.wallet__activity), color = Colors.White64)
Spacer(modifier = Modifier.height(16.dp))
val activity = activityListViewModel ?: return@Column
val latestActivities by activity.latestActivities.collectAsState()
val latestActivities by activity.latestActivities.collectAsStateWithLifecycle()
ActivityList(
items = latestActivities,
onAllActivityClick = { walletNavController.navigate(HomeRoutes.AllActivity) },
onActivityItemClick = { rootNavController.navigateToActivityItem(it) },
onEmptyActivityRowClick = { app.showSheet(BottomSheetType.Receive) },
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import to.bitkit.ui.utils.withAccent
@Composable
fun SavingsWalletScreen(
onAllActivityButtonClick: () -> Unit,
onEmptyActivityRowClick: () -> Unit,
onActivityItemClick: (String) -> Unit,
onTransferToSpendingClick: () -> Unit,
onBackClick: () -> Unit,
Expand Down Expand Up @@ -95,6 +96,7 @@ fun SavingsWalletScreen(
showFooter = true,
onAllActivityButtonClick = onAllActivityButtonClick,
onActivityItemClick = onActivityItemClick,
onEmptyActivityRowClick = onEmptyActivityRowClick,
)
}
}
Expand All @@ -117,8 +119,9 @@ private fun SavingsWalletScreenPreview() {
SavingsWalletScreen(
onAllActivityButtonClick = {},
onActivityItemClick = {},
onEmptyActivityRowClick = {},
onTransferToSpendingClick = {},
onBackClick = { },
onBackClick = {},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ fun SpendingWalletScreen(
uiState: MainUiState,
onAllActivityButtonClick: () -> Unit,
onActivityItemClick: (String) -> Unit,
onEmptyActivityRowClick: () -> Unit,
onTransferToSavingsClick: () -> Unit,
onBackCLick: () -> Unit,
onBackClick: () -> Unit,
) {
val balances = LocalBalances.current
val showEmptyState by remember(balances.totalLightningSats) {
Expand Down Expand Up @@ -77,7 +78,7 @@ fun SpendingWalletScreen(
AppTopBar(
titleText = stringResource(R.string.wallet__spending__title),
icon = painterResource(R.drawable.ic_ln_circle),
onBackClick = onBackCLick,
onBackClick = onBackClick,
)
Column(
modifier = Modifier.padding(horizontal = 16.dp)
Expand Down Expand Up @@ -109,6 +110,7 @@ fun SpendingWalletScreen(
showFooter = true,
onAllActivityButtonClick = onAllActivityButtonClick,
onActivityItemClick = onActivityItemClick,
onEmptyActivityRowClick = onEmptyActivityRowClick,
)
}
}
Expand All @@ -132,8 +134,9 @@ private fun SpendingWalletScreenPreview() {
uiState = MainUiState(),
onAllActivityButtonClick = {},
onActivityItemClick = {},
onEmptyActivityRowClick = {},
onTransferToSavingsClick = {},
onBackCLick = {},
onBackClick = {},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import to.bitkit.R
import to.bitkit.ext.toActivityItemDate
import to.bitkit.ext.toActivityItemTime
import to.bitkit.ui.Routes
import to.bitkit.ui.components.ActivityIcon
import to.bitkit.ui.screens.wallets.activity.components.ActivityIcon
import to.bitkit.ui.components.BalanceHeaderView
import to.bitkit.ui.components.BodySSB
import to.bitkit.ui.components.ButtonSize
Expand Down
Loading