@@ -49,6 +49,7 @@ import kotlinx.coroutines.flow.combine
4949import kotlinx.coroutines.flow.debounce
5050import kotlinx.coroutines.flow.distinctUntilChanged
5151import kotlinx.coroutines.flow.drop
52+ import kotlinx.coroutines.flow.filter
5253import kotlinx.coroutines.flow.filterIsInstance
5354import kotlinx.coroutines.flow.flatMapLatest
5455import kotlinx.coroutines.flow.flowOf
@@ -137,7 +138,6 @@ class TokenInfoViewModel @Inject constructor(
137138
138139 eventFlow
139140 .filterIsInstance<Event .OnMintProvided >()
140- .distinctUntilChanged()
141141 .onEach {
142142 tokenController.getTokenMetadata(it.mint)
143143 .onSuccess { result ->
@@ -155,7 +155,7 @@ class TokenInfoViewModel @Inject constructor(
155155 eventFlow
156156 .filterIsInstance<Event .OnTokenChanged >()
157157 .distinctUntilChanged()
158- .flatMapLatest { (token, needsFunds ) ->
158+ .flatMapLatest { (token, _ ) ->
159159 combine(
160160 tokenController.balanceForToken(token.address),
161161 tokenController.appreciationForToken(token.address),
@@ -179,21 +179,22 @@ class TokenInfoViewModel @Inject constructor(
179179 null
180180 }
181181
182- localizedBalance to localizedAppreciation to needsFunds
182+ localizedBalance to localizedAppreciation
183183 }
184- }.map { (balance, appreciation, needsFunds ) ->
184+ }.onEach { (balance, appreciation) ->
185185 dispatchEvent(Event .OnBalanceUpdated (balance))
186186 dispatchEvent(Event .OnAppreciationUpdated (appreciation))
187-
188- needsFunds
189- }.take(1 )
190- .onEach {
191- if (it) {
192- dispatchEvent(Event .OpenPurchaseMethods (true ))
193- }
194187 }
195188 .launchIn(viewModelScope)
196189
190+ eventFlow
191+ .filterIsInstance<Event .OnTokenChanged >()
192+ .distinctUntilChanged()
193+ .filter { it.forNeededFunds }
194+ .onEach {
195+ dispatchEvent(Event .OpenPurchaseMethods (true ))
196+ }.launchIn(viewModelScope)
197+
197198 combine(
198199 tokenController.observeReservesBalance(),
199200 exchange.observeBalanceRate(),
@@ -202,7 +203,7 @@ class TokenInfoViewModel @Inject constructor(
202203 usdf = balance,
203204 nativeAmount = balance.convertingTo(rate),
204205 )
205- }.distinctUntilChanged(). onEach {
206+ }.onEach {
206207 dispatchEvent(Event .OnReservesUpdated (it))
207208 }.launchIn(viewModelScope)
208209
@@ -386,7 +387,6 @@ class TokenInfoViewModel @Inject constructor(
386387
387388 companion object {
388389 val updateStateForEvent: (Event ) -> ((State ) -> State ) = { event ->
389- println (" TOKEN INFO EVENT: ${event.javaClass.simpleName} " )
390390 when (event) {
391391 is Event .CashReservesEnabled -> { state -> state.copy(cashReservesEnabled = event.enabled) }
392392 is Event .MarketCapChartEnabled -> { state -> state.copy(marketCapChartEnabled = event.enabled) }
0 commit comments