Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove conversion token changer from settings #7514

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ class BaseTokenManager(
setBaseToken(tokens.getOrNull(indexOfNext) ?: tokens.firstOrNull())
}

fun setBaseToken(token: Token?) {
fun setBaseTokenQueryId(tokenQueryId: String) {
val token = TokenQuery.fromId(tokenQueryId)?.let { coinManager.getToken(it) } ?: tokens.first()

setBaseToken(token)
}

private fun setBaseToken(token: Token?) {
this.token = token
localStorage.balanceTotalCoinUid = token?.coin?.uid

Expand All @@ -45,10 +51,4 @@ class BaseTokenManager(
}
}

fun setBaseTokenQueryId(tokenQueryId: String) {
val token = TokenQuery.fromId(tokenQueryId)?.let { coinManager.getToken(it) } ?: tokens.first()

setBaseToken(token)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Badge
import androidx.compose.material.BadgedBox
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.Icon
import androidx.compose.material.ModalBottomSheetLayout
import androidx.compose.material.ModalBottomSheetValue
import androidx.compose.material.Scaffold
import androidx.compose.material.Text
import androidx.compose.material.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
Expand Down Expand Up @@ -65,6 +63,7 @@ import io.horizontalsystems.bankwallet.modules.transactions.TransactionsViewMode
import io.horizontalsystems.bankwallet.modules.walletconnect.WCAccountTypeNotSupportedDialog
import io.horizontalsystems.bankwallet.modules.walletconnect.WCManager.SupportState
import io.horizontalsystems.bankwallet.ui.compose.ComposeAppTheme
import io.horizontalsystems.bankwallet.ui.compose.components.BadgeText
import io.horizontalsystems.bankwallet.ui.compose.components.HsBottomNavigation
import io.horizontalsystems.bankwallet.ui.compose.components.HsBottomNavigationItem
import io.horizontalsystems.bankwallet.ui.extensions.WalletSwitchBottomSheet
Expand Down Expand Up @@ -317,15 +316,9 @@ private fun BadgedIcon(
is MainModule.BadgeType.BadgeNumber ->
BadgedBox(
badge = {
Badge(
backgroundColor = ComposeAppTheme.colors.lucian
) {
Text(
text = badge.number.toString(),
style = ComposeAppTheme.typography.micro,
color = ComposeAppTheme.colors.white,
)
}
BadgeText(
text = badge.number.toString(),
)
},
content = icon
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.ModalBottomSheetLayout
import androidx.compose.material.ModalBottomSheetValue
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
Expand All @@ -40,16 +39,13 @@ import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavController
import io.horizontalsystems.bankwallet.R
import io.horizontalsystems.bankwallet.core.BaseComposeFragment
import io.horizontalsystems.bankwallet.ui.compose.ComposeAppTheme
import io.horizontalsystems.bankwallet.ui.compose.Select
import io.horizontalsystems.bankwallet.ui.compose.components.AlertGroup
import io.horizontalsystems.bankwallet.ui.compose.components.AlertHeader
import io.horizontalsystems.bankwallet.ui.compose.components.AlertItem
import io.horizontalsystems.bankwallet.ui.compose.components.AppBar
import io.horizontalsystems.bankwallet.ui.compose.components.B2
import io.horizontalsystems.bankwallet.ui.compose.components.ButtonPrimaryTransparent
Expand Down Expand Up @@ -94,7 +90,6 @@ fun AppearanceScreen(navController: NavController) {
var openThemeSelector by rememberSaveable { mutableStateOf(false) }
var openLaunchPageSelector by rememberSaveable { mutableStateOf(false) }
var openBalanceValueSelector by rememberSaveable { mutableStateOf(false) }
var openBalanceConversionSelector by rememberSaveable { mutableStateOf(false) }

Surface(color = ComposeAppTheme.colors.tyler) {
ModalBottomSheetLayout(
Expand Down Expand Up @@ -202,13 +197,6 @@ fun AppearanceScreen(navController: NavController) {
value = uiState.selectedBalanceViewType.title.getString(),
onClick = { openBalanceValueSelector = true }
)
},
{
MenuItemWithDialog(
R.string.Appearance_BalanceConversion,
value = uiState.baseTokenOptions.selected?.coin?.code ?: "",
onClick = { openBalanceConversionSelector = true }
)
}
)
)
Expand Down Expand Up @@ -259,33 +247,6 @@ fun AppearanceScreen(navController: NavController) {
{ openBalanceValueSelector = false }
)
}
if (openBalanceConversionSelector) {
Dialog(onDismissRequest = {
openBalanceConversionSelector = false
}) {
Column(
modifier = Modifier
.padding(horizontal = 20.dp)
.clip(RoundedCornerShape(16.dp))
) {
AlertHeader(R.string.Appearance_BalanceConversion)
uiState.baseTokenOptions.options.forEach { option ->
AlertItem(
onClick = {
viewModel.onEnterBaseToken(option)
openBalanceConversionSelector = false
}
) {
Text(
option.coin.code,
color = if (option == uiState.baseTokenOptions.selected) ComposeAppTheme.colors.jacob else ComposeAppTheme.colors.leah,
style = ComposeAppTheme.typography.body,
)
}
}
}
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ object AppearanceModule {
launchScreenService,
appIconService,
themeService,
App.baseTokenManager,
App.balanceViewTypeManager,
App.localStorage,
) as T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,24 @@ package io.horizontalsystems.bankwallet.modules.settings.appearance
import androidx.lifecycle.viewModelScope
import io.horizontalsystems.bankwallet.core.ILocalStorage
import io.horizontalsystems.bankwallet.core.ViewModelUiState
import io.horizontalsystems.bankwallet.core.managers.BaseTokenManager
import io.horizontalsystems.bankwallet.entities.LaunchPage
import io.horizontalsystems.bankwallet.modules.balance.BalanceViewType
import io.horizontalsystems.bankwallet.modules.balance.BalanceViewTypeManager
import io.horizontalsystems.bankwallet.modules.theme.ThemeService
import io.horizontalsystems.bankwallet.modules.theme.ThemeType
import io.horizontalsystems.bankwallet.ui.compose.Select
import io.horizontalsystems.bankwallet.ui.compose.SelectOptional
import io.horizontalsystems.marketkit.models.Token
import kotlinx.coroutines.launch


class AppearanceViewModel(
private val launchScreenService: LaunchScreenService,
private val appIconService: AppIconService,
private val themeService: ThemeService,
private val baseTokenManager: BaseTokenManager,
private val balanceViewTypeManager: BalanceViewTypeManager,
private val localStorage: ILocalStorage,
) : ViewModelUiState<AppearanceUIState>() {
private var launchScreenOptions = launchScreenService.optionsFlow.value
private var appIconOptions = appIconService.optionsFlow.value
private var themeOptions = themeService.optionsFlow.value
private var baseTokenOptions = buildBaseTokenSelect(baseTokenManager.baseTokenFlow.value)
private var marketsTabHidden = !localStorage.marketsTabEnabled
private var balanceTabButtonsHidden = !localStorage.balanceTabButtonsEnabled
private var balanceViewTypeOptions =
Expand All @@ -51,12 +45,6 @@ class AppearanceViewModel(
handleUpdatedThemeOptions(it)
}
}
viewModelScope.launch {
baseTokenManager.baseTokenFlow
.collect { baseToken ->
handleUpdatedBaseToken(buildBaseTokenSelect(baseToken))
}
}
viewModelScope.launch {
balanceViewTypeManager.balanceViewTypeFlow
.collect {
Expand All @@ -69,7 +57,6 @@ class AppearanceViewModel(
launchScreenOptions = launchScreenOptions,
appIconOptions = appIconOptions,
themeOptions = themeOptions,
baseTokenOptions = baseTokenOptions,
balanceViewTypeOptions = balanceViewTypeOptions,
marketsTabHidden = marketsTabHidden,
balanceTabButtonsHidden = balanceTabButtonsHidden,
Expand All @@ -78,10 +65,6 @@ class AppearanceViewModel(
selectedBalanceViewType = balanceViewTypeManager.balanceViewType,
)

private fun buildBaseTokenSelect(token: Token?): SelectOptional<Token> {
return SelectOptional(token, baseTokenManager.tokens)
}

private fun buildBalanceViewTypeSelect(value: BalanceViewType): Select<BalanceViewType> {
return Select(value, balanceViewTypeManager.viewTypes)
}
Expand All @@ -106,11 +89,6 @@ class AppearanceViewModel(
emitState()
}

private fun handleUpdatedBaseToken(baseTokenOptions: SelectOptional<Token>) {
this.baseTokenOptions = baseTokenOptions
emitState()
}

fun onEnterLaunchPage(launchPage: LaunchPage) {
launchScreenService.setLaunchScreen(launchPage)
}
Expand All @@ -123,10 +101,6 @@ class AppearanceViewModel(
themeService.setThemeType(themeType)
}

fun onEnterBaseToken(token: Token) {
baseTokenManager.setBaseToken(token)
}

fun onEnterBalanceViewType(viewType: BalanceViewType) {
balanceViewTypeManager.setViewType(viewType)
}
Expand Down Expand Up @@ -154,7 +128,6 @@ data class AppearanceUIState(
val launchScreenOptions: Select<LaunchPage>,
val appIconOptions: Select<AppIcon>,
val themeOptions: Select<ThemeType>,
val baseTokenOptions: SelectOptional<Token>,
val balanceViewTypeOptions: Select<BalanceViewType>,
val marketsTabHidden: Boolean,
val balanceTabButtonsHidden: Boolean,
Expand Down
Loading