Skip to content

Commit

Permalink
PERA-1364 :: Fix cards flag to show on staging testnet builds (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeltchuang authored Jan 11, 2025
1 parent 8f3bfed commit 76a3795
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.algorand.android.BuildConfig.DISCOVER_BROWSE_DAPP_TESTNET_URL
import com.algorand.android.BuildConfig.DISCOVER_MAINNET_URL
import com.algorand.android.BuildConfig.DISCOVER_TESTNET_URL
import com.algorand.android.usecase.GetIsActiveNodeTestnetUseCase
import com.algorand.android.usecase.GetIsProductionReleaseUseCase
import com.algorand.common.remoteconfig.domain.usecase.IMMERSVE_BUTTON_TOGGLE
import com.algorand.common.remoteconfig.domain.usecase.IsFeatureToggleEnabled
import com.algorand.common.remoteconfig.domain.usecase.STAKING_BUTTON_TOGGLE
Expand All @@ -28,15 +29,17 @@ import javax.inject.Inject

@HiltViewModel
class CoreActionsTabBarViewModel @Inject constructor(
private val getIsProductionReleaseUseCase: GetIsProductionReleaseUseCase,
private val getIsActiveNodeTestnetUseCase: GetIsActiveNodeTestnetUseCase,
private val isFeatureToggleEnabled: IsFeatureToggleEnabled
) : ViewModel() {

private val _viewState = MutableStateFlow<ViewState>(ViewState.Idle)
val viewState get() = _viewState.asStateFlow()

fun initViewState() {
val isImmersveToggleEnabled = isFeatureToggleEnabled(IMMERSVE_BUTTON_TOGGLE) && !isConnectedToTestnet()
fun changeViewStateForFeatureFlag() {
val isImmersveToggleEnabled = isFeatureToggleEnabled(IMMERSVE_BUTTON_TOGGLE) &&
!(isConnectedToTestnet() && isProdReleaseVariant())
val isStakingToggleEnabled = isFeatureToggleEnabled(STAKING_BUTTON_TOGGLE)
_viewState.value = ViewState.Content(isImmersveToggleEnabled, isStakingToggleEnabled)
}
Expand All @@ -61,6 +64,10 @@ class CoreActionsTabBarViewModel @Inject constructor(
return getIsActiveNodeTestnetUseCase.invoke()
}

fun isProdReleaseVariant(): Boolean {
return getIsProductionReleaseUseCase.invoke()
}

sealed interface ViewState {
data object Idle : ViewState
data class Content(
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/algorand/android/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ class MainActivity :
}

private fun setupCoreActionsTabBarView() {
coreActionsTabBarViewModel.initViewState()
coreActionsTabBarViewModel.changeViewStateForFeatureFlag()
binding.coreActionsTabBarView.setListener(object : CoreActionsTabBarView.Listener {
override fun onSendClick() {
firebaseAnalytics.logTapSend()
Expand Down Expand Up @@ -753,6 +753,7 @@ class MainActivity :
private fun onNewNodeActivated() {
hideProgress()
mainViewModel.onNewNodeActivated()
coreActionsTabBarViewModel.changeViewStateForFeatureFlag()
}

private fun onNewNodeLoading() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2022 Pera Wallet, LDA
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License
*/

package com.algorand.android.usecase

import com.algorand.android.BuildConfig
import javax.inject.Inject

// TODO: Update this class after deciding on where is the correct place to get the active node
class GetIsProductionReleaseUseCase @Inject constructor() {
operator fun invoke(): Boolean {
// return true if prodRelease variant
return BuildConfig.BUILD_TYPE == "release" && BuildConfig.FLAVOR == "prod"
}
}

0 comments on commit 76a3795

Please sign in to comment.