Updated on 2026-08-14

This commit is contained in:
Tangem 2025-03-19 13:24:37 +05:00
parent 06d435a58f
commit d4fe3896f3
10 changed files with 102 additions and 41 deletions

View file

@ -2,6 +2,7 @@ package com.tangem.tap.di.domain
import com.tangem.domain.staking.*
import com.tangem.domain.staking.repositories.*
import com.tangem.domain.walletmanager.WalletManagersFacade
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
@ -209,4 +210,12 @@ internal object StakingDomainModule {
fun provideGetStakingIntegrationIdUseCase(stakingRepository: StakingRepository): GetStakingIntegrationIdUseCase {
return GetStakingIntegrationIdUseCase(stakingRepository)
}
@Provides
@Singleton
fun provideCheckAccountInitializedUseCase(
walletManagersFacade: WalletManagersFacade,
): CheckAccountInitializedUseCase {
return CheckAccountInitializedUseCase(walletManagersFacade)
}
}

View file

@ -738,7 +738,7 @@ internal class DefaultStakingRepository(
private companion object {
const val YIELDS_STORE_KEY = "yields"
const val TON_INTEGRATION_ID = "ton-ton-tonwhales-pools-staking"
const val TON_INTEGRATION_ID = "ton-ton-chorus-one-pools-staking"
const val SOLANA_INTEGRATION_ID = "solana-sol-native-multivalidator-staking"
const val COSMOS_INTEGRATION_ID = "cosmos-atom-native-staking"
const val ETHEREUM_POLYGON_INTEGRATION_ID = "ethereum-matic-native-staking"

View file

@ -682,6 +682,12 @@ class DefaultWalletManagersFacade(
return walletManager.getAsset(collectionIdentifier, assetIdentifier)
}
override suspend fun isAccountInitialized(userWalletId: UserWalletId, network: Network): Boolean {
val walletManager = getOrCreateWalletManager(userWalletId = userWalletId, network = network)
val initializableAccountWalletManger = walletManager as? InitializableAccount ?: return false
return initializableAccountWalletManger.accountInitializationState == InitializableAccount.State.INITIALIZED
}
private fun updateWalletManagerTokensIfNeeded(walletManager: WalletManager, tokens: Set<CryptoCurrency.Token>) {
if (tokens.isEmpty()) return

View file

@ -265,4 +265,10 @@ interface WalletManagersFacade {
collectionIdentifier: NFTCollection.Identifier,
assetIdentifier: NFTAsset.Identifier,
): NFTAsset?
/**
* If wallet manager implements [InitializableAccount] then returns [InitializableAccount.isAccountInitialized]
* value. Otherwise always return true
*/
suspend fun isAccountInitialized(userWalletId: UserWalletId, network: Network): Boolean
}

View file

@ -18,6 +18,7 @@ dependencies {
implementation(deps.kotlin.serialization)
implementation(deps.jodatime)
implementation(projects.domain.legacy)
implementation(projects.domain.tokens.models)
implementation(projects.domain.wallets.models)

View file

@ -0,0 +1,13 @@
package com.tangem.domain.staking
import arrow.core.Either
import com.tangem.domain.tokens.model.Network
import com.tangem.domain.walletmanager.WalletManagersFacade
import com.tangem.domain.wallets.models.UserWalletId
class CheckAccountInitializedUseCase(private val walletManagersFacade: WalletManagersFacade) {
suspend operator fun invoke(userWalletId: UserWalletId, network: Network): Either<Throwable, Boolean> {
return Either.catch { walletManagersFacade.isAccountInitialized(userWalletId, network) }
}
}

View file

@ -114,6 +114,7 @@ internal class StakingModel @Inject constructor(
private val sendFeedbackEmailUseCase: SendFeedbackEmailUseCase,
private val getActionsUseCase: GetActionsUseCase,
private val getYieldUseCase: GetYieldUseCase,
private val checkAccountInitializedUseCase: CheckAccountInitializedUseCase,
private val paramsInterceptorHolder: ParamsInterceptorHolder,
private val shareManager: ShareManager,
@DelayedWork private val coroutineScope: CoroutineScope,
@ -229,49 +230,62 @@ internal class StakingModel @Inject constructor(
}
override fun onNextClick(balanceState: BalanceState?) {
val isInitialInfoStep = value.currentStep == StakingStep.InitialInfo
val noBalanceState = balanceState == null
val noYieldBalanceData = cryptoCurrencyStatus.value.yieldBalance !is YieldBalance.Data
modelScope.launch {
val isInitialInfoStep = value.currentStep == StakingStep.InitialInfo
val noBalanceState = balanceState == null
val noYieldBalanceData = cryptoCurrencyStatus.value.yieldBalance !is YieldBalance.Data
val isAccountInitialized = checkAccountInitializedUseCase.invoke(
userWalletId = userWalletId,
network = cryptoCurrencyStatus.currency.network,
).getOrElse {
Timber.e(it)
false
}
when {
isInitialInfoStep && noBalanceState && yield.allValidatorsFull && noYieldBalanceData -> {
stakingEventFactory.createStakingValidatorsUnavailableAlert()
return
}
isInitialInfoStep && noBalanceState -> {
val list = buildList {
SetConfirmationStateInitTransformer(
isEnter = true,
isExplicitExit = false,
balanceState = null,
cryptoCurrencyStatus = cryptoCurrencyStatus,
stakingApproval = stakingApproval,
stakingAllowance = stakingAllowance,
yieldArgs = yield.args,
).let(::add)
if (yield.args.enter.isPartialAmountDisabled) {
ValidatorSelectChangeTransformer(
selectedValidator = yield.preferredValidators.firstOrNull(),
yield = yield,
).let(::add)
SetAmountDataTransformer(
clickIntents = this@StakingModel,
cryptoCurrencyStatusProvider = Provider { cryptoCurrencyStatus },
userWalletProvider = Provider { userWallet },
appCurrencyProvider = Provider { appCurrency },
).let(::add)
AmountMaxValueStateTransformer(
cryptoCurrencyStatus = cryptoCurrencyStatus,
minimumTransactionAmount = minimumTransactionAmount,
actionType = uiState.value.actionType,
yield = yield,
).let(::add)
}
when {
isInitialInfoStep && noBalanceState && yield.allValidatorsFull && noYieldBalanceData -> {
stakingEventFactory.createStakingValidatorsUnavailableAlert()
return@launch
}
isInitialInfoStep && noBalanceState && !isAccountInitialized -> {
stakingEventFactory.createInitializeAccountAlert()
return@launch
}
isInitialInfoStep && noBalanceState -> {
val list = buildList {
SetConfirmationStateInitTransformer(
isEnter = true,
isExplicitExit = false,
balanceState = null,
cryptoCurrencyStatus = cryptoCurrencyStatus,
stakingApproval = stakingApproval,
stakingAllowance = stakingAllowance,
yieldArgs = yield.args,
).let(::add)
if (yield.args.enter.isPartialAmountDisabled) {
ValidatorSelectChangeTransformer(
selectedValidator = yield.preferredValidators.firstOrNull(),
yield = yield,
).let(::add)
SetAmountDataTransformer(
clickIntents = this@StakingModel,
cryptoCurrencyStatusProvider = Provider { cryptoCurrencyStatus },
userWalletProvider = Provider { userWallet },
appCurrencyProvider = Provider { appCurrency },
).let(::add)
AmountMaxValueStateTransformer(
cryptoCurrencyStatus = cryptoCurrencyStatus,
minimumTransactionAmount = minimumTransactionAmount,
actionType = uiState.value.actionType,
yield = yield,
).let(::add)
}
}
stateController.updateAll(*list.toTypedArray())
}
stateController.updateAll(*list.toTypedArray())
}
stakingStateRouter.onNextClick()
}
stakingStateRouter.onNextClick()
}
override fun getFee() {

View file

@ -61,4 +61,11 @@ internal sealed class StakingAlertUM : AlertUM {
)
override val confirmButtonText: TextReference = resourceReference(id = R.string.common_ok)
}
data object InitializeAccount : StakingAlertUM() {
override val onConfirmClick: (() -> Unit)? = null
override val title: TextReference = resourceReference(id = R.string.staking_error_no_validators_title)
override val message: TextReference = resourceReference(id = R.string.staking_notification_ton_activate_account)
override val confirmButtonText: TextReference = resourceReference(id = R.string.common_ok)
}
}

View file

@ -46,4 +46,9 @@ internal class StakingEventFactory(
val alert = StakingEvent.ShowAlert(alert = StakingAlertUM.ValidatorsUnavailable)
stateController.updateEvent(alert)
}
fun createInitializeAccountAlert() {
val alert = StakingEvent.ShowAlert(alert = StakingAlertUM.InitializeAccount)
stateController.updateEvent(alert)
}
}

View file

@ -1,5 +1,5 @@
[versions]
tangemBlockchainSdk = "develop-984"
tangemBlockchainSdk = "develop-986"
#tangemBlockchainSdk = "0.0.1" # Keep it! - used for local builds
tangemCardSdk = "develop-443"
#tangemCardSdk = "0.0.1" # Keep it! - used for local builds ^