Skip to content

Commit be00594

Browse files
fix: Fix navigation flow on successful transaction (#2800)
1 parent 2a4b2f4 commit be00594

File tree

17 files changed

+134
-19
lines changed

17 files changed

+134
-19
lines changed

androidApp/src/main/kotlin/org/mifos/mobile/navigation/MifosNavHost.kt

+26-2
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ import org.mifos.library.passcode.navigateToPasscodeScreen
2626
import org.mifos.mobile.HomeActivity
2727
import org.mifos.mobile.R
2828
import org.mifos.mobile.core.common.Constants.TRANSFER_PAY_TO
29+
import org.mifos.mobile.core.model.entity.TransferSuccessDestination
2930
import org.mifos.mobile.core.model.enums.AccountType
3031
import org.mifos.mobile.core.model.enums.ChargeType
3132
import org.mifos.mobile.core.model.enums.TransferType
3233
import org.mifos.mobile.feature.about.navigation.aboutUsNavGraph
3334
import org.mifos.mobile.feature.about.navigation.navigateToAboutUsScreen
35+
import org.mifos.mobile.feature.account.navigation.ClientAccountsNavigation
3436
import org.mifos.mobile.feature.account.navigation.clientAccountsNavGraph
3537
import org.mifos.mobile.feature.account.navigation.navigateToClientAccountsScreen
3638
import org.mifos.mobile.feature.auth.navigation.authenticationNavGraph
@@ -48,6 +50,7 @@ import org.mifos.mobile.feature.help.navigation.navigateToHelpScreen
4850
import org.mifos.mobile.feature.home.navigation.HomeDestinations
4951
import org.mifos.mobile.feature.home.navigation.HomeNavigation
5052
import org.mifos.mobile.feature.home.navigation.homeNavGraph
53+
import org.mifos.mobile.feature.home.navigation.navigateToHomeScreen
5154
import org.mifos.mobile.feature.loan.navigation.loanNavGraph
5255
import org.mifos.mobile.feature.loan.navigation.navigateToLoanApplication
5356
import org.mifos.mobile.feature.loan.navigation.navigateToLoanDetailScreen
@@ -158,7 +161,23 @@ fun MifosNavHost(
158161
},
159162
)
160163

161-
transferProcessNavGraph(navigateBack = navController::popBackStack)
164+
transferProcessNavGraph(
165+
navigateBack = navController::popBackStack,
166+
onTransferSuccessNavigate = { destination ->
167+
when (destination) {
168+
TransferSuccessDestination.HOME -> navController.navigateToHomeScreen()
169+
TransferSuccessDestination.LOAN_ACCOUNT -> navController.navigateToClientAccountsScreen(
170+
AccountType.LOAN,
171+
ClientAccountsNavigation.ClientAccountsBase.route,
172+
)
173+
174+
TransferSuccessDestination.SAVINGS_ACCOUNT -> navController.navigateToClientAccountsScreen(
175+
AccountType.SAVINGS,
176+
ClientAccountsNavigation.ClientAccountsBase.route,
177+
)
178+
}
179+
},
180+
)
162181

163182
beneficiaryNavGraph(
164183
navController = navController,
@@ -212,7 +231,11 @@ fun handleHomeNavigation(
212231
}
213232

214233
HomeDestinations.RECENT_TRANSACTIONS -> navController.navigateToRecentTransaction()
215-
HomeDestinations.CHARGES -> navController.navigateToClientChargeScreen(ChargeType.CLIENT, -1L)
234+
HomeDestinations.CHARGES -> navController.navigateToClientChargeScreen(
235+
ChargeType.CLIENT,
236+
-1L,
237+
)
238+
216239
HomeDestinations.THIRD_PARTY_TRANSFER -> navController.navigateToThirdPartyTransfer()
217240
HomeDestinations.SETTINGS -> navController.navigateToSettings()
218241
HomeDestinations.ABOUT_US -> navController.navigateToAboutUsScreen()
@@ -230,6 +253,7 @@ fun handleHomeNavigation(
230253
accountId = 1,
231254
transferType = TRANSFER_PAY_TO,
232255
transferTarget = TransferType.SELF,
256+
transferSuccessDestination = TransferSuccessDestination.HOME,
233257
)
234258

235259
HomeDestinations.BENEFICIARIES -> navController.navigateToBeneficiaryListScreen()

core/common/src/main/java/org/mifos/mobile/core/common/Constants.kt

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ object Constants {
2929
const val DFRAG_DATE_PICKER = "Date Picker"
3030
const val TRANSFER_TYPE = "transfer_type"
3131
const val TRANSFER_TARGET = "transfer_target"
32+
const val TRANSFER_SUCCESS_DESTINATION = "transfer_success_destination"
3233
const val TRANSFER_QUICK = "transfer_quick"
3334
const val TRANSFER_PAY_TO = "transfer_pay_to"
3435
const val TRANSFER_PAY_FROM = "transfer_pay_from"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright 2025 Mifos Initiative
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
7+
*
8+
* See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
9+
*/
10+
package org.mifos.mobile.core.model.entity
11+
12+
enum class TransferSuccessDestination {
13+
SAVINGS_ACCOUNT,
14+
LOAN_ACCOUNT,
15+
HOME,
16+
}

feature/account/src/main/java/org/mifos/mobile/feature/account/clientAccount/screens/ClientAccountsScreen.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ internal fun ClientAccountsScreen(
5555
val context = LocalContext.current
5656

5757
var isDialogActive by rememberSaveable { mutableStateOf(false) }
58-
var currentPage by rememberSaveable { mutableIntStateOf(0) }
5958

6059
val accountType by viewModel.accountType.collectAsStateWithLifecycle()
60+
61+
var currentPage by rememberSaveable { mutableIntStateOf(accountType?.ordinal ?: 0) }
6162
val filterList by viewModel.filterList.collectAsStateWithLifecycle()
6263

6364
LaunchedEffect(key1 = accountType) {

feature/account/src/main/java/org/mifos/mobile/feature/account/navigation/AccountNavGraph.kt

+11-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,17 @@ import org.mifos.mobile.core.common.Constants
1919
import org.mifos.mobile.core.model.enums.AccountType
2020
import org.mifos.mobile.feature.account.clientAccount.screens.ClientAccountsScreen
2121

22-
fun NavController.navigateToClientAccountsScreen(accountType: AccountType = AccountType.SAVINGS) {
23-
navigate(ClientAccountsNavigation.ClientAccountsScreen.passArguments(accountType = accountType))
22+
fun NavController.navigateToClientAccountsScreen(
23+
accountType: AccountType = AccountType.SAVINGS,
24+
popUpToDestination: String? = null,
25+
) {
26+
navigate(ClientAccountsNavigation.ClientAccountsScreen.passArguments(accountType = accountType)) {
27+
if (popUpToDestination != null) {
28+
popUpTo(
29+
popUpToDestination,
30+
)
31+
}
32+
}
2433
}
2534

2635
fun NavGraphBuilder.clientAccountsNavGraph(

feature/loan/src/main/java/org/mifos/mobile/feature/loan/loanAccount/LoanAccountDetailScreen.kt

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import org.mifos.mobile.core.common.Constants.TRANSFER_PAY_TO
2424
import org.mifos.mobile.core.common.Network
2525
import org.mifos.mobile.core.designsystem.components.MifosScaffold
2626
import org.mifos.mobile.core.designsystem.theme.MifosMobileTheme
27+
import org.mifos.mobile.core.model.entity.TransferSuccessDestination
2728
import org.mifos.mobile.core.model.entity.accounts.loan.LoanWithAssociations
2829
import org.mifos.mobile.core.model.enums.ChargeType
2930
import org.mifos.mobile.core.model.enums.TransferType
@@ -49,6 +50,7 @@ internal fun LoanAccountDetailScreen(
4950
outstandingBalance: Double?,
5051
transferType: String,
5152
transferTarget: TransferType,
53+
transferSuccessDestination: TransferSuccessDestination,
5254
) -> Unit,
5355
modifier: Modifier = Modifier,
5456
viewModel: LoanAccountsDetailViewModel = hiltViewModel(),
@@ -75,6 +77,7 @@ internal fun LoanAccountDetailScreen(
7577
viewModel.loanWithAssociations?.summary?.totalOutstanding,
7678
TRANSFER_PAY_TO,
7779
TransferType.SELF,
80+
TransferSuccessDestination.LOAN_ACCOUNT,
7881
)
7982
},
8083
)

feature/loan/src/main/java/org/mifos/mobile/feature/loan/navigation/LoanNavGraph.kt

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import androidx.navigation.compose.composable
1616
import androidx.navigation.compose.navigation
1717
import androidx.navigation.navArgument
1818
import org.mifos.mobile.core.common.Constants
19+
import org.mifos.mobile.core.model.entity.TransferSuccessDestination
1920
import org.mifos.mobile.core.model.enums.ChargeType
2021
import org.mifos.mobile.core.model.enums.LoanState
2122
import org.mifos.mobile.core.model.enums.TransferType
@@ -68,6 +69,7 @@ fun NavGraphBuilder.loanNavGraph(
6869
outstandingBalance: Double?,
6970
transferType: String,
7071
transferTarget: TransferType,
72+
transferSuccessDestination: TransferSuccessDestination,
7173
) -> Unit,
7274
) {
7375
navigation(
@@ -149,6 +151,7 @@ fun NavGraphBuilder.loanDetailRoute(
149151
outstandingBalance: Double?,
150152
transferType: String,
151153
transferTarget: TransferType,
154+
transferSuccessDestination: TransferSuccessDestination,
152155
) -> Unit,
153156
) {
154157
composable(

feature/savings/src/main/java/org/mifos/mobile/feature/savings/navigation/SavingsNavGraph.kt

+11-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ import org.mifos.mobile.core.common.Constants.OUTSTANDING_BALANCE
2121
import org.mifos.mobile.core.common.Constants.SAVINGS_ID
2222
import org.mifos.mobile.core.common.Constants.TRANSFER_PAY_FROM
2323
import org.mifos.mobile.core.common.Constants.TRANSFER_PAY_TO
24+
import org.mifos.mobile.core.common.Constants.TRANSFER_SUCCESS_DESTINATION
2425
import org.mifos.mobile.core.common.Constants.TRANSFER_TARGET
2526
import org.mifos.mobile.core.common.Constants.TRANSFER_TYPE
27+
import org.mifos.mobile.core.model.entity.TransferSuccessDestination
2628
import org.mifos.mobile.core.model.entity.payload.ReviewTransferPayload
2729
import org.mifos.mobile.core.model.enums.ChargeType
2830
import org.mifos.mobile.core.model.enums.SavingsAccountState
@@ -38,13 +40,15 @@ fun NavController.navigateToSavingsMakeTransfer(
3840
outstandingBalance: Double? = null,
3941
transferType: String,
4042
transferTarget: TransferType,
43+
transferSuccessDestination: TransferSuccessDestination,
4144
) {
4245
navigate(
4346
SavingsNavigation.SavingsMakeTransfer.passArguments(
4447
accountId = accountId,
4548
outstandingBalance = (outstandingBalance ?: 0.0).toString(),
4649
transferType = transferType,
4750
transferTarget = transferTarget,
51+
transferSuccessDestination = transferSuccessDestination,
4852
),
4953
)
5054
}
@@ -66,7 +70,7 @@ fun NavGraphBuilder.savingsNavGraph(
6670
navController: NavController,
6771
viewQrCode: (String) -> Unit,
6872
viewCharges: (ChargeType, Long) -> Unit,
69-
reviewTransfer: (ReviewTransferPayload, TransferType) -> Unit,
73+
reviewTransfer: (ReviewTransferPayload, TransferType, TransferSuccessDestination) -> Unit,
7074
callHelpline: () -> Unit,
7175
) {
7276
navigation(
@@ -80,13 +84,15 @@ fun NavGraphBuilder.savingsNavGraph(
8084
accountId = it,
8185
transferType = TRANSFER_PAY_TO,
8286
transferTarget = TransferType.TPT,
87+
transferSuccessDestination = TransferSuccessDestination.SAVINGS_ACCOUNT,
8388
)
8489
},
8590
makeTransfer = {
8691
navController.navigateToSavingsMakeTransfer(
8792
accountId = it,
8893
transferType = TRANSFER_PAY_FROM,
8994
transferTarget = TransferType.TPT,
95+
transferSuccessDestination = TransferSuccessDestination.SAVINGS_ACCOUNT,
9096
)
9197
},
9298
navigateBack = navController::popBackStack,
@@ -208,7 +214,7 @@ fun NavGraphBuilder.savingsWithdraw(
208214

209215
fun NavGraphBuilder.savingsMakeTransfer(
210216
navigateBack: () -> Unit,
211-
reviewTransfer: (ReviewTransferPayload, TransferType) -> Unit,
217+
reviewTransfer: (ReviewTransferPayload, TransferType, TransferSuccessDestination) -> Unit,
212218
) {
213219
composable(
214220
route = SavingsNavigation.SavingsMakeTransfer.route,
@@ -221,6 +227,9 @@ fun NavGraphBuilder.savingsMakeTransfer(
221227
},
222228
navArgument(name = TRANSFER_TYPE) { type = NavType.StringType },
223229
navArgument(name = TRANSFER_TARGET) { type = NavType.StringType },
230+
navArgument(name = TRANSFER_SUCCESS_DESTINATION) {
231+
type = NavType.EnumType(TransferSuccessDestination::class.java)
232+
},
224233
),
225234
) {
226235
SavingsMakeTransferScreen(

feature/savings/src/main/java/org/mifos/mobile/feature/savings/navigation/SavingsNavigation.kt

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ import org.mifos.mobile.core.common.Constants.ACCOUNT_ID
1313
import org.mifos.mobile.core.common.Constants.OUTSTANDING_BALANCE
1414
import org.mifos.mobile.core.common.Constants.SAVINGS_ACCOUNT_STATE
1515
import org.mifos.mobile.core.common.Constants.SAVINGS_ID
16+
import org.mifos.mobile.core.common.Constants.TRANSFER_SUCCESS_DESTINATION
1617
import org.mifos.mobile.core.common.Constants.TRANSFER_TARGET
1718
import org.mifos.mobile.core.common.Constants.TRANSFER_TYPE
19+
import org.mifos.mobile.core.model.entity.TransferSuccessDestination
1820
import org.mifos.mobile.core.model.enums.SavingsAccountState
1921
import org.mifos.mobile.core.model.enums.TransferType
2022

@@ -66,19 +68,22 @@ sealed class SavingsNavigation(val route: String) {
6668
"{$ACCOUNT_ID}/" +
6769
"{$OUTSTANDING_BALANCE}/" +
6870
"{$TRANSFER_TYPE}/" +
69-
"{$TRANSFER_TARGET}",
71+
"{$TRANSFER_TARGET}/" +
72+
"{$TRANSFER_SUCCESS_DESTINATION}",
7073
) {
7174
fun passArguments(
7275
accountId: Long,
7376
outstandingBalance: String? = null,
7477
transferType: String,
7578
transferTarget: TransferType,
79+
transferSuccessDestination: TransferSuccessDestination,
7680
): String {
7781
return "$SAVINGS_MAKE_TRANSFER_SCREEN_ROUTE/" +
7882
"$accountId/" +
7983
"$outstandingBalance/" +
8084
"$transferType/" +
81-
transferTarget.name
85+
"${transferTarget.name}/" +
86+
transferSuccessDestination
8287
}
8388
}
8489
}

feature/savings/src/main/java/org/mifos/mobile/feature/savings/savingsMakeTransfer/SavingsMakeTransferScreen.kt

+12-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import androidx.compose.foundation.layout.Box
1313
import androidx.compose.foundation.layout.fillMaxSize
1414
import androidx.compose.foundation.layout.padding
1515
import androidx.compose.runtime.Composable
16+
import androidx.compose.runtime.getValue
1617
import androidx.compose.ui.Modifier
1718
import androidx.compose.ui.platform.LocalContext
1819
import androidx.compose.ui.tooling.preview.PreviewParameter
@@ -23,6 +24,7 @@ import org.mifos.mobile.core.common.Constants
2324
import org.mifos.mobile.core.common.Network
2425
import org.mifos.mobile.core.designsystem.components.MifosScaffold
2526
import org.mifos.mobile.core.designsystem.theme.MifosMobileTheme
27+
import org.mifos.mobile.core.model.entity.TransferSuccessDestination
2628
import org.mifos.mobile.core.model.entity.payload.ReviewTransferPayload
2729
import org.mifos.mobile.core.model.enums.TransferType
2830
import org.mifos.mobile.core.ui.component.MifosErrorComponent
@@ -34,18 +36,26 @@ import org.mifos.mobile.feature.savings.R
3436
internal fun SavingsMakeTransferScreen(
3537
onCancelledClicked: () -> Unit,
3638
navigateBack: () -> Unit,
37-
reviewTransfer: (ReviewTransferPayload, TransferType) -> Unit,
39+
reviewTransfer: (ReviewTransferPayload, TransferType, TransferSuccessDestination) -> Unit,
3840
modifier: Modifier = Modifier,
3941
viewModel: SavingsMakeTransferViewModel = hiltViewModel(),
4042
) {
4143
val uiState = viewModel.savingsMakeTransferUiState.collectAsStateWithLifecycle()
44+
val transferSuccessDestination by
45+
viewModel.transferSuccessDestination.collectAsStateWithLifecycle()
4246

4347
SavingsMakeTransferScreen(
4448
navigateBack = navigateBack,
4549
onCancelledClicked = onCancelledClicked,
4650
uiState = uiState.value,
4751
modifier = modifier,
48-
reviewTransfer = { reviewTransfer(it, TransferType.SELF) },
52+
reviewTransfer = {
53+
reviewTransfer(
54+
it,
55+
TransferType.SELF,
56+
transferSuccessDestination,
57+
)
58+
},
4959
)
5060
}
5161

feature/savings/src/main/java/org/mifos/mobile/feature/savings/savingsMakeTransfer/SavingsMakeTransferViewModel.kt

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import kotlinx.coroutines.flow.stateIn
2121
import org.mifos.mobile.core.common.Constants
2222
import org.mifos.mobile.core.common.Constants.TRANSFER_PAY_TO
2323
import org.mifos.mobile.core.data.repository.SavingsAccountRepository
24+
import org.mifos.mobile.core.model.entity.TransferSuccessDestination
2425
import org.mifos.mobile.core.model.entity.templates.account.AccountOption
2526
import org.mifos.mobile.core.model.enums.TransferType
2627
import org.mifos.mobile.core.network.Result
@@ -47,6 +48,11 @@ internal class SavingsMakeTransferViewModel @Inject constructor(
4748
initialValue = TransferType.TPT.name,
4849
)
4950

51+
val transferSuccessDestination: StateFlow<TransferSuccessDestination> = savedStateHandle.getStateFlow(
52+
key = Constants.TRANSFER_SUCCESS_DESTINATION,
53+
initialValue = TransferSuccessDestination.SAVINGS_ACCOUNT,
54+
)
55+
5056
private val outstandingBalance: StateFlow<Double?> = savedStateHandle.getStateFlow<String?>(
5157
key = Constants.OUTSTANDING_BALANCE,
5258
initialValue = null,

feature/third-party-transfer/src/main/java/org/mifos/mobile/feature/third/party/transfer/ThirdPartyTransferScreen.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
2323
import org.mifos.mobile.core.common.Network
2424
import org.mifos.mobile.core.designsystem.components.MifosScaffold
2525
import org.mifos.mobile.core.designsystem.theme.MifosMobileTheme
26+
import org.mifos.mobile.core.model.entity.TransferSuccessDestination
2627
import org.mifos.mobile.core.model.entity.payload.ReviewTransferPayload
2728
import org.mifos.mobile.core.model.enums.TransferType
2829
import org.mifos.mobile.core.ui.component.MifosErrorComponent
@@ -33,7 +34,7 @@ import org.mifos.mobile.core.ui.utils.DevicePreviews
3334
internal fun ThirdPartyTransferScreen(
3435
navigateBack: () -> Unit,
3536
addBeneficiary: () -> Unit,
36-
reviewTransfer: (ReviewTransferPayload, TransferType) -> Unit,
37+
reviewTransfer: (ReviewTransferPayload, TransferType, TransferSuccessDestination) -> Unit,
3738
modifier: Modifier = Modifier,
3839
viewModel: ThirdPartyTransferViewModel = hiltViewModel(),
3940
) {
@@ -43,7 +44,7 @@ internal fun ThirdPartyTransferScreen(
4344
uiState = uiState,
4445
navigateBack = navigateBack,
4546
addBeneficiary = addBeneficiary,
46-
reviewTransfer = { reviewTransfer(it, TransferType.TPT) },
47+
reviewTransfer = { reviewTransfer(it, TransferType.TPT, TransferSuccessDestination.HOME) },
4748
modifier = modifier,
4849
)
4950
}

feature/third-party-transfer/src/main/java/org/mifos/mobile/feature/third/party/transfer/navigation/ThirdPartyTransferNavGraph.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import androidx.navigation.NavController
1313
import androidx.navigation.NavGraphBuilder
1414
import androidx.navigation.compose.composable
1515
import androidx.navigation.compose.navigation
16+
import org.mifos.mobile.core.model.entity.TransferSuccessDestination
1617
import org.mifos.mobile.core.model.entity.payload.ReviewTransferPayload
1718
import org.mifos.mobile.core.model.enums.TransferType
1819
import org.mifos.mobile.feature.third.party.transfer.ThirdPartyTransferScreen
@@ -24,7 +25,7 @@ fun NavController.navigateToThirdPartyTransfer() {
2425
fun NavGraphBuilder.thirdPartyTransferNavGraph(
2526
navigateBack: () -> Unit,
2627
addBeneficiary: () -> Unit,
27-
reviewTransfer: (ReviewTransferPayload, TransferType) -> Unit,
28+
reviewTransfer: (ReviewTransferPayload, TransferType, TransferSuccessDestination) -> Unit,
2829
) {
2930
navigation(
3031
startDestination = ThirdPartyTransferNavigation.ThirdPartyTransferScreen.route,
@@ -41,7 +42,7 @@ fun NavGraphBuilder.thirdPartyTransferNavGraph(
4142
fun NavGraphBuilder.thirdPartyTransferRoute(
4243
navigateBack: () -> Unit,
4344
addBeneficiary: () -> Unit,
44-
reviewTransfer: (ReviewTransferPayload, TransferType) -> Unit,
45+
reviewTransfer: (ReviewTransferPayload, TransferType, TransferSuccessDestination) -> Unit,
4546
) {
4647
composable(
4748
route = ThirdPartyTransferNavigation.ThirdPartyTransferScreen.route,

0 commit comments

Comments
 (0)