Skip to content

Commit

Permalink
MBL-1182: Crash from rx chain returning null in TwoFactorViewModel.kt (
Browse files Browse the repository at this point in the history
…#1951)

* cleanup null checks

* linter
  • Loading branch information
leighdouglas committed Feb 15, 2024
1 parent fb9e580 commit 7d33deb
Showing 1 changed file with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import androidx.lifecycle.ViewModelProvider
import com.kickstarter.libs.Environment
import com.kickstarter.libs.rx.transformers.Transformers
import com.kickstarter.libs.utils.extensions.addToDisposable
import com.kickstarter.libs.utils.extensions.isNotNull
import com.kickstarter.models.User
import com.kickstarter.services.ApiClientTypeV2
import com.kickstarter.services.apiresponses.AccessTokenEnvelope
Expand Down Expand Up @@ -50,7 +49,7 @@ interface TwoFactorViewModel {

class TwoFactorViewModel(
environment: Environment,
intent: Intent? = null
intent: Intent
) : ViewModel(), Inputs, Outputs {
private val client: ApiClientTypeV2 = requireNotNull(environment.apiClientV2())
private val analytics = requireNotNull(environment.analytics())
Expand Down Expand Up @@ -155,15 +154,14 @@ interface TwoFactorViewModel {
)
companion object {
private fun isCodeValid(code: String?): Boolean {
return code != null && code.isNotEmpty()
return !code.isNullOrEmpty()
}
}

init {

val email = internalIntent
.map { it.getStringExtra(IntentKey.EMAIL) }
.filter { it.isNotNull() }
.map { it.getStringExtra(IntentKey.EMAIL) ?: "" }

val fbAccessToken = internalIntent
.map { it.getStringExtra(IntentKey.FACEBOOK_TOKEN) ?: "" }
Expand All @@ -172,8 +170,7 @@ interface TwoFactorViewModel {
.map { it.getBooleanExtra(IntentKey.FACEBOOK_LOGIN, false) }

val password = internalIntent
.map { it.getStringExtra(IntentKey.PASSWORD) }
.filter { it.isNotNull() }
.map { it.getStringExtra(IntentKey.PASSWORD) ?: "" }

val tfaData = Observable.combineLatest(
email,
Expand All @@ -198,7 +195,7 @@ interface TwoFactorViewModel {
}

this.code
.map { code: String? -> isCodeValid(code) }
.map { isCodeValid(it) }
.subscribe { formIsValid.onNext(it) }
.addToDisposable(disposables)

Expand Down Expand Up @@ -264,7 +261,7 @@ interface TwoFactorViewModel {
}
}

class Factory(private val environment: Environment, private val intent: Intent? = null) : ViewModelProvider.Factory {
class Factory(private val environment: Environment, private val intent: Intent) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return TwoFactorViewModel(environment, intent) as T
}
Expand Down

0 comments on commit 7d33deb

Please sign in to comment.