File tree Expand file tree Collapse file tree
apps/flipcash/shared/tokens/src/main/kotlin/com/flipcash/app/tokens/ui
services/opencode/src/main/kotlin/com/getcode/opencode/controllers Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -289,8 +289,10 @@ class TokenInfoViewModel @Inject constructor(
289289 eventFlow
290290 .filterIsInstance<Event .OnBalanceUpdated >()
291291 .mapNotNull { stateFlow.value.mint }
292- .onEach {
293- val hasAccount = accountController.hasAccountFor(it)
292+ .flatMapLatest { mint ->
293+ accountController.observeHasAccountFor(mint)
294+ }
295+ .onEach { hasAccount ->
294296 dispatchEvent(Event .OnAppreciatedEnabled (hasAccount))
295297 dispatchEvent(Event .OnTransactionHistoryEnabled (hasAccount))
296298 }.launchIn(viewModelScope)
Original file line number Diff line number Diff line change @@ -18,10 +18,12 @@ import com.getcode.utils.trace
1818import kotlinx.coroutines.CoroutineScope
1919import kotlinx.coroutines.Dispatchers
2020import kotlinx.coroutines.SupervisorJob
21+ import kotlinx.coroutines.flow.Flow
2122import kotlinx.coroutines.flow.MutableStateFlow
2223import kotlinx.coroutines.flow.filterNotNull
2324import kotlinx.coroutines.flow.flatMapLatest
2425import kotlinx.coroutines.flow.launchIn
26+ import kotlinx.coroutines.flow.distinctUntilChanged
2527import kotlinx.coroutines.flow.map
2628import kotlinx.coroutines.flow.onEach
2729import javax.inject.Inject
@@ -45,6 +47,9 @@ class AccountController @Inject constructor(
4547 return accounts.value.any { it.mint == mint }
4648 }
4749
50+ fun observeHasAccountFor (mint : Mint ): Flow <Boolean > =
51+ accounts.map { list -> list.any { it.mint == mint } }.distinctUntilChanged()
52+
4853 private val fetching = AtomicBoolean (false )
4954
5055 var onTimelockUnlocked: (() -> Unit ) = { }
You can’t perform that action at this time.
0 commit comments