Skip to content

Commit

Permalink
Merge branch 'develop' of github_p2p:p2p-org/key-app-android into fea…
Browse files Browse the repository at this point in the history
…ture/PWN-8969-striga-sms-errors-handling

� Conflicts:
�	app/src/main/java/org/p2p/wallet/smsinput/SmsInputFactory.kt
  • Loading branch information
eduardmaximovich committed Jun 26, 2023
2 parents 00b71ab + 4c7aa68 commit cbb533e
Show file tree
Hide file tree
Showing 56 changed files with 922 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ class RestoreFlowDataLocalRepository(signUpDetailsStorage: UserSignUpDetailsStor
var torusKey: String? = null
set(value) {
field = value
torusKeyTimestamp = DateTimeUtils.getCurrentTimestampInSeconds()
torusKeyTimestamp = value?.let { DateTimeUtils.getCurrentTimestampInSeconds() } ?: 0

Timber.tag(TAG).i("torusKey is generated and set: ${torusKey?.length}")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.p2p.wallet.auth.ui.generalerror.timer
import androidx.activity.addCallback
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updatePadding
import androidx.fragment.app.Fragment
import android.os.Bundle
import android.text.method.LinkMovementMethod
import android.view.View
Expand All @@ -14,13 +15,16 @@ import org.p2p.core.utils.insets.systemAndIme
import org.p2p.wallet.R
import org.p2p.wallet.auth.ui.generalerror.timer.OnboardingGeneralErrorTimerContract.Presenter
import org.p2p.wallet.auth.ui.onboarding.root.OnboardingRootFragment
import org.p2p.wallet.common.NavigationStrategy
import org.p2p.wallet.common.NavigationStrategy.Companion.ARG_NAVIGATION_STRATEGY
import org.p2p.wallet.common.NavigationStrategy.Companion.ARG_NEXT_DESTINATION_CLASS
import org.p2p.wallet.common.NavigationStrategy.Replace.navigateNext
import org.p2p.wallet.common.mvp.BaseMvpFragment
import org.p2p.wallet.databinding.FragmentOnboardingGeneralErrorTimerBinding
import org.p2p.wallet.intercom.IntercomService
import org.p2p.wallet.utils.OnboardingSpanUtils
import org.p2p.wallet.utils.args
import org.p2p.wallet.utils.openFile
import org.p2p.wallet.utils.popAndReplaceFragment
import org.p2p.wallet.utils.viewbinding.viewBinding
import org.p2p.wallet.utils.withArgs
import org.p2p.wallet.auth.ui.generalerror.timer.OnboardingGeneralErrorTimerContract.View as ContractView
Expand All @@ -33,15 +37,29 @@ class OnboardingGeneralErrorTimerFragment :
ContractView {

companion object {
fun create(error: GeneralErrorTimerScreenError, timerLeftTime: Long): OnboardingGeneralErrorTimerFragment =
OnboardingGeneralErrorTimerFragment().withArgs(
fun create(
error: GeneralErrorTimerScreenError,
timerLeftTime: Long,
destinationFragment: Class<out Fragment>? = null,
navigationStrategy: NavigationStrategy? = null
): OnboardingGeneralErrorTimerFragment {
val destinationClass = destinationFragment ?: OnboardingRootFragment::class.java
val defaultStrategy = NavigationStrategy.PopAndReplace(null, true)
val strategy = navigationStrategy ?: defaultStrategy
return OnboardingGeneralErrorTimerFragment().withArgs(
ARG_TIMER_ERROR_TYPE to error,
ARG_TIMER_LEFT_TIME to timerLeftTime
ARG_TIMER_LEFT_TIME to timerLeftTime,
ARG_NEXT_DESTINATION_CLASS to destinationClass,
ARG_NAVIGATION_STRATEGY to strategy
)
}
}

override val presenter: Presenter by inject { parametersOf(error, timerLeftTime) }

private val nextDestinationClass: Class<Fragment> by args(ARG_NEXT_DESTINATION_CLASS)
private val navigationStrategy: NavigationStrategy by args(ARG_NAVIGATION_STRATEGY)

private val binding: FragmentOnboardingGeneralErrorTimerBinding by viewBinding()
private val error: GeneralErrorTimerScreenError by args(ARG_TIMER_ERROR_TYPE)
private val timerLeftTime: Long by args(ARG_TIMER_LEFT_TIME)
Expand Down Expand Up @@ -90,7 +108,7 @@ class OnboardingGeneralErrorTimerFragment :
}

override fun navigateToStartingScreen() {
popAndReplaceFragment(OnboardingRootFragment.create(), inclusive = true)
navigationStrategy.navigateNext(this, nextDestinationClass)
}

override fun showFile(file: File) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.p2p.wallet.databinding.FragmentRestoreErrorScreenBinding
import org.p2p.wallet.intercom.IntercomService
import org.p2p.wallet.root.SystemIconsStyle
import org.p2p.wallet.utils.args
import org.p2p.wallet.utils.emptyString
import org.p2p.wallet.utils.popAndReplaceFragment
import org.p2p.wallet.utils.viewbinding.viewBinding
import org.p2p.wallet.utils.withArgs
Expand Down Expand Up @@ -65,6 +66,7 @@ class RestoreErrorScreenFragment :
binding.toolbar.inflateMenu(R.menu.menu_onboarding_help)
binding.toolbar.setOnMenuItemClickListener {
if (it.itemId == R.id.helpItem) {
IntercomService.signIn(userId = emptyString())
IntercomService.showMessenger()
}
return@setOnMenuItemClickListener true
Expand Down
72 changes: 72 additions & 0 deletions app/src/main/java/org/p2p/wallet/common/NavigationStrategy.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package org.p2p.wallet.common

import androidx.fragment.app.Fragment
import android.os.Bundle
import android.os.Parcelable
import kotlinx.parcelize.Parcelize
import org.p2p.wallet.utils.popAndReplaceFragment
import org.p2p.wallet.utils.popBackStackTo
import org.p2p.wallet.utils.replaceFragment

@Parcelize
sealed class NavigationStrategy : Parcelable {

companion object {
const val ARG_NEXT_DESTINATION_CLASS = "ARG_NEXT_DESTINATION_CLASS"
const val ARG_NEXT_DESTINATION_ARGS = "ARG_NEXT_DESTINATION_ARGS"
const val ARG_NAVIGATION_STRATEGY = "ARG_NAVIGATION_STRATEGY"

fun createNextDestination(
nextDestinationClass: Class<Fragment>,
nextDestinationArgs: Bundle? = null
): Fragment {
return nextDestinationClass.newInstance().apply {
arguments = nextDestinationArgs
}
}
}

object Replace : NavigationStrategy() {
override fun execute(sourceFragment: Fragment, destinationFragment: Fragment) {
sourceFragment.replaceFragment(destinationFragment)
}
}

@Parcelize
data class PopAndReplace(
val popTo: Class<out Fragment>? = null,
val inclusive: Boolean = false
) : Parcelable, NavigationStrategy() {
override fun execute(sourceFragment: Fragment, destinationFragment: Fragment) {
sourceFragment.popAndReplaceFragment(
target = destinationFragment,
popTo = popTo?.kotlin,
inclusive = inclusive
)
}
}

@Parcelize
data class PopBackStackTo(
val popTo: Class<out Fragment>,
val inclusive: Boolean = false
) : Parcelable, NavigationStrategy() {
override fun execute(sourceFragment: Fragment, destinationFragment: Fragment) {
sourceFragment.popBackStackTo(
target = popTo.kotlin,
inclusive = inclusive
)
}
}

abstract fun execute(sourceFragment: Fragment, destinationFragment: Fragment)

fun navigateNext(
sourceFragment: Fragment,
nextDestinationClass: Class<Fragment>,
nextDestinationArgs: Bundle? = null
) {
val destination = createNextDestination(nextDestinationClass, nextDestinationArgs)
execute(sourceFragment, destination)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.p2p.wallet.common.feature_toggles.toggles.remote.SocketSubscriptionsF
import org.p2p.wallet.common.feature_toggles.toggles.remote.SolendEnabledFeatureToggle
import org.p2p.wallet.common.feature_toggles.toggles.remote.SslPinningFeatureToggle
import org.p2p.wallet.common.feature_toggles.toggles.remote.StrigaSignupEnabledFeatureToggle
import org.p2p.wallet.common.feature_toggles.toggles.remote.SwapRoutesRefreshFeatureToggle
import org.p2p.wallet.common.feature_toggles.toggles.remote.SwapRoutesValidationEnabledFeatureToggle
import org.p2p.wallet.common.feature_toggles.toggles.remote.TokenMetadataUpdateFeatureToggle
import org.p2p.wallet.common.feature_toggles.toggles.remote.UsernameDomainFeatureToggle
Expand Down Expand Up @@ -52,6 +53,7 @@ object FeatureTogglesModule : InjectionModule {
get<SocketSubscriptionsFeatureToggle>(),
get<SwapRoutesValidationEnabledFeatureToggle>(),
get<StrigaSignupEnabledFeatureToggle>(),
get<SwapRoutesRefreshFeatureToggle>(),
).toList()
}

Expand All @@ -70,6 +72,7 @@ object FeatureTogglesModule : InjectionModule {
factoryOf(::RegisterUsernameSkipEnabledFeatureToggle)
factoryOf(::SellEnabledFeatureToggle)
factoryOf(::EthAddressEnabledFeatureToggle)
factoryOf(::SwapRoutesRefreshFeatureToggle)
factoryOf(::SocketSubscriptionsFeatureToggle)
factoryOf(::SwapRoutesValidationEnabledFeatureToggle)
factoryOf(::StrigaSignupEnabledFeatureToggle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ class AppFirebaseRemoteConfig(
return remoteConfig.getString(toggleKey).toIntOrNull()
}

override fun getLong(toggleKey: String): Long? {
if (isFetchFailed) {
return null
}
return remoteConfig.getString(toggleKey).toLongOrNull()
}

override fun getFloat(toggleKey: String): Float? {
if (isFetchFailed) {
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ class FeatureTogglesValuesSource(
override fun getBoolean(toggleKey: String): Boolean? = sourceToGetFrom.getBoolean(toggleKey)
override fun getFloat(toggleKey: String): Float? = sourceToGetFrom.getFloat(toggleKey)
override fun getInt(toggleKey: String): Int? = sourceToGetFrom.getInt(toggleKey)
override fun getLong(toggleKey: String): Long? = sourceToGetFrom.getLong(toggleKey)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ class LocalFirebaseRemoteConfig(
override fun getBoolean(toggleKey: String): Boolean = storage[toggleKey].toBoolean()
override fun getString(toggleKey: String): String? = storage[toggleKey]
override fun getInt(toggleKey: String): Int? = storage[toggleKey]?.toIntOrNull()
override fun getLong(toggleKey: String): Long? = storage[toggleKey]?.toLongOrNull()
override fun getFloat(toggleKey: String): Float? = storage[toggleKey]?.toFloatOrNull()
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ interface RemoteConfigValuesProvider {
fun getBoolean(toggleKey: String): Boolean?
fun getFloat(toggleKey: String): Float?
fun getInt(toggleKey: String): Int?
fun getLong(toggleKey: String): Long?
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.p2p.wallet.common.feature_toggles.toggles.remote

import org.p2p.wallet.common.feature_toggles.remote_config.RemoteConfigValuesProvider
import timber.log.Timber
import org.p2p.wallet.common.feature_toggles.remote_config.RemoteConfigValuesProvider

sealed class RemoteFeatureToggle<ValueType> {
/**
Expand Down Expand Up @@ -39,6 +39,16 @@ abstract class IntFeatureToggle(
}
}

abstract class LongFeatureToggle(
private val valuesProvider: RemoteConfigValuesProvider
) : RemoteFeatureToggle<Long>() {
override val value: Long
get() = valuesProvider.getLong(featureKey) ?: kotlin.run {
Timber.tag("LongFeatureToggle").i("No value found for $featureKey; using defaults = $defaultValue")
defaultValue
}
}

abstract class StringFeatureToggle(
private val valuesProvider: RemoteConfigValuesProvider
) : RemoteFeatureToggle<String>() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.p2p.wallet.common.feature_toggles.toggles.remote

import java.util.concurrent.TimeUnit
import org.p2p.wallet.common.feature_toggles.remote_config.RemoteConfigValuesProvider

private const val DEFAULT_INTERVAL_IN_SECONDS = 20L

class SwapRoutesRefreshFeatureToggle(
valuesProvider: RemoteConfigValuesProvider
) : LongFeatureToggle(valuesProvider) {
override val featureKey: String = "swap_route_refresh"
override val featureDescription: String = "The interval for refreshing routes"
override val defaultValue: Long = DEFAULT_INTERVAL_IN_SECONDS

val durationInMilliseconds: Long = TimeUnit.SECONDS.toMillis(value)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.annotation.StringRes
import android.os.Bundle
import android.view.View
import org.koin.android.ext.android.inject
import org.p2p.core.network.environment.NetworkEnvironment
import org.p2p.uikit.utils.attachAdapter
import org.p2p.wallet.R
import org.p2p.wallet.common.mvp.BaseMvpFragment
Expand All @@ -23,7 +24,7 @@ import org.p2p.wallet.debug.settings.adapter.settingsRowSectionItemDelegate
import org.p2p.wallet.debug.settings.adapter.settingsRowSwtichItemDelegate
import org.p2p.wallet.debug.settings.adapter.settingsRowTitleItemDelegate
import org.p2p.wallet.debug.torus.DebugTorusFragment
import org.p2p.core.network.environment.NetworkEnvironment
import org.p2p.wallet.debug.uikit.DebugUiKitFragmentFragment
import org.p2p.wallet.settings.model.SettingsRow
import org.p2p.wallet.settings.ui.network.SettingsNetworkBottomSheet
import org.p2p.wallet.utils.getSerializableOrNull
Expand Down Expand Up @@ -115,6 +116,9 @@ class DebugSettingsFragment :
R.string.debug_settings_striga_detach_user_id_title -> {
presenter.onClickDetachStrigaUser()
}
R.string.debug_settings_ui_kit -> {
replaceFragment(DebugUiKitFragmentFragment())
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ class DebugSettingsMapper(
}

this += createStrigaSettings()

this += SettingsRow.Section(
titleResId = R.string.debug_settings_ui_kit,
iconRes = R.drawable.ic_settings_cloud
)
}

private fun createEnvironmentSettings(): List<SettingsRow> = buildList {
Expand Down
Loading

0 comments on commit cbb533e

Please sign in to comment.