@@ -25,6 +25,7 @@ import kotlinx.coroutines.flow.onEach
2525import kotlinx.coroutines.flow.stateIn
2626import kotlinx.coroutines.flow.update
2727import kotlinx.coroutines.launch
28+ import kotlinx.serialization.Contextual
2829import kotlinx.serialization.Serializable
2930import mobile_wallet.feature.send_money.generated.resources.Res
3031import mobile_wallet.feature.send_money.generated.resources.feature_send_money_error_account_cannot_be_empty
@@ -33,7 +34,6 @@ import mobile_wallet.feature.send_money.generated.resources.feature_send_money_e
3334import mobile_wallet.feature.send_money.generated.resources.feature_send_money_error_requesting_payment_qr_but_found
3435import mobile_wallet.feature.send_money.generated.resources.feature_send_money_error_requesting_payment_qr_data_missing
3536import org.jetbrains.compose.resources.StringResource
36- import org.jetbrains.compose.resources.getString
3737import org.mifospay.core.common.DataState
3838import org.mifospay.core.common.getSerialized
3939import org.mifospay.core.common.setSerialized
@@ -45,7 +45,6 @@ import org.mifospay.core.model.utils.toAccount
4545import org.mifospay.core.ui.utils.BaseViewModel
4646import org.mifospay.feature.send.money.SendMoneyAction.HandleRequestData
4747import org.mifospay.feature.send.money.SendMoneyState.DialogState.Error
48- import org.mifospay.feature.send.money.SendMoneyState.DialogState.ValidationError
4948
5049class SendMoneyViewModel (
5150 private val scanner : QrScanner ,
@@ -170,7 +169,7 @@ class SendMoneyViewModel(
170169
171170 private fun updateErrorState (res : StringResource ) {
172171 mutableStateFlow.update {
173- it.copy(dialogState = ValidationError (res))
172+ it.copy(dialogState = Error . ResourceMessage (res))
174173 }
175174 }
176175
@@ -187,17 +186,19 @@ class SendMoneyViewModel(
187186 )
188187 }
189188 } catch (e: Exception ) {
190- val message = if (action.requestData.isNotEmpty()) {
191- getString (
189+ val errorState = if (action.requestData.isNotEmpty()) {
190+ Error . GenericResourceMessage (
192191 Res .string.feature_send_money_error_requesting_payment_qr_but_found,
193- action.requestData,
192+ listOf ( action.requestData) ,
194193 )
195194 } else {
196- getString (Res .string.feature_send_money_error_requesting_payment_qr_data_missing)
195+ Error . ResourceMessage (Res .string.feature_send_money_error_requesting_payment_qr_data_missing)
197196 }
198197
199198 mutableStateFlow.update {
200- it.copy(dialogState = Error (message))
199+ it.copy(
200+ dialogState = errorState,
201+ )
201202 }
202203 }
203204 }
@@ -234,9 +235,16 @@ data class SendMoneyState(
234235 data object Loading : DialogState
235236
236237 @Serializable
237- data class Error (val message : String ) : DialogState
238-
239- data class ValidationError (val res : StringResource ) : DialogState
238+ sealed interface Error : DialogState {
239+ @Serializable
240+ data class ResourceMessage (@Contextual val message : StringResource ) : Error
241+
242+ @Serializable
243+ data class GenericResourceMessage (
244+ @Contextual val message : StringResource ,
245+ val args : List <String >,
246+ ) : Error
247+ }
240248 }
241249}
242250
0 commit comments