Skip to content

Commit 61da0ba

Browse files
committed
fix(ocp): make account check by mint observable
Utilize when determining appreciation is visible Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 302c7f7 commit 61da0ba

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

apps/flipcash/shared/tokens/src/main/kotlin/com/flipcash/app/tokens/ui/TokenInfoViewModel.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff 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)

services/opencode/src/main/kotlin/com/getcode/opencode/controllers/AccountController.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ import com.getcode.utils.trace
1818
import kotlinx.coroutines.CoroutineScope
1919
import kotlinx.coroutines.Dispatchers
2020
import kotlinx.coroutines.SupervisorJob
21+
import kotlinx.coroutines.flow.Flow
2122
import kotlinx.coroutines.flow.MutableStateFlow
2223
import kotlinx.coroutines.flow.filterNotNull
2324
import kotlinx.coroutines.flow.flatMapLatest
2425
import kotlinx.coroutines.flow.launchIn
26+
import kotlinx.coroutines.flow.distinctUntilChanged
2527
import kotlinx.coroutines.flow.map
2628
import kotlinx.coroutines.flow.onEach
2729
import 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) = { }

0 commit comments

Comments
 (0)