Skip to content

Commit

Permalink
AND-8917 [Onboarding V2] Entry component + routing
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterBin committed Oct 29, 2024
1 parent 9cdaa39 commit f85c2d9
Show file tree
Hide file tree
Showing 14 changed files with 149 additions and 4 deletions.
3 changes: 3 additions & 0 deletions app/src/main/java/com/tangem/tap/ApplicationEntryPoint.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.tangem.domain.walletmanager.WalletManagersFacade
import com.tangem.domain.wallets.legacy.UserWalletsListManager
import com.tangem.domain.wallets.repository.WalletsRepository
import com.tangem.domain.wallets.usecase.GenerateWalletNameUseCase
import com.tangem.features.onboarding.v2.OnboardingV2FeatureToggles
import com.tangem.features.onramp.OnrampFeatureToggles
import com.tangem.tap.common.log.TangemAppLoggerInitializer
import com.tangem.tap.domain.scanCard.CardScanningFeatureToggles
Expand Down Expand Up @@ -110,4 +111,6 @@ interface ApplicationEntryPoint {
fun getGetUserCountryCodeUseCase(): GetUserCountryUseCase

fun getOnrampFeatureToggles(): OnrampFeatureToggles

fun getOnboardingV2FeatureToggles(): OnboardingV2FeatureToggles
}
5 changes: 5 additions & 0 deletions app/src/main/java/com/tangem/tap/TangemApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import com.tangem.domain.walletmanager.WalletManagersFacade
import com.tangem.domain.wallets.legacy.UserWalletsListManager
import com.tangem.domain.wallets.repository.WalletsRepository
import com.tangem.domain.wallets.usecase.GenerateWalletNameUseCase
import com.tangem.features.onboarding.v2.OnboardingV2FeatureToggles
import com.tangem.features.onramp.OnrampFeatureToggles
import com.tangem.tap.common.analytics.AnalyticsFactory
import com.tangem.tap.common.analytics.api.AnalyticsHandlerBuilder
Expand Down Expand Up @@ -176,6 +177,9 @@ abstract class TangemApplication : Application(), ImageLoaderFactory {

private val onrampFeatureToggles: OnrampFeatureToggles
get() = entryPoint.getOnrampFeatureToggles()

private val onboardingV2FeatureToggles: OnboardingV2FeatureToggles
get() = entryPoint.getOnboardingV2FeatureToggles()
// endregion

override fun onCreate() {
Expand Down Expand Up @@ -253,6 +257,7 @@ abstract class TangemApplication : Application(), ImageLoaderFactory {
getUserCountryUseCase = getUserCountryUseCase,
onrampFeatureToggles = onrampFeatureToggles,
environmentConfigStorage = environmentConfigStorage,
onboardingV2FeatureToggles = onboardingV2FeatureToggles,
),
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ object OnboardingHelper {
}

fun whereToNavigate(scanResponse: ScanResponse): AppRoute {
if (store.inject(DaggerGraphState::onboardingV2FeatureToggles).isOnboardingV2Enabled) {
return AppRoute.Onboarding(scanResponse)
}

return when (val type = scanResponse.productType) {
ProductType.Note -> AppRoute.OnboardingNote
ProductType.Wallet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.tangem.domain.walletmanager.WalletManagersFacade
import com.tangem.domain.wallets.legacy.UserWalletsListManager
import com.tangem.domain.wallets.repository.WalletsRepository
import com.tangem.domain.wallets.usecase.GenerateWalletNameUseCase
import com.tangem.features.onboarding.v2.OnboardingV2FeatureToggles
import com.tangem.features.onramp.OnrampFeatureToggles
import com.tangem.features.pushnotifications.api.navigation.PushNotificationsRouter
import com.tangem.features.staking.api.navigation.StakingRouter
Expand Down Expand Up @@ -69,4 +70,5 @@ data class DaggerGraphState(
val getUserCountryUseCase: GetUserCountryUseCase? = null,
val onrampFeatureToggles: OnrampFeatureToggles? = null,
val environmentConfigStorage: EnvironmentConfigStorage? = null,
val onboardingV2FeatureToggles: OnboardingV2FeatureToggles? = null,
) : StateType
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.tangem.features.managetokens.component.ManageTokensComponent
import com.tangem.features.managetokens.component.ManageTokensSource
import com.tangem.features.markets.details.MarketsTokenDetailsComponent
import com.tangem.features.onramp.component.BuyCryptoComponent
import com.tangem.features.onboarding.v2.entry.OnboardingEntryComponent
import com.tangem.features.onramp.component.OnrampComponent
import com.tangem.features.pushnotifications.api.navigation.PushNotificationsRouter
import com.tangem.features.send.api.navigation.SendRouter
Expand Down Expand Up @@ -50,6 +51,7 @@ internal class ChildFactory @Inject constructor(
private val marketsTokenDetailsComponentFactory: MarketsTokenDetailsComponent.Factory,
private val onrampComponentFactory: OnrampComponent.Factory,
private val buyCryptoComponentFactory: BuyCryptoComponent.Factory,
private val onboardingEntryComponentFactory: OnboardingEntryComponent.Factory,
private val sendRouter: SendRouter,
private val tokenDetailsRouter: TokenDetailsRouter,
private val walletRouter: WalletRouter,
Expand Down Expand Up @@ -204,6 +206,13 @@ internal class ChildFactory @Inject constructor(
componentFactory = buyCryptoComponentFactory,
)
}
is AppRoute.Onboarding -> {
route.asComponentChild(
contextProvider = contextProvider(route, contextFactory),
params = OnboardingEntryComponent.Params(route.scanResponse),
componentFactory = onboardingEntryComponentFactory,
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.tangem.common.routing.entity.SerializableIntent
import com.tangem.core.decompose.navigation.Route
import com.tangem.domain.appcurrency.model.AppCurrency
import com.tangem.domain.markets.TokenMarketParams
import com.tangem.domain.models.scan.ScanResponse
import com.tangem.domain.qrscanning.models.SourceType
import com.tangem.domain.staking.model.stakekit.Yield
import com.tangem.domain.tokens.model.CryptoCurrency
Expand Down Expand Up @@ -292,4 +293,7 @@ sealed class AppRoute(val path: String) : Route {
data class BuyCrypto(
val userWalletId: UserWalletId,
) : AppRoute(path = "/buy_crypto/${userWalletId.stringValue}")

// Onboarding V2
data class Onboarding(val scanResponse: ScanResponse) : AppRoute(path = "/onboarding_v2")
}
2 changes: 1 addition & 1 deletion features/onboarding-v2/api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {
dependencies {

/* Project - Domain */
implementation(projects.domain.wallets.models)
implementation(projects.domain.models)

/* Project - Core */
implementation(projects.core.decompose)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.tangem.features.onboarding.v2

interface OnboardingV2FeatureToggles {
val isRewrittenOnboardingCodeInUse: Boolean
val isOnboardingV2Enabled: Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package com.tangem.features.onboarding.v2.entry

import com.tangem.core.decompose.factory.ComponentFactory
import com.tangem.core.ui.decompose.ComposableContentComponent
import com.tangem.domain.models.scan.ScanResponse

interface OnboardingEntryComponent : ComposableContentComponent {

data class Params(
val todo: String,
val scanResponse: ScanResponse,
)

interface Factory : ComponentFactory<Params, OnboardingEntryComponent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import javax.inject.Inject
internal class DefaultOnboardingV2FeatureToggles @Inject constructor(
private val featureTogglesManager: FeatureTogglesManager,
) : OnboardingV2FeatureToggles {
override val isRewrittenOnboardingCodeInUse: Boolean
override val isOnboardingV2Enabled: Boolean
get() = featureTogglesManager.isFeatureEnabled("ONBOARDING_CODE_REFACTORING_ENABLED")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.tangem.features.onboarding.v2.entry.impl

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.tangem.core.decompose.context.AppComponentContext
import com.tangem.core.decompose.context.child
import com.tangem.core.ui.extensions.stringReference
import com.tangem.features.onboarding.v2.entry.OnboardingEntryComponent
import com.tangem.features.onboarding.v2.entry.impl.ui.OnboardingEntry
import com.tangem.features.onboarding.v2.stepper.api.OnboardingStepperComponent
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject

internal class DefaultOnboardingEntryComponent @AssistedInject constructor(
@Assisted val context: AppComponentContext,
@Assisted val params: OnboardingEntryComponent.Params,
stepperFactory: OnboardingStepperComponent.Factory,
) : OnboardingEntryComponent, AppComponentContext by context {

private val stepperComponent = stepperFactory.create(
context = child("stepper"),
params = OnboardingStepperComponent.Params(
scanResponse = params.scanResponse,
initState = OnboardingStepperComponent.StepperState(
currentStep = 0,
steps = 3,
title = stringReference(""),
),
popBack = { router.pop() },
),
)

@Composable
override fun Content(modifier: Modifier) {
OnboardingEntry(
modifier = modifier,
stepperContent = { modifierParam ->
stepperComponent.Content(modifierParam)
},
)
}

@AssistedFactory
interface Factory : OnboardingEntryComponent.Factory {
override fun create(
context: AppComponentContext,
params: OnboardingEntryComponent.Params,
): DefaultOnboardingEntryComponent
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.tangem.features.onboarding.v2.entry.impl.di

import com.tangem.features.onboarding.v2.entry.OnboardingEntryComponent
import com.tangem.features.onboarding.v2.entry.impl.DefaultOnboardingEntryComponent
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
internal interface ComponentModule {

@Binds
@Singleton
fun bindOnboardingEntryComponent(
factory: DefaultOnboardingEntryComponent.Factory,
): OnboardingEntryComponent.Factory
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.tangem.features.onboarding.v2.entry.impl.ui

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.tangem.core.ui.components.appbar.TangemTopAppBar
import com.tangem.core.ui.components.appbar.models.TopAppBarButtonUM
import com.tangem.core.ui.res.TangemTheme
import com.tangem.core.ui.res.TangemThemePreview
import com.tangem.features.onboarding.v2.impl.R

@Composable
internal inline fun OnboardingEntry(modifier: Modifier = Modifier, stepperContent: @Composable (Modifier) -> Unit) {
Column(
modifier = modifier
.fillMaxSize()
.statusBarsPadding()
.background(TangemTheme.colors.background.primary),
) {
stepperContent(Modifier.fillMaxWidth())
}
}

@Preview
@Composable
private fun Preview() {
TangemThemePreview {
OnboardingEntry {
TangemTopAppBar(
title = "Onboarding",
startButton = TopAppBarButtonUM(
iconRes = R.drawable.ic_back_24,
enabled = true,
onIconClicked = {},
),
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.tangem.features.onboarding.v2.stepper.api

import androidx.annotation.IntRange
import androidx.compose.runtime.Stable
import com.tangem.core.decompose.factory.ComponentFactory
import com.tangem.core.ui.decompose.ComposableContentComponent
import com.tangem.core.ui.extensions.TextReference
import com.tangem.domain.models.scan.ScanResponse
import kotlinx.coroutines.flow.StateFlow

@Stable
interface OnboardingStepperComponent : ComposableContentComponent {

data class StepperState(
Expand Down

0 comments on commit f85c2d9

Please sign in to comment.