Skip to content

Commit 274472e

Browse files
refactor: integrate savings transfer & deposit flow (#2883)
Co-authored-by: revanthkumarJ <[email protected]>
1 parent a2b304b commit 274472e

File tree

15 files changed

+196
-51
lines changed

15 files changed

+196
-51
lines changed

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

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import cmp.navigation.authenticatednavbar.AuthenticatedNavbarRoute
1919
import cmp.navigation.authenticatednavbar.authenticatedNavbarGraph
2020
import kotlinx.serialization.Serializable
2121
import org.mifos.mobile.core.common.Constants
22+
import org.mifos.mobile.core.model.entity.TransferSuccessDestination
2223
import org.mifos.mobile.core.ui.utils.ShareUtils.callHelpline
2324
import org.mifos.mobile.core.ui.utils.ShareUtils.mailHelpline
2425
import org.mifos.mobile.feature.accounts.accountTransactions.accountTransactionsDestination
@@ -50,10 +51,15 @@ import org.mifos.mobile.feature.qr.navigation.navigateToQrReaderScreen
5051
import org.mifos.mobile.feature.qr.navigation.qrNavGraph
5152
import org.mifos.mobile.feature.recent.transaction.navigation.navigateToRecentTransactionScreen
5253
import org.mifos.mobile.feature.recent.transaction.navigation.recentTransactionNavGraph
54+
import org.mifos.mobile.feature.savings.navigation.navigateToSavingsMakeTransfer
55+
import org.mifos.mobile.feature.savings.navigation.oldSavingsNavGraph
5356
import org.mifos.mobile.feature.savingsaccount.navigation.savingsNavGraph
5457
import org.mifos.mobile.feature.savingsaccount.savingsAccountDetails.navigateToSavingsAccountDetailsScreen
5558
import org.mifos.mobile.feature.status.navigation.StatusNavigationRoute
5659
import org.mifos.mobile.feature.status.navigation.statusDestination
60+
import org.mifos.mobile.feature.third.party.transfer.navigation.thirdPartyTransferNavGraph
61+
import org.mifos.mobile.feature.transfer.process.navigation.navigateToTransferProcessScreen
62+
import org.mifos.mobile.feature.transfer.process.navigation.transferProcessNavGraph
5763

5864
@Serializable
5965
internal data object AuthenticatedGraphRoute
@@ -121,6 +127,8 @@ internal fun NavGraphBuilder.authenticatedGraph(
121127
navigateToClientChargeScreen = navController::navigateToClientChargeScreen,
122128
navigateToStatusScreen = navController::navigateToStatusAfterUpdate,
123129
navigateToAuthenticateScreen = navController::navigateToVerifyPasscodeScreen,
130+
navigateToDepositScreen = navController::navigateToSavingsMakeTransfer,
131+
navigateToTransferScreen = navController::navigateToSavingsMakeTransfer,
124132
navigateToSavingsAccountTransactionScreen = {
125133
navController.navigateToAccountTransactionsScreen(Constants.SAVINGS_ACCOUNT, it)
126134
},
@@ -129,12 +137,18 @@ internal fun NavGraphBuilder.authenticatedGraph(
129137

130138
loanNavGraph(
131139
navController = navController,
132-
navigateToMakePaymentScreen = {},
140+
navigateToMakePaymentScreen = { args ->
141+
navController.navigateToSavingsMakeTransfer(
142+
args,
143+
)
144+
},
133145
navigateToQrCodeScreen = navController::navigateToQrDisplayScreen,
134146
navigateToClientChargeScreen = navController::navigateToClientChargeScreen,
135147
navigateToLoanAccountTransactionScreen = {
136148
navController.navigateToAccountTransactionsScreen(Constants.LOAN_ACCOUNT, it)
137149
},
150+
// navigateToDepositScreen = navController::navigateToSavingsMakeTransfer,
151+
// navigateToTransferScreen = navController::navigateToSavingsMakeTransfer,
138152
)
139153

140154
passcodeDestination(
@@ -164,6 +178,50 @@ internal fun NavGraphBuilder.authenticatedGraph(
164178
navController = navController,
165179
openBeneficiaryApplication = navController::navigateToBeneficiaryApplicationScreen,
166180
)
181+
182+
oldSavingsNavGraph(
183+
navController = navController,
184+
viewQrCode = {},
185+
viewCharges = { _, _ -> },
186+
reviewTransfer = { transferPayload, transferType, transferDestination ->
187+
navController.navigateToTransferProcessScreen(
188+
transferPayload,
189+
transferType,
190+
transferDestination,
191+
)
192+
},
193+
callHelpline = {},
194+
)
195+
196+
thirdPartyTransferNavGraph(
197+
navigateBack = navController::popBackStack,
198+
addBeneficiary = { },
199+
reviewTransfer = { transferPayload, transferType, transferDestination ->
200+
navController.navigateToTransferProcessScreen(
201+
transferPayload,
202+
transferType,
203+
transferDestination,
204+
)
205+
},
206+
)
207+
208+
transferProcessNavGraph(
209+
navigateBack = navController::popBackStack,
210+
onTransferSuccessNavigate = { destination ->
211+
println("getting destination from handle $destination")
212+
when (destination) {
213+
TransferSuccessDestination.HOME -> navController.navigateUpToAuthenticatedNavbarRoot()
214+
TransferSuccessDestination.LOAN_ACCOUNT ->
215+
navController.navigateToAccountsScreen(
216+
Constants.LOAN_ACCOUNT,
217+
)
218+
219+
TransferSuccessDestination.SAVINGS_ACCOUNT -> navController.navigateToAccountsScreen(
220+
Constants.SAVINGS_ACCOUNT,
221+
)
222+
}
223+
},
224+
)
167225
}
168226
}
169227

core/data/src/commonMain/kotlin/org/mifos/mobile/core/data/repositoryImpl/TransferRepositoryImp.kt

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
package org.mifos.mobile.core.data.repositoryImpl
1111

12+
import io.ktor.client.plugins.ClientRequestException
1213
import io.ktor.client.statement.bodyAsText
1314
import kotlinx.coroutines.CoroutineDispatcher
1415
import kotlinx.coroutines.withContext
@@ -35,18 +36,12 @@ class TransferRepositoryImp(
3536
TransferType.SELF -> dataManager.savingAccountsListApi.makeTransfer(payload)
3637
else -> dataManager.thirdPartyTransferApi.makeTransfer(payload)
3738
}
38-
if (response.status.value != 200) {
39-
val errorMessage = extractErrorMessage(response)
40-
return@withContext DataState.Error(
41-
Exception(errorMessage),
42-
null,
43-
)
44-
}
4539

4640
val transferResponse = Json.decodeFromString<TransferResponse>(response.bodyAsText())
4741
DataState.Success(transferResponse.resourceId.toString())
48-
} catch (e: Exception) {
49-
DataState.Error(e, null)
42+
} catch (e: ClientRequestException) {
43+
val errorMessage = extractErrorMessage(e.response)
44+
DataState.Error(Exception(errorMessage), null)
5045
}
5146
}
5247
}

feature/loan-account/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ kotlin {
2525
implementation(compose.material3)
2626
implementation(compose.ui)
2727
implementation(compose.components.uiToolingPreview)
28+
implementation(libs.kotlinx.serialization.json)
2829

2930
api(projects.core.ui)
3031
api(projects.core.model)

feature/loan-account/src/commonMain/kotlin/org/mifos/mobile/feature/loanaccount/loanAccountDetails/LoanAccountDetailsNavigation.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import androidx.navigation.NavController
1515
import androidx.navigation.NavGraphBuilder
1616
import androidx.navigation.NavOptions
1717
import kotlinx.serialization.Serializable
18+
import org.mifos.mobile.core.model.entity.TransferArgs
1819
import org.mifos.mobile.core.ui.composableWithSlideTransitions
1920

2021
@Serializable
@@ -27,7 +28,7 @@ fun NavController.navigateToLoanAccountDetailsScreen(accountId: Long, navOptions
2728

2829
fun NavGraphBuilder.loanAccountDetailsDestination(
2930
navigateBack: () -> Unit,
30-
navigateToMakePaymentScreen: () -> Unit,
31+
navigateToMakePaymentScreen: (args: TransferArgs) -> Unit,
3132
navigateToRepaymentScheduleScreen: (Long) -> Unit,
3233
navigateToLoanSummaryScreen: (Long) -> Unit,
3334
navigateToQrCodeScreen: (String) -> Unit,

feature/loan-account/src/commonMain/kotlin/org/mifos/mobile/feature/loanaccount/loanAccountDetails/LoanAccountDetailsScreen.kt

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import androidx.compose.ui.Modifier
2929
import androidx.compose.ui.unit.dp
3030
import androidx.lifecycle.compose.collectAsStateWithLifecycle
3131
import kotlinx.collections.immutable.ImmutableList
32+
import kotlinx.serialization.encodeToString
33+
import kotlinx.serialization.json.Json
3234
import mifos_mobile.feature.loan_account.generated.resources.Res
3335
import mifos_mobile.feature.loan_account.generated.resources.feature_account_details_action
3436
import mifos_mobile.feature.loan_account.generated.resources.feature_account_details_top_bar_title
@@ -39,12 +41,17 @@ import org.jetbrains.compose.resources.stringResource
3941
import org.jetbrains.compose.ui.tooling.preview.Preview
4042
import org.koin.compose.viewmodel.koinViewModel
4143
import org.mifos.mobile.core.common.Constants
44+
import org.mifos.mobile.core.common.Constants.TRANSFER_PAY_TO
4245
import org.mifos.mobile.core.designsystem.component.MifosElevatedScaffold
4346
import org.mifos.mobile.core.designsystem.theme.AppColors
4447
import org.mifos.mobile.core.designsystem.theme.DesignToken
4548
import org.mifos.mobile.core.designsystem.theme.MifosMobileTheme
4649
import org.mifos.mobile.core.designsystem.theme.MifosTypography
50+
import org.mifos.mobile.core.model.entity.AccountDetails
51+
import org.mifos.mobile.core.model.entity.TransferArgs
52+
import org.mifos.mobile.core.model.entity.TransferSuccessDestination
4753
import org.mifos.mobile.core.model.enums.ChargeType
54+
import org.mifos.mobile.core.model.enums.TransferType
4855
import org.mifos.mobile.core.ui.component.MifosActionCard
4956
import org.mifos.mobile.core.ui.component.MifosErrorComponent
5057
import org.mifos.mobile.core.ui.component.MifosLabelValueCard
@@ -57,7 +64,7 @@ import org.mifos.mobile.feature.loanaccount.component.loanAccountActions
5764
@Composable
5865
internal fun LoanAccountDetailsScreen(
5966
navigateBack: () -> Unit,
60-
navigateToMakePaymentScreen: () -> Unit,
67+
navigateToMakePaymentScreen: (args: TransferArgs) -> Unit,
6168
navigateToRepaymentScheduleScreen: (Long) -> Unit,
6269
navigateToLoanSummaryScreen: (Long) -> Unit,
6370
navigateToQrCodeScreen: (String) -> Unit,
@@ -80,9 +87,22 @@ internal fun LoanAccountDetailsScreen(
8087
navigateToLoanAccountTransactionScreen(uiState.accountId)
8188
}
8289

90+
// TODO: move this to viewmodel after making new screens
8391
event.route == Constants.MAKE_PAYMENT -> {
84-
navigateToMakePaymentScreen.invoke()
92+
val transferArgs = TransferArgs(
93+
transferPayloadJson = Json.encodeToString(
94+
AccountDetails(
95+
accountId = uiState.accountId,
96+
outstandingBalance = uiState.totalOutStandingBalance ?: 1.00,
97+
transferType = TRANSFER_PAY_TO,
98+
transferTarget = TransferType.SELF,
99+
transferSuccessDestination = TransferSuccessDestination.LOAN_ACCOUNT,
100+
),
101+
),
102+
)
103+
navigateToMakePaymentScreen(transferArgs)
85104
}
105+
86106
event.route == Constants.REPAYMENT_SCHEDULE -> {
87107
navigateToRepaymentScheduleScreen(uiState.accountId)
88108
}

feature/loan-account/src/commonMain/kotlin/org/mifos/mobile/feature/loanaccount/loanAccountDetails/LoanAccountDetailsViewModel.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ internal class LoanAccountDetailsViewModel(
181181
displayItems = displayItems,
182182
transactionList = transactions,
183183
dialogState = null,
184+
totalOutStandingBalance = loan?.summary?.totalOutstanding,
184185
)
185186
}
186187
}
@@ -200,6 +201,7 @@ internal class LoanAccountDetailsViewModel(
200201
@Immutable
201202
internal data class LoanAccountDetailsState(
202203
val accountId: Long = -1L,
204+
val totalOutStandingBalance: Double? = null,
203205
val isEmpty: Boolean = true,
204206
val clientName: String? = "",
205207
val submissionDate: String? = "",

feature/loan-account/src/commonMain/kotlin/org/mifos/mobile/feature/loanaccount/navigation/LoanNavigation.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import androidx.navigation.NavGraphBuilder
1616
import androidx.navigation.NavOptions
1717
import androidx.navigation.navigation
1818
import kotlinx.serialization.Serializable
19+
import org.mifos.mobile.core.model.entity.TransferArgs
1920
import org.mifos.mobile.feature.loanaccount.loanAccount.LoanAccountRoute
2021
import org.mifos.mobile.feature.loanaccount.loanAccount.loanAccountDestination
2122
import org.mifos.mobile.feature.loanaccount.loanAccountDetails.loanAccountDetailsDestination
@@ -32,7 +33,7 @@ fun NavController.navigateToLoanGraph(navOptions: NavOptions? = null) =
3233

3334
fun NavGraphBuilder.loanNavGraph(
3435
navController: NavController,
35-
navigateToMakePaymentScreen: () -> Unit,
36+
navigateToMakePaymentScreen: (args: TransferArgs) -> Unit,
3637
navigateToQrCodeScreen: (String) -> Unit,
3738
navigateToClientChargeScreen: (String, Long) -> Unit,
3839
navigateToLoanAccountTransactionScreen: (Long) -> Unit,

feature/savings-account/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ kotlin {
2626
implementation(compose.ui)
2727
implementation(compose.components.resources)
2828
implementation(compose.components.uiToolingPreview)
29+
implementation(libs.kotlinx.serialization.json)
2930

3031
api(projects.core.ui)
3132
api(projects.core.model)

feature/savings-account/src/commonMain/kotlin/org/mifos/mobile/feature/savingsaccount/navigation/SavingsNavigation.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import androidx.navigation.NavGraphBuilder
1616
import androidx.navigation.NavOptions
1717
import androidx.navigation.navigation
1818
import kotlinx.serialization.Serializable
19+
import org.mifos.mobile.core.model.entity.TransferArgs
1920
import org.mifos.mobile.feature.savingsaccount.savingsAccount.SavingsAccountRoute
2021
import org.mifos.mobile.feature.savingsaccount.savingsAccount.savingsAccountDestination
2122
import org.mifos.mobile.feature.savingsaccount.savingsAccountDetails.savingsAccountDetailsDestination
@@ -33,6 +34,8 @@ fun NavController.navigateToSavingsGraph(navOptions: NavOptions? = null) =
3334
fun NavGraphBuilder.savingsNavGraph(
3435
navController: NavController,
3536
navigateToClientChargeScreen: (String, Long) -> Unit,
37+
navigateToTransferScreen: (TransferArgs) -> Unit,
38+
navigateToDepositScreen: (TransferArgs) -> Unit,
3639
navigateToAuthenticateScreen: () -> Unit,
3740
navigateToStatusScreen: (String, String, String, String, String) -> Unit,
3841
navigateToSavingsAccountTransactionScreen: (Long) -> Unit,
@@ -52,6 +55,8 @@ fun NavGraphBuilder.savingsNavGraph(
5255
navigateToSavingsAccountTransactionScreen = navigateToSavingsAccountTransactionScreen,
5356
navigateToWithdrawScreen = navController::navigateToSavingsAccountWithdrawScreen,
5457
navigateToQrCodeScreen = navigateToQrCodeScreen,
58+
navigateToTransferScreen = navigateToTransferScreen,
59+
navigateToDepositScreen = navigateToDepositScreen,
5560
)
5661

5762
savingsAccountUpdateDestination(

feature/savings-account/src/commonMain/kotlin/org/mifos/mobile/feature/savingsaccount/savingsAccountDetails/SavingsAccountDetailsNavigation.kt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ import androidx.navigation.NavController
1515
import androidx.navigation.NavGraphBuilder
1616
import androidx.navigation.NavOptions
1717
import kotlinx.serialization.Serializable
18+
import kotlinx.serialization.encodeToString
19+
import kotlinx.serialization.json.Json
20+
import org.mifos.mobile.core.common.Constants.TRANSFER_PAY_FROM
21+
import org.mifos.mobile.core.common.Constants.TRANSFER_PAY_TO
22+
import org.mifos.mobile.core.model.entity.AccountDetails
23+
import org.mifos.mobile.core.model.entity.TransferArgs
24+
import org.mifos.mobile.core.model.entity.TransferSuccessDestination
25+
import org.mifos.mobile.core.model.enums.TransferType
1826
import org.mifos.mobile.core.ui.composableWithSlideTransitions
1927

2028
@Serializable
@@ -27,6 +35,8 @@ fun NavController.navigateToSavingsAccountDetailsScreen(accountId: Long, navOpti
2735

2836
fun NavGraphBuilder.savingsAccountDetailsDestination(
2937
navigateBack: () -> Unit,
38+
navigateToDepositScreen: (TransferArgs) -> Unit,
39+
navigateToTransferScreen: (TransferArgs) -> Unit,
3040
navigateToClientChargeScreen: (String, Long) -> Unit,
3141
navigateToUpdateScreen: (Long, String?, String?, String?, String?) -> Unit,
3242
navigateToSavingsAccountTransactionScreen: (Long) -> Unit,
@@ -41,6 +51,32 @@ fun NavGraphBuilder.savingsAccountDetailsDestination(
4151
navigateToWithdrawScreen = navigateToWithdrawScreen,
4252
navigateToSavingsAccountTransactionScreen = navigateToSavingsAccountTransactionScreen,
4353
navigateToQrCodeScreen = navigateToQrCodeScreen,
54+
navigateToDepositScreen = {
55+
val args = TransferArgs(
56+
transferPayloadJson = Json.encodeToString(
57+
AccountDetails(
58+
accountId = it,
59+
transferType = TRANSFER_PAY_TO,
60+
transferTarget = TransferType.TPT,
61+
transferSuccessDestination = TransferSuccessDestination.SAVINGS_ACCOUNT,
62+
),
63+
),
64+
)
65+
navigateToDepositScreen(args)
66+
},
67+
navigateToTransferScreen = {
68+
val args = TransferArgs(
69+
transferPayloadJson = Json.encodeToString(
70+
AccountDetails(
71+
accountId = it,
72+
transferType = TRANSFER_PAY_FROM,
73+
transferTarget = TransferType.TPT,
74+
transferSuccessDestination = TransferSuccessDestination.SAVINGS_ACCOUNT,
75+
),
76+
),
77+
)
78+
navigateToTransferScreen(args)
79+
},
4480
)
4581
}
4682
}

0 commit comments

Comments
 (0)