@@ -22,6 +22,7 @@ import dagger.hilt.android.lifecycle.HiltViewModel
2222import io.reactivex.rxjava3.core.Completable
2323import io.reactivex.rxjava3.schedulers.Schedulers
2424import kotlinx.coroutines.delay
25+ import kotlinx.coroutines.flow.filter
2526import kotlinx.coroutines.flow.filterIsInstance
2627import kotlinx.coroutines.flow.flatMapLatest
2728import kotlinx.coroutines.flow.launchIn
@@ -52,7 +53,7 @@ class GetKinSheetViewModel @Inject constructor(
5253 )
5354
5455 sealed interface Event {
55- data class OnGetEligibilityChanged (val eligible : Boolean ) : Event
56+ data class OnGetEligibilityChanged (val eligible : Boolean , val fromEvent : Boolean = false ) : Event
5657 data class OnGiveEligibilityChanged (val eligible : Boolean ) : Event
5758 data class OnLoadingChanged (val loading : Boolean ) : Event
5859
@@ -103,14 +104,13 @@ class GetKinSheetViewModel @Inject constructor(
103104 }
104105 .catchSafely(
105106 action = { amount ->
106- dispatchEvent(Event .OnKinRequestSuccessful (amount))
107- dispatchEvent(Event .OnGetEligibilityChanged (false ))
107+ dispatchEvent(Event .OnGetEligibilityChanged (eligible = false , fromEvent = true ))
108108 dispatchEvent(Event .OnLoadingChanged (false ))
109+ dispatchEvent(Event .OnKinRequestSuccessful (amount))
109110 },
110111 onFailure = {
111112 if (it is TransactionRepository .AirdropException .AlreadyClaimedException ) {
112- prefsRepository.set(PrefsBool .IS_ELIGIBLE_GET_FIRST_KIN_AIRDROP , false )
113- dispatchEvent(Event .OnGetEligibilityChanged (false ))
113+ dispatchEvent(Event .OnGetEligibilityChanged (eligible = false , fromEvent = true ))
114114 } else {
115115 TopBarManager .showMessage(
116116 resources.getString(R .string.title_failed),
@@ -129,6 +129,13 @@ class GetKinSheetViewModel @Inject constructor(
129129 }
130130 .launchIn(viewModelScope)
131131
132+ eventFlow
133+ .filterIsInstance<Event .OnGetEligibilityChanged >()
134+ .filter { it.fromEvent }
135+ .map { it.eligible }
136+ .onEach { prefsRepository.set(PrefsBool .IS_ELIGIBLE_GET_FIRST_KIN_AIRDROP , it) }
137+ .launchIn(viewModelScope)
138+
132139 eventFlow
133140 .filterIsInstance<Event .OnKinRequestSuccessful >()
134141 .onEach { delay(300 .milliseconds) }
0 commit comments