@@ -25,6 +25,7 @@ import kotlinx.coroutines.flow.onEach
25
25
import kotlinx.coroutines.flow.stateIn
26
26
import kotlinx.coroutines.flow.update
27
27
import kotlinx.coroutines.launch
28
+ import kotlinx.serialization.Contextual
28
29
import kotlinx.serialization.Serializable
29
30
import mobile_wallet.feature.send_money.generated.resources.Res
30
31
import 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
33
34
import mobile_wallet.feature.send_money.generated.resources.feature_send_money_error_requesting_payment_qr_but_found
34
35
import mobile_wallet.feature.send_money.generated.resources.feature_send_money_error_requesting_payment_qr_data_missing
35
36
import org.jetbrains.compose.resources.StringResource
36
- import org.jetbrains.compose.resources.getString
37
37
import org.mifospay.core.common.DataState
38
38
import org.mifospay.core.common.getSerialized
39
39
import org.mifospay.core.common.setSerialized
@@ -45,7 +45,6 @@ import org.mifospay.core.model.utils.toAccount
45
45
import org.mifospay.core.ui.utils.BaseViewModel
46
46
import org.mifospay.feature.send.money.SendMoneyAction.HandleRequestData
47
47
import org.mifospay.feature.send.money.SendMoneyState.DialogState.Error
48
- import org.mifospay.feature.send.money.SendMoneyState.DialogState.ValidationError
49
48
50
49
class SendMoneyViewModel (
51
50
private val scanner : QrScanner ,
@@ -170,7 +169,7 @@ class SendMoneyViewModel(
170
169
171
170
private fun updateErrorState (res : StringResource ) {
172
171
mutableStateFlow.update {
173
- it.copy(dialogState = ValidationError (res))
172
+ it.copy(dialogState = Error . ResourceMessage (res))
174
173
}
175
174
}
176
175
@@ -187,17 +186,19 @@ class SendMoneyViewModel(
187
186
)
188
187
}
189
188
} catch (e: Exception ) {
190
- val message = if (action.requestData.isNotEmpty()) {
191
- getString (
189
+ val errorState = if (action.requestData.isNotEmpty()) {
190
+ Error . GenericResourceMessage (
192
191
Res .string.feature_send_money_error_requesting_payment_qr_but_found,
193
- action.requestData,
192
+ listOf ( action.requestData) ,
194
193
)
195
194
} 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)
197
196
}
198
197
199
198
mutableStateFlow.update {
200
- it.copy(dialogState = Error (message))
199
+ it.copy(
200
+ dialogState = errorState,
201
+ )
201
202
}
202
203
}
203
204
}
@@ -234,9 +235,16 @@ data class SendMoneyState(
234
235
data object Loading : DialogState
235
236
236
237
@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
+ }
240
248
}
241
249
}
242
250
0 commit comments