Skip to content

Commit

Permalink
Remove conversion token changer from settings
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelekol committed Jun 3, 2024
1 parent 8f677b3 commit bd14002
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 74 deletions.
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 @@ -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

0 comments on commit bd14002

Please sign in to comment.