Flexa hidden behind feature flag (#1676)
* Flexa hidden behind feature flag * Remove unused flag IS_FIAT_CONVERSION_ENABLED * Code cleanup * Kotlin flow handling --------- Co-authored-by: Honza <rychnovsky.honza@gmail.com>
This commit is contained in:
parent
882605d7a9
commit
d4be4a5dda
|
@ -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() {
|
||||
|
|
|
@ -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 = {},
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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<Configuration?>
|
||||
|
||||
/**
|
||||
* Returns true if Flexa is available, false otherwise & null if loading.
|
||||
*/
|
||||
val isFlexaAvailable: StateFlow<Boolean?>
|
||||
|
||||
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<Configuration?> =
|
||||
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<Boolean?> =
|
||||
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()
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -5,5 +5,4 @@ package co.electriccoin.zcash.ui.screen.balances
|
|||
*/
|
||||
object BalancesTag {
|
||||
const val STATUS = "status"
|
||||
const val FIAT_CONVERSION = "fiat_conversion"
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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<Unit>()
|
||||
val flexaNavigationCommand = MutableSharedFlow<Unit>()
|
||||
val coinbaseNavigationCommand = MutableSharedFlow<String>()
|
||||
val showFlexaErrorToastCommand = MutableSharedFlow<Unit>()
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<SettingsState> =
|
||||
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(
|
||||
|
|
|
@ -7,5 +7,4 @@
|
|||
<string name="integrations_flexa">Paga con Flexa</string>
|
||||
<string name="integrations_flexa_subtitle">Paga con clips de pago de Flexa y explora una nueva forma de gastar Zcash.</string>
|
||||
<string name="integrations_flexa_biometric_message">Autentifícate para pagar con Flexa</string>
|
||||
<string name="integrations_flexa_key_missing">Clave de Flexa faltante</string>
|
||||
</resources>
|
||||
|
|
|
@ -7,5 +7,4 @@
|
|||
<string name="integrations_flexa">Pay with Flexa</string>
|
||||
<string name="integrations_flexa_subtitle">Pay with Flexa payment clips and explore a new way of spending Zcash.</string>
|
||||
<string name="integrations_flexa_biometric_message">Authenticate yourself to pay with Flexa</string>
|
||||
<string name="integrations_flexa_key_missing">Flexa key missing</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue