Skip to content

Commit b83ed04

Browse files
committed
feat(tokens/info): hide balance and fully expand currency info when user doesn't have a balance for the token
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 81cbd0c commit b83ed04

5 files changed

Lines changed: 55 additions & 12 deletions

File tree

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.flipcash.app.tokens.internal
22

3+
import androidx.compose.animation.AnimatedContent
34
import androidx.compose.foundation.Image
45
import androidx.compose.foundation.layout.Arrangement
56
import androidx.compose.foundation.layout.Box
@@ -134,20 +135,28 @@ private fun TokenInfoScreen(
134135
}
135136
is Loadable.Loaded -> {
136137
item {
137-
TokenBalance(
138-
modifier = Modifier
139-
.fillMaxWidth()
140-
.padding(horizontal = CodeTheme.dimens.inset),
141-
balance = state.balance.nativeAmount,
142-
appreciation = state.appreciation?.nativeAmount?.takeIf { state.showAppreciation },
143-
onClick = {
144-
dispatch(
145-
TokenInfoViewModel.Event.OpenScreen(
146-
AppRoute.Main.RegionSelection(kind = RegionSelectionKind.Balance)
147-
)
138+
AnimatedContent(
139+
targetState = !state.minimalUi
140+
) { holds ->
141+
if (holds) {
142+
TokenBalance(
143+
modifier = Modifier
144+
.fillMaxWidth()
145+
.padding(horizontal = CodeTheme.dimens.inset),
146+
balance = state.balance.nativeAmount,
147+
appreciation = state.appreciation?.nativeAmount?.takeIf { state.showAppreciation },
148+
onClick = {
149+
dispatch(
150+
TokenInfoViewModel.Event.OpenScreen(
151+
AppRoute.Main.RegionSelection(kind = RegionSelectionKind.Balance)
152+
)
153+
)
154+
}
148155
)
156+
} else {
157+
Spacer(Modifier.height(CodeTheme.dimens.grid.x10))
149158
}
150-
)
159+
}
151160
}
152161

153162
if (!state.isCashReserve && state.showTransactionHistory) {

apps/flipcash/features/tokens/src/main/kotlin/com/flipcash/app/tokens/internal/components/info/TokenDetails.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ internal fun TokenDetailsSection(
8181
text = state.token.dataOrNull?.description.orEmpty(),
8282
style = CodeTheme.typography.textMedium,
8383
color = CodeTheme.colors.textSecondary,
84+
isExpandable = !state.minimalUi,
8485
isExpanded = state.descriptionExpanded,
8586
contentPadding = PaddingValues(horizontal = CodeTheme.dimens.inset)
8687
) {

apps/flipcash/shared/featureflags/src/main/kotlin/com/flipcash/app/featureflags/FeatureFlag.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,15 @@ sealed interface FeatureFlag {
135135
override val persistLogOut: Boolean = false
136136
}
137137

138+
@FeatureFlagMarker
139+
data object HideUnownedTokenBalances: FeatureFlag {
140+
override val key: String = "hide_unowned_balances_enabled"
141+
override val default: Boolean = false
142+
override val launched: Boolean = false
143+
override val visible: Boolean = true
144+
override val persistLogOut: Boolean = false
145+
}
146+
138147
companion object {
139148
val entries: List<FeatureFlag>
140149
get() = FeatureFlagEntries.entries
@@ -162,6 +171,7 @@ val FeatureFlag.title: String
162171
FeatureFlag.TokenDiscovery -> "Token Discovery"
163172
FeatureFlag.CurrencyCreator -> "Currency Creator"
164173
FeatureFlag.BillTextures -> "Bill Textures"
174+
FeatureFlag.HideUnownedTokenBalances -> "Hide Balance for Unowned Tokens In Info"
165175
}
166176

167177
val FeatureFlag.message: String
@@ -180,6 +190,7 @@ val FeatureFlag.message: String
180190
FeatureFlag.TokenDiscovery -> "When enabled, you'll gain access to leaderboards for tokens and discovery"
181191
FeatureFlag.CurrencyCreator -> "When enabled, you'll gain access to create new currencies"
182192
FeatureFlag.BillTextures -> "When enabled, you'll gain the ability to select textures for bills during currency creation"
193+
FeatureFlag.HideUnownedTokenBalances -> "When enabled, the balance header will be hidden for tokens you don't hold in Currency Info"
183194
}
184195

185196

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,13 @@ class TokenCoordinator @Inject constructor(
218218

219219
// endregion
220220

221+
// region Public API - Account check
222+
fun holds(mint: Mint): Boolean {
223+
return accountController.hasAccountFor(mint)
224+
}
225+
226+
// endregion
227+
221228
// region Public API — Token Metadata (implements TokenMetadataProvider)
222229

223230
/**

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,15 @@ class TokenInfoViewModel @Inject constructor(
7171
val descriptionExpanded: Boolean = false,
7272
val historicalMarketCapData: Map<Period, Loadable<List<MarketCapPoint>>> = emptyMap(),
7373
val selectedPeriod: Period = Period.All,
74+
val hideBalanceWhenUnowned: Boolean = false,
7475
) {
76+
val minimalUi: Boolean
77+
get() {
78+
if (!hideBalanceWhenUnowned) return false
79+
if (balance.nativeAmount.hasDisplayableValue) return false
80+
return true
81+
}
82+
7583
val canSell: Boolean
7684
get() = balance.underlyingTokenAmount.valueNonZero()
7785

@@ -91,6 +99,7 @@ class TokenInfoViewModel @Inject constructor(
9199
val data: Loadable<List<MarketCapPoint>>
92100
) : Event
93101

102+
data class HideBalanceWhenUnowned(val enabled: Boolean): Event
94103
data class OnMarketCapPeriodSelected(val period: Period) : Event
95104
data class OnBalanceUpdated(val balance: LocalFiat) : Event
96105
data class OnAppreciatedEnabled(val enabled: Boolean) : Event
@@ -110,6 +119,11 @@ class TokenInfoViewModel @Inject constructor(
110119
dispatchEvent(Event.MarketCapChartEnabled(it))
111120
}.launchIn(viewModelScope)
112121

122+
features.observe(FeatureFlag.HideUnownedTokenBalances)
123+
.onEach {
124+
dispatchEvent(Event.HideBalanceWhenUnowned(it))
125+
}.launchIn(viewModelScope)
126+
113127
eventFlow
114128
.filterIsInstance<Event.OnMintProvided>()
115129
.onEach { dispatchEvent(Event.OnTokenChanged(Loadable.Loading())) }
@@ -315,6 +329,7 @@ class TokenInfoViewModel @Inject constructor(
315329
is Event.MarketCapChartEnabled -> { state -> state.copy(marketCapChartEnabled = event.enabled) }
316330
is Event.OnMintProvided -> { state -> state.copy(mint = event.mint) }
317331
is Event.OnTokenChanged -> { state -> state.copy(token = event.token) }
332+
is Event.HideBalanceWhenUnowned -> { state -> state.copy(hideBalanceWhenUnowned = event.enabled) }
318333
is Event.OnMarketCapChanged -> { state -> state.copy(marketCap = event.mcap) }
319334
is Event.OnBalanceUpdated -> { state -> state.copy(balance = event.balance) }
320335
is Event.OnAppreciationUpdated -> { state -> state.copy(appreciation = event.amount) }

0 commit comments

Comments
 (0)