Skip to content

Commit 91fb091

Browse files
feat: Third Party Transfer ui & viewModel (#2944)
1 parent e26c8a6 commit 91fb091

File tree

22 files changed

+1188
-914
lines changed

22 files changed

+1188
-914
lines changed

cmp-navigation/src/commonMain/kotlin/cmp/navigation/authenticated/AuthenticatedNavigation.kt

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import kotlinx.serialization.InternalSerializationApi
2222
import kotlinx.serialization.Serializable
2323
import org.mifos.mobile.core.common.Constants
2424
import org.mifos.mobile.core.model.entity.TransferSuccessDestination
25+
import org.mifos.mobile.core.model.enums.TransferType
2526
import org.mifos.mobile.feature.accounts.accountTransactions.accountTransactionsDestination
2627
import org.mifos.mobile.feature.accounts.accountTransactions.navigateToAccountTransactionsScreen
2728
import org.mifos.mobile.feature.accounts.accounts.accountsDestination
@@ -59,7 +60,7 @@ import org.mifos.mobile.feature.share.application.navigation.navigateToShareAppl
5960
import org.mifos.mobile.feature.share.application.navigation.shareApplicationNavGraph
6061
import org.mifos.mobile.feature.status.navigation.StatusNavigationRoute
6162
import org.mifos.mobile.feature.status.navigation.statusDestination
62-
import org.mifos.mobile.feature.third.party.transfer.navigation.thirdPartyTransferNavGraph
63+
import org.mifos.mobile.feature.third.party.transfer.navigation.TptNavigationDestination
6364
import org.mifos.mobile.feature.transfer.process.makeTransfer.makeTransferDestination
6465
import org.mifos.mobile.feature.transfer.process.makeTransfer.navigateToMakeTransferScreen
6566
import org.mifos.mobile.feature.transfer.process.transferProcess.navigateToTransferProcessScreen
@@ -72,54 +73,74 @@ internal fun NavController.navigateToAuthenticatedGraph(navOptions: NavOptions?
7273
navigate(route = AuthenticatedGraphRoute, navOptions = navOptions)
7374
}
7475

76+
@Suppress("CyclomaticComplexMethod")
7577
@OptIn(InternalSerializationApi::class, ExperimentalSerializationApi::class)
7678
internal fun NavGraphBuilder.authenticatedGraph(
7779
navController: NavController,
7880
) {
7981
navigation<AuthenticatedGraphRoute>(
8082
startDestination = AuthenticatedNavbarRoute,
8183
) {
82-
authenticatedNavbarGraph { destination ->
83-
when (destination) {
84-
is HomeNavigationDestination.AccountsWithType -> {
85-
if (destination.type in listOf(
86-
Constants.SAVINGS_ACCOUNT,
87-
Constants.LOAN_ACCOUNT,
88-
Constants.SHARE_ACCOUNTS,
89-
)
90-
) {
91-
navController.navigateToAccountsScreen(destination.type)
84+
authenticatedNavbarGraph(
85+
homeNavigator = { destination ->
86+
when (destination) {
87+
is HomeNavigationDestination.AccountsWithType -> {
88+
if (destination.type in listOf(
89+
Constants.SAVINGS_ACCOUNT,
90+
Constants.LOAN_ACCOUNT,
91+
Constants.SHARE_ACCOUNTS,
92+
)
93+
) {
94+
navController.navigateToAccountsScreen(destination.type)
95+
}
9296
}
93-
}
9497

95-
is HomeNavigationDestination.Notification ->
96-
navController.navigateToNotificationScreen()
98+
is HomeNavigationDestination.Notification ->
99+
navController.navigateToNotificationScreen()
97100

98-
is HomeNavigationDestination.Charge ->
99-
navController.navigateToChargeGraph()
101+
is HomeNavigationDestination.Charge ->
102+
navController.navigateToChargeGraph()
100103

101-
is HomeNavigationDestination.Faq ->
102-
navController.navigateToFaq()
104+
is HomeNavigationDestination.Faq ->
105+
navController.navigateToFaq()
103106

104-
is HomeNavigationDestination.Beneficiary ->
105-
navController.navigateToBeneficiaryNavGraph()
107+
is HomeNavigationDestination.Beneficiary ->
108+
navController.navigateToBeneficiaryNavGraph()
106109

107-
is HomeNavigationDestination.Transaction ->
108-
navController.navigateToAccountTransactionsScreen(
109-
Constants.RECENT_TRANSACTIONS,
110-
-1L,
111-
)
110+
is HomeNavigationDestination.Transaction ->
111+
navController.navigateToAccountTransactionsScreen(
112+
Constants.RECENT_TRANSACTIONS,
113+
-1L,
114+
)
112115

113-
is HomeNavigationDestination.ApplyLoan ->
114-
navController.navigateToLoanApplicationGraph()
116+
is HomeNavigationDestination.ApplyLoan ->
117+
navController.navigateToLoanApplicationGraph()
115118

116-
is HomeNavigationDestination.ApplySavings ->
117-
navController.navigateToSavingsApplicationGraph()
119+
is HomeNavigationDestination.ApplySavings ->
120+
navController.navigateToSavingsApplicationGraph()
118121

119-
is HomeNavigationDestination.ApplyShare ->
120-
navController.navigateToShareApplicationGraph()
121-
}
122-
}
122+
is HomeNavigationDestination.ApplyShare ->
123+
navController.navigateToShareApplicationGraph()
124+
}
125+
},
126+
127+
tptNavigator = { destination ->
128+
when (destination) {
129+
TptNavigationDestination.Notification -> navController.navigateToNotificationScreen()
130+
131+
is TptNavigationDestination.TransferProcess -> {
132+
navController.navigateToTransferProcessScreen(
133+
destination.payload,
134+
TransferType.TPT,
135+
TransferSuccessDestination.TRANSFER_TAB.name,
136+
)
137+
}
138+
else -> {
139+
navController.navigateToManualBeneficiaryAddScreen()
140+
}
141+
}
142+
},
143+
)
123144

124145
notificationDestination(
125146
navigateBack = navController::popBackStack,
@@ -242,23 +263,12 @@ internal fun NavGraphBuilder.authenticatedGraph(
242263
TransferSuccessDestination.SAVINGS_ACCOUNT -> Constants.NAVIGATE_BACK_TO_SAVINGS
243264
TransferSuccessDestination.LOAN_ACCOUNT -> Constants.NAVIGATE_BACK_TO_LOAN
244265
TransferSuccessDestination.HOME -> ""
266+
TransferSuccessDestination.TRANSFER_TAB -> Constants.TRANSFER_TAB
245267
},
246268
)
247269
},
248270
)
249271

250-
thirdPartyTransferNavGraph(
251-
navigateBack = navController::popBackStack,
252-
addBeneficiary = { },
253-
reviewTransfer = { transferPayload, transferType, transferDestination ->
254-
navController.navigateToTransferProcessScreen(
255-
transferPayload,
256-
transferType,
257-
transferDestination.name,
258-
)
259-
},
260-
)
261-
262272
transferProcessDestination(
263273
navigateBack = navController::popBackStack,
264274
navigateToAuthenticateScreen = navController::navigateToVerifyPasscodeScreen,

cmp-navigation/src/commonMain/kotlin/cmp/navigation/authenticatednavbar/AuthenticatedNavBarTabItem.kt

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ import org.mifos.mobile.core.designsystem.icon.MifosIcons
1616
import org.mifos.mobile.core.ui.navigation.NavigationItem
1717
import org.mifos.mobile.feature.home.navigation.HomeRoute
1818
import org.mifos.mobile.feature.settings.navigation.SettingsNavGraphRoute
19+
import org.mifos.mobile.feature.third.party.transfer.navigation.ThirdPartyTransferNavGraphRoute
1920
import org.mifos.mobile.navigation.generated.resources.Res
2021
import org.mifos.mobile.navigation.generated.resources.home
2122
import org.mifos.mobile.navigation.generated.resources.profile
23+
import org.mifos.mobile.navigation.generated.resources.transfer
2224

2325
sealed class AuthenticatedNavBarTabItem : NavigationItem {
2426

@@ -41,22 +43,22 @@ sealed class AuthenticatedNavBarTabItem : NavigationItem {
4143

4244
// TODO Add Top level destinations here
4345

44-
// data object TransferTab : AuthenticatedNavBarTabItem() {
45-
// override val iconResSelected: ImageVector
46-
// get() = MifosIcons.TransferTab
47-
// override val iconRes: ImageVector
48-
// get() = MifosIcons.TransferTab
49-
// override val labelRes: StringResource
50-
// get() = Res.string.transfer
51-
// override val contentDescriptionRes: StringResource
52-
// get() = Res.string.transfer
53-
// override val graphRoute: String
54-
// get() = transferNavRoute.toObjectNavigationRoute()
55-
// override val startDestinationRoute: String
56-
// get() = transferNavRoute.toObjectNavigationRoute()
57-
// override val testTag: String
58-
// get() = "TransferTab"
59-
// }
46+
data object TransferTab : AuthenticatedNavBarTabItem() {
47+
override val iconResSelected: ImageVector
48+
get() = MifosIcons.MoneyHand
49+
override val iconRes: ImageVector
50+
get() = MifosIcons.MoneyHand
51+
override val labelRes: StringResource
52+
get() = Res.string.transfer
53+
override val contentDescriptionRes: StringResource
54+
get() = Res.string.transfer
55+
override val graphRoute: String
56+
get() = ThirdPartyTransferNavGraphRoute.toObjectNavigationRoute()
57+
override val startDestinationRoute: String
58+
get() = ThirdPartyTransferNavGraphRoute.toObjectNavigationRoute()
59+
override val testTag: String
60+
get() = "TransferTab"
61+
}
6062

6163
data object ProfileTab : AuthenticatedNavBarTabItem() {
6264
override val iconResSelected: ImageVector

cmp-navigation/src/commonMain/kotlin/cmp/navigation/authenticatednavbar/AuthenticatedNavbarNavigation.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import androidx.navigation.NavOptions
1717
import kotlinx.serialization.Serializable
1818
import org.mifos.mobile.core.ui.composableWithStayTransitions
1919
import org.mifos.mobile.feature.home.navigation.HomeNavigator
20+
import org.mifos.mobile.feature.third.party.transfer.navigation.TptNavigator
2021

2122
@Serializable
2223
data object AuthenticatedNavbarRoute
@@ -27,10 +28,13 @@ internal fun NavController.navigateToAuthenticatedNavBar(navOptions: NavOptions?
2728

2829
internal fun NavGraphBuilder.authenticatedNavbarGraph(
2930
homeNavigator: HomeNavigator,
31+
tptNavigator: TptNavigator,
3032
) {
3133
composableWithStayTransitions<AuthenticatedNavbarRoute> {
3234
AuthenticatedNavbarNavigationScreen(
3335
homeNavigator = homeNavigator,
36+
tptNavigator = tptNavigator,
37+
3438
)
3539
}
3640
}

cmp-navigation/src/commonMain/kotlin/cmp/navigation/authenticatednavbar/AuthenticatedNavbarNavigationScreen.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,16 @@ import org.mifos.mobile.feature.home.navigation.homeDestination
4646
import org.mifos.mobile.feature.home.navigation.navigateToHomeScreen
4747
import org.mifos.mobile.feature.settings.navigation.navigateToSettingsGraph
4848
import org.mifos.mobile.feature.settings.navigation.settingsGraph
49+
import org.mifos.mobile.feature.third.party.transfer.navigation.TptNavigator
50+
import org.mifos.mobile.feature.third.party.transfer.navigation.navigateToTptGraph
51+
import org.mifos.mobile.feature.third.party.transfer.navigation.tptGraphDestination
4952
import org.mifos.mobile.navigation.generated.resources.Res
5053
import org.mifos.mobile.navigation.generated.resources.not_connected
5154

5255
@Composable
5356
internal fun AuthenticatedNavbarNavigationScreen(
5457
homeNavigator: HomeNavigator,
58+
tptNavigator: TptNavigator,
5559
modifier: Modifier = Modifier,
5660
navController: NavHostController = rememberMifosNavController(
5761
name = "AuthenticatedNavbarScreen",
@@ -72,6 +76,12 @@ internal fun AuthenticatedNavbarNavigationScreen(
7276
}
7377
}
7478

79+
AuthenticatedNavBarEvent.NavigateToThirdPartyTransferScreen -> {
80+
navigateToTabOrRoot(tabToNavigateTo = event.tab) {
81+
navigateToTptGraph(navOptions = it)
82+
}
83+
}
84+
7585
AuthenticatedNavBarEvent.NavigateToUserProfileScreen -> {
7686
navigateToTabOrRoot(tabToNavigateTo = event.tab) {
7787
navigateToSettingsGraph(navOptions = it)
@@ -103,20 +113,23 @@ internal fun AuthenticatedNavbarNavigationScreen(
103113
{ viewModel.trySendAction(it) }
104114
},
105115
homeNavigator = homeNavigator,
116+
tptNavigator = tptNavigator,
106117
)
107118
}
108119

109120
@Composable
110121
internal fun AuthenticatedNavbarNavigationScreenContent(
111122
navController: NavHostController,
112123
homeNavigator: HomeNavigator,
124+
tptNavigator: TptNavigator,
113125
modifier: Modifier = Modifier,
114126
snackbarHostState: SnackbarHostState = remember { SnackbarHostState() },
115127
onAction: (AuthenticatedNavBarAction) -> Unit,
116128
) {
117129
val navBackStackEntry by navController.currentBackStackEntryAsState()
118130
val navigationItems = persistentListOf<NavigationItem>(
119131
AuthenticatedNavBarTabItem.HomeTab,
132+
AuthenticatedNavBarTabItem.TransferTab,
120133
AuthenticatedNavBarTabItem.ProfileTab,
121134
)
122135

@@ -137,6 +150,10 @@ internal fun AuthenticatedNavbarNavigationScreenContent(
137150
is AuthenticatedNavBarTabItem.ProfileTab -> {
138151
onAction(AuthenticatedNavBarAction.ProfileTabClick)
139152
}
153+
154+
is AuthenticatedNavBarTabItem.TransferTab -> {
155+
onAction(AuthenticatedNavBarAction.TransferTabClick)
156+
}
140157
}
141158
},
142159
shouldShowNavigation = navigationItems.any {
@@ -162,6 +179,10 @@ internal fun AuthenticatedNavbarNavigationScreenContent(
162179
// TODO Add top level destination screens
163180
homeDestination(onNavigate = homeNavigator)
164181

182+
tptGraphDestination(
183+
onNavigate = tptNavigator,
184+
)
185+
165186
settingsGraph(
166187
navController = navController,
167188
)

cmp-navigation/src/commonMain/kotlin/cmp/navigation/authenticatednavbar/AuthenticatedNavbarNavigationViewModel.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,19 @@ internal class AuthenticatedNavbarNavigationViewModel(
3838
is AuthenticatedNavBarAction.Internal -> handleInternalAction(action)
3939

4040
AuthenticatedNavBarAction.ProfileTabClick -> handleProfileTabClicked()
41+
42+
AuthenticatedNavBarAction.TransferTabClick -> handleTransferTabClicked()
4143
}
4244
}
4345

4446
private fun handleVaultTabClicked() {
4547
sendEvent(AuthenticatedNavBarEvent.NavigateToHomeScreen)
4648
}
4749

50+
private fun handleTransferTabClicked() {
51+
sendEvent(AuthenticatedNavBarEvent.NavigateToThirdPartyTransferScreen)
52+
}
53+
4854
private fun handleProfileTabClicked() {
4955
sendEvent(AuthenticatedNavBarEvent.NavigateToUserProfileScreen)
5056
}
@@ -65,6 +71,8 @@ internal sealed class AuthenticatedNavBarAction {
6571

6672
data object ProfileTabClick : AuthenticatedNavBarAction()
6773

74+
data object TransferTabClick : AuthenticatedNavBarAction()
75+
6876
sealed class Internal : AuthenticatedNavBarAction() {
6977
data class UserStateUpdateReceive(val appSettings: AppSettings?) : Internal()
7078
}
@@ -78,6 +86,10 @@ internal sealed class AuthenticatedNavBarEvent {
7886
override val tab: AuthenticatedNavBarTabItem = AuthenticatedNavBarTabItem.HomeTab
7987
}
8088

89+
data object NavigateToThirdPartyTransferScreen : AuthenticatedNavBarEvent() {
90+
override val tab: AuthenticatedNavBarTabItem = AuthenticatedNavBarTabItem.TransferTab
91+
}
92+
8193
data object NavigateToUserProfileScreen : AuthenticatedNavBarEvent() {
8294
override val tab: AuthenticatedNavBarTabItem = AuthenticatedNavBarTabItem.ProfileTab
8395
}

core/common/src/commonMain/kotlin/org/mifos/mobile/core/common/Constants.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,5 @@ object Constants {
114114

115115
const val APPLY_SAVINGS = "apply_savings"
116116
const val APPLY_SHARE = "apply_share"
117+
const val TRANSFER_TAB = "transfer_tab"
117118
}

core/model/src/commonMain/kotlin/org/mifos/mobile/core/model/entity/TransferSuccessDestination.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ enum class TransferSuccessDestination {
1313
SAVINGS_ACCOUNT,
1414
LOAN_ACCOUNT,
1515
HOME,
16+
TRANSFER_TAB,
1617
}

core/model/src/commonMain/kotlin/org/mifos/mobile/core/model/entity/payload/ReviewTransferPayload.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
*/
1010
package org.mifos.mobile.core.model.entity.payload
1111

12+
import kotlinx.serialization.Serializable
1213
import org.mifos.mobile.core.model.entity.templates.account.AccountOption
1314

15+
@Serializable
1416
data class ReviewTransferPayload(
1517
val payToAccount: AccountOption? = null,
1618
val payFromAccount: AccountOption? = null,

core/model/src/commonMain/kotlin/org/mifos/mobile/core/model/enums/AccountType.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ package org.mifos.mobile.core.model.enums
1414
* On 24/03/17.
1515
*/
1616

17-
enum class AccountType {
17+
enum class AccountType(val value: String) {
1818

19-
SAVINGS,
19+
SAVINGS("Savings Account"),
2020

21-
LOAN,
21+
LOAN("Loan Account"),
2222

23-
SHARE,
23+
SHARE("Share Account"),
2424
}

0 commit comments

Comments
 (0)