Skip to content

Commit 519291a

Browse files
committed
fix(tokens): remove aggressive keying that was prevent needed recomps
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 9c949b9 commit 519291a

3 files changed

Lines changed: 20 additions & 19 deletions

File tree

apps/flipcash/features/tokens/src/main/kotlin/com/flipcash/app/tokens/internal/TokenInfoScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ private fun TokenInfoScreen(
148148
// market cap
149149
state.marketCap?.let { mcap ->
150150
val loadable = state.historicalMarketCapData[state.selectedPeriod] ?: Loadable.Loaded(emptyList())
151-
item(key = "mcap") {
151+
item {
152152
MarketCapSection(
153153
modifier = Modifier
154154
.fillParentMaxWidth(),

apps/flipcash/features/tokens/src/main/kotlin/com/flipcash/app/tokens/internal/components/marketcap/MarketCapChart.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,9 @@ internal fun MarketCapChart(
9696
}
9797
}
9898

99-
var trend by remember { mutableStateOf<LineTrend>(LineTrend.Up) }
100-
10199
// Update the model when the window changes
102100
LaunchedEffect(windowedData) {
103101
if (windowedData.isNotEmpty()) {
104-
// Update trend BEFORE the model transaction
105-
trend = trendType.determineTrend(windowedData.yValues)
106-
107102
modelProducer.runTransaction {
108103
lineSeries {
109104
series(
@@ -115,6 +110,12 @@ internal fun MarketCapChart(
115110
}
116111
}
117112

113+
val trend by remember(windowedData) {
114+
derivedStateOf {
115+
trendType.determineTrend(windowedData.yValues)
116+
}
117+
}
118+
118119
MarketCapChart(
119120
modelProducer = modelProducer,
120121
trend = trend,

apps/flipcash/shared/tokens/src/main/kotlin/TokenInfoViewModel.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import kotlinx.coroutines.flow.combine
4949
import kotlinx.coroutines.flow.debounce
5050
import kotlinx.coroutines.flow.distinctUntilChanged
5151
import kotlinx.coroutines.flow.drop
52+
import kotlinx.coroutines.flow.filter
5253
import kotlinx.coroutines.flow.filterIsInstance
5354
import kotlinx.coroutines.flow.flatMapLatest
5455
import 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

Comments
 (0)