diff --git a/ui-design-lib/src/main/java/co/electriccoin/zcash/ui/design/component/Text.kt b/ui-design-lib/src/main/java/co/electriccoin/zcash/ui/design/component/Text.kt index e2ffb682..7ce3efa5 100644 --- a/ui-design-lib/src/main/java/co/electriccoin/zcash/ui/design/component/Text.kt +++ b/ui-design-lib/src/main/java/co/electriccoin/zcash/ui/design/component/Text.kt @@ -297,19 +297,6 @@ fun Reference( } } -@Composable -fun BodyWithFiatCurrencySymbol( - amount: String, - modifier: Modifier = Modifier -) { - Text( - text = amount, - style = MaterialTheme.typography.bodyLarge, - color = ZcashTheme.colors.textPrimary, - modifier = modifier - ) -} - @Preview @Composable private fun NavigationTabTextPreview() { diff --git a/ui-lib/src/androidTest/java/co/electriccoin/zcash/ui/screen/balances/BalancesTestSetup.kt b/ui-lib/src/androidTest/java/co/electriccoin/zcash/ui/screen/balances/BalancesTestSetup.kt index 6eb28d51..b165e3ee 100644 --- a/ui-lib/src/androidTest/java/co/electriccoin/zcash/ui/screen/balances/BalancesTestSetup.kt +++ b/ui-lib/src/androidTest/java/co/electriccoin/zcash/ui/screen/balances/BalancesTestSetup.kt @@ -15,7 +15,6 @@ import java.util.concurrent.atomic.AtomicInteger class BalancesTestSetup( private val composeTestRule: ComposeContentTestRule, private val walletSnapshot: WalletSnapshot, - private val isShowFiatConversion: Boolean ) { private val onSettingsCount = AtomicInteger(0) @@ -43,7 +42,6 @@ class BalancesTestSetup( showStatusDialog = null, onStatusClick = {}, snackbarHostState = SnackbarHostState(), - isFiatConversionEnabled = isShowFiatConversion, isUpdateAvailable = false, isShowingErrorDialog = false, setShowErrorDialog = {}, diff --git a/ui-lib/src/androidTest/java/co/electriccoin/zcash/ui/screen/balances/integration/BalancesViewIntegrationTest.kt b/ui-lib/src/androidTest/java/co/electriccoin/zcash/ui/screen/balances/integration/BalancesViewIntegrationTest.kt index a4a75187..fbac68b5 100644 --- a/ui-lib/src/androidTest/java/co/electriccoin/zcash/ui/screen/balances/integration/BalancesViewIntegrationTest.kt +++ b/ui-lib/src/androidTest/java/co/electriccoin/zcash/ui/screen/balances/integration/BalancesViewIntegrationTest.kt @@ -27,7 +27,6 @@ class BalancesViewIntegrationTest : UiTestPrerequisites() { BalancesTestSetup( composeTestRule, walletSnapshot, - isShowFiatConversion = true ) // This is just basic sanity check that we still have UI set up as expected after the state restore diff --git a/ui-lib/src/androidTest/java/co/electriccoin/zcash/ui/screen/balances/view/BalancesViewTest.kt b/ui-lib/src/androidTest/java/co/electriccoin/zcash/ui/screen/balances/view/BalancesViewTest.kt index a46ed624..8758225c 100644 --- a/ui-lib/src/androidTest/java/co/electriccoin/zcash/ui/screen/balances/view/BalancesViewTest.kt +++ b/ui-lib/src/androidTest/java/co/electriccoin/zcash/ui/screen/balances/view/BalancesViewTest.kt @@ -8,7 +8,6 @@ import co.electriccoin.zcash.test.UiTestPrerequisites import co.electriccoin.zcash.ui.common.model.WalletSnapshot import co.electriccoin.zcash.ui.design.component.CommonTag import co.electriccoin.zcash.ui.fixture.WalletSnapshotFixture -import co.electriccoin.zcash.ui.screen.balances.BalancesTag import co.electriccoin.zcash.ui.screen.balances.BalancesTestSetup import co.electriccoin.zcash.ui.screen.send.clickSettingsTopAppBarMenu import org.junit.Assert @@ -23,6 +22,14 @@ class BalancesViewTest : UiTestPrerequisites() { @get:Rule val composeTestRule = createComposeRule() + private fun newTestSetup(walletSnapshot: WalletSnapshot = WalletSnapshotFixture.new()) = + BalancesTestSetup( + composeTestRule, + walletSnapshot = walletSnapshot, + ).apply { + setDefaultContent() + } + @Test @MediumTest fun check_all_elementary_ui_elements_displayed() { @@ -34,16 +41,6 @@ class BalancesViewTest : UiTestPrerequisites() { } } - @Test - @MediumTest - fun hide_fiat_conversion() { - newTestSetup(isShowFiatConversion = false) - - composeTestRule.onNodeWithTag(BalancesTag.FIAT_CONVERSION).also { - it.assertDoesNotExist() - } - } - @Test @MediumTest fun hamburger_settings_test() { @@ -55,15 +52,4 @@ class BalancesViewTest : UiTestPrerequisites() { Assert.assertEquals(1, testSetup.getOnSettingsCount()) } - - private fun newTestSetup( - isShowFiatConversion: Boolean = true, - walletSnapshot: WalletSnapshot = WalletSnapshotFixture.new() - ) = BalancesTestSetup( - composeTestRule, - walletSnapshot = walletSnapshot, - isShowFiatConversion = isShowFiatConversion - ).apply { - setDefaultContent() - } } diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/di/UseCaseModule.kt b/ui-lib/src/main/java/co/electriccoin/zcash/di/UseCaseModule.kt index dd55ab4b..263c0fe8 100644 --- a/ui-lib/src/main/java/co/electriccoin/zcash/di/UseCaseModule.kt +++ b/ui-lib/src/main/java/co/electriccoin/zcash/di/UseCaseModule.kt @@ -17,6 +17,7 @@ import co.electriccoin.zcash.ui.common.usecase.ObserveConfigurationUseCase import co.electriccoin.zcash.ui.common.usecase.ObserveContactByAddressUseCase import co.electriccoin.zcash.ui.common.usecase.ObserveContactPickedUseCase import co.electriccoin.zcash.ui.common.usecase.ObserveFastestServersUseCase +import co.electriccoin.zcash.ui.common.usecase.ObserveIsFlexaAvailableUseCase import co.electriccoin.zcash.ui.common.usecase.ObserveSelectedEndpointUseCase import co.electriccoin.zcash.ui.common.usecase.ObserveSynchronizerUseCase import co.electriccoin.zcash.ui.common.usecase.ObserveWalletStateUseCase @@ -63,6 +64,7 @@ val useCaseModule = singleOf(::GetAddressesUseCase) singleOf(::CopyToClipboardUseCase) singleOf(::IsFlexaAvailableUseCase) + singleOf(::ObserveIsFlexaAvailableUseCase) singleOf(::ShareImageUseCase) singleOf(::Zip321BuildUriUseCase) singleOf(::Zip321ProposalFromUriUseCase) diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/repository/ConfigurationRepository.kt b/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/repository/ConfigurationRepository.kt index 880ab292..1698d749 100644 --- a/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/repository/ConfigurationRepository.kt +++ b/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/repository/ConfigurationRepository.kt @@ -3,25 +3,59 @@ package co.electriccoin.zcash.ui.common.repository import cash.z.ecc.sdk.ANDROID_STATE_FLOW_TIMEOUT import co.electriccoin.zcash.configuration.api.ConfigurationProvider import co.electriccoin.zcash.configuration.model.map.Configuration +import co.electriccoin.zcash.ui.BuildConfig +import co.electriccoin.zcash.ui.common.provider.GetVersionInfoProvider +import co.electriccoin.zcash.ui.configuration.ConfigurationEntries import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.WhileSubscribed +import kotlinx.coroutines.flow.filterNotNull +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn interface ConfigurationRepository { val configurationFlow: StateFlow + + /** + * Returns true if Flexa is available, false otherwise & null if loading. + */ + val isFlexaAvailable: StateFlow + + suspend fun isFlexaAvailable(): Boolean } -class ConfigurationRepositoryImpl(androidConfigurationProvider: ConfigurationProvider) : ConfigurationRepository { +class ConfigurationRepositoryImpl( + androidConfigurationProvider: ConfigurationProvider, + private val getVersionInfo: GetVersionInfoProvider, +) : ConfigurationRepository { private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob()) override val configurationFlow: StateFlow = androidConfigurationProvider.getConfigurationFlow() .stateIn( - scope, - SharingStarted.WhileSubscribed(ANDROID_STATE_FLOW_TIMEOUT.inWholeMilliseconds), - null + scope = scope, + started = SharingStarted.WhileSubscribed(ANDROID_STATE_FLOW_TIMEOUT), + initialValue = null ) + + override val isFlexaAvailable: StateFlow = + configurationFlow + .filterNotNull() + .map { + val versionInfo = getVersionInfo() + !versionInfo.isTestnet && + ConfigurationEntries.IS_FLEXA_AVAILABLE.getValue(it) && + BuildConfig.ZCASH_FLEXA_KEY.isNotEmpty() + } + .stateIn( + scope = scope, + started = SharingStarted.WhileSubscribed(ANDROID_STATE_FLOW_TIMEOUT), + initialValue = null + ) + + override suspend fun isFlexaAvailable(): Boolean = isFlexaAvailable.filterNotNull().first() } diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/repository/FlexaRepository.kt b/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/repository/FlexaRepository.kt index 84931ba0..b13380cb 100644 --- a/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/repository/FlexaRepository.kt +++ b/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/repository/FlexaRepository.kt @@ -25,6 +25,7 @@ interface FlexaRepository { class FlexaRepositoryImpl( private val balanceRepository: BalanceRepository, private val application: Application, + private val configurationRepository: ConfigurationRepository, ) : FlexaRepository { private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob()) @@ -32,9 +33,8 @@ class FlexaRepositoryImpl( get() = BuildConfig.ZCASH_FLEXA_KEY.takeIf { it.isNotEmpty() } override fun init() { - if (publishableKey == null) return - scope.launch { + if (!configurationRepository.isFlexaAvailable()) return@launch val configuration = getFlexaClientConfiguration() if (configuration != null) { Flexa.init(configuration) diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/usecase/IsFlexaAvailableUseCase.kt b/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/usecase/IsFlexaAvailableUseCase.kt index 6bda2baa..3b693d16 100644 --- a/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/usecase/IsFlexaAvailableUseCase.kt +++ b/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/usecase/IsFlexaAvailableUseCase.kt @@ -1,14 +1,9 @@ package co.electriccoin.zcash.ui.common.usecase -import co.electriccoin.zcash.ui.BuildConfig -import co.electriccoin.zcash.ui.common.provider.GetVersionInfoProvider +import co.electriccoin.zcash.ui.common.repository.ConfigurationRepository class IsFlexaAvailableUseCase( - private val getVersionInfo: GetVersionInfoProvider, + private val configurationRepository: ConfigurationRepository ) { - operator fun invoke(): Boolean { - val versionInfo = getVersionInfo() - val isDebug = versionInfo.let { it.isDebuggable && !it.isRunningUnderTestService } - return !versionInfo.isTestnet && (BuildConfig.ZCASH_FLEXA_KEY.isNotEmpty() || isDebug) - } + suspend operator fun invoke() = configurationRepository.isFlexaAvailable() } diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/usecase/ObserveIsFlexaAvailableUseCase.kt b/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/usecase/ObserveIsFlexaAvailableUseCase.kt new file mode 100644 index 00000000..969cc13a --- /dev/null +++ b/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/usecase/ObserveIsFlexaAvailableUseCase.kt @@ -0,0 +1,9 @@ +package co.electriccoin.zcash.ui.common.usecase + +import co.electriccoin.zcash.ui.common.repository.ConfigurationRepository + +class ObserveIsFlexaAvailableUseCase( + private val configurationRepository: ConfigurationRepository +) { + operator fun invoke() = configurationRepository.isFlexaAvailable +} diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/viewmodel/WalletViewModel.kt b/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/viewmodel/WalletViewModel.kt index dd959c57..a78405a4 100644 --- a/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/viewmodel/WalletViewModel.kt +++ b/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/viewmodel/WalletViewModel.kt @@ -17,7 +17,6 @@ import cash.z.ecc.sdk.type.fromResources import co.electriccoin.zcash.preference.EncryptedPreferenceProvider import co.electriccoin.zcash.preference.StandardPreferenceProvider import co.electriccoin.zcash.spackle.Twig -import co.electriccoin.zcash.ui.BuildConfig import co.electriccoin.zcash.ui.common.model.OnboardingState import co.electriccoin.zcash.ui.common.model.WalletRestoringState import co.electriccoin.zcash.ui.common.model.WalletSnapshot @@ -50,8 +49,6 @@ import kotlinx.coroutines.flow.firstOrNull import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch -import kotlin.coroutines.resume -import kotlin.coroutines.suspendCoroutine // To make this more multiplatform compatible, we need to remove the dependency on Context // for loading the preferences. @@ -271,15 +268,11 @@ class WalletViewModel( } } - private suspend fun disconnectFlexa() = - suspendCoroutine { cont -> - if (isFlexaAvailable() && BuildConfig.ZCASH_FLEXA_KEY.isNotEmpty()) { - Flexa.buildIdentity().build().disconnect() - cont.resume(Unit) - } else { - cont.resume(Unit) - } + private suspend inline fun disconnectFlexa() { + if (isFlexaAvailable()) { + Flexa.buildIdentity().build().disconnect() } + } } /** diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/ui/configuration/ConfigurationEntries.kt b/ui-lib/src/main/java/co/electriccoin/zcash/ui/configuration/ConfigurationEntries.kt index cadde413..607547fc 100644 --- a/ui-lib/src/main/java/co/electriccoin/zcash/ui/configuration/ConfigurationEntries.kt +++ b/ui-lib/src/main/java/co/electriccoin/zcash/ui/configuration/ConfigurationEntries.kt @@ -6,13 +6,10 @@ import co.electriccoin.zcash.configuration.model.entry.ConfigKey object ConfigurationEntries { val IS_APP_UPDATE_CHECK_ENABLED = BooleanConfigurationEntry(ConfigKey("is_update_check_enabled"), true) - /* - * This isn't fully implemented yet, so it is disabled from being shown. - */ - val IS_FIAT_CONVERSION_ENABLED = BooleanConfigurationEntry(ConfigKey("is_fiat_conversion_enabled"), false) - /* * A troubleshooting step. If we fix our bugs, this should be unnecessary. */ val IS_RESCAN_ENABLED = BooleanConfigurationEntry(ConfigKey("is_rescan_enabled"), true) + + val IS_FLEXA_AVAILABLE = BooleanConfigurationEntry(ConfigKey("is_flexa_available"), false) } diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/balances/AndroidBalances.kt b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/balances/AndroidBalances.kt index ccd911ba..bbd4e42c 100644 --- a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/balances/AndroidBalances.kt +++ b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/balances/AndroidBalances.kt @@ -29,8 +29,6 @@ import co.electriccoin.zcash.ui.common.model.WalletSnapshot import co.electriccoin.zcash.ui.common.viewmodel.CheckUpdateViewModel import co.electriccoin.zcash.ui.common.viewmodel.HomeViewModel import co.electriccoin.zcash.ui.common.viewmodel.WalletViewModel -import co.electriccoin.zcash.ui.configuration.ConfigurationEntries -import co.electriccoin.zcash.ui.configuration.RemoteConfig import co.electriccoin.zcash.ui.design.component.CircularScreenProgressIndicator import co.electriccoin.zcash.ui.screen.balances.model.ShieldState import co.electriccoin.zcash.ui.screen.balances.model.StatusAction @@ -133,8 +131,6 @@ internal fun WrapBalances( it?.appUpdateInfo != null && it.state == UpdateState.Prepared } - val isFiatConversionEnabled = ConfigurationEntries.IS_FIAT_CONVERSION_ENABLED.getValue(RemoteConfig.current) - val (shieldState, setShieldState) = rememberSaveable(stateSaver = ShieldState.Saver) { mutableStateOf(ShieldState.None) } @@ -171,7 +167,6 @@ internal fun WrapBalances( } else { Balances( balanceState = balanceState, - isFiatConversionEnabled = isFiatConversionEnabled, isHideBalances = isHideBalances, isUpdateAvailable = isUpdateAvailable, onHideBalances = onHideBalances, diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/balances/BalancesTag.kt b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/balances/BalancesTag.kt index efd07ce0..7bb6f03c 100644 --- a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/balances/BalancesTag.kt +++ b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/balances/BalancesTag.kt @@ -5,5 +5,4 @@ package co.electriccoin.zcash.ui.screen.balances */ object BalancesTag { const val STATUS = "status" - const val FIAT_CONVERSION = "fiat_conversion" } diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/balances/view/BalancesView.kt b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/balances/view/BalancesView.kt index 0f1ada30..60f05f1f 100644 --- a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/balances/view/BalancesView.kt +++ b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/balances/view/BalancesView.kt @@ -45,7 +45,6 @@ import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp -import cash.z.ecc.android.sdk.model.FiatCurrencyConversionRateState import cash.z.ecc.sdk.extension.DEFAULT_FEE import cash.z.ecc.sdk.extension.toZecStringFull import cash.z.ecc.sdk.type.ZcashCurrency @@ -67,9 +66,7 @@ import co.electriccoin.zcash.ui.common.test.CommonTag import co.electriccoin.zcash.ui.design.component.AppAlertDialog import co.electriccoin.zcash.ui.design.component.BlankBgScaffold import co.electriccoin.zcash.ui.design.component.BlankSurface -import co.electriccoin.zcash.ui.design.component.Body import co.electriccoin.zcash.ui.design.component.BodySmall -import co.electriccoin.zcash.ui.design.component.BodyWithFiatCurrencySymbol import co.electriccoin.zcash.ui.design.component.CircularScreenProgressIndicator import co.electriccoin.zcash.ui.design.component.CircularSmallProgressIndicator import co.electriccoin.zcash.ui.design.component.Reference @@ -88,7 +85,6 @@ import co.electriccoin.zcash.ui.fixture.WalletSnapshotFixture import co.electriccoin.zcash.ui.screen.balances.BalancesTag import co.electriccoin.zcash.ui.screen.balances.model.ShieldState import co.electriccoin.zcash.ui.screen.balances.model.StatusAction -import co.electriccoin.zcash.ui.screen.balances.model.WalletDisplayValues @Preview @Composable @@ -96,7 +92,6 @@ private fun ComposableBalancesPreview() { ZcashTheme(forceDarkMode = false) { Balances( balanceState = BalanceStateFixture.new(), - isFiatConversionEnabled = false, isHideBalances = false, isUpdateAvailable = false, isShowingErrorDialog = false, @@ -123,7 +118,6 @@ private fun ComposableBalancesShieldDarkPreview() { ZcashTheme(forceDarkMode = true) { Balances( balanceState = BalanceStateFixture.new(), - isFiatConversionEnabled = false, isHideBalances = false, isUpdateAvailable = false, isShowingErrorDialog = true, @@ -162,7 +156,6 @@ private fun ComposableBalancesShieldErrorDialogPreview() { @Composable fun Balances( balanceState: BalanceState, - isFiatConversionEnabled: Boolean, isHideBalances: Boolean, isUpdateAvailable: Boolean, isShowingErrorDialog: Boolean, @@ -198,7 +191,6 @@ fun Balances( } else { BalancesMainContent( balanceState = balanceState, - isFiatConversionEnabled = isFiatConversionEnabled, isHideBalances = isHideBalances, isUpdateAvailable = isUpdateAvailable, onShielding = onShielding, @@ -353,7 +345,6 @@ private fun BalancesTopAppBar( @Composable private fun BalancesMainContent( balanceState: BalanceState, - isFiatConversionEnabled: Boolean, isHideBalances: Boolean, isUpdateAvailable: Boolean, onShielding: () -> Unit, @@ -390,7 +381,6 @@ private fun BalancesMainContent( Spacer(modifier = Modifier.height(ZcashTheme.dimens.spacingDefault)) BalancesOverview( - isFiatConversionEnabled = isFiatConversionEnabled, isHideBalances = isHideBalances, walletSnapshot = walletSnapshot, ) @@ -571,7 +561,6 @@ fun TransparentBalanceHelpPanel(onHideHelpPanel: () -> Unit) { @Composable fun BalancesOverview( walletSnapshot: WalletSnapshot, - isFiatConversionEnabled: Boolean, isHideBalances: Boolean, ) { Column { @@ -585,38 +574,6 @@ fun BalancesOverview( // aka value pending PendingTransactionsRow(isHideBalances, walletSnapshot) - - if (isFiatConversionEnabled) { - val walletDisplayValues = - WalletDisplayValues.getNextValues( - context = LocalContext.current, - walletSnapshot = walletSnapshot, - isUpdateAvailable = false, - ) - - Column(Modifier.testTag(BalancesTag.FIAT_CONVERSION)) { - Spacer(modifier = Modifier.height(ZcashTheme.dimens.spacingSmall)) - - when (walletDisplayValues.fiatCurrencyAmountState) { - is FiatCurrencyConversionRateState.Current -> { - BodyWithFiatCurrencySymbol( - amount = walletDisplayValues.fiatCurrencyAmountText - ) - } - - is FiatCurrencyConversionRateState.Stale -> { - // Note: we should show information about staleness too - BodyWithFiatCurrencySymbol( - amount = walletDisplayValues.fiatCurrencyAmountText - ) - } - - is FiatCurrencyConversionRateState.Unavailable -> { - Body(text = walletDisplayValues.fiatCurrencyAmountText) - } - } - } - } } } diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/integrations/AndroidIntegrations.kt b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/integrations/AndroidIntegrations.kt index e716b741..cb417c1a 100644 --- a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/integrations/AndroidIntegrations.kt +++ b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/integrations/AndroidIntegrations.kt @@ -1,7 +1,6 @@ package co.electriccoin.zcash.ui.screen.integrations import android.net.Uri -import android.widget.Toast import androidx.activity.compose.BackHandler import androidx.browser.customtabs.CustomTabsIntent import androidx.compose.runtime.Composable @@ -9,7 +8,6 @@ import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.lifecycle.compose.collectAsStateWithLifecycle import co.electriccoin.zcash.di.koinActivityViewModel -import co.electriccoin.zcash.ui.R import co.electriccoin.zcash.ui.common.compose.LocalActivity import co.electriccoin.zcash.ui.common.compose.LocalNavController import co.electriccoin.zcash.ui.common.viewmodel.WalletViewModel @@ -57,12 +55,6 @@ internal fun WrapIntegrations() { } } - LaunchedEffect(Unit) { - viewModel.showFlexaErrorToastCommand.collect { - Toast.makeText(activity, R.string.integrations_flexa_key_missing, Toast.LENGTH_LONG).show() - } - } - BackHandler { viewModel.onBack() } diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/integrations/viewmodel/IntegrationsViewModel.kt b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/integrations/viewmodel/IntegrationsViewModel.kt index 5c5afef8..a610bf37 100644 --- a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/integrations/viewmodel/IntegrationsViewModel.kt +++ b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/integrations/viewmodel/IntegrationsViewModel.kt @@ -27,6 +27,7 @@ import co.electriccoin.zcash.ui.common.usecase.GetSynchronizerUseCase import co.electriccoin.zcash.ui.common.usecase.GetTransparentAddressUseCase import co.electriccoin.zcash.ui.common.usecase.IsCoinbaseAvailableUseCase import co.electriccoin.zcash.ui.common.usecase.IsFlexaAvailableUseCase +import co.electriccoin.zcash.ui.common.usecase.ObserveIsFlexaAvailableUseCase import co.electriccoin.zcash.ui.common.usecase.ObserveWalletStateUseCase import co.electriccoin.zcash.ui.design.component.ZashiSettingsListItemState import co.electriccoin.zcash.ui.design.util.stringRes @@ -40,6 +41,7 @@ import kotlinx.collections.immutable.toImmutableList import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.WhileSubscribed +import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch @@ -48,6 +50,7 @@ class IntegrationsViewModel( getVersionInfo: GetVersionInfoProvider, getZcashCurrency: GetZcashCurrencyProvider, observeWalletState: ObserveWalletStateUseCase, + observeIsFlexaAvailableUseCase: ObserveIsFlexaAvailableUseCase, private val getSynchronizer: GetSynchronizerUseCase, private val getTransparentAddress: GetTransparentAddressUseCase, private val isFlexaAvailable: IsFlexaAvailableUseCase, @@ -59,7 +62,6 @@ class IntegrationsViewModel( val backNavigationCommand = MutableSharedFlow() val flexaNavigationCommand = MutableSharedFlow() val coinbaseNavigationCommand = MutableSharedFlow() - val showFlexaErrorToastCommand = MutableSharedFlow() private val versionInfo = getVersionInfo() private val isDebug = versionInfo.let { it.isDebuggable && !it.isRunningUnderTestService } @@ -71,7 +73,7 @@ class IntegrationsViewModel( } val state = - isEnabled.map { isEnabled -> + combine(observeIsFlexaAvailableUseCase(), isEnabled) { isFlexaAvailable, isEnabled -> IntegrationsState( version = stringRes(R.string.integrations_version, versionInfo.versionName), disabledInfo = stringRes(R.string.integrations_disabled_info).takeIf { isEnabled.not() }, @@ -103,7 +105,7 @@ class IntegrationsViewModel( text = stringRes(R.string.integrations_flexa), subtitle = stringRes(R.string.integrations_flexa_subtitle), onClick = ::onFlexaClicked - ).takeIf { isFlexaAvailable() } + ).takeIf { isFlexaAvailable == true } ).toImmutableList() ) }.stateIn( @@ -144,9 +146,7 @@ class IntegrationsViewModel( private fun onFlexaClicked() = viewModelScope.launch { - if (BuildConfig.ZCASH_FLEXA_KEY.isEmpty()) { - showFlexaErrorToastCommand.emit(Unit) - } else { + if (isFlexaAvailable()) { flexaNavigationCommand.emit(Unit) } } diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/settings/viewmodel/SettingsViewModel.kt b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/settings/viewmodel/SettingsViewModel.kt index e66b0c37..994b3ab0 100644 --- a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/settings/viewmodel/SettingsViewModel.kt +++ b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/settings/viewmodel/SettingsViewModel.kt @@ -11,8 +11,8 @@ import co.electriccoin.zcash.ui.NavigationTargets.INTEGRATIONS import co.electriccoin.zcash.ui.NavigationTargets.SUPPORT import co.electriccoin.zcash.ui.R import co.electriccoin.zcash.ui.common.provider.GetVersionInfoProvider -import co.electriccoin.zcash.ui.common.usecase.IsFlexaAvailableUseCase import co.electriccoin.zcash.ui.common.usecase.ObserveConfigurationUseCase +import co.electriccoin.zcash.ui.common.usecase.ObserveIsFlexaAvailableUseCase import co.electriccoin.zcash.ui.common.usecase.RescanBlockchainUseCase import co.electriccoin.zcash.ui.common.usecase.SensitiveSettingsVisibleUseCase import co.electriccoin.zcash.ui.configuration.ConfigurationEntries @@ -38,10 +38,10 @@ import kotlinx.coroutines.launch class SettingsViewModel( observeConfiguration: ObserveConfigurationUseCase, isSensitiveSettingsVisible: SensitiveSettingsVisibleUseCase, + observeIsFlexaAvailable: ObserveIsFlexaAvailableUseCase, private val standardPreferenceProvider: StandardPreferenceProvider, private val getVersionInfo: GetVersionInfoProvider, private val rescanBlockchain: RescanBlockchainUseCase, - private val isFlexaAvailable: IsFlexaAvailableUseCase ) : ViewModel() { private val versionInfo by lazy { getVersionInfo() } @@ -92,22 +92,29 @@ class SettingsViewModel( val state: StateFlow = combine( troubleshootingState, - isSensitiveSettingsVisible() - ) { troubleshootingState, isSensitiveSettingsVisible -> - createState(troubleshootingState, isSensitiveSettingsVisible) + isSensitiveSettingsVisible(), + observeIsFlexaAvailable(), + ) { troubleshootingState, isSensitiveSettingsVisible, isFlexaAvailable -> + createState( + troubleshootingState = troubleshootingState, + isSensitiveSettingsVisible = isSensitiveSettingsVisible, + isFlexaAvailable = isFlexaAvailable == true + ) }.stateIn( scope = viewModelScope, started = SharingStarted.WhileSubscribed(ANDROID_STATE_FLOW_TIMEOUT), initialValue = createState( troubleshootingState = null, - isSensitiveSettingsVisible = isSensitiveSettingsVisible().value + isSensitiveSettingsVisible = isSensitiveSettingsVisible().value, + isFlexaAvailable = observeIsFlexaAvailable().value == true ) ) private fun createState( troubleshootingState: SettingsTroubleshootingState?, - isSensitiveSettingsVisible: Boolean + isSensitiveSettingsVisible: Boolean, + isFlexaAvailable: Boolean ) = SettingsState( debugMenu = troubleshootingState, onBack = ::onBack, @@ -125,7 +132,7 @@ class SettingsViewModel( titleIcons = listOfNotNull( R.drawable.ic_integrations_coinbase, - R.drawable.ic_integrations_flexa.takeIf { isFlexaAvailable() } + R.drawable.ic_integrations_flexa.takeIf { isFlexaAvailable } ).toImmutableList() ).takeIf { isSensitiveSettingsVisible }, ZashiSettingsListItemState( diff --git a/ui-lib/src/main/res/ui/integrations/values-es/strings.xml b/ui-lib/src/main/res/ui/integrations/values-es/strings.xml index 195f6d76..0e801ea3 100644 --- a/ui-lib/src/main/res/ui/integrations/values-es/strings.xml +++ b/ui-lib/src/main/res/ui/integrations/values-es/strings.xml @@ -7,5 +7,4 @@ Paga con Flexa Paga con clips de pago de Flexa y explora una nueva forma de gastar Zcash. Autentifícate para pagar con Flexa - Clave de Flexa faltante diff --git a/ui-lib/src/main/res/ui/integrations/values/strings.xml b/ui-lib/src/main/res/ui/integrations/values/strings.xml index b0d30d6e..3c7d1362 100644 --- a/ui-lib/src/main/res/ui/integrations/values/strings.xml +++ b/ui-lib/src/main/res/ui/integrations/values/strings.xml @@ -7,5 +7,4 @@ Pay with Flexa Pay with Flexa payment clips and explore a new way of spending Zcash. Authenticate yourself to pay with Flexa - Flexa key missing