From 9047bca866258deb0719e76e1e123ea3e100bc44 Mon Sep 17 00:00:00 2001 From: Rui <102453770+ruixhuang@users.noreply.github.com> Date: Sat, 18 May 2024 12:37:45 -0700 Subject: [PATCH] Fix deployment issues with mainnet test users (#111) * Stop app from exiting at region restriction * Not showing the button * Lint * Force TESTNET when user debugging is enabled. * Force deployment web host * Fix URL * Clean up * Made ethereumAddress null instead empty string * Update version to 1.0.2 * Increase heap size * Update from TESTNET to TESTFLIGHT --- gradle.properties | 2 +- v4/app/build.gradle | 2 +- .../java/exchange/dydx/trading/AppModule.kt | 4 +++ .../exchange/dydx/trading/common/AppConfig.kt | 27 +++++++++++++++++-- .../desktopscan/DydxDesktopScanViewModel.kt | 2 +- .../DydxTransferDepositCtaButtonModel.kt | 3 ++- .../dydxstatemanager/AbacusStateManager.kt | 22 ++++++++++----- .../clientState/wallets/DydxWalletState.kt | 4 +-- 8 files changed, 52 insertions(+), 14 deletions(-) diff --git a/gradle.properties b/gradle.properties index 28e18b99..68fc85a2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ # http://www.gradle.org/docs/current/userguide/build_environment.html # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. -org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 +org.gradle.jvmargs=-Xmx4096m -Dfile.encoding=UTF-8 org.gradle.parallel=true org.gradle.caching=true diff --git a/v4/app/build.gradle b/v4/app/build.gradle index eacc7ab7..e3d97e07 100644 --- a/v4/app/build.gradle +++ b/v4/app/build.gradle @@ -19,7 +19,7 @@ android { minSdkVersion parent.minSdkVersion targetSdkVersion parent.targetSdkVersion versionCode 9 - versionName "1.0.1" + versionName "1.0.2" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" diff --git a/v4/app/src/main/java/exchange/dydx/trading/AppModule.kt b/v4/app/src/main/java/exchange/dydx/trading/AppModule.kt index d6d1a803..057306af 100644 --- a/v4/app/src/main/java/exchange/dydx/trading/AppModule.kt +++ b/v4/app/src/main/java/exchange/dydx/trading/AppModule.kt @@ -140,12 +140,16 @@ interface AppModule { @Provides fun provideAppConfig( application: Application, + preferenceStore: SharedPreferencesStore, + logger: Logging, ): AppConfig = AppConfigImpl( appContext = application, appVersionName = BuildConfig.VERSION_NAME, appVersionCode = BuildConfig.VERSION_CODE.toString(), debug = BuildConfig.DEBUG, activityClass = TradingActivity::class.java, + preferencesStore = preferenceStore, + logger = logger, ) @Provides diff --git a/v4/common/src/main/java/exchange/dydx/trading/common/AppConfig.kt b/v4/common/src/main/java/exchange/dydx/trading/common/AppConfig.kt index b7c9b095..26546851 100644 --- a/v4/common/src/main/java/exchange/dydx/trading/common/AppConfig.kt +++ b/v4/common/src/main/java/exchange/dydx/trading/common/AppConfig.kt @@ -5,6 +5,9 @@ import android.content.Context import android.util.Log import androidx.compose.runtime.Composable import androidx.compose.ui.platform.LocalInspectionMode +import exchange.dydx.utilities.utils.DebugEnabled +import exchange.dydx.utilities.utils.Logging +import exchange.dydx.utilities.utils.SharedPreferencesStore interface AppConfig { val appContext: Context? @@ -17,7 +20,6 @@ interface AppConfig { val appSchemeHost: String? get() = appContext?.getString(R.string.app_scheme_host) val appWebHost: String? - get() = appContext?.getString(R.string.app_web_host) companion object { const val ANDROID_LOGGING = Log.INFO @@ -31,6 +33,7 @@ interface AppConfig { appVersionCode = "0", debug = BuildConfig.DEBUG, activityClass = null, + preferencesStore = null, ) } } @@ -41,7 +44,27 @@ data class AppConfigImpl( override val appVersionCode: String, override val debug: Boolean, override val activityClass: Class<*>?, -) : AppConfig + private val preferencesStore: SharedPreferencesStore?, + private val logger: Logging? = null, +) : AppConfig { + override val appWebHost: String? + get() { + if (appContext == null || preferencesStore == null) { + logger?.e("AppConfigImpl", "appContext or preferencesStore is null") + return null + } + + val appDeployment = appContext.getString(R.string.app_deployment) + return if (appDeployment == "MAINNET" && DebugEnabled.enabled(preferencesStore)) { + // Force to public testnet host if user has enabled debug mode, otherwise US test + // users will be blocked from accessing the asset images/descriptions, which are fetched + // based on app_web_host. + "v4.testnet.dydx.exchange" + } else { + appContext.getString(R.string.app_web_host) + } + } +} @Composable fun PreviewAppConfig(): AppConfig { diff --git a/v4/feature/onboarding/src/main/java/exchange/dydx/feature/onboarding/desktopscan/DydxDesktopScanViewModel.kt b/v4/feature/onboarding/src/main/java/exchange/dydx/feature/onboarding/desktopscan/DydxDesktopScanViewModel.kt index 9a3a5a46..45098430 100644 --- a/v4/feature/onboarding/src/main/java/exchange/dydx/feature/onboarding/desktopscan/DydxDesktopScanViewModel.kt +++ b/v4/feature/onboarding/src/main/java/exchange/dydx/feature/onboarding/desktopscan/DydxDesktopScanViewModel.kt @@ -74,7 +74,7 @@ class DydxDesktopScanViewModel @Inject constructor( onboardingAnalytics.log(OnboardingAnalytics.OnboardingSteps.KEY_DERIVATION) walletAnalytics.logConnected(null) abacusStateManager.setV4( - ethereumAddress = "", + ethereumAddress = null, mnemonic = mnemonic, cosmosAddress = cosmosAddress, walletId = null, diff --git a/v4/feature/transfer/src/main/java/exchange/dydx/trading/feature/transfer/deposit/DydxTransferDepositCtaButtonModel.kt b/v4/feature/transfer/src/main/java/exchange/dydx/trading/feature/transfer/deposit/DydxTransferDepositCtaButtonModel.kt index 1e44ae4f..309dc93c 100644 --- a/v4/feature/transfer/src/main/java/exchange/dydx/trading/feature/transfer/deposit/DydxTransferDepositCtaButtonModel.kt +++ b/v4/feature/transfer/src/main/java/exchange/dydx/trading/feature/transfer/deposit/DydxTransferDepositCtaButtonModel.kt @@ -135,6 +135,7 @@ class DydxTransferDepositCtaButtonModel @Inject constructor( wallet: DydxWalletInstance?, ) { val wallet = wallet ?: return + val walletAddress = wallet.ethereumAddress ?: return val chain = transferInput.chain ?: return val token = transferInput.token ?: return val chainRpc = transferInput.resources?.chainResources?.get(chain)?.rpc ?: return @@ -143,7 +144,7 @@ class DydxTransferDepositCtaButtonModel @Inject constructor( DydxTransferDepositStep( transferInput = transferInput, provider = carteraProvider, - walletAddress = wallet.ethereumAddress, + walletAddress = walletAddress, walletId = wallet.walletId, chainRpc = chainRpc, tokenAddress = tokenAddress, diff --git a/v4/integration/dydxStateManager/src/main/java/exchange/dydx/dydxstatemanager/AbacusStateManager.kt b/v4/integration/dydxStateManager/src/main/java/exchange/dydx/dydxstatemanager/AbacusStateManager.kt index f35b9f57..d70250e3 100644 --- a/v4/integration/dydxStateManager/src/main/java/exchange/dydx/dydxstatemanager/AbacusStateManager.kt +++ b/v4/integration/dydxStateManager/src/main/java/exchange/dydx/dydxstatemanager/AbacusStateManager.kt @@ -44,11 +44,13 @@ import exchange.dydx.dydxstatemanager.clientState.transfers.DydxTransferStateMan import exchange.dydx.dydxstatemanager.clientState.wallets.DydxWalletInstance import exchange.dydx.dydxstatemanager.clientState.wallets.DydxWalletStateManagerProtocol import exchange.dydx.dydxstatemanager.protocolImplementations.UIImplementationsExtensions +import exchange.dydx.trading.common.AppConfig import exchange.dydx.trading.common.R import exchange.dydx.trading.common.di.CoroutineScopes import exchange.dydx.trading.common.featureflags.DydxFeatureFlag import exchange.dydx.trading.common.featureflags.DydxFeatureFlags import exchange.dydx.trading.integration.cosmos.CosmosV4ClientProtocol +import exchange.dydx.utilities.utils.DebugEnabled import exchange.dydx.utilities.utils.SharedPreferencesStore import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.MutableStateFlow @@ -77,7 +79,7 @@ interface AbacusStateManagerProtocol { fun setEnvironmentId(environment: String?) - fun setV4(ethereumAddress: String, walletId: String?, cosmosAddress: String, mnemonic: String) + fun setV4(ethereumAddress: String?, walletId: String?, cosmosAddress: String, mnemonic: String) fun logOut() fun replaceCurrentWallet() @@ -134,6 +136,7 @@ interface AbacusStateManagerProtocol { @Singleton class AbacusStateManager @Inject constructor( private val application: Application, + private val appConfig: AppConfig, private val ioImplementations: IOImplementations, private val walletStateManager: DydxWalletStateManagerProtocol, private val transferStateManager: DydxTransferStateManagerProtocol, @@ -164,7 +167,14 @@ class AbacusStateManager @Inject constructor( appConfigs = AppConfigs.forApp appConfigsV2 = AppConfigsV2.forApp } else { - deployment = application.getString(R.string.app_deployment) + val appDeployment = application.getString(R.string.app_deployment) + deployment = if (appDeployment == "MAINNET" && DebugEnabled.enabled(preferencesStore)) { + // Force to TESTFLIGHT if user has enabled debug mode, so that both MAINNET and TESTNET can be + // switched from Settings + "TESTFLIGHT" + } else { + appDeployment + } appConfigs = if (BuildConfig.DEBUG && deployment != "MAINNET") AppConfigs.forAppDebug else AppConfigs.forApp appConfigsV2 = @@ -223,10 +233,10 @@ class AbacusStateManager @Inject constructor( override val deploymentUri: String get() { val urlOverride = featureFlags.valueForFeature(DydxFeatureFlag.deployment_url) - if (!urlOverride.isNullOrEmpty()) { - return urlOverride + return if (!urlOverride.isNullOrEmpty()) { + urlOverride } else { - return "https://" + application.getString(R.string.app_web_host) + "https://" + appConfig.appWebHost } } @@ -263,7 +273,7 @@ class AbacusStateManager @Inject constructor( } } - override fun setV4(ethereumAddress: String, walletId: String?, cosmosAddress: String, mnemonic: String) { + override fun setV4(ethereumAddress: String?, walletId: String?, cosmosAddress: String, mnemonic: String) { cosmosClient.connectWallet(mnemonic) { val wallet = DydxWalletInstance.v4(ethereumAddress, walletId, cosmosAddress, mnemonic) walletStateManager.setCurrentWallet(wallet) diff --git a/v4/integration/dydxStateManager/src/main/java/exchange/dydx/dydxstatemanager/clientState/wallets/DydxWalletState.kt b/v4/integration/dydxStateManager/src/main/java/exchange/dydx/dydxstatemanager/clientState/wallets/DydxWalletState.kt index 23464f1e..ac9c8b9c 100644 --- a/v4/integration/dydxStateManager/src/main/java/exchange/dydx/dydxstatemanager/clientState/wallets/DydxWalletState.kt +++ b/v4/integration/dydxStateManager/src/main/java/exchange/dydx/dydxstatemanager/clientState/wallets/DydxWalletState.kt @@ -88,7 +88,7 @@ data class DydxWalletState( @Serializable data class DydxWalletInstance( - var ethereumAddress: String, + var ethereumAddress: String? = null, var walletId: String? = null, var cosmoAddress: String? = null, var mnemonic: String? = null, @@ -99,7 +99,7 @@ data class DydxWalletInstance( ) { companion object { fun v4( - ethereumAddress: String, + ethereumAddress: String?, walletId: String?, cosmoAddress: String, mnemonic: String,