Skip to content

Commit 627d878

Browse files
biplab1niyajali
andauthored
refactor(feature:send-money): replace hardcoded strings with string resource (#1883)
Co-authored-by: Sk Niyaj Ali <[email protected]>
1 parent 126878c commit 627d878

File tree

4 files changed

+76
-21
lines changed

4 files changed

+76
-21
lines changed

feature/send-money/src/commonMain/composeResources/values/strings.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,21 @@
2121
<string name="feature_send_money_submit">Submit</string>
2222
<string name="feature_send_money_please_wait">Please wait…</string>
2323
<string name="feature_send_money_phone_number">Phone Number</string>
24+
25+
<string name="feature_send_money_oops">Oops!</string>
26+
<string name="feature_send_money_something_went_wrong">Something went wrong!</string>
27+
<string name="feature_send_money_no_accounts_found">No accounts found!</string>
28+
<string name="feature_send_money_vpa_mobile_account_number">VPA/Mobile/Account Number</string>
29+
<string name="feature_send_money_to_account">To Account</string>
30+
<string name="feature_send_money_proceed">Proceed</string>
31+
<string name="feature_send_money_bottom_bar">Bottom Bar</string>
32+
<string name="feature_send_money_scan_qr">Scan QR</string>
33+
<string name="feature_send_money_close">Close</string>
34+
<string name="feature_send_money_loading">Loading</string>
35+
<string name="feature_send_money_selected">Selected</string>
36+
<string name="feature_send_money_error_amount_cannot_be_empty">Amount cannot be empty</string>
37+
<string name="feature_send_money_error_invalid_amount">Invalid amount</string>
38+
<string name="feature_send_money_error_account_cannot_be_empty">Account cannot be empty</string>
39+
<string name="feature_send_money_error_requesting_payment_qr_but_found">Requesting payment QR but found - %1$s</string>
40+
<string name="feature_send_money_error_requesting_payment_qr_data_missing">Failed to request payment QR: required data is missing</string>
2441
</resources>

feature/send-money/src/commonMain/kotlin/org/mifospay/feature/send/money/SendMoneyScreen.kt

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,22 @@ import androidx.compose.ui.unit.dp
5656
import androidx.lifecycle.compose.collectAsStateWithLifecycle
5757
import mobile_wallet.feature.send_money.generated.resources.Res
5858
import mobile_wallet.feature.send_money.generated.resources.feature_send_money_amount
59+
import mobile_wallet.feature.send_money.generated.resources.feature_send_money_bottom_bar
60+
import mobile_wallet.feature.send_money.generated.resources.feature_send_money_close
61+
import mobile_wallet.feature.send_money.generated.resources.feature_send_money_loading
62+
import mobile_wallet.feature.send_money.generated.resources.feature_send_money_no_accounts_found
63+
import mobile_wallet.feature.send_money.generated.resources.feature_send_money_oops
64+
import mobile_wallet.feature.send_money.generated.resources.feature_send_money_proceed
65+
import mobile_wallet.feature.send_money.generated.resources.feature_send_money_scan_qr
66+
import mobile_wallet.feature.send_money.generated.resources.feature_send_money_selected
5967
import mobile_wallet.feature.send_money.generated.resources.feature_send_money_send
68+
import mobile_wallet.feature.send_money.generated.resources.feature_send_money_something_went_wrong
69+
import mobile_wallet.feature.send_money.generated.resources.feature_send_money_to_account
70+
import mobile_wallet.feature.send_money.generated.resources.feature_send_money_vpa_mobile_account_number
6071
import org.jetbrains.compose.resources.stringResource
6172
import org.koin.compose.viewmodel.koinViewModel
6273
import org.mifospay.core.common.utils.maskString
63-
import org.mifospay.core.designsystem.component.BasicDialogState
74+
import org.mifospay.core.designsystem.component.BasicDialogState.Shown
6475
import org.mifospay.core.designsystem.component.LoadingDialogState
6576
import org.mifospay.core.designsystem.component.MifosBasicDialog
6677
import org.mifospay.core.designsystem.component.MifosButton
@@ -149,7 +160,7 @@ private fun SendMoneyScreen(
149160
) {
150161
Icon(
151162
imageVector = MifosIcons.Scan,
152-
contentDescription = "Scan QR",
163+
contentDescription = stringResource(Res.string.feature_send_money_scan_qr),
153164
)
154165
}
155166
},
@@ -216,7 +227,7 @@ private fun SendMoneyBottomBar(
216227
) {
217228
AnimatedVisibility(
218229
visible = showDetails && selectedAccount != null,
219-
label = "BottomBar",
230+
label = stringResource(Res.string.feature_send_money_bottom_bar),
220231
enter = fadeIn() + slideInVertically(
221232
initialOffsetY = { fullHeight ->
222233
fullHeight / 4
@@ -242,7 +253,7 @@ private fun SendMoneyBottomBar(
242253
enabled = showDetails,
243254
modifier = Modifier.fillMaxWidth(),
244255
) {
245-
Text(text = "Proceed")
256+
Text(text = stringResource(Res.string.feature_send_money_proceed))
246257
}
247258
}
248259
}
@@ -260,7 +271,7 @@ private fun SelectedAccountCard(
260271
verticalArrangement = Arrangement.spacedBy(8.dp),
261272
) {
262273
Text(
263-
text = "To Account",
274+
text = stringResource(Res.string.feature_send_money_to_account),
264275
style = MaterialTheme.typography.labelLarge,
265276
)
266277

@@ -304,7 +315,7 @@ private fun SelectedAccountCard(
304315
) {
305316
Icon(
306317
imageVector = Icons.Default.Close,
307-
contentDescription = "Close",
318+
contentDescription = stringResource(Res.string.feature_send_money_close),
308319
)
309320
}
310321
}
@@ -374,7 +385,7 @@ private fun SendMoneyCard(
374385
)
375386

376387
MifosTextField(
377-
label = "VPA/Mobile/Account Number",
388+
label = stringResource(Res.string.feature_send_money_vpa_mobile_account_number),
378389
value = state.accountNumber,
379390
onValueChange = remember(onAction) {
380391
{ onAction(SendMoneyAction.AccountNumberChanged(it)) }
@@ -399,16 +410,16 @@ private fun LazyListScope.accountListContent(
399410
modifier = Modifier.fillParentMaxWidth(),
400411
contentAlignment = Alignment.Center,
401412
) {
402-
MifosLoadingWheel(contentDesc = "Loading")
413+
MifosLoadingWheel(contentDesc = stringResource(Res.string.feature_send_money_loading))
403414
}
404415
}
405416
}
406417

407418
is ViewState.Error -> {
408419
item {
409420
EmptyContentScreen(
410-
title = "Oops!",
411-
subTitle = "Something went wrong!",
421+
title = stringResource(Res.string.feature_send_money_oops),
422+
subTitle = stringResource(Res.string.feature_send_money_something_went_wrong),
412423
modifier = Modifier.fillParentMaxSize(),
413424
iconTint = MaterialTheme.colorScheme.error,
414425
)
@@ -418,8 +429,8 @@ private fun LazyListScope.accountListContent(
418429
is ViewState.Empty -> {
419430
item {
420431
EmptyContentScreen(
421-
title = "Oops!",
422-
subTitle = "No accounts found!",
432+
title = stringResource(Res.string.feature_send_money_oops),
433+
subTitle = stringResource(Res.string.feature_send_money_no_accounts_found),
423434
modifier = Modifier.fillParentMaxSize(),
424435
)
425436
}
@@ -477,7 +488,7 @@ private fun AccountCard(
477488
) {
478489
Icon(
479490
imageVector = MifosIcons.Check,
480-
contentDescription = "Selected",
491+
contentDescription = stringResource(Res.string.feature_send_money_selected),
481492
)
482493
}
483494
},
@@ -496,7 +507,7 @@ private fun SendMoneyDialogs(
496507
) {
497508
when (dialogState) {
498509
is SendMoneyState.DialogState.Error -> MifosBasicDialog(
499-
visibilityState = BasicDialogState.Shown(
510+
visibilityState = Shown(
500511
message = dialogState.message,
501512
),
502513
onDismissRequest = onDismissRequest,
@@ -506,6 +517,13 @@ private fun SendMoneyDialogs(
506517
visibilityState = LoadingDialogState.Shown,
507518
)
508519

520+
is SendMoneyState.DialogState.ValidationError -> MifosBasicDialog(
521+
visibilityState = Shown(
522+
message = stringResource(dialogState.res),
523+
),
524+
onDismissRequest = onDismissRequest,
525+
)
526+
509527
null -> Unit
510528
}
511529
}

feature/send-money/src/commonMain/kotlin/org/mifospay/feature/send/money/SendMoneyViewModel.kt

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ import kotlinx.coroutines.flow.stateIn
2626
import kotlinx.coroutines.flow.update
2727
import kotlinx.coroutines.launch
2828
import kotlinx.serialization.Serializable
29+
import mobile_wallet.feature.send_money.generated.resources.Res
30+
import mobile_wallet.feature.send_money.generated.resources.feature_send_money_error_account_cannot_be_empty
31+
import mobile_wallet.feature.send_money.generated.resources.feature_send_money_error_amount_cannot_be_empty
32+
import mobile_wallet.feature.send_money.generated.resources.feature_send_money_error_invalid_amount
33+
import mobile_wallet.feature.send_money.generated.resources.feature_send_money_error_requesting_payment_qr_but_found
34+
import mobile_wallet.feature.send_money.generated.resources.feature_send_money_error_requesting_payment_qr_data_missing
35+
import org.jetbrains.compose.resources.StringResource
36+
import org.jetbrains.compose.resources.getString
2937
import org.mifospay.core.common.DataState
3038
import org.mifospay.core.common.getSerialized
3139
import org.mifospay.core.common.setSerialized
@@ -37,6 +45,7 @@ import org.mifospay.core.model.utils.toAccount
3745
import org.mifospay.core.ui.utils.BaseViewModel
3846
import org.mifospay.feature.send.money.SendMoneyAction.HandleRequestData
3947
import org.mifospay.feature.send.money.SendMoneyState.DialogState.Error
48+
import org.mifospay.feature.send.money.SendMoneyState.DialogState.ValidationError
4049

4150
class SendMoneyViewModel(
4251
private val scanner: QrScanner,
@@ -138,11 +147,11 @@ class SendMoneyViewModel(
138147
}
139148

140149
private fun validateTransferFlow() = when {
141-
state.amount.isBlank() -> updateErrorState("Amount cannot be empty")
150+
state.amount.isBlank() -> updateErrorState(Res.string.feature_send_money_error_amount_cannot_be_empty)
142151

143-
state.amount.toDoubleOrNull() == null -> updateErrorState("Invalid amount")
152+
state.amount.toDoubleOrNull() == null -> updateErrorState(Res.string.feature_send_money_error_invalid_amount)
144153

145-
state.selectedAccount == null -> updateErrorState("Account cannot be empty")
154+
state.selectedAccount == null -> updateErrorState(Res.string.feature_send_money_error_account_cannot_be_empty)
146155

147156
else -> initiateTransfer()
148157
}
@@ -159,9 +168,9 @@ class SendMoneyViewModel(
159168
}
160169
}
161170

162-
private fun updateErrorState(message: String) {
171+
private fun updateErrorState(res: StringResource) {
163172
mutableStateFlow.update {
164-
it.copy(dialogState = Error(message))
173+
it.copy(dialogState = ValidationError(res))
165174
}
166175
}
167176

@@ -178,8 +187,17 @@ class SendMoneyViewModel(
178187
)
179188
}
180189
} catch (e: Exception) {
190+
val message = if (action.requestData.isNotEmpty()) {
191+
getString(
192+
Res.string.feature_send_money_error_requesting_payment_qr_but_found,
193+
action.requestData,
194+
)
195+
} else {
196+
getString(Res.string.feature_send_money_error_requesting_payment_qr_data_missing)
197+
}
198+
181199
mutableStateFlow.update {
182-
it.copy(dialogState = Error("Requesting payment QR but found - ${action.requestData}"))
200+
it.copy(dialogState = Error(message))
183201
}
184202
}
185203
}
@@ -217,6 +235,8 @@ data class SendMoneyState(
217235

218236
@Serializable
219237
data class Error(val message: String) : DialogState
238+
239+
data class ValidationError(val res: StringResource) : DialogState
220240
}
221241
}
222242

mifospay-android/prodRelease-badging.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package: name='org.mifospay' versionCode='1' versionName='2025.7.2-beta.0.10' platformBuildVersionName='15' platformBuildVersionCode='35' compileSdkVersion='35' compileSdkVersionCodename='15'
1+
package: name='org.mifospay' versionCode='1' versionName='2025.7.3-beta.0.13' platformBuildVersionName='15' platformBuildVersionCode='35' compileSdkVersion='35' compileSdkVersionCodename='15'
22
sdkVersion:'26'
33
targetSdkVersion:'34'
44
uses-permission: name='android.permission.INTERNET'

0 commit comments

Comments
 (0)