Skip to content

Commit

Permalink
Flexa optimization (#1661)
Browse files Browse the repository at this point in the history
* Flexa optimization

* Code cleanup

* Code cleanup
  • Loading branch information
Milan-Cerovsky authored Nov 4, 2024
1 parent 438071a commit e638499
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class FlexaRepositoryImpl(
get() = BuildConfig.ZCASH_FLEXA_KEY.takeIf { it.isNotEmpty() }

override fun init() {
if (publishableKey == null) return

scope.launch {
val configuration = getFlexaClientConfiguration()
if (configuration != null) {
Expand Down Expand Up @@ -102,6 +104,7 @@ class FlexaRepositoryImpl(
assetId = "bip122:00040fe8ec8471911baa1db1266ea15d/slip44:133",
balance = zecBalance,
symbol = "ZEC",
icon = "https://cryptologos.cc/logos/zcash-zec-logo.png"
)
),
custodyModel = CustodyModel.LOCAL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ 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.MainActivity
import co.electriccoin.zcash.ui.common.model.OnboardingState
import co.electriccoin.zcash.ui.common.model.WalletRestoringState
Expand Down Expand Up @@ -276,7 +277,7 @@ class WalletViewModel(

private suspend fun disconnectFlexa() =
suspendCoroutine { cont ->
if (isFlexaAvailable()) {
if (isFlexaAvailable() && BuildConfig.ZCASH_FLEXA_KEY.isNotEmpty()) {
Flexa.buildIdentity().build().disconnect()
cont.resume(Unit)
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
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
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
Expand Down Expand Up @@ -55,6 +57,12 @@ internal fun WrapIntegrations() {
}
}

LaunchedEffect(Unit) {
viewModel.showFlexaErrorToastCommand.collect {
Toast.makeText(activity, R.string.integrations_flexa_key_missing, Toast.LENGTH_LONG).show()
}
}

BackHandler {
viewModel.onBack()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ 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 }
Expand Down Expand Up @@ -143,7 +144,11 @@ class IntegrationsViewModel(

private fun onFlexaClicked() =
viewModelScope.launch {
flexaNavigationCommand.emit(Unit)
if (BuildConfig.ZCASH_FLEXA_KEY.isEmpty()) {
showFlexaErrorToastCommand.emit(Unit)
} else {
flexaNavigationCommand.emit(Unit)
}
}

fun onFlexaResultCallback(transaction: Result<Transaction>) =
Expand Down
1 change: 1 addition & 0 deletions ui-lib/src/main/res/ui/integrations/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
<string name="integrations_version">Version <xliff:g id="version" example="1.2.1">%1$s</xliff:g></string>
<string name="integrations_disabled_info">During the Restore process, it is not possible to use payment integrations.</string>
<string name="integrations_biometric_message">Authenticate yourself to pay with Flexa</string>
<string name="integrations_flexa_key_missing">Flexa key missing</string>
</resources>

0 comments on commit e638499

Please sign in to comment.