Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deployment issues with mainnet test users #111

Merged
merged 12 commits into from
May 18, 2024
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

were we running into issues here locally or on bitrise? ideally this should be configured differently for local vs ci

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI


org.gradle.parallel=true
org.gradle.caching=true
Expand Down
2 changes: 1 addition & 1 deletion v4/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
4 changes: 4 additions & 0 deletions v4/app/src/main/java/exchange/dydx/trading/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 25 additions & 2 deletions v4/common/src/main/java/exchange/dydx/trading/common/AppConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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
Expand All @@ -31,6 +33,7 @@ interface AppConfig {
appVersionCode = "0",
debug = BuildConfig.DEBUG,
activityClass = null,
preferencesStore = null,
)
}
}
Expand All @@ -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
}
Comment on lines +52 to +55
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a huge code smell, we should address later. appContext by definition is never null, same with preferencesStore (since we are always providing it in the graph)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppConfig needs mocks. No big deal.. can refactor when we run out of stuff to do.


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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -99,7 +99,7 @@ data class DydxWalletInstance(
) {
companion object {
fun v4(
ethereumAddress: String,
ethereumAddress: String?,
walletId: String?,
cosmoAddress: String,
mnemonic: String,
Expand Down
Loading