Updated on 2026-08-14
This commit is contained in:
parent
18da968728
commit
aba2f43c34
11 changed files with 224 additions and 4 deletions
|
|
@ -68,6 +68,7 @@ dependencies {
|
|||
implementation(projects.domain.notifications.models)
|
||||
implementation(projects.domain.account)
|
||||
implementation(projects.domain.account.status)
|
||||
implementation(projects.domain.marketing.models)
|
||||
|
||||
/** Common */
|
||||
implementation(projects.common.ui)
|
||||
|
|
@ -80,6 +81,7 @@ dependencies {
|
|||
implementation(projects.features.staking.api)
|
||||
implementation(projects.features.txhistory.api)
|
||||
implementation(projects.features.approval.api)
|
||||
implementation(projects.features.marketing.api)
|
||||
|
||||
/** Decompose */
|
||||
implementation(deps.decompose.ext.compose)
|
||||
|
|
|
|||
|
|
@ -7,9 +7,11 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
|||
import com.arkivanov.decompose.extensions.compose.subscribeAsState
|
||||
import com.arkivanov.decompose.router.slot.childSlot
|
||||
import com.tangem.core.decompose.context.AppComponentContext
|
||||
import com.tangem.core.decompose.context.child
|
||||
import com.tangem.core.decompose.context.childByContext
|
||||
import com.tangem.core.decompose.model.getOrCreateModel
|
||||
import com.tangem.features.approval.api.GiveApprovalComponent
|
||||
import com.tangem.features.marketing.api.MarketingBannerComponent
|
||||
import com.tangem.features.staking.api.StakingComponent
|
||||
import com.tangem.features.staking.impl.presentation.model.StakingModel
|
||||
import com.tangem.features.staking.impl.presentation.ui.StakingScreen
|
||||
|
|
@ -21,10 +23,19 @@ internal class DefaultStakingComponent @AssistedInject constructor(
|
|||
@Assisted appComponentContext: AppComponentContext,
|
||||
@Assisted params: StakingComponent.Params,
|
||||
private val giveApprovalComponentFactory: GiveApprovalComponent.Factory,
|
||||
private val marketingBannerComponentFactory: MarketingBannerComponent.Factory,
|
||||
) : StakingComponent, AppComponentContext by appComponentContext {
|
||||
|
||||
private val model: StakingModel = getOrCreateModel(params)
|
||||
|
||||
private val marketingBannerComponent: MarketingBannerComponent = marketingBannerComponentFactory.create(
|
||||
context = child("stakingMarketingBanner"),
|
||||
params = MarketingBannerComponent.Params.Standalone(
|
||||
requestFlow = model.marketingRequest,
|
||||
onDeeplinkClick = model::onMarketingBannerDeeplink,
|
||||
),
|
||||
)
|
||||
|
||||
private val approvalSlot = childSlot(
|
||||
key = "stakingApprovalSlot",
|
||||
source = model.approvalSlotNavigation,
|
||||
|
|
@ -45,7 +56,7 @@ internal class DefaultStakingComponent @AssistedInject constructor(
|
|||
val currentState by model.uiState.collectAsStateWithLifecycle()
|
||||
val approvalSlotState by approvalSlot.subscribeAsState()
|
||||
|
||||
StakingScreen(currentState)
|
||||
StakingScreen(currentState, marketingBannerComponent)
|
||||
|
||||
approvalSlotState.child?.instance?.BottomSheet()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ import com.tangem.blockchain.common.transaction.Fee
|
|||
import com.tangem.common.TangemBlogUrlBuilder
|
||||
import com.tangem.common.getValidatorsCount
|
||||
import com.tangem.common.routing.AppRouter
|
||||
import com.tangem.common.routing.deeplink.resolveMarketingDeeplink
|
||||
import com.tangem.common.routing.deeplink.toContextualRoute
|
||||
import com.tangem.common.ui.amountScreen.converters.AmountReduceByTransformer.ReduceByData
|
||||
import com.tangem.common.ui.amountScreen.models.AmountState
|
||||
import com.tangem.common.ui.amountScreen.models.EnterAmountBoundary
|
||||
|
|
@ -42,6 +44,7 @@ import com.tangem.domain.feedback.SaveBlockchainErrorUseCase
|
|||
import com.tangem.domain.feedback.SendFeedbackEmailUseCase
|
||||
import com.tangem.domain.feedback.models.BlockchainErrorInfo
|
||||
import com.tangem.domain.feedback.models.FeedbackEmailType
|
||||
import com.tangem.domain.marketing.models.MarketingScreen
|
||||
import com.tangem.domain.models.account.Account
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.currency.CryptoCurrencyStatus
|
||||
|
|
@ -67,6 +70,7 @@ import com.tangem.domain.transaction.usecase.SendTransactionUseCase
|
|||
import com.tangem.domain.utils.convertToSdkAmount
|
||||
import com.tangem.domain.wallets.usecase.GetUserWalletUseCase
|
||||
import com.tangem.features.approval.api.GiveApprovalComponent
|
||||
import com.tangem.features.marketing.api.MarketingBannerRequest
|
||||
import com.tangem.features.staking.api.StakingComponent
|
||||
import com.tangem.features.staking.impl.R
|
||||
import com.tangem.features.staking.impl.analytics.StakingParamsInterceptor
|
||||
|
|
@ -153,7 +157,7 @@ internal class StakingModel @Inject constructor(
|
|||
private val innerRouter: InnerStakingRouter,
|
||||
private val messageSender: UiMessageSender,
|
||||
private val stakingFeatureToggles: StakingFeatureToggles,
|
||||
appRouter: AppRouter,
|
||||
private val appRouter: AppRouter,
|
||||
) : Model(), StakingClickIntents {
|
||||
|
||||
val uiState: StateFlow<StakingUiState> = stateController.uiState
|
||||
|
|
@ -163,6 +167,15 @@ internal class StakingModel @Inject constructor(
|
|||
|
||||
private val params = paramsContainer.require<StakingComponent.Params>()
|
||||
|
||||
val marketingRequest: Flow<MarketingBannerRequest?> = flowOf(
|
||||
MarketingBannerRequest(
|
||||
screen = MarketingScreen.Staking(
|
||||
networkId = params.cryptoCurrency.network.rawId,
|
||||
contractAddress = (params.cryptoCurrency as? CryptoCurrency.Token)?.contractAddress.orEmpty(),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
private val stakingStateRouter: StakingStateRouter = StakingStateRouter(
|
||||
appRouter = appRouter,
|
||||
stateController = stateController,
|
||||
|
|
@ -317,6 +330,16 @@ internal class StakingModel @Inject constructor(
|
|||
stateController.initializeWithUserWallet(userWallet)
|
||||
}
|
||||
|
||||
fun onMarketingBannerDeeplink(deeplink: String): Boolean {
|
||||
val route = resolveMarketingDeeplink(deeplink).toContextualRoute(
|
||||
userWalletId = params.userWalletId,
|
||||
currency = params.cryptoCurrency,
|
||||
screenSource = AnalyticsParam.ScreensSources.Staking,
|
||||
) ?: return false
|
||||
appRouter.push(route)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
paramsInterceptorHolder.removeParamsInterceptor(StakingParamsInterceptor.ID)
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import androidx.compose.ui.tooling.preview.Preview
|
|||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
||||
import androidx.compose.ui.unit.Density
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.tangem.common.ui.navigationButtons.NavigationButtonsState
|
||||
import com.tangem.common.ui.navigationButtons.NavigationPrimaryButton
|
||||
import com.tangem.core.ui.components.SpacerH12
|
||||
|
|
@ -51,6 +52,7 @@ import com.tangem.core.ui.test.StakingDetailsScreenTestTags
|
|||
import com.tangem.domain.models.staking.BalanceType
|
||||
import com.tangem.domain.models.staking.RewardBlockType
|
||||
import com.tangem.domain.staking.model.common.RewardType
|
||||
import com.tangem.features.marketing.api.MarketingBannerComponent
|
||||
import com.tangem.features.staking.impl.R
|
||||
import com.tangem.features.staking.impl.presentation.model.StakingClickIntents
|
||||
import com.tangem.features.staking.impl.presentation.state.BalanceState
|
||||
|
|
@ -67,6 +69,7 @@ private const val BANNER_BLOCK_KEY = "BannerBlock"
|
|||
private const val STAKING_REWARD_BLOCK_KEY = "StakingRewardBlock"
|
||||
private const val ACTIVE_STAKING_BLOCK_KEY = "ActiveStakingBlock"
|
||||
private const val STAKE_PRIMARY_BUTTON_KEY = "StakePrimaryButton"
|
||||
private const val MARKETING_BANNER_BLOCK_KEY = "MarketingBannerBlock"
|
||||
|
||||
@Composable
|
||||
internal fun StakingInitialInfoContent(
|
||||
|
|
@ -74,6 +77,7 @@ internal fun StakingInitialInfoContent(
|
|||
buttonState: NavigationButtonsState,
|
||||
clickIntents: StakingClickIntents,
|
||||
isBalanceHidden: Boolean,
|
||||
marketingBannerComponent: MarketingBannerComponent,
|
||||
) {
|
||||
if (state !is StakingStates.InitialInfoState.Data) return
|
||||
|
||||
|
|
@ -104,6 +108,10 @@ internal fun StakingInitialInfoContent(
|
|||
hideEndText = isBalanceHidden,
|
||||
)
|
||||
|
||||
item(key = MARKETING_BANNER_BLOCK_KEY) {
|
||||
marketingBannerComponent.Content(Modifier.fillMaxWidth().padding(bottom = 12.dp))
|
||||
}
|
||||
|
||||
activeStakingBlock(
|
||||
state = state,
|
||||
clickIntents = clickIntents,
|
||||
|
|
@ -491,6 +499,10 @@ private fun StakingInitialInfoContent_Preview(
|
|||
buttonState = NavigationButtonsState.Empty,
|
||||
clickIntents = StakingClickIntentsStub,
|
||||
isBalanceHidden = false,
|
||||
marketingBannerComponent = object : MarketingBannerComponent {
|
||||
@Composable
|
||||
override fun Content(modifier: Modifier) = Unit
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig
|
|||
import com.tangem.core.ui.extensions.resolveReference
|
||||
import com.tangem.core.ui.res.TangemTheme
|
||||
import com.tangem.core.ui.test.SendScreenTestTags
|
||||
import com.tangem.features.marketing.api.MarketingBannerComponent
|
||||
import com.tangem.features.staking.impl.R
|
||||
import com.tangem.features.staking.impl.presentation.state.StakingStates
|
||||
import com.tangem.features.staking.impl.presentation.state.StakingStep
|
||||
|
|
@ -35,7 +36,7 @@ import kotlinx.coroutines.flow.map
|
|||
import kotlinx.coroutines.flow.withIndex
|
||||
|
||||
@Composable
|
||||
internal fun StakingScreen(uiState: StakingUiState) {
|
||||
internal fun StakingScreen(uiState: StakingUiState, marketingBannerComponent: MarketingBannerComponent) {
|
||||
val confirmationState = uiState.confirmationState as? StakingStates.ConfirmationState.Data
|
||||
|
||||
BackHandler(onBack = uiState.clickIntents::onPrevClick)
|
||||
|
|
@ -53,6 +54,7 @@ internal fun StakingScreen(uiState: StakingUiState) {
|
|||
)
|
||||
StakingScreenContent(
|
||||
uiState = uiState,
|
||||
marketingBannerComponent = marketingBannerComponent,
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
NavigationButtonsBlock(
|
||||
|
|
@ -104,7 +106,11 @@ private fun StakingAppBar(uiState: StakingUiState) {
|
|||
|
||||
@Suppress("LongMethod")
|
||||
@Composable
|
||||
private fun StakingScreenContent(uiState: StakingUiState, modifier: Modifier = Modifier) {
|
||||
private fun StakingScreenContent(
|
||||
uiState: StakingUiState,
|
||||
marketingBannerComponent: MarketingBannerComponent,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val currentScreen = uiState.currentStep
|
||||
var currentStateProxy by remember { mutableStateOf(currentScreen) }
|
||||
var isTransitionAnimationRunning by remember { mutableStateOf(false) }
|
||||
|
|
@ -149,6 +155,7 @@ private fun StakingScreenContent(uiState: StakingUiState, modifier: Modifier = M
|
|||
buttonState = uiState.buttonsState,
|
||||
clickIntents = uiState.clickIntents,
|
||||
isBalanceHidden = uiState.isBalanceHidden,
|
||||
marketingBannerComponent = marketingBannerComponent,
|
||||
)
|
||||
StakingStep.RewardsValidators -> {
|
||||
StakingClaimRewardsValidatorContent(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,89 @@
|
|||
package com.tangem.features.staking.impl.presentation.model
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import com.tangem.common.routing.AppRoute
|
||||
import com.tangem.core.analytics.models.AnalyticsParam
|
||||
import com.tangem.domain.onramp.model.OnrampSource
|
||||
import io.mockk.Runs
|
||||
import io.mockk.every
|
||||
import io.mockk.just
|
||||
import io.mockk.verify
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.test.advanceUntilIdle
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
internal class StakingModelMarketingDeeplinkTest : StakingModelTestBase() {
|
||||
|
||||
@Test
|
||||
fun `GIVEN swap deeplink WHEN onMarketingBannerDeeplink THEN pushes Swap for current token`() = runTest {
|
||||
// Arrange
|
||||
every { appRouter.push(any(), any()) } just Runs
|
||||
val model = createModel(testScope = this)
|
||||
advanceUntilIdle()
|
||||
|
||||
// Act
|
||||
val handled = model.onMarketingBannerDeeplink("tangem://swap")
|
||||
|
||||
// Assert
|
||||
assertThat(handled).isTrue()
|
||||
verify {
|
||||
appRouter.push(
|
||||
match {
|
||||
it is AppRoute.Swap &&
|
||||
it.userWalletId == testUserWalletId &&
|
||||
it.fromCryptoCurrency == testCryptoCurrency &&
|
||||
it.screenSource == AnalyticsParam.ScreensSources.Staking.value
|
||||
},
|
||||
any(),
|
||||
)
|
||||
}
|
||||
|
||||
model.onDestroy()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN buy deeplink WHEN onMarketingBannerDeeplink THEN pushes Onramp for current token`() = runTest {
|
||||
// Arrange
|
||||
every { appRouter.push(any(), any()) } just Runs
|
||||
val model = createModel(testScope = this)
|
||||
advanceUntilIdle()
|
||||
|
||||
// Act
|
||||
val handled = model.onMarketingBannerDeeplink("tangem://buy")
|
||||
|
||||
// Assert
|
||||
assertThat(handled).isTrue()
|
||||
verify {
|
||||
appRouter.push(
|
||||
match {
|
||||
it is AppRoute.Onramp &&
|
||||
it.userWalletId == testUserWalletId &&
|
||||
it.currency == testCryptoCurrency &&
|
||||
it.source == OnrampSource.MARKETING_BANNER
|
||||
},
|
||||
any(),
|
||||
)
|
||||
}
|
||||
|
||||
model.onDestroy()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN external deeplink WHEN onMarketingBannerDeeplink THEN not handled and no navigation`() = runTest {
|
||||
// Arrange
|
||||
every { appRouter.push(any(), any()) } just Runs
|
||||
val model = createModel(testScope = this)
|
||||
advanceUntilIdle()
|
||||
|
||||
// Act
|
||||
val handled = model.onMarketingBannerDeeplink("https://tangem.com/promo")
|
||||
|
||||
// Assert
|
||||
assertThat(handled).isFalse()
|
||||
verify(exactly = 0) { appRouter.push(any(), any()) }
|
||||
|
||||
model.onDestroy()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue