Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ import org.mifospay.feature.payments.PaymentsScreenContents
import org.mifospay.feature.payments.RequestScreen
import org.mifospay.feature.payments.paymentsScreen
import org.mifospay.feature.payments.selectTransferType.SelectTransferTypeScreen
import org.mifospay.feature.pocket.navigation.managePocketDestination
import org.mifospay.feature.pocket.navigation.navigateToManagePocket
import org.mifospay.feature.pocket.navigation.navigateToPocketDashboard
import org.mifospay.feature.pocket.navigation.pocketDashboardScreen
import org.mifospay.feature.profile.navigation.navigateToProfile
Expand Down Expand Up @@ -347,12 +349,16 @@ internal fun MifosNavHost(

pocketDashboardScreen(
navigateBack = navController::navigateUp,
navigateToManagePocket = { /* TODO: Implement manage pocket */ },
navigateToManagePocket = navController::navigateToManagePocket,
navigateToLoanAccountDetail = { /* TODO: Implement loan account detail */ },
navigateToShareAccountDetail = { /* TODO: Implement share account detail */ },
navigateToSavingsAccountDetail = navController::navigateToSavingAccountDetails,
)

managePocketDestination(
navigateBack = navController::navigateUp,
)

settingsScreen(
onBackPress = navController::navigateUp,
onLogout = onClickLogout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class PocketRepositoryImp(
currencyCode = detail?.currency?.code,
decimalPlaces = detail?.currency?.decimalPlaces,
status = detail?.status?.toAccountStatus(),
currencyDisplaySymbol = detail?.currency?.displaySymbol,
)
}
AccountType.SAVINGS -> {
Expand All @@ -100,6 +101,7 @@ class PocketRepositoryImp(
currencyCode = detail?.currency?.code,
decimalPlaces = detail?.currency?.decimalPlaces,
status = detail?.status?.toAccountStatus(),
currencyDisplaySymbol = detail?.currency?.displaySymbol,
)
}
AccountType.SHARE -> {
Expand All @@ -108,6 +110,7 @@ class PocketRepositoryImp(
var currencyCode: String?
var decimalPlaces: Int?
var accountStatus: AccountStatus?
var currencyDisplaySymbol: String?

try {
val shareAccountDetails = dataManager.shareAccountApi
Expand All @@ -116,6 +119,7 @@ class PocketRepositoryImp(
currencyCode = shareAccountDetails.currency?.code
decimalPlaces = shareAccountDetails.currency?.decimalPlaces
accountStatus = shareAccountDetails.status?.toAccountStatus()
currencyDisplaySymbol = shareAccountDetails.currency?.displaySymbol

val approvedShares = shareAccountDetails.summary?.totalApprovedShares ?: 0
val currentMarketPrice = shareAccountDetails.currentMarketPrice ?: 0.0
Expand All @@ -126,6 +130,7 @@ class PocketRepositoryImp(
currencyCode = detail?.currency?.code
decimalPlaces = detail?.currency?.decimalPlaces
accountStatus = detail?.status?.toAccountStatus()
currencyDisplaySymbol = detail?.currency?.displaySymbol
}

DetailedPocketAccount(
Expand All @@ -135,6 +140,7 @@ class PocketRepositoryImp(
currencyCode = currencyCode,
decimalPlaces = decimalPlaces,
status = accountStatus,
currencyDisplaySymbol = currencyDisplaySymbol,
)
}
}
Expand All @@ -146,7 +152,6 @@ class PocketRepositoryImp(
): Flow<DataState<List<DetailedPocketAccount>>> {
return networkMonitor.withNetworkCheck(
flow {
emit(DataState.Loading)
syncPockets(clientId, forceRefresh)

detailedPocketCache.collect { state ->
Expand Down Expand Up @@ -178,7 +183,8 @@ class PocketRepositoryImp(
val updatedList = currentState.data.toMutableList()
explicitlyAddedAccounts.forEach { explicitlyAddedAccount ->
val newlyGeneratedPocket = updatedBasicPockets.find {
it.accountId == explicitlyAddedAccount.pocket.accountId
it.accountId == explicitlyAddedAccount.pocket.accountId &&
it.accountType == explicitlyAddedAccount.pocket.accountType
}
if (newlyGeneratedPocket != null) {
val finalAccount = explicitlyAddedAccount.copy(pocket = newlyGeneratedPocket)
Expand Down Expand Up @@ -216,11 +222,11 @@ class PocketRepositoryImp(
val clientAccounts = dataManager.clientsApi.getClientAccounts(clientId)
val availableAccounts = mutableListOf<LinkableAccount>()

val alreadyLinkedAccountIds = (detailedPocketCache.value as? DataState.Success)
?.data?.map { it.pocket.accountId } ?: emptyList()
val alreadyLinkedAccounts = (detailedPocketCache.value as? DataState.Success)
?.data?.map { Pair(it.pocket.accountId, it.pocket.accountType) } ?: emptyList()

clientAccounts.loanAccounts.forEach { loan ->
if (loan.id !in alreadyLinkedAccountIds) {
if (Pair(loan.id ?: 0L, AccountType.LOAN) !in alreadyLinkedAccounts) {
availableAccounts.add(
LinkableAccount(
accountId = loan.id ?: 0L,
Expand All @@ -229,6 +235,7 @@ class PocketRepositoryImp(
accountType = AccountType.LOAN,
balance = loan.loanBalance,
currencyCode = loan.currency?.code,
currencyDisplaySymbol = loan.currency?.displaySymbol,
decimalPlaces = loan.currency?.decimalPlaces,
status = loan.status?.toAccountStatus(),
),
Expand All @@ -237,7 +244,7 @@ class PocketRepositoryImp(
}

clientAccounts.savingsAccounts.forEach { savings ->
if (savings.id !in alreadyLinkedAccountIds) {
if (Pair(savings.id, AccountType.SAVINGS) !in alreadyLinkedAccounts) {
availableAccounts.add(
LinkableAccount(
accountId = savings.id,
Expand All @@ -246,6 +253,7 @@ class PocketRepositoryImp(
accountType = AccountType.SAVINGS,
balance = savings.accountBalance,
currencyCode = savings.currency.code,
currencyDisplaySymbol = savings.currency.displaySymbol,
decimalPlaces = savings.currency.decimalPlaces,
status = savings.status.toAccountStatus(),
),
Expand All @@ -254,9 +262,10 @@ class PocketRepositoryImp(
}

clientAccounts.shareAccounts.forEach { share ->
if (share.id !in alreadyLinkedAccountIds) {
if (Pair(share.id ?: 0L, AccountType.SHARE) !in alreadyLinkedAccounts) {
var balance = 0.0
var currencyCode: String? = share.currency?.code
var currencyDisplaySymbol: String? = share.currency?.displaySymbol
var decimalPlaces: Int? = share.currency?.decimalPlaces

try {
Expand All @@ -267,6 +276,7 @@ class PocketRepositoryImp(
balance = approvedShares * currentMarketPrice

currencyCode = shareAccountDetails.currency?.code ?: currencyCode
currencyDisplaySymbol = shareAccountDetails.currency?.displaySymbol ?: currencyDisplaySymbol
decimalPlaces = shareAccountDetails.currency?.decimalPlaces ?: decimalPlaces
} catch (e: Exception) {
// do nothing
Expand All @@ -280,6 +290,7 @@ class PocketRepositoryImp(
accountType = AccountType.SHARE,
balance = balance,
currencyCode = currencyCode,
currencyDisplaySymbol = currencyDisplaySymbol,
decimalPlaces = decimalPlaces,
status = share.status?.toAccountStatus(),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fun MifosAccountCard(
modifier = modifier
.fillMaxWidth()
.clickable { onAccountClick(accountId) }
.padding(vertical = 16.dp),
.padding(vertical = 12.dp),
) {
Row(
modifier = Modifier.fillMaxWidth(),
Expand All @@ -74,7 +74,7 @@ fun MifosAccountCard(
) {
Text(
text = accountNumber ?: "",
style = MaterialTheme.typography.titleMedium.copy(fontWeight = FontWeight.SemiBold),
style = MaterialTheme.typography.titleSmall.copy(fontWeight = FontWeight.SemiBold),
color = MaterialTheme.colorScheme.onBackground,
)
Text(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2026 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md
*/
package org.mifospay.core.designsystem.component

import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector

@Composable
fun MifosAlertDialog(
title: String,
message: String,
icon: ImageVector,
confirmText: String,
dismissText: String,
onConfirm: () -> Unit,
onDismiss: () -> Unit,
modifier: Modifier = Modifier,
) {
AlertDialog(
onDismissRequest = onDismiss,
title = { Text(text = title) },
text = { Text(text = message) },
confirmButton = {
TextButton(onClick = onConfirm) {
Text(text = confirmText)
}
},
dismissButton = {
TextButton(onClick = onDismiss) {
Text(text = dismissText)
}
},
icon = { Icon(icon, contentDescription = null) },
modifier = modifier,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
package org.mifospay.core.designsystem.component

import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Tab
import androidx.compose.material3.Text
import androidx.compose.material3.contentColorFor
Expand All @@ -32,7 +30,6 @@ fun MifosTab(
modifier: Modifier = Modifier,
selectedColor: Color = KptTheme.colorScheme.primary,
unselectedColor: Color = KptTheme.colorScheme.primaryContainer,
unselectedBorderColor: Color = Color.Unspecified,
) {
Tab(
text = {
Expand All @@ -43,14 +40,8 @@ fun MifosTab(
selectedContentColor = contentColorFor(selectedColor),
unselectedContentColor = contentColorFor(unselectedColor),
modifier = modifier
.height(40.dp)
.padding(horizontal = KptTheme.spacing.xs)
.clip(KptTheme.shapes.extraLarge)
.clip(RoundedCornerShape(25.dp))
.background(if (selected) selectedColor else unselectedColor)
.border(
width = 1.dp,
color = if (!selected) unselectedBorderColor else Color.Transparent,
shape = KptTheme.shapes.extraLarge,
),
.padding(horizontal = 20.dp),
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md
*/
package org.mifospay.core.designsystem.component

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.PagerState
import androidx.compose.material3.Tab
import androidx.compose.material3.TabRow
import androidx.compose.material3.TabRowDefaults
import androidx.compose.material3.TabRowDefaults.tabIndicatorOffset
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

@Composable
fun MifosTabPager(
pagerState: PagerState,
currentPage: Int,
tabs: List<String>,
setCurrentPage: (Int) -> Unit,
modifier: Modifier = Modifier,
content: @Composable (Int) -> Unit,
) {
Column(modifier = modifier) {
TabRow(
modifier = Modifier.fillMaxWidth(),
selectedTabIndex = currentPage,
indicator = { tabPositions ->
TabRowDefaults.SecondaryIndicator(
modifier = Modifier
.tabIndicatorOffset(tabPositions[currentPage])
.padding(start = 16.dp, end = 16.dp),
)
},
Comment thread
Kartikey15dem marked this conversation as resolved.
) {
tabs.forEachIndexed { index, tabTitle ->
Tab(
modifier = Modifier.padding(all = 16.dp),
selected = currentPage == index,
onClick = { setCurrentPage(index) },
) {
Text(text = tabTitle)
}
}
}

HorizontalPager(
state = pagerState,
modifier = Modifier.fillMaxWidth(),
pageContent = { page ->
content(page)
},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ data class DetailedPocketAccount(
val productName: String?,
val balance: Double?,
val currencyCode: String?,
val currencyDisplaySymbol: String?,
val decimalPlaces: Int?,
val status: AccountStatus?,
)
Expand All @@ -35,6 +36,7 @@ data class LinkableAccount(
val accountType: AccountType,
val balance: Double?,
val currencyCode: String?,
val currencyDisplaySymbol: String?,
val decimalPlaces: Int?,
val status: AccountStatus?,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ fun MifosScrollableTabRow(
containerColor: Color = Color.Transparent,
selectedContentColor: Color = KptTheme.colorScheme.primary,
unselectedContentColor: Color = KptTheme.colorScheme.surfaceContainerLow,
unselectedBorderColor: Color = KptTheme.colorScheme.primary,
edgePadding: Dp = KptTheme.spacing.sm,
) {
val scope = rememberCoroutineScope()
Expand All @@ -50,7 +49,6 @@ fun MifosScrollableTabRow(
selected = pagerState.currentPage == index,
selectedColor = selectedContentColor,
unselectedColor = unselectedContentColor,
unselectedBorderColor = unselectedBorderColor,
onClick = {
scope.launch {
pagerState.animateScrollToPage(index)
Expand Down
Loading
Loading